CreateSubdomainMasks#
- class mhm_tools.pre.subdomain_masks.CreateSubdomainMasks(output_dir, output_file_name, basin_id_file, basin_clusters, land_mask, land_mask_variable='land_mask')[source]#
Bases:
objectA class for creating subdomain masks based on input data.
- Parameters:
output_dir (str) – The directory path where the output files will be saved.
output_file_name (str) – The name of the output file.
basin_id_file (str) – The file name of the reference basin IDs.
basin_clusters (str) – The file name of the basin cluster IDs.
land_mask (str) – The file name of the land mask and grid of target resolution.
- Raises:
ValueError – If the input path is not a directory.
Methods
Create subdomain masks based on the input data.
get_mask_from_polygon(arr, vertices)Create a boolean mask for points inside a polygon.
read_var(fname, var_name)Read a variable from a netcdf file.
use_land_mask(lat, lon)Reencode and mask the input files.
- static get_mask_from_polygon(arr, vertices)[source]#
Create a boolean mask for points inside a polygon.
The input arr is a 2D array with lat and lon coordinates; the mask is True for cells whose (lon, lat) fall inside the polygon defined by vertices.
- Parameters:
arr (xarray.DataArray) – 2D data array with coordinates lat and lon.
vertices (sequence[tuple[float, float]]) – Polygon vertices as (lon, lat) pairs.
- Returns:
Boolean mask with the same shape as arr, True inside the polygon.
- Return type: