def _(a, value): a = asanyarray(a) value = asanyarray(value) ainds = tuple(range(a.ndim))[::-1] vinds = tuple(range(value.ndim))[::-1] oinds = max(ainds, vinds, key=len) return blockwise(f, oinds, a, ainds, value, vinds, dtype=a.dtype)
def masked_array(data, mask=np.ma.nomask, fill_value=None, **kwargs): data = asanyarray(data) inds = tuple(range(data.ndim)) arginds = [inds, data, inds] if getattr(fill_value, "shape", ()): raise ValueError("non-scalar fill_value not supported") kwargs["fill_value"] = fill_value if mask is not np.ma.nomask: mask = asanyarray(mask) if mask.size == 1: mask = mask.reshape((1, ) * data.ndim) elif data.shape != mask.shape: raise np.ma.MaskError("Mask and data not compatible: data shape " "is %s, and mask shape is " "%s." % (repr(data.shape), repr(mask.shape))) arginds.extend([mask, inds]) if "dtype" in kwargs: kwargs["masked_dtype"] = kwargs["dtype"] else: kwargs["dtype"] = data.dtype return blockwise(_masked_array, *arginds, **kwargs)
def masked_where(condition, a): cshape = getattr(condition, "shape", ()) if cshape and cshape != a.shape: raise IndexError("Inconsistant shape between the condition and the " "input (got %s and %s)" % (cshape, a.shape)) condition = asanyarray(condition) a = asanyarray(a) ainds = tuple(range(a.ndim)) cinds = tuple(range(condition.ndim)) return blockwise(np.ma.masked_where, ainds, condition, cinds, a, ainds, dtype=a.dtype)
def set_fill_value(a, fill_value): a = asanyarray(a) if getattr(fill_value, "shape", ()): raise ValueError("da.ma.set_fill_value doesn't support array `value`s") fill_value = np.ma.core._check_fill_value(fill_value, a.dtype) res = a.map_blocks(_set_fill_value, fill_value) a.dask = res.dask a._name = res.name
def masked_values(x, value, rtol=1e-05, atol=1e-08, shrink=True): x = asanyarray(x) if getattr(value, "shape", ()): raise ValueError("da.ma.masked_values doesn't support array `value`s") return map_blocks(np.ma.masked_values, x, value, rtol=rtol, atol=atol, shrink=shrink)
def masked_equal(a, value): a = asanyarray(a) if getattr(value, "shape", ()): raise ValueError("da.ma.masked_equal doesn't support array `value`s") inds = tuple(range(a.ndim)) return blockwise(np.ma.masked_equal, inds, a, inds, value, (), dtype=a.dtype)
def masked_outside(x, v1, v2): x = asanyarray(x) return x.map_blocks(np.ma.masked_outside, v1, v2)
def masked_invalid(a): return asanyarray(a).map_blocks(np.ma.masked_invalid)
def filled(a, fill_value=None): a = asanyarray(a) return a.map_blocks(np.ma.filled, fill_value=fill_value)
def getmaskarray(a): a = asanyarray(a) return a.map_blocks(np.ma.getmaskarray)
def getdata(a): a = asanyarray(a) return a.map_blocks(np.ma.getdata)