Component Modules#
The component modules represent the major hydrologic components of an IWFM model.
All components inherit from BaseComponent,
which provides a consistent interface with validate() and n_items
methods.
Groundwater Module#
The groundwater module contains classes for representing aquifer properties and groundwater simulation parameters.
Groundwater component classes for IWFM models.
This module provides classes for representing groundwater system components including wells, pumping, boundary conditions, tile drains, and aquifer parameters. It mirrors IWFM’s Package_AppGW.
- class pyiwfm.components.groundwater.Well(id, x, y, element, name='', top_screen=0.0, bottom_screen=0.0, max_pump_rate=inf, pump_rate=0.0, layers=<factory>, radius=0.0, pump_column=0, pump_fraction=1.0, dist_method=0, dest_type=-1, dest_id=0, irig_frac_column=0, adjust_column=0, pump_max_column=0, pump_max_fraction=0.0)[source]#
Bases:
objectA pumping well in the groundwater system.
- Variables:
id (int) – Unique well identifier
name (str) – Well name/description
x (float) – X coordinate
y (float) – Y coordinate
element (int) – Element ID containing the well
top_screen (float) – Top of screen elevation
bottom_screen (float) – Bottom of screen elevation
max_pump_rate (float) – Maximum allowable pumping rate
pump_rate (float) – Current pumping rate
radius (float) – Well radius
pump_column (int) – Column in time series pumping file
pump_fraction (float) – Fraction of pumping at this column
dist_method (int) – Distribution method (0-4)
dest_type (int) – Destination type (-1, 0, 1, 2, 3)
dest_id (int) – Destination ID (element, subregion, or group)
irig_frac_column (int) – Column for irrigation fraction
adjust_column (int) – Column for supply adjustment
pump_max_column (int) – Column for maximum pumping
pump_max_fraction (float) – Fraction of maximum pumping
- __init__(id, x, y, element, name='', top_screen=0.0, bottom_screen=0.0, max_pump_rate=inf, pump_rate=0.0, layers=<factory>, radius=0.0, pump_column=0, pump_fraction=1.0, dist_method=0, dest_type=-1, dest_id=0, irig_frac_column=0, adjust_column=0, pump_max_column=0, pump_max_fraction=0.0)#
- class pyiwfm.components.groundwater.ElementPumping(element_id, layer, pump_rate, layer_fraction=1.0, pump_column=0, pump_fraction=1.0, dist_method=0, layer_factors=<factory>, dest_type=-1, dest_id=0, irig_frac_column=0, adjust_column=0, pump_max_column=0, pump_max_fraction=0.0)[source]#
Bases:
objectPumping applied to an element (distributed pumping).
- Variables:
element_id (int) – Element ID
layer (int) – Layer number
pump_rate (float) – Total pumping rate
layer_fraction (float) – Fraction of pumping from this layer
pump_column (int) – Column in time series pumping file
pump_fraction (float) – Fraction of pumping at this column
dist_method (int) – Distribution method (0-4)
dest_type (int) – Destination type (-1, 0, 1, 2, 3)
dest_id (int) – Destination ID
irig_frac_column (int) – Column for irrigation fraction
adjust_column (int) – Column for supply adjustment
pump_max_column (int) – Column for maximum pumping
pump_max_fraction (float) – Fraction of maximum pumping
- __init__(element_id, layer, pump_rate, layer_fraction=1.0, pump_column=0, pump_fraction=1.0, dist_method=0, layer_factors=<factory>, dest_type=-1, dest_id=0, irig_frac_column=0, adjust_column=0, pump_max_column=0, pump_max_fraction=0.0)#
- class pyiwfm.components.groundwater.BoundaryCondition(id, bc_type, nodes, values, layer, conductance=<factory>, constraining_head=0.0, max_flow=0.0, ts_column=0, max_flow_ts_column=0)[source]#
Bases:
objectA groundwater boundary condition.
- Variables:
id (int) – Unique BC identifier
bc_type (str) – Type of boundary (‘specified_head’, ‘specified_flow’, ‘general_head’, ‘constrained_general_head’)
layer (int) – Layer number
conductance (list[float]) – Conductance values for general head BC
constraining_head (float) – Constraining head for constrained GH BC
max_flow (float) – Maximum flow for constrained GH BC
ts_column (int) – Time series column (0 = static)
max_flow_ts_column (int) – Time series column for max flow (0 = static)
- __init__(id, bc_type, nodes, values, layer, conductance=<factory>, constraining_head=0.0, max_flow=0.0, ts_column=0, max_flow_ts_column=0)#
- class pyiwfm.components.groundwater.TileDrain(id, element, elevation, conductance, destination_type='outside', destination_id=None)[source]#
Bases:
objectA tile drain in the groundwater system.
- Variables:
id (int) – Unique drain identifier
element (int) – Element ID containing the drain
elevation (float) – Drain elevation
conductance (float) – Drain conductance
destination_type (str) – Where drain water goes (‘stream’, ‘outside’, etc.)
destination_id (int | None) – ID of destination (e.g., stream node)
- __init__(id, element, elevation, conductance, destination_type='outside', destination_id=None)#
- class pyiwfm.components.groundwater.Subsidence(element, layer, elastic_storage, inelastic_storage, preconsolidation_head, interbed_thick=0.0, interbed_thick_min=0.0)[source]#
Bases:
objectSubsidence parameters for a node/layer.
- Variables:
element (int) – Node ID (historical name; actually per-node in IWFM)
layer (int) – Layer number
elastic_storage (float) – Elastic skeletal storage coefficient
inelastic_storage (float) – Inelastic skeletal storage coefficient
preconsolidation_head (float) – Preconsolidation head
interbed_thick (float) – Interbed thickness
interbed_thick_min (float) – Minimum interbed thickness
- __init__(element, layer, elastic_storage, inelastic_storage, preconsolidation_head, interbed_thick=0.0, interbed_thick_min=0.0)#
- class pyiwfm.components.groundwater.NodeSubsidence(node_id, elastic_sc=<factory>, inelastic_sc=<factory>, interbed_thick=<factory>, interbed_thick_min=<factory>, precompact_head=<factory>, kv_sub=<factory>, n_eq=<factory>)[source]#
Bases:
objectSubsidence parameters for a node across all layers.
Mirrors the per-node subsidence data from IWFM’s subsidence file.
- Variables:
node_id (int) – GW node ID (1-based)
elastic_sc (list[float]) – Elastic storage coefficient per layer
inelastic_sc (list[float]) – Inelastic storage coefficient per layer
interbed_thick_min (list[float]) – Minimum interbed thickness per layer
precompact_head (list[float]) – Pre-compaction head per layer
kv_sub (list[float]) – Vertical conductivity of interbeds per layer (v5.0 only)
n_eq (list[float]) – Number of equivalent delay interbeds per layer (v5.0 only)
- __init__(node_id, elastic_sc=<factory>, inelastic_sc=<factory>, interbed_thick=<factory>, interbed_thick_min=<factory>, precompact_head=<factory>, kv_sub=<factory>, n_eq=<factory>)#
- class pyiwfm.components.groundwater.SubIrrigation(id, gw_node, elevation, conductance)[source]#
Bases:
objectA sub-irrigation location in the groundwater system.
- Variables:
- __init__(id, gw_node, elevation, conductance)#
- class pyiwfm.components.groundwater.AquiferParameters(n_nodes, n_layers, kh=None, kv=None, specific_storage=None, specific_yield=None, aquitard_kv=None)[source]#
Bases:
objectAquifer parameters for the groundwater system.
- Variables:
n_nodes (int) – Number of nodes
n_layers (int) – Number of layers
kh (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Horizontal hydraulic conductivity (n_nodes, n_layers)
kv (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Vertical hydraulic conductivity (n_nodes, n_layers)
specific_storage (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Specific storage (n_nodes, n_layers)
specific_yield (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Specific yield (n_nodes, n_layers)
aquitard_kv (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Aquitard vertical hydraulic conductivity (n_nodes, n_layers)
- __init__(n_nodes, n_layers, kh=None, kv=None, specific_storage=None, specific_yield=None, aquitard_kv=None)#
- class pyiwfm.components.groundwater.HydrographLocation(node_id, layer, x, y, name='')[source]#
Bases:
objectA groundwater hydrograph output location (observation point).
These are locations in the model where groundwater heads are tracked over time for comparison with field observations.
- Variables:
- __init__(node_id, layer, x, y, name='')#
- class pyiwfm.components.groundwater.AppGW(n_nodes, n_layers, n_elements, wells=<factory>, boundary_conditions=<factory>, tile_drains=<factory>, element_pumping=<factory>, subsidence=<factory>, node_subsidence=<factory>, sub_irrigations=<factory>, aquifer_params=None, heads=None, hydrograph_locations=<factory>, face_flow_specs=<factory>, kh_anomalies=<factory>, return_flow_destinations=<factory>, parametric_groups=<factory>, subsidence_config=None, bc_config=None, gw_main_config=None, pumping_ts_file=None, bc_ts_file=None, n_bc_output_nodes=0, bc_output_file='', bc_output_file_raw='', bc_output_specs=<factory>, td_elev_factor=1.0, td_cond_factor=1.0, td_time_unit='1DAY', si_elev_factor=1.0, si_cond_factor=1.0, si_time_unit='1MON', td_n_hydro=0, td_hydro_volume_factor=1.0, td_hydro_volume_unit='', td_output_file_raw='', td_hydro_specs=<factory>)[source]#
Bases:
BaseComponentGroundwater application component.
This class manages the groundwater system including wells, pumping, boundary conditions, and aquifer parameters. It mirrors IWFM’s Package_AppGW.
- Variables:
n_nodes (int) – Number of nodes
n_layers (int) – Number of aquifer layers
n_elements (int) – Number of elements
wells (dict[int, pyiwfm.components.groundwater.Well]) – Dictionary mapping well ID to Well
boundary_conditions (list[pyiwfm.components.groundwater.BoundaryCondition]) – List of boundary conditions
tile_drains (dict[int, pyiwfm.components.groundwater.TileDrain]) – Dictionary mapping drain ID to TileDrain
aquifer_params (pyiwfm.components.groundwater.AquiferParameters | None) – Aquifer parameters
heads (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Current heads array (n_nodes, n_layers)
hydrograph_locations (list[pyiwfm.components.groundwater.HydrographLocation]) – List of observation points for head output
- boundary_conditions: list[BoundaryCondition]#
- element_pumping: list[ElementPumping]#
- subsidence: list[Subsidence]#
- node_subsidence: list[NodeSubsidence]#
- sub_irrigations: list[SubIrrigation]#
- aquifer_params: AquiferParameters | None = None#
- hydrograph_locations: list[HydrographLocation]#
- validate()[source]#
Validate the groundwater component.
- Raises:
ComponentError – If component is invalid
- classmethod from_arrays(n_nodes, n_layers, n_elements, heads=None, kh=None, kv=None, specific_storage=None, specific_yield=None)[source]#
Create groundwater component from arrays.
- Parameters:
n_nodes (int) – Number of nodes
n_layers (int) – Number of layers
n_elements (int) – Number of elements
heads (ndarray[tuple[Any, ...], dtype[float64]] | None) – Initial heads array
kh (ndarray[tuple[Any, ...], dtype[float64]] | None) – Horizontal hydraulic conductivity
kv (ndarray[tuple[Any, ...], dtype[float64]] | None) – Vertical hydraulic conductivity
specific_storage (ndarray[tuple[Any, ...], dtype[float64]] | None) – Specific storage
specific_yield (ndarray[tuple[Any, ...], dtype[float64]] | None) – Specific yield
- Returns:
AppGW instance
- Return type:
- __init__(n_nodes, n_layers, n_elements, wells=<factory>, boundary_conditions=<factory>, tile_drains=<factory>, element_pumping=<factory>, subsidence=<factory>, node_subsidence=<factory>, sub_irrigations=<factory>, aquifer_params=None, heads=None, hydrograph_locations=<factory>, face_flow_specs=<factory>, kh_anomalies=<factory>, return_flow_destinations=<factory>, parametric_groups=<factory>, subsidence_config=None, bc_config=None, gw_main_config=None, pumping_ts_file=None, bc_ts_file=None, n_bc_output_nodes=0, bc_output_file='', bc_output_file_raw='', bc_output_specs=<factory>, td_elev_factor=1.0, td_cond_factor=1.0, td_time_unit='1DAY', si_elev_factor=1.0, si_cond_factor=1.0, si_time_unit='1MON', td_n_hydro=0, td_hydro_volume_factor=1.0, td_hydro_volume_unit='', td_output_file_raw='', td_hydro_specs=<factory>)#
Stream Module#
The stream module contains classes for representing stream networks, including stream nodes and reaches.
Stream network classes for IWFM models.
This module provides classes for representing stream networks, including stream nodes, reaches, diversions, and bypasses. It mirrors IWFM’s Package_AppStream.
- pyiwfm.components.stream.segments_intersect(p1, p2, p3, p4, tolerance=1e-10)[source]#
Check if two line segments intersect (excluding shared endpoints).
Segment 1: p1 to p2 Segment 2: p3 to p4
- Parameters:
tolerance (
float) – Distance tolerance for considering points as shared endpoints.
- Returns:
True if segments intersect at a point that is not a shared endpoint.
- Return type:
Examples
>>> segments_intersect((0, 0), (2, 2), (0, 2), (2, 0)) # X crossing True >>> segments_intersect((0, 0), (1, 1), (1, 1), (2, 2)) # Shared endpoint False >>> segments_intersect((0, 0), (1, 0), (2, 0), (3, 0)) # Parallel, no overlap False
- class pyiwfm.components.stream.ReachCrossing(segment1, segment2, intersection_point=None)[source]#
Bases:
objectRepresents a detected crossing between two stream reach segments.
- Variables:
- __init__(segment1, segment2, intersection_point=None)#
- class pyiwfm.components.stream.CrossSectionData(bottom_elev=0.0, B0=0.0, s=0.0, n=0.04, max_flow_depth=10.0)[source]#
Bases:
objectv5.0 hydraulic cross-section parameters for Manning’s equation.
- Variables:
- __init__(bottom_elev=0.0, B0=0.0, s=0.0, n=0.04, max_flow_depth=10.0)#
- class pyiwfm.components.stream.StrmEvapNodeSpec(node_id, et_column=0, area_column=0)[source]#
Bases:
objectPer-node stream evaporation column pointers.
- Variables:
- __init__(node_id, et_column=0, area_column=0)#
- class pyiwfm.components.stream.StreamRating(stages, flows)[source]#
Bases:
objectStage-discharge rating curve for a stream node.
- Variables:
stages (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]]) – Array of stage (water level) values
flows (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]]) – Array of corresponding flow values
- __init__(stages, flows)#
- class pyiwfm.components.stream.StrmNode(id, x, y, reach_id=0, gw_node=None, bottom_elev=0.0, wetted_perimeter=0.0, upstream_node=None, downstream_node=None, rating=None, conductivity=0.0, bed_thickness=0.0, cross_section=None, initial_condition=0.0)[source]#
Bases:
objectA stream node representing a point in the stream network.
- Variables:
id (int) – Unique node identifier
x (float) – X coordinate
y (float) – Y coordinate
reach_id (int) – ID of the reach this node belongs to
gw_node (int | None) – ID of the associated groundwater node (for stream-aquifer interaction)
bottom_elev (float) – Stream bed elevation
wetted_perimeter (float) – Wetted perimeter for flow calculations
upstream_node (int | None) – ID of upstream node
downstream_node (int | None) – ID of downstream node
rating (pyiwfm.components.stream.StreamRating | None) – Stage-discharge rating curve
- rating: StreamRating | None = None#
- cross_section: CrossSectionData | None = None#
- __init__(id, x, y, reach_id=0, gw_node=None, bottom_elev=0.0, wetted_perimeter=0.0, upstream_node=None, downstream_node=None, rating=None, conductivity=0.0, bed_thickness=0.0, cross_section=None, initial_condition=0.0)#
- class pyiwfm.components.stream.StrmReach(id, upstream_node, downstream_node, name='', nodes=<factory>, outflow_destination=None)[source]#
Bases:
objectA stream reach representing a segment of the stream network.
- Variables:
id (int) – Unique reach identifier
name (str) – Descriptive name
upstream_node (int) – ID of the most upstream node
downstream_node (int) – ID of the most downstream node
nodes (list[int]) – List of node IDs in this reach (upstream to downstream order)
outflow_destination (tuple[str, int] | None) – Where outflow goes - tuple of (type, id) type: ‘reach’, ‘lake’, ‘boundary’, etc. id: destination ID
- __init__(id, upstream_node, downstream_node, name='', nodes=<factory>, outflow_destination=None)#
- class pyiwfm.components.stream.Diversion(id, source_node, destination_type, destination_id, name='', max_rate=inf, priority=99, reach_id=0, max_div_column=0, max_div_fraction=1.0, recoverable_loss_column=0, recoverable_loss_fraction=0.0, non_recoverable_loss_column=0, non_recoverable_loss_fraction=0.0, spill_column=0, spill_fraction=0.0, delivery_dest_type=0, delivery_dest_id=0, delivery_column=0, delivery_fraction=1.0, irrigation_fraction_column=0, adjustment_column=0, element_groups=<factory>, recharge_zones=<factory>, spill_locations=<factory>)[source]#
Bases:
objectA stream diversion that removes water from the stream.
- Variables:
id (int) – Unique diversion identifier
name (str) – Descriptive name
source_node (int) – Stream node ID where water is diverted
destination_type (str) – Type of destination (‘element’, ‘stream_node’, ‘outside’)
destination_id (int) – ID of destination
max_rate (float) – Maximum diversion rate
priority (int) – Allocation priority (lower = higher priority)
- __init__(id, source_node, destination_type, destination_id, name='', max_rate=inf, priority=99, reach_id=0, max_div_column=0, max_div_fraction=1.0, recoverable_loss_column=0, recoverable_loss_fraction=0.0, non_recoverable_loss_column=0, non_recoverable_loss_fraction=0.0, spill_column=0, spill_fraction=0.0, delivery_dest_type=0, delivery_dest_id=0, delivery_column=0, delivery_fraction=1.0, irrigation_fraction_column=0, adjustment_column=0, element_groups=<factory>, recharge_zones=<factory>, spill_locations=<factory>)#
- class pyiwfm.components.stream.Bypass(id, source_node, destination_node, dest_type=0, name='', capacity=inf, flow_factor=1.0, flow_time_unit='1DAY', spill_factor=1.0, spill_time_unit='1DAY', diversion_column=0, recoverable_loss_fraction=0.0, non_recoverable_loss_fraction=0.0, rating_table_flows=<factory>, rating_table_spills=<factory>, seepage_locations=<factory>)[source]#
Bases:
objectA stream bypass that routes water around a section.
- Variables:
- __init__(id, source_node, destination_node, dest_type=0, name='', capacity=inf, flow_factor=1.0, flow_time_unit='1DAY', spill_factor=1.0, spill_time_unit='1DAY', diversion_column=0, recoverable_loss_fraction=0.0, non_recoverable_loss_fraction=0.0, rating_table_flows=<factory>, rating_table_spills=<factory>, seepage_locations=<factory>)#
- class pyiwfm.components.stream.AppStream(nodes=<factory>, reaches=<factory>, diversions=<factory>, bypasses=<factory>, conductivity_factor=1.0, conductivity_time_unit='', length_factor=1.0, interaction_type=1, evap_area_file='', evap_node_specs=<factory>, ic_type=0, ic_time_unit='', ic_factor=1.0, final_flow_file='', budget_node_count=0, budget_output_file='', budget_node_ids=<factory>, roughness_factor=1.0, cross_section_length_factor=1.0, diversion_element_groups=<factory>, diversion_recharge_zones=<factory>, diversion_spill_zones=<factory>, diversion_has_spills=False, _downstream_map=<factory>, _upstream_map=<factory>)[source]#
Bases:
BaseComponentStream network application class.
This class manages the complete stream network including nodes, reaches, diversions, and bypasses. It mirrors IWFM’s Package_AppStream.
- Variables:
nodes (dict[int, pyiwfm.components.stream.StrmNode]) – Dictionary mapping node ID to StrmNode
reaches (dict[int, pyiwfm.components.stream.StrmReach]) – Dictionary mapping reach ID to StrmReach
diversions (dict[int, pyiwfm.components.stream.Diversion]) – Dictionary mapping diversion ID to Diversion
bypasses (dict[int, pyiwfm.components.stream.Bypass]) – Dictionary mapping bypass ID to Bypass
- evap_node_specs: list[StrmEvapNodeSpec]#
- detect_crossings()[source]#
Detect all crossing (intersecting) reach segments in the network.
Stream reaches can share endpoints (confluences/junctions) but cannot cross each other geometrically. This method identifies all such invalid crossings.
- Returns:
List of detected crossings. Empty if no crossings found.
- Return type:
Examples
>>> stream = AppStream() >>> # ... add nodes and reaches ... >>> crossings = stream.detect_crossings() >>> if crossings: ... print(f"Found {len(crossings)} crossing(s)") ... for c in crossings: ... print(f" {c}")
- validate_no_crossings(raise_on_error=True)[source]#
Validate that no stream reaches cross each other.
Stream reaches can share endpoints (confluences) but cannot cross (intersect at non-endpoint locations).
- Parameters:
raise_on_error (
bool, defaultTrue) – If True, raise ComponentError when crossings are found. If False, just return the list of crossings.- Returns:
List of detected crossings.
- Return type:
- Raises:
ComponentError – If raise_on_error is True and crossings are found.
Examples
>>> stream.validate_no_crossings() # Raises if crossings found
>>> crossings = stream.validate_no_crossings(raise_on_error=False) >>> if crossings: ... print(f"Found {len(crossings)} invalid crossing(s)")
- classmethod from_arrays(node_ids, x, y, reach_ids, gw_nodes=None)[source]#
Create stream network from arrays.
- Parameters:
node_ids (ndarray[tuple[Any, ...], dtype[int32]]) – Array of node IDs
x (ndarray[tuple[Any, ...], dtype[float64]]) – Array of x coordinates
y (ndarray[tuple[Any, ...], dtype[float64]]) – Array of y coordinates
reach_ids (ndarray[tuple[Any, ...], dtype[int32]]) – Array of reach IDs for each node
gw_nodes (ndarray[tuple[Any, ...], dtype[int32]] | None) – Array of groundwater node IDs (optional)
- Returns:
AppStream instance
- Return type:
- __init__(nodes=<factory>, reaches=<factory>, diversions=<factory>, bypasses=<factory>, conductivity_factor=1.0, conductivity_time_unit='', length_factor=1.0, interaction_type=1, evap_area_file='', evap_node_specs=<factory>, ic_type=0, ic_time_unit='', ic_factor=1.0, final_flow_file='', budget_node_count=0, budget_output_file='', budget_node_ids=<factory>, roughness_factor=1.0, cross_section_length_factor=1.0, diversion_element_groups=<factory>, diversion_recharge_zones=<factory>, diversion_spill_zones=<factory>, diversion_has_spills=False, _downstream_map=<factory>, _upstream_map=<factory>)#
Lake Module#
The lake module contains classes for representing lakes and reservoirs.
Lake component classes for IWFM models.
This module provides classes for representing lakes, including lake elements, outflows, rating curves, and the main lake application class. It mirrors IWFM’s Package_AppLake.
- class pyiwfm.components.lake.LakeRating(elevations, areas, volumes)[source]#
Bases:
objectElevation-area-volume rating curve for a lake.
- Variables:
elevations (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]]) – Array of water surface elevations
areas (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]]) – Array of corresponding surface areas
volumes (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]]) – Array of corresponding storage volumes
- __init__(elevations, areas, volumes)#
- class pyiwfm.components.lake.LakeElement(element_id, lake_id, fraction=1.0)[source]#
Bases:
objectAn element that is part of a lake.
- Variables:
- __init__(element_id, lake_id, fraction=1.0)#
- class pyiwfm.components.lake.LakeOutflow(lake_id, destination_type, destination_id, max_rate=inf)[source]#
Bases:
objectLake outflow configuration.
- Variables:
- __init__(lake_id, destination_type, destination_id, max_rate=inf)#
- class pyiwfm.components.lake.Lake(id, name='', max_elevation=inf, initial_storage=0.0, initial_elevation=280.0, elements=<factory>, gw_nodes=<factory>, rating=None, outflow=None, bed_conductivity=2.0, bed_thickness=1.0, et_column=7, precip_column=2, max_elev_column=0, outflow_rating_elevations=<factory>, outflow_rating_flows=<factory>)[source]#
Bases:
objectA lake in the model domain.
- Variables:
id (int) – Unique lake identifier
name (str) – Descriptive name
max_elevation (float) – Maximum water surface elevation
initial_storage (float) – Initial storage volume
elements (list[int]) – List of element IDs that make up the lake
gw_nodes (list[int]) – List of groundwater node IDs for lake-aquifer interaction
rating (pyiwfm.components.lake.LakeRating | None) – Elevation-area-volume rating curve
outflow (pyiwfm.components.lake.LakeOutflow | None) – Outflow configuration
- rating: LakeRating | None = None#
- outflow: LakeOutflow | None = None#
- __init__(id, name='', max_elevation=inf, initial_storage=0.0, initial_elevation=280.0, elements=<factory>, gw_nodes=<factory>, rating=None, outflow=None, bed_conductivity=2.0, bed_thickness=1.0, et_column=7, precip_column=2, max_elev_column=0, outflow_rating_elevations=<factory>, outflow_rating_flows=<factory>)#
- class pyiwfm.components.lake.AppLake(lakes=<factory>, lake_elements=<factory>, current_elevations=<factory>)[source]#
Bases:
BaseComponentLake application component.
This class manages all lakes in the model domain including lake elements, outflows, and rating curves. It mirrors IWFM’s Package_AppLake.
- Variables:
lakes (dict[int, pyiwfm.components.lake.Lake]) – Dictionary mapping lake ID to Lake
lake_elements (list[pyiwfm.components.lake.LakeElement]) – List of lake elements
current_elevations (dict[int, float]) – Dictionary of current water surface elevations
- lake_elements: list[LakeElement]#
- classmethod from_arrays(lake_ids, names, max_elevations=None)[source]#
Create lake component from arrays.
- __init__(lakes=<factory>, lake_elements=<factory>, current_elevations=<factory>)#
Root Zone Module#
The root zone module contains classes for representing land use and root zone processes.
Root zone component classes for IWFM models.
This module provides classes for representing the root zone including land use types, crop parameters, soil properties, and water budget calculations. It mirrors IWFM’s Package_RootZone.
- class pyiwfm.components.rootzone.LandUseType(*values)[source]#
Bases:
EnumLand use type enumeration.
- AGRICULTURAL = 'agricultural'#
- URBAN = 'urban'#
- NATIVE_RIPARIAN = 'native_riparian'#
- WATER = 'water'#
- class pyiwfm.components.rootzone.CropType(id, name='', root_depth=0.0, kc=1.0, monthly_kc=None)[source]#
Bases:
objectCrop type definition with water requirements.
- Variables:
id (int) – Unique crop identifier
name (str) – Crop name
root_depth (float) – Root zone depth (length units)
kc (float) – Crop coefficient for ET calculation
monthly_kc (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Optional monthly crop coefficients (12 values)
- __init__(id, name='', root_depth=0.0, kc=1.0, monthly_kc=None)#
- class pyiwfm.components.rootzone.SoilParameters(porosity, field_capacity, wilting_point, saturated_kv, lambda_param=0.5, kunsat_method=2, k_ponded=-1.0, capillary_rise=0.0, precip_column=1, precip_factor=1.0, generic_moisture_column=0)[source]#
Bases:
objectSoil hydraulic parameters.
- Variables:
porosity (float) – Total porosity (volume fraction)
field_capacity (float) – Water content at field capacity
wilting_point (float) – Water content at wilting point
saturated_kv (float) – Saturated vertical hydraulic conductivity
lambda_param (float) – Pore size distribution index
kunsat_method (int) – Unsaturated K method (1=Campbell, 2=van Genuchten-Mualem)
k_ponded (float) – Ponded hydraulic conductivity (-1 = same as saturated_kv)
capillary_rise (float) – Capillary rise depth (v4.1+)
precip_column (int) – Column pointer to precipitation data
precip_factor (float) – Precipitation scaling factor
generic_moisture_column (int) – Column pointer to generic moisture data
- __init__(porosity, field_capacity, wilting_point, saturated_kv, lambda_param=0.5, kunsat_method=2, k_ponded=-1.0, capillary_rise=0.0, precip_column=1, precip_factor=1.0, generic_moisture_column=0)#
- class pyiwfm.components.rootzone.ElementLandUse(element_id, land_use_type, area, crop_fractions=<factory>, impervious_fraction=0.0)[source]#
Bases:
objectLand use assignment for an element.
- Variables:
element_id (int) – Element ID
land_use_type (pyiwfm.components.rootzone.LandUseType) – Type of land use
area (float) – Area of this land use in the element
crop_fractions (dict[int, float]) – For agricultural, mapping of crop_id to area fraction
impervious_fraction (float) – For urban, fraction of impervious surface
- land_use_type: LandUseType#
- __init__(element_id, land_use_type, area, crop_fractions=<factory>, impervious_fraction=0.0)#
- class pyiwfm.components.rootzone.RootZone(n_elements, n_layers, crop_types=<factory>, soil_params=<factory>, element_landuse=<factory>, soil_moisture=None, nonponded_config=None, ponded_config=None, urban_config=None, native_riparian_config=None, surface_flow_destinations=<factory>, nonponded_area_file=None, ponded_area_file=None, urban_area_file=None, native_area_file=None, surface_flow_dest_ag=<factory>, surface_flow_dest_urban_in=<factory>, surface_flow_dest_urban_out=<factory>, surface_flow_dest_nvrv=<factory>)[source]#
Bases:
BaseComponentRoot zone application component.
This class manages land use, soil parameters, and soil moisture for the model domain. It mirrors IWFM’s Package_RootZone.
- Variables:
n_elements (int) – Number of elements
n_layers (int) – Number of soil layers
crop_types (dict[int, pyiwfm.components.rootzone.CropType]) – Dictionary mapping crop ID to CropType
soil_params (dict[int, pyiwfm.components.rootzone.SoilParameters]) – Dictionary mapping element ID to SoilParameters
element_landuse (list[pyiwfm.components.rootzone.ElementLandUse]) – List of element land use assignments
soil_moisture (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Soil moisture array (n_elements, n_layers)
- soil_params: dict[int, SoilParameters]#
- element_landuse: list[ElementLandUse]#
- load_land_use_from_arrays(snapshot)[source]#
Populate
element_landusefrom pre-aggregated snapshot data.This is used by the web viewer when the HDF5 area manager has already loaded and aggregated the area data.
- load_land_use_snapshot(timestep=0)[source]#
Read land use areas for a single timestep from area data files.
Populates
element_landusefrom the IWFM area time-series files referenced bynonponded_area_file,ponded_area_file,urban_area_file, andnative_area_file.- Parameters:
timestep (int) – Zero-based timestep index to read.
- validate()[source]#
Validate the root zone component.
- Raises:
ComponentError – If component is invalid
- classmethod from_arrays(n_elements, n_layers, soil_moisture=None)[source]#
Create root zone component from arrays.
- __init__(n_elements, n_layers, crop_types=<factory>, soil_params=<factory>, element_landuse=<factory>, soil_moisture=None, nonponded_config=None, ponded_config=None, urban_config=None, native_riparian_config=None, surface_flow_destinations=<factory>, nonponded_area_file=None, ponded_area_file=None, urban_area_file=None, native_area_file=None, surface_flow_dest_ag=<factory>, surface_flow_dest_urban_in=<factory>, surface_flow_dest_urban_out=<factory>, surface_flow_dest_nvrv=<factory>)#
Small Watershed Module#
The small watershed module contains classes for representing small watershed units with integrated root zone and aquifer processes.
Small Watershed component classes for IWFM models.
This module provides classes for representing small watersheds, including watershed units with root zone and aquifer parameters, and the main application class. It mirrors IWFM’s Package_AppSmallWatershed.
- class pyiwfm.components.small_watershed.WatershedGWNode(gw_node_id=0, max_perc_rate=0.0, is_baseflow=False, layer=0)[source]#
Bases:
objectGroundwater node connection for a small watershed.
- Variables:
- __init__(gw_node_id=0, max_perc_rate=0.0, is_baseflow=False, layer=0)#
- class pyiwfm.components.small_watershed.WatershedUnit(id=0, area=0.0, dest_stream_node=0, gw_nodes=<factory>, precip_col=0, precip_factor=1.0, et_col=0, wilting_point=0.0, field_capacity=0.0, total_porosity=0.0, lambda_param=0.0, root_depth=0.0, hydraulic_cond=0.0, kunsat_method=0, curve_number=0.0, gw_threshold=0.0, max_gw_storage=0.0, surface_flow_coeff=0.0, baseflow_coeff=0.0, initial_soil_moisture=0.0, initial_gw_storage=0.0)[source]#
Bases:
objectA single small watershed unit.
- Variables:
id (int) – Watershed unit ID (1-based)
area (float) – Watershed area
dest_stream_node (int) – Destination stream node for outflow (1-based)
gw_nodes (list[pyiwfm.components.small_watershed.WatershedGWNode]) – Connected groundwater nodes
precip_col (int) – Precipitation time-series column index
precip_factor (float) – Precipitation conversion factor
et_col (int) – ET time-series column index
wilting_point (float) – Soil wilting point
field_capacity (float) – Soil field capacity
total_porosity (float) – Total porosity
lambda_param (float) – Pore size distribution parameter
root_depth (float) – Root zone depth
hydraulic_cond (float) – Hydraulic conductivity
kunsat_method (int) – Unsaturated K method code
curve_number (float) – SCS curve number
gw_threshold (float) – Groundwater storage threshold
max_gw_storage (float) – Maximum groundwater storage
surface_flow_coeff (float) – Surface flow recession coefficient
baseflow_coeff (float) – Baseflow recession coefficient
- gw_nodes: list[WatershedGWNode]#
- __init__(id=0, area=0.0, dest_stream_node=0, gw_nodes=<factory>, precip_col=0, precip_factor=1.0, et_col=0, wilting_point=0.0, field_capacity=0.0, total_porosity=0.0, lambda_param=0.0, root_depth=0.0, hydraulic_cond=0.0, kunsat_method=0, curve_number=0.0, gw_threshold=0.0, max_gw_storage=0.0, surface_flow_coeff=0.0, baseflow_coeff=0.0, initial_soil_moisture=0.0, initial_gw_storage=0.0)#
- class pyiwfm.components.small_watershed.AppSmallWatershed(watersheds=<factory>, area_factor=1.0, flow_factor=1.0, flow_time_unit='', rz_solver_tolerance=1e-08, rz_max_iterations=2000, rz_length_factor=1.0, rz_cn_factor=1.0, rz_k_factor=1.0, rz_k_time_unit='', aq_gw_factor=1.0, aq_time_factor=1.0, aq_time_unit='', ic_factor=1.0, budget_output_file='', final_results_file='')[source]#
Bases:
BaseComponentSmall Watershed application component.
This class manages all small watersheds in the model domain including watershed units with root zone and aquifer parameters. It mirrors IWFM’s Package_AppSmallWatershed.
- Variables:
watersheds (dict[int, pyiwfm.components.small_watershed.WatershedUnit]) – Dictionary mapping watershed ID to WatershedUnit
area_factor (float) – Area conversion factor
flow_factor (float) – Flow rate conversion factor
flow_time_unit (str) – Time unit for flow rates
rz_solver_tolerance (float) – Root zone solver tolerance
rz_max_iterations (int) – Root zone solver max iterations
rz_length_factor (float) – Root zone length conversion factor
rz_cn_factor (float) – Curve number conversion factor
rz_k_factor (float) – Hydraulic conductivity conversion factor
rz_k_time_unit (str) – Time unit for hydraulic conductivity
aq_gw_factor (float) – GW conversion factor
aq_time_factor (float) – Time conversion factor
aq_time_unit (str) – Time unit for recession coefficients
budget_output_file (str) – Path to budget output file
final_results_file (str) – Path to final simulation results file
- watersheds: dict[int, WatershedUnit]#
- validate()[source]#
Validate the small watershed component.
- Raises:
ComponentError – If component is invalid
- classmethod from_config(config)[source]#
Create component from a parsed SmallWatershedMainConfig.
- Parameters:
config (SmallWatershedMainConfig) – Parsed configuration from the reader
- Returns:
AppSmallWatershed instance
- Return type:
- __init__(watersheds=<factory>, area_factor=1.0, flow_factor=1.0, flow_time_unit='', rz_solver_tolerance=1e-08, rz_max_iterations=2000, rz_length_factor=1.0, rz_cn_factor=1.0, rz_k_factor=1.0, rz_k_time_unit='', aq_gw_factor=1.0, aq_time_factor=1.0, aq_time_unit='', ic_factor=1.0, budget_output_file='', final_results_file='')#
Unsaturated Zone Module#
The unsaturated zone module contains classes for representing unsaturated zone layers and element-level soil moisture processes.
Unsaturated Zone component classes for IWFM models.
This module provides classes for representing the unsaturated (vadose) zone, including per-element layer properties and initial moisture conditions. It mirrors IWFM’s Package_AppUnsatZone.
- class pyiwfm.components.unsaturated_zone.UnsatZoneLayer(thickness_max=0.0, total_porosity=0.0, lambda_param=0.0, hyd_cond=0.0, kunsat_method=0)[source]#
Bases:
objectPer-layer unsaturated zone properties for a single element.
- Variables:
- __init__(thickness_max=0.0, total_porosity=0.0, lambda_param=0.0, hyd_cond=0.0, kunsat_method=0)#
- class pyiwfm.components.unsaturated_zone.UnsatZoneElement(element_id=0, layers=<factory>, initial_moisture=None)[source]#
Bases:
objectPer-element unsaturated zone data.
- Variables:
element_id (int) – 1-based element ID
layers (list[pyiwfm.components.unsaturated_zone.UnsatZoneLayer]) – List of per-layer properties
initial_moisture (numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float64]] | None) – Initial soil moisture per layer (optional)
- layers: list[UnsatZoneLayer]#
- __init__(element_id=0, layers=<factory>, initial_moisture=None)#
- class pyiwfm.components.unsaturated_zone.AppUnsatZone(n_layers=0, elements=<factory>, solver_tolerance=1e-08, max_iterations=2000, coord_factor=1.0, thickness_factor=1.0, hyd_cond_factor=1.0, time_unit='', n_parametric_grids=0, budget_file='', zbudget_file='', final_results_file='')[source]#
Bases:
BaseComponentUnsaturated Zone application component.
This class manages the vadose zone modeling parameters for all elements. It mirrors IWFM’s Package_AppUnsatZone.
- Variables:
n_layers (int) – Number of unsaturated zone layers
elements (dict[int, pyiwfm.components.unsaturated_zone.UnsatZoneElement]) – Dictionary mapping element ID to UnsatZoneElement
solver_tolerance (float) – Solver convergence tolerance
max_iterations (int) – Maximum solver iterations
coord_factor (float) – Conversion factor for x-y coordinates
thickness_factor (float) – Conversion factor for layer thickness
hyd_cond_factor (float) – Conversion factor for hydraulic conductivity
time_unit (str) – Time unit for hydraulic conductivity
n_parametric_grids (int) – Number of parametric grids (0=direct input)
budget_file (str) – Path to HDF5 budget output file
zbudget_file (str) – Path to HDF5 zone budget output file
final_results_file (str) – Path to final simulation results file
- elements: dict[int, UnsatZoneElement]#
- validate()[source]#
Validate the unsaturated zone component.
- Raises:
ComponentError – If component is invalid
- classmethod from_config(config)[source]#
Create component from a parsed UnsatZoneMainConfig.
- Parameters:
config (UnsatZoneMainConfig) – Parsed configuration from the reader
- Returns:
AppUnsatZone instance
- Return type:
- __init__(n_layers=0, elements=<factory>, solver_tolerance=1e-08, max_iterations=2000, coord_factor=1.0, thickness_factor=1.0, hyd_cond_factor=1.0, time_unit='', n_parametric_grids=0, budget_file='', zbudget_file='', final_results_file='')#
Connectors Module#
The connectors module contains classes for representing interactions between different model components.
Component connectors for IWFM models.
This module provides classes for representing connections between model components: stream-groundwater, lake-groundwater, and stream-lake interactions. It mirrors IWFM’s Package_ComponentConnectors.
- class pyiwfm.components.connectors.StreamGWConnection(stream_node_id, gw_node_id, layer=1, conductance=0.0, stream_bed_elev=0.0, stream_bed_thickness=0.0)[source]#
Bases:
objectA connection between a stream node and groundwater node.
- Variables:
- __init__(stream_node_id, gw_node_id, layer=1, conductance=0.0, stream_bed_elev=0.0, stream_bed_thickness=0.0)#
- class pyiwfm.components.connectors.StreamGWConnector(connections=<factory>)[source]#
Bases:
objectConnector managing stream-groundwater interactions.
This class manages all connections between stream nodes and groundwater nodes, calculating exchange flows based on head differences and conductances.
- Variables:
connections (list[pyiwfm.components.connectors.StreamGWConnection]) – List of stream-groundwater connections
- connections: list[StreamGWConnection]#
- calculate_flow(stream_node_id, stream_stage, gw_head)[source]#
Calculate stream-aquifer exchange flow for a stream node.
Positive flow = stream to aquifer (losing stream) Negative flow = aquifer to stream (gaining stream)
- __init__(connections=<factory>)#
- class pyiwfm.components.connectors.LakeGWConnection(lake_id, gw_node_id, layer=1, conductance=0.0, lake_bed_elev=0.0, lake_bed_thickness=0.0)[source]#
Bases:
objectA connection between a lake and groundwater node.
- Variables:
- __init__(lake_id, gw_node_id, layer=1, conductance=0.0, lake_bed_elev=0.0, lake_bed_thickness=0.0)#
- class pyiwfm.components.connectors.LakeGWConnector(connections=<factory>)[source]#
Bases:
objectConnector managing lake-groundwater interactions.
This class manages all connections between lakes and groundwater nodes, calculating exchange flows based on head differences.
- Variables:
connections (list[pyiwfm.components.connectors.LakeGWConnection]) – List of lake-groundwater connections
- connections: list[LakeGWConnection]#
- calculate_flow(lake_id, lake_stage, gw_head)[source]#
Calculate lake-aquifer exchange flow.
Positive flow = lake to aquifer (losing lake) Negative flow = aquifer to lake (gaining lake)
- __init__(connections=<factory>)#
- class pyiwfm.components.connectors.StreamLakeConnection(stream_node_id, lake_id, connection_type, max_flow=inf)[source]#
Bases:
objectA connection between a stream node and a lake.
- Variables:
- __init__(stream_node_id, lake_id, connection_type, max_flow=inf)#
- class pyiwfm.components.connectors.StreamLakeConnector(connections=<factory>)[source]#
Bases:
objectConnector managing stream-lake interactions.
This class manages connections where streams flow into or out of lakes.
- Variables:
connections (list[pyiwfm.components.connectors.StreamLakeConnection]) – List of stream-lake connections
- connections: list[StreamLakeConnection]#
- __init__(connections=<factory>)#