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 or geopandas.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, 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) β choose whether to mask data outside the shape (False) or inside the shape (True), by default True (masks inside of shape)
grid (xarray.DataArray or str, optional) β _xarray.DataArray or path to a .nc file; to use to define region, or to mask, by default None
xr_grid (xarray.DataArray, optional) β deprecated, use grid instead, by default None
grid_file (str, optional) β deprecated, use grid instead, by default None
region (str or tuple[float, float, float, float], optional) β bounding region in format [xmin, xmax, ymin, ymax] in meters to create a dummy grid if none are supplied, by default None
spacing (str or int, optional) β grid spacing in meters to create a dummy grid if none are supplied, by default None
masked (bool, optional) β choose whether to return the masked grid (True) or the mask itself (False), by default False
pixel_register (bool, optional) β choose whether the grid is pixel registered (True) or grid registered (False), by default True
input_coord_names (tuple[str, str], optional) β set names for input coordinate columns, by default (βeastingβ, βnorthingβ)
- Returns:
Returns either a masked grid, or the mask grid itself.
- Return type: