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, 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, 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'}
    

  • 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. :param plot_hrus: If true, the exact area hrus will be plotted as well.

draw_pie(year: int, n_merge: int = 0, title: bool = False, save: bool = False, name: Optional[str] = None, show: bool = True, **kwargs)[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. :param year: int, the year for which area of hrus will be used. :param n_merge: number of hrus to merge :param title: :param save: :param name: :param show: :param kwargs: Following keyword arguments are allowed

shadow strartangle autopct textprops

get_hrus(idx_shp, year)[source]

lu_path: path of landuse shapefile :return:

make_gif()[source]
plot(what, index=None, show_all_together=True)[source]
plot_as_ts(save=False, name=None, show=True, **kwargs)[source]

hru_object.plot_as_ts(save=True, min_xticks=3, max_xticks=4

plot_hru(hru_name, bbox=None, save=False)[source]

plot only one hru from hru_geoms. The value of each key in hru_geoms is a list with three shapes :usage

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 :param hru_name: str, name of hru to be plotted :param make_gif: bool, if True, a gif file will be created from evolution plots :return: plots the hru.

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