poly_mask

poly_mask(data, lats, lons, missing=False)

New in Metview version 5.16.0.

If data is a Fieldset for each field poly_mask() creates a field containing 0 or 1 values according to whether a grid point is inside (1) or outside (0) the specified polygon(s). If data is a Geopoints a similar operation is performed for all the points in it.

Parameters
  • data (Fieldset or Geopoints) – input data

  • lats (ndarray or list of ndarrays) – the latitude of the polygon points. Use a list of ndarrays to define multiple polygons.

  • lons (ndarray or list of ndarrays) – the longitude of the polygon points. Use a list of ndarrays to define multiple polygons.

  • missing (bool) – when it is True it will change the behaviour so that points outside the polygon(s) will become missing values and point inside the polygon(s) retain their original value.

Return type

Fieldset or Geopoints

The polygons are automatically closed if the first and last coordinates are not the same. If multiple polygons are specified the output mask is generated by forming their union.

Note

See also mask(), rmask(), bitmap() and nobitmap().

Notebooks using metview.poly_mask