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.

Parameters:
  • year (int,) – the year for which area of hrus will be used.

  • n_merge – number of hrus to merge

  • shadow (bool) –

  • title

  • **kwargs – any keyword arguments for easy_mpl.pie

Return type:

tuple

get_hrus(idx_shp, year)[source]
idx_shp :

shapefile whose area distribution changes with time e.g land use

make_gif()[source]
plot(what: str, index=None, show_all_together=True)[source]
plot_as_ts(marker='o', ms=8, min_xticks=None, max_xticks=None, figsize=None, **kwargs) Axes[source]
Parameters:
  • marker

  • ms – marker size as integer

  • min_xticks (int) – minimum ticks on x-axis

  • max_xticks (int) – maximum ticks on x-axis

  • figsize – figure size

  • **kwargs – any keyword arguments for easy_mpl.plot

  • hru_object.plot_as_ts()

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)
plot_hru_evolution(hru_name, make_gif=False)[source]

plots how the hru evolved during the years

Parameters:
  • hru_name (str,) – name of hru to be plotted

  • make_gif (bool) – if True, a gif file will be created from evolution plots

plot_hrus(year, bbox, _polygon_dict, annotate=False, nrows=3, ncols=4, name='', annotate_missing_hru=False) Figure[source]