def notmasked_edges(a, axis=None): """Finds the indices of the first and last not masked values along the given axis in a masked array. If all values are masked, returns None. Otherwise, returns a list of 2 tuples, corresponding to the indices of the first and last unmasked values respectively. """ a = asarray(a) if axis is None or a.ndim == 1: return flatnotmasked_edges(a) m = getmask(a) idx = array(numpy.indices(a.shape), mask=nxasarray([m]*a.ndim)) return [tuple([idx[i].min(axis).compressed() for i in range(a.ndim)]), tuple([idx[i].max(axis).compressed() for i in range(a.ndim)]),]
def __call__(self, *args, **params): func = getattr(numpy, self._function) if len(args)==1: x = args[0] if isinstance(x,ndarray): _d = func(nxasarray(x), **params) _m = func(getmaskarray(x), **params) return masked_array(_d, mask=_m) elif isinstance(x, tuple) or isinstance(x, list): _d = func(tuple([nxasarray(a) for a in x]), **params) _m = func(tuple([getmaskarray(a) for a in x]), **params) return masked_array(_d, mask=_m) else: arrays = [] args = list(args) while len(args)>0 and issequence(args[0]): arrays.append(args.pop(0)) res = [] for x in arrays: _d = func(nxasarray(x), *args, **params) _m = func(getmaskarray(x), *args, **params) res.append(masked_array(_d, mask=_m)) return res