polartoolkit.mask_from_polygon

polartoolkit.mask_from_polygon#

mask_from_polygon(polygon, hemisphere=None, epsg=None, invert=False, drop_nans=False, grid=None, region=None, spacing=None, **kwargs)[source]#

convert the output of ptk.draw_region to a mask or use it to mask a grid

Parameters:
  • polygon (list) – list of polygon vertices

  • hemisphere (str, optional,) – set projection based on β€œnorth” or β€œsouth” hemispheres, by default None

  • epsg (str | None, optional) – set projection from EPSG code string (β€œ3031”), by default None

  • invert (bool, optional) – reverse the sense of masking, by default False

  • drop_nans (bool, optional) – drop nans after masking, by default False

  • grid (Union[str, xarray.DataArray], optional) – grid to mask, by default None

  • region (tuple[float, float, float, float], optional) – region to create a grid if none is supplied, in format [xmin, xmax, ymin, ymax], by default None

  • spacing (int, optional) – spacing to create a grid if none is supplied, by default None

  • kwargs (Any)

Returns:

masked grid or mask grid with 1’s inside the mask.

Return type:

xarray.DataArray