def apply(self, mode='reflect', weights=None, compute=True):
"""
Convolve the current window with the data
"""
# Check if the data has more dimensions than the window and add
# extra-dimensions to the window if it is the case
mask = self.obj.notnull()
if weights is None:
weights = im.convolve(mask.astype(float), self.coefficients, mode=mode)
filled_data = self.obj.fillna(0.).data
def convolve(x):
xf = im.convolve(x, self.coefficients, mode=mode)
return xf
data = filled_data.map_overlap(convolve, depth=self._depth,
boundary=mode, trim=True)
if compute:
with ProgressBar():
out = data.compute()
else:
out = data
res = xr.DataArray(out, dims=self.obj.dims, coords=self.coords, name=self.obj.name) / weights
return res.where(mask == 1)
评论列表
文章目录