def maskout(data, mask, x=None, y=None): """ Maskout data by polygons - NaN values of elements outside polygons. :param data: (*array_like*) Array data for maskout. :param mask: (*list*) Polygon list as maskout borders. :param x: (*array_like*) X coordinate array. :param y: (*array_like*) Y coordinate array. :returns: (*array_like*) Maskouted data array. """ if mask is None: return data elif isinstance(mask, (MIArray, DimArray)): r = ArrayMath.maskout(data.asarray(), mask.asarray()) if isinstance(data, DimArray): return DimArray(r, data.dims, data.fill_value, data.proj) else: return MIArray(r) if x is None or y is None: if isinstance(data, DimArray): x = data.dimvalue(data.ndim - 1) y = data.dimvalue(data.ndim - 2) else: return None if not isinstance(mask, (list, ArrayList)): mask = [mask] r = ArrayMath.maskout(data.array, x.array, y.array, mask) if isinstance(data, DimArray): return DimArray(r, data.dims, data.fill_value, data.proj) else: return MIArray(r)
def maskout(self, mask): if isinstance(mask, (MIArray, DimArray)): r = ArrayMath.maskout(self.asarray(), mask.asarray()) return DimArray(MIArray(r), self.dims, self.fill_value, self.proj) else: x = self.dims[1].getDimValue() y = self.dims[0].getDimValue() if not isinstance(mask, (list, ArrayList)): mask = [mask] r = ArrayMath.maskout(self.asarray(), x, y, mask) r = DimArray(MIArray(r), self.dims, self.fill_value, self.proj) return r
def maskout(self, mask): ''' Maskout data by polygons - the elements outside polygons will be set as NaN. :param mask: (*list*) Polygon list as mask borders. :returns: (*DimArray*) Maskouted data. ''' if isinstance(mask, MIArray): r = ArrayMath.maskout(self.asarray(), mask.asarray()) return DimArray(MIArray(r), self.dims, self.fill_value, self.proj) else: x = self.dims[1].getDimValue() y = self.dims[0].getDimValue() if not isinstance(mask, (list, ArrayList)): mask = [mask] r = ArrayMath.maskout(self.asarray(), x, y, mask) r = DimArray(MIArray(r), self.dims, self.fill_value, self.proj) return r
def maskout(self, x, y, polygon, fill_value=Double.NaN): if isinstance(x, MIArray): xl = x.aslist() else: xl = x if isinstance(y, MIArray): yl = y.aslist() else: yl = y if isinstance(polygon, MILayer): polygon = polygon.layer return MIArray(ArrayMath.maskout(self.array, xl, yl, polygon, fill_value))
def maskout(self, x, y, polygon, fill_value=Double.NaN): if isinstance(x, MIArray): xl = x.aslist() else: xl = x if isinstance(y, MIArray): yl = y.aslist() else: yl = y if isinstance(polygon, MILayer): polygon = polygon.layer return MIArray( ArrayMath.maskout(self.array, xl, yl, polygon, fill_value))