def detrend_wrap(detrend_func):
"""
Wrapper function for `xrft.detrendn`.
"""
def func(a, axes=None):
if a.ndim > 4 or len(axes) > 3:
raise ValueError("Data has too many dimensions "
"and/or too many axes to detrend over.")
if axes is None:
axes = tuple(range(a.ndim))
else:
if len(set(axes)) < len(axes):
raise ValueError("Duplicate axes are not allowed.")
for each_axis in axes:
if len(a.chunks[each_axis]) != 1:
raise ValueError('The axis along the detrending is upon '
'cannot be chunked.')
if len(axes) == 1:
return dsar.map_blocks(sps.detrend, a, axis=axes[0],
chunks=a.chunks, dtype=a.dtype
)
else:
for each_axis in range(a.ndim):
if each_axis not in axes:
if len(a.chunks[each_axis]) != a.shape[each_axis]:
raise ValueError("The axes other than ones to detrend "
"over should have a chunk length of 1.")
return dsar.map_blocks(detrend_func, a, axes,
chunks=a.chunks, dtype=a.dtype
)
return func
评论列表
文章目录