mask
- mask(fs, area, missing=False)
For each field in
fs
creates a field containing 0 or 1 values according to whether a grid point is inside (1) or outside (0) thearea
. An additional named argument,missing
set toTrue
will change the behaviour so that points outside the area will become missing values and points inside the area retain their original value.- Parameters
fs (
Fieldset
) – input fieldsetarea (list) – area as [N, W, S, E]
missing (bool) – set to
True
to change the behaviour as described above. New in Metview version 5.13.0.
- Return type
- Example
Non-rectangular masks, and even convex masks can be created by using the operators and, or and not. To create the following mask:
first decompose it into basic rectangles:
then create a mask for each of them and use and and or to compose the desired mask like this:
import metview as mv # Define basic rectangles a = [50,-120,10,-30] b = [20,20,50,10] c = [50,50,40,100] d = [35,-60,-40,100] # The field defining the grids f = mv.read(path_to_your_grib_file) # First compute the union of a,c and d m = mv.mask(f,a) or mv.mask(f,d) or mv.mask(f,c) # Then remove b m = m and not mv.mask(f,b)
Note
See also
rmask()
,poly_mask()
,bitmap()
andnobitmap()
.
- mask(gpt, area)
Creates a
Geopoints
containing values of 0 or 1 according to whether they are inside (1) or outside (0) thearea
.- Parameters
gpt (
Geopoints
) – input geopointsarea (list) – area as [N, W, S, E]
- Return type
Points with missing latitudes or longitudes are considered to be outside any area. See the documentation for the fieldset version of this function to see how to compose more complex regions than a simple rectangular area.