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 Noneepsg (
str|None) β set projection from EPSG code string (β3031β), by default Noneinvert (
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 Nonexr_grid (
DataArray|None) β deprecated, use grid instead, by default Nonegrid_file (
str|None) β deprecated, use grid instead, by default Noneregion (
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 Nonespacing (
float|None) β grid spacing in meters to create a dummy grid if none are supplied, by default Nonemasked (
bool) β choose whether to return the masked grid (True) or the mask itself (False), by default Falsepixel_register (
bool) β choose whether the grid is pixel registered (True) or grid registered (False), by default Trueinput_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: