def contains(self, lon, lat): """ Return a boolean array of same shape as lon and lat with points contained in the patch """ lon = np.asarray(lon) lat = np.asarray(lat) mlon, mlat = self.coords assert lon.shape == lat.shape, "lon, lat must have the same shape" #lon = rectify_longitude(lon, lon0=self.lon0, sort=False) # first fix lon0 to match new data lon0 = get_lon0(*lon.flatten()) if lon0 != self.lon0: self = copy(self) mlon, self.mask = rectify_longitude_data(mlon, self.mask, lon0) if not (np.all(lon == mlon) and np.all(lat == mlat)): self = copy(self) # interpolate the mask onto the input grid maskf = interp(np.asarray(self.mask, dtype=float), mlon, mlat, lon, lat) mask = maskf >= 0.5 else: mask = self.mask return mask
def interpolate(self, lon, lat): """ interpolate the mask lon, lat: 1-D arrays to be passed to meshgrid """ assert lon.ndim == 1 and lat.ndim == 1, "must be 1-D coordinates compatible with meshgrid" # first fix lon0 to match new data lon0 = get_lon0(*lon.flatten()) mlon, mlat = self.coords mlon, mask = rectify_longitude_data(mlon, self.mask, lon0) # make input coords is 2-D #if lon.ndim == 1 and meshgrid: lon2, lat2 = np.meshgrid(lon, lat) maskf = interp(np.asarray(self.mask, dtype=float), mlon, mlat, lon2, lat2) mask = maskf >= 0.5 return Mask(lon, lat, mask, lon0)
def shift_longitude(lon, values, lon0): """ Shift longitude axis, making it start at lon0 """ lon, values = grid.rectify_longitude_data(lon, values, lon0) return GeoArray(values, [('lon', lon)])
def shift_longitude(lon, values, lon0): """ Shift longitude axis, making it start at lon0 """ lon, values = grid.rectify_longitude_data(lon, values, lon0) return GeoArray(values, [('lon',lon)])