polartoolkit.mask_from_shapefile

polartoolkit.mask_from_shapefile#

mask_from_shapefile(shapefile, hemisphere=None, epsg=None, invert=True, grid=None, xr_grid=None, grid_file=None, region=None, spacing=None, masked=False, pixel_register=True, input_coord_names=('easting', 'northing'))[source]#

Create a mask or a masked grid from area inside or outside of a closed shapefile.

Parameters:
  • shapefile (str | GeoDataFrame) – either path to .shp filename, must by in same directory as accompanying files : .shx, .prj, .dbf, should be a closed polygon file, or shapefile which as already been loaded into a geodataframe.

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

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

  • invert (bool) – choose whether to mask data outside the shape (False) or inside the shape (True), by default True (masks inside of shape)

  • grid (DataArray | str | None) – _xarray.DataArray or path to a .nc file; to use to define region, or to mask, by default None

  • xr_grid (DataArray | None) – deprecated, use grid instead, by default None

  • grid_file (str | None) – deprecated, use grid instead, by default None

  • region (str | tuple[float, float, float, float] | None) – bounding region in format [xmin, xmax, ymin, ymax] in meters to create a dummy grid if none are supplied, by default None

  • spacing (float | None) – grid spacing in meters to create a dummy grid if none are supplied, by default None

  • masked (bool) – choose whether to return the masked grid (True) or the mask itself (False), by default False

  • pixel_register (bool) – choose whether the grid is pixel registered (True) or grid registered (False), by default True

  • input_coord_names (tuple[str, str]) – set names for input coordinate columns, by default (β€œeasting”, β€œnorthing”)

Returns:

Returns either a masked grid, or the mask grid itself.

Return type:

DataArray