Hydrologic Projects
ESPAM2 Recharge Tools 1.5 Documentation
espam.irrigation
ESPAM Irrigation Module Contains methods for building the IAR files for MKMOD and the PDate utility.
All file builders subclass the class Builder, and have a method called generate_file, which at the minimum takes a settings object as an input, and a path to an output file. Some of the file types take additional information about stress periods, or PEST multipliers. See documentation for each individual Builder for details.
- class espam.irrigation.BaseIarBuilder(settings)
Builder for the Iar file format.
Generates Iar files for standard runs and curtailment runs.
This class is a subclass of Builder. Do not call this class directly, use either IarBuilder or CurtailmentIarBuilder.
- build_espa_grid_raster()
Build ESPAM Grid Raster From Vector
Convert ESPAM Grid vector defined in settings to a raster format
- generate_file(output_file, stress_periods, curtailment=False, fraction_builder=None, surface_multiplier=0.0, ground_multiplier=0.0, write_warning=False, warning_message='')>
Builds a IAR file from the input settings
- Generates a IAR file, using the datasources from the settings.ini file:
- Wetland/Urban Mask rasters defined by the wetlandmask key
- Groundwater Entities raster defined by the groundwaterentity key
- Surface Water Entities raster defined by the surfacewaterentity key
- Groundwater Fraction raster defied by the groundwaterfraction key
- Irrigation raster by irrigation year defined by the irrigation key
- ESPA Model Grid Feature Class defined by the espagrid key
This method requires a Spatial Analyst license to perform some of the raster operations. See Processing Steps for details on how the IAR file is generated.
See the IAR File Format document for more details on the PRE file format.
generate_file is a common method shared by all Builder classes. The generate_file method always takes an output_file parameter, which is the location the file will be saved to. The settings used by generate_file are passed to the Builder object in the constructor.
Parameters: - output_file (str) – Location to store output IAR file
- stress_periods (int) – Number of stress periods to run
- curtailment (Boolean) – Is this run for a curtailment scenario
- fraction_builder (JuniorFractionGrid) – Junior fraction grid builder
- surface_multiplier (float) – Multiplier to apply to Surface Water for Curtailment Scenarios
- ground_multiplier (float) – Multiplier to apply to Groundwater for Curtailment Scenarios
- write_warning (Boolean) – Does a warning message need to be written in comments
- warning_message (str) – Warning message to be written if write_warning = True
- class espam.irrigation.CurtailmentIarBuilder(settings)
Builder for Curtailment IAR file format.
Creates a IAR file for input into MKMOD given processed Irrigation Rasters, Wetland/Urban Mask, Surface Water Entity Rasters, and Groundwater Entity Rasters, Groundwater Fraction Raster, and ESPA Grid
This class is a subclass of BaseIarBuilder
>>> buildIAR = CurtailmentIarBuilder(settings) >>> buildIAR.generate_file("D:\out.iar",100)
- generate_file(output_file, output_raster_dir, stress_periods, priority_date, est_flag, gw_multiplier, sw_multiplier)
Builds a Curtailment IAR file from the input settings
- Generates a IAR file, using the datasources from the settings.ini file:
- Wetland/Urban Mask rasters defined by the wetlandmask key
- Groundwater Entities raster defined by the groundwaterentity key
- Surface Water Entities raster defined by the surfacewaterentity key
- Groundwater Fraction raster defied by the groundwaterfraction key
- Irrigation raster by irrigation year defined by the irrigation key
- ESPA Model Grid Feature Class defined by the espagrid key
- Point of Diversion vector defined by the pointofdiversion key
This method requires a Spatial Analyst license to perform some of the raster operations. See Processing Steps for details on how the IAR file is generated.
See the IAR File Format document for more details on the PRE file format.
generate_file is a common method shared by all Builder classes. The generate_file method always takes an output_file parameter, which is the location the file will be saved to. The settings used by generate_file are passed to the Builder object in the constructor.
Parameters: - output_file (str) – Location to store output IAR file
- output_raster_dir (str) – Location to store output rasters
- stress_periods (int) – Number of stress periods to run
- priority_date (str) – Priority date to determine jr/sr fractions
- est_flag (str (Either A or G). A is average neighboring eight cells. G is use global fraction.) – Method to estimate fractions for grid cells without point of diversions
- gw_multiplier (float) – Multiplier to apply to Groundwater for Curtailment Scenarios
- sw_multiplier (float) – Multiplier to apply to Surface Water for Curtailment Scenarios
- class espam.irrigation.IarBuilder(settings)
Builder for IAR file format.
Creates a IAR file for input into MKMOD given processed Irrigation Rasters, Wetland/Urban Mask, Surface Water Entity Rasters, and Groundwater Entity Rasters, Groundwater Fraction Raster, and ESPA Grid
This class is a subclass of BaseIarBuilder
>>> buildIAR = IarBuilder(settings) >>> buildIAR.generate_file("D:\out.iar",100)
- generate_file(output_file, stress_periods)
Builds a IAR file from the input settings
- Generates a IAR file, using the datasources from the settings.ini file:
- Wetland/Urban Mask rasters defined by the wetlandmask key
- Groundwater Entities raster defined by the groundwaterentity key
- Surface Water Entities raster defined by the surfacewaterentity key
- Groundwater Fraction raster defied by the groundwaterfraction key
- Irrigation raster by irrigation year defined by the irrigation key
- ESPA Model Grid Feature Class defined by the espagrid key
This method requires a Spatial Analyst license to perform some of the raster operations. See Processing Steps for details on how the IAR file is generated.
See the IAR File Format document for more details on the IAR file format.
generate_file is a common method shared by all Builder classes. The generate_file method always takes an output_file parameter, which is the location the file will be saved to. The settings used by generate_file are passed to the Builder object in the constructor.
Parameters: - output_file (str) – Location to store output IAR file
- stress_periods (int) – Number of stress periods to run
- class espam.irrigation.JuniorFractionGrid(pod_file)
Utilities for generating Junior Fractions for the ESPA Model Grid
Implementation of PDate.pl perl library for generating junior fractions for ESPA model grid cells.
- build_raster_lookup(output_csv, espa_grid)
Generates a raster with junior fractions
Combines the ESPA Model Grid Raster with a CSV file with junior fractions into an output raster that has a junior fraction for each ESPAM grid cell
Parameters: - output_csv (str) – CSV file containing junior fractions
- espa_grid (str) – ESPA Model grid raster
- get_junior_fraction_priority_date(priority_date, est_flag)
Generates junior fractions and global fractions for the ESPA Model Grid
Builds junior fractions and global fractions based on the PDate.pl algorithm. Diversion rates are summed up per grid cell, and a fraction is calculated based on the diversions in the grid cell that are junior to the given priority date. A global fraction is also generated for the entire ESPA.
Parameters: - priority_date (str) – Priority date from which after every right is junior
- est_flag (str (Either A or G). A is average neighboring eight cells. G is use global fraction.) – Method to estimate fractions for grid cells without point of diversions
Returns: Tuple - Tuple with three values: - Item 0: Global senior fraction - Item 1: Global junior fraction - Dictionary of junior, senior and total fractions keyed by CELL_INT (grid cell id), DIV_SUM (Total diversions per cell), SR_SUM (Total senior diversions per cell), SR_FRAC (Senior fraction), JR_FRAC (junior fraction), EST_FLAG (flag used for estimating values in cells without diversions), CELL (row column tuple).
- get_junior_fractions_as_dict()
Returns Junior Fractions in a dict with keys on CELLINT
- output_fractions_to_csv(output_csv)
Converts junior fractions into a CSV table
Writes junior fraction results into a CSV file
Parameters: output_csv (str) – Path to csv file
- espam.irrigation.build_pdate_table(settings, priority_date, est_flag, output_csv)
Generate table of junior groundwater fractions
This mimics the original PDate.pl perl application. A csv file is generated containing junior groundwater fractions based on the user defined priority date, and est_flag
Parameters: - settings (espam.settings.Settings) – Representation of settings.ini file
- priority_date (str) – Priority date that separates junior/senior rights
- est_flag (str (Either A or G). A is average neighboring eight cells. G is use global fraction.) – Method to estimate fractions for grid cells without point of diversions
- espam.irrigation.convert_col_row_to_cellint(row, col)
Converts a ESPAM Grid Row and Column Number to a combined number
Takes a Row and Column and appends into one number that can be used for a key in a hash table for quick lookup. This number will be unique for each model row/column combination.
>>> row = 3 >>> col = 10 >>> col_row = convert_col_row_to_cellint(row, col) 1003010
Parameters: - row (int) – ESPA Model Grid Row Number
- col (int) – ESPA Model Grid Column Number
Returns: int – Concatenated row/column