revrt.costs.masks.Masks#

class Masks(shape, crs, transform, masks_dir='.')[source]#

Bases: object

Create, load, and store mask data layers

Parameters:
  • shape (tuple) – Shape of mask rasters (height, width).

  • crs (str or dict) – 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

LANDFALL_MASK_FNAME

One pixel width line at shore

LAND_MASK_FNAME

Raw mask - landfall mask

OFFSHORE_MASK_FNAME

Offshore mask filename

RAW_LAND_MASK_FNAME

Rasterized land vector

dry_mask

Dry cells bool mask; no landfall cells

dry_plus_mask

Dry cells bool mask; with landfall

landfall_mask

Landfalls cells bool mask; 1 cell wide

wet_mask

Wet cells bool mask; no landfall cells

wet_plus_mask

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:

array_like

property wet_mask#

Wet cells bool mask; no landfall cells

Type:

array_like

property dry_mask#

Dry cells bool mask; no landfall cells

Type:

array_like

property dry_plus_mask#

Dry cells bool mask; with landfall

Type:

array_like

property wet_plus_mask#

Wet cells mask, with landfall cells

Type:

array_like

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 file

  • save_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 (bool or 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 LayeredFile on 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.