当尝试将熵卷积滤波器应用于从a读取的数字的蒙版二维字段时 netCDF文件遇到两个奇怪的行为
{ "key": "ctrl+shift+]", "command": "editor.unfold", "when": "editorTextFocus" }
使用numpy.where将屏蔽的数组转换为常规的Numpy数组
phi2 = np.where(phi,phi,phi)
修复了复制错误,但随后的输出是
sstC = ap_convolve(sstReg,b2dk)
具有奇怪的值。
答案 0 :(得分:0)
解决这些问题的一种方法是使用
转换掩码数组numpy.ma.filled()
与
TypeError Traceback (most recent call last)
<ipython-input-16-6aeef1d2166f> in <module>()
3 from astropy.convolution import Box2DKernel
4 b2dk=Box2DKernel(9)
----> 5 sstC=ap_convolve(sstReg,b2dk)
/nfs/.../decorators.py
in convolve(array, kernel, boundary, fill_value, nan_treatment,
normalize_kernel, mask, preserve_nan, normalization_zero_tol)
825 name = func.__name__
826
--> 827 func = make_function_with_signature(func, name=name, **wrapped_args)
828 func = functools.update_wrapper(func, wrapped, assigned=assigned,
829 updated=updated)
/nfs/.../decorators.py
in wrapper(data, *args, **kwargs)
243 AstropyUserWarning)
244
--> 245 result = func(data, *args, **kwargs)
246
247 if unpack and repack:
/nfs/.../convolve.py
in convolve(array, kernel, boundary, fill_value, nan_treatment,
normalize_kernel, mask, preserve_nan, normalization_zero_tol)
167 # because none of what follows modifies array_internal.
168 array_dtype = array.dtype
--> 169 array_internal = array.astype(float, copy=False)
170 else:
171 raise TypeError("array should be a list or a Numpy array")
TypeError: astype() got an unexpected keyword argument 'copy'
作为掩码值,例如
float('nan')
。这产生
未屏蔽的数组phi2=numpy.ma.filled(phi,float('nan'))
。这样可以防止发生复制错误。使用
卷积中的nan的值会使卷积运算适当调整。没有
掩码值将与实际数据进行卷积-通常这不是您想要的!