digger.utils.create_mask

Module Contents

Functions

create_mask

Creates boolean mask.

API

digger.utils.create_mask.create_mask(in_rast, out_path=None, poly_path=None, buffer_len=np.nan, consider_z=False, above_z=True, z_threshold=0, delete_holes=False, nodata=np.nan)

Creates boolean mask.

This function creates a boolean mask from a raster (e.g., DEM) or from a polygon shapefile.

There are four main ways to create a mask:

  1. Based on valid data: Where raster data are valid data is True, otherwise False. Use default parameters.

  2. Based on DEM value: Where raster data above a threshold value is True, otherwise False. Parameters: consider_z = True, above_z = True, z_threshold = int (default is 0)

  3. Based on DEM value: Where raster data below or equal to a certain threshold value is True, otherwise False. Parameters: consider_z = True, above_z = False, z_threshold = int (default is 0)

  4. Based on a provided polygon: Where the polygon exists is True, otherwise False. Parameters: poly_path must not be empty

Notes:

  • in_rast is always required to determine the resolution, extent, and projection of the mask

  • if poly_path has a value, the mask will always be made from the polygons

  • each mask can also be buffered (buffer_len = int) and/or have the interior holes deleted (delete_holes = True).

Inputs:
in_raststr (required)

If string, path to raster (rioxarray-readable). Otherwise, needs to be rioxarray dataset

out_pathstr (required)

Path to save output raster mask.

poly_pathstr (optional)

Path to one or more polygons to create mask of (fiona-readable). Output is written at the res, extent, and crs of in_rast file.

buffer_len: int (optional)

Length to buffer area by. Default = np.nan.

consider_zbool (optional)

Flag to indicate whether you want to mask based on elevation. Default = False.

above_zbool (optional)

Flag when True, data above a threshold is True, otherwise False. Default = True.

z_thresholdint (optional)

Value where to create mask border Default = 0

delete_holesbool (optional)

Flag to indicate whether to delete holes within the polygons. Default = False.

nodataint (optional)

No data value of raster if not specified in its metadata Default = np.nan

Outputs:
data_maskbool array

The size and shape of data_mask will be the same as in_rast.