revrt.costs.masks.Masks#
- class Masks(shape, crs, transform, masks_dir='.')[source]#
Bases:
objectCreate, load, and store mask data layers
- Parameters:
shape (
tuple) – Shape of mask rasters (height, width).crs (
strordict) – Coordinate reference system of mask rasters.transform (
affine.Affine) – Affine transform of mask rasters.masks_dir (path-like, optional) – Directory for storing/finding mask GeoTIFFs. By default,
".".
Methods
create(land_mask_shp_fp[, save_tiff, ...])Create mask layers from a polygon land vector file
load(layer_fp[, validate])Load the mask layers from GeoTIFFs
Attributes
One pixel width line at shore
Raw mask - landfall mask
Offshore mask filename
Rasterized land vector
Dry cells bool mask; no landfall cells
Dry cells bool mask; with landfall
Landfalls cells bool mask; 1 cell wide
Wet cells bool mask; no landfall cells
Wet cells mask, with landfall cells
- LANDFALL_MASK_FNAME = 'landfall_mask.tif'#
One pixel width line at shore
- RAW_LAND_MASK_FNAME = 'raw_land_mask.tif'#
Rasterized land vector
- LAND_MASK_FNAME = 'land_mask.tif'#
Raw mask - landfall mask
- OFFSHORE_MASK_FNAME = 'offshore_mask.tif'#
Offshore mask filename
- property landfall_mask#
Landfalls cells bool mask; 1 cell wide
- Type:
- property wet_mask#
Wet cells bool mask; no landfall cells
- Type:
- property dry_mask#
Dry cells bool mask; no landfall cells
- Type:
- property dry_plus_mask#
Dry cells bool mask; with landfall
- Type:
- property wet_plus_mask#
Wet cells mask, with landfall cells
- Type:
- create(land_mask_shp_fp, save_tiff=True, reproject_vector=True, lock=None)[source]#
Create mask layers from a polygon land vector file
- Parameters:
land_mask_shp_fp (
str) – Full path to land polygon GPKG or shp filesave_tiff (
bool, optional) – Save mask as tiff if true. By default,True.reproject_vector (
bool, optional) – Reproject CRS of vector to match template raster if True. By default,True.lock (
boolor dask.distributed.Lock, optional) – Lock to use to write data using dask. If not supplied, a single process is used for writing data to the mask GeoTIFFs. By default,None.
- load(layer_fp, validate=False)[source]#
Load the mask layers from GeoTIFFs
- Parameters:
layer_fp (path-like) – Path to
LayeredFileon disk for which masks were created. The masks will be of the same shape/crs/transform as this file.validate (
bool, optional) – Whether to validate that loaded masks have appropriate values. This breaks the lazy (Dask) loading of the masks, so it is not recommended to use this if you know your masks are valid. By default,False.
Notes
This does not need to be called if
Masks.create()was run previously. Mask files must be in the current directory.