Description
Working with scattering for weather forecasts image analysis, I was wondering what influence the type of padding did have on results.
The reflection padding implemented by default seems to produce high gradients on the boundaries. After a few subsamplings, the large values on the boundary gain a certain weight in the spatial average, that could lead to estimation biases.
This is visible on orientation averaged second-order coefficients.
Question 1 : have the topic already been discussed ?
Question 2 : what about providing numpy padding modes as an option to scattering ?
Now for a bit of demo, if it adds to the discussion.
After a fork and 1 or 2 adds on numpy frontend/backend, one comes to the following code :
from kymatio import Scattering2D
import numpy as np
import matplotlib.pyplot as plt
wind_norm=np.load('wind_norm.npy')
J,L=4,8
# defining indexing of order 2 coefficients
order2_ind=[[[[L**2*(j1*(J-1)-j1*(j1-1)//2)\
+L*(j2-j1-1)\
+L*(J-j1-1)*l1\
+l2 \
for l2 in range(L)]\
for l1 in range(L)]\
for j2 in range(j1+1,J)] \
for j1 in range(J-1)]
def order2(data, pad_type):
"""
compute orientation averaged l2 coefficients
"""
scattering=Scattering2D(4,data.shape,8,
max_order=2,pre_pad=False,
frontend='numpy',backend='numpy',
out_type='array', pad_type=pad_type)
################### order 2 coefficients
results_order2=scattering(data)[1+4*8:]
################### averaging over l2 orientations
S2_j1j2l1=[]
for j1 in range(J-1):
for j2 in range(J-j1-1):
for l1 in range(L):
S2_j1j2l1.append(
np.mean(results_order2[order2_ind[j1][j2][l1],:,:],axis=0)
)
S2_j1j2l1=np.array(S2_j1j2l1)
return S2_j1j2l1
S2_symm=order2(wind_norm, 'symmetric')
S2_reflect=order2(wind_norm, 'reflect')
ratio=100*(S2_symm/S2_reflect -1.0)
print(ratio.min(), ratio.max(), ratio.mean())
plt.imshow(ratio[-1][::-1,:])
plt.colorbar()
plt.show()
The data is downloadable in the zip attached.
wind_norm.zip
The result of this yields:
-19.169381905671035 13.210792343005728 -0.07116768707598231
Here both transforms coincide at the center, but not on the border. Overestimation by reflection padding is manifest here.