HRU Discretization
HRU Discretization
- class ai4water.preprocessing.spatial_processing.MakeHRUs(hru_definition: str, index: dict, soil_shape: Optional[dict] = None, slope_shape: Optional[dict] = None, subbasins_shape: Optional[dict] = None, save: bool = False, show: bool = True, verbosity: int = 1)[source]
Bases:
object
Distributes a given time series data for HRUs in a catchment according to the hru_definition. Currently it is supposed that only land use changes with time.
Example
>>> import os >>> from ai4water.preprocessing.spatial_processing import MakeHRUs >>> # shapefile_paths is the path where shapefiles are located. todo >>> SubBasin_shp = os.path.join(shapefile_paths, 'sub_basins.shp') >>> shapefile_paths = os.path.join(os.getcwd(), 'shapefiles') >>> hru_object = MakeHRUs('unique_lu_sub', ... index={2011: {'shapefile': os.path.join(shapefile_paths, 'lu2011.shp'), 'feature': 'NAME'}, ... 2012: {'shapefile': os.path.join(shapefile_paths, 'lu2012.shp'), 'feature': 'NAME'}}, ... subbasins_shape={'shapefile': SubBasin_shp, 'feature': 'id'} ... ) >>> hru_object.call()
- __init__(hru_definition: str, index: dict, soil_shape: Optional[dict] = None, slope_shape: Optional[dict] = None, subbasins_shape: Optional[dict] = None, save: bool = False, show: bool = True, verbosity: int = 1)[source]
- Parameters:
hru_definition – hru definition. For valid hru_definitions check MakeHRUs.HRU_DEFINITIONS
index –
dictionary defining shapefiles of landuse which change with time. For example in following a land use shapefile for two years is defined. All attributes in land use shapefiles must have the feature NAME.
>>> {2011: {'shapefile': os.path.join(shapefile_paths, 'lu2011.shp'), 'feature': 'NAME'}, ... 2012: {'shapefile': os.path.join(shapefile_paths, 'lu2012.shp'), 'feature': 'NAME'}}
soil_shape –
only applicable if soil exists in hru_definition. All attributes in land use soil.shp must have the feature NAME.
>>> {'shapefile': os.path.join(shapefile_paths, 'soil.shp'), 'feature': 'NAME'}
slope_shape –
only applicable if slope exists in hru_definition. All attributes in slope.shp shapefiles must have the feature percent.
>>> {'shapefile': os.path.join(shapefile_paths, 'slope.shp'), 'feature': 'percent'}
subbasins_shape –
only applicable if sub exists in hru_definition. All attributes in land use shapefiles must have the feature id.
>>> {'shapefile': os.path.join(shapefile_paths, 'subbasins.shp'), 'feature': 'id'}
save (bool) –
show (bool, default=False) – whether to save the plots or not.
verbosity – Determines verbosity.
- HRU_DEFINITIONS = ['unique_sub', 'unique_lu', 'unique_soil', 'unique_slope', 'unique_lu_sub', 'unique_lu_soil', 'unique_lu_slope', 'unique_soil_sub', 'unique_soil_slope', 'unique_slope_sub', 'unique_lu_soil_sub', 'unique_lu_soil_slope']
- call(plot_hrus=True)[source]
Makes the HRUs.
- Parameters:
plot_hrus – If true, the exact area hrus will be plotted as well.
- draw_pie(year: int, n_merge: int = 0, shadow: bool = True, title: bool = False, **kwargs) tuple [source]
todo draw nested pie chart for all years https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.pie.html Draws a pie chart showing relative area of HRUs for a particular year. Since the hrus can change with time, selecting one year is based on supposition that area of hrus remain constant during the whole year.
- get_hrus(idx_shp, year)[source]
- idx_shp :
shapefile whose area distribution changes with time e.g land use
- plot_as_ts(marker='o', ms=8, min_xticks=None, max_xticks=None, figsize=None, **kwargs) Axes [source]
- plot_hru(hru_name, bbox=None) Figure [source]
plot only one hru from hru_geoms. The value of each key in hru_geoms is a list with three shapes
Examples
>>> self.plot_an_hru(self.hru_names[0], bbox=True)