pywrdrb.ModelBuilder#
- class pywrdrb.ModelBuilder(start_date, end_date, inflow_type, diversion_type=None, options={})#
A model builder to create model file Pywr for the Delaware River Basin (DRB).
ModelBuilder class to construct a pywr model for the Delaware River Basin. Essentially, this class creates model dictionary to hold all model nodes, edges, params, etc, following Pywr protocol. The model dictionary will be saved to a JSON file.
- start_date#
Start date of the model simulation.
- Type:
str
- end_date#
End date of the model simulation.
- Type:
str
- inflow_type#
Type of inflow data to use. Options are ‘nhmv10_withObsScaled’, ‘nwmv21_withObsScaled’, ‘nhmv10’, and ‘nwmv21’.
- Type:
str
- diversion_type#
Type of diversion data to use. Default is None.
- Type:
str, optional
- options#
Options for the model builder, including number of scenarios, inflow ensemble indices, and other parameters.
- Type:
Options
- reservoirs#
List of reservoirs in the model.
- Type:
list
- edges#
List of edges in the model.
- Type:
list
- parameters#
List of parameters in the model.
- Type:
list
- levels#
List of reservoir operational regimes.
- Type:
list
- EPS#
A small epsilon value for numerical stability.
- Type:
float
- model_dict#
Dictionary to hold the model structure, including metadata, timestepper, parameters, etc.
- Type:
dict
- istarf#
DataFrame to hold the ISTARF data for reservoir capacities.
- Type:
pd.DataFrame, optional
- hist_releases#
DataFrame to hold historical releases data for NYC reservoirs.
- Type:
pd.DataFrame, optional
- hist_diversions#
DataFrame to hold historical diversions data for NYC reservoirs.
- Type:
pd.DataFrame, optional
- reset_model_dict()#
Resets the model dictionary to its initial state.
- make_model()#
Constructs the model by adding nodes, edges, and parameters based on the DRB structure.
- write_model(model_filename)#
Writes the model dictionary to a JSON file.
- detach_data()#
Detaches data from the model builder to release memory.
- _get_reservoir_capacity(reservoir)#
Returns the capacity of a reservoir from the ISTARF data.
- _get_reservoir_max_release(reservoir, release_type)#
Returns the maximum release for a reservoir based on historical data.
- _get_reservoir_max_diversion_NYC(reservoir)#
Returns the maximum diversion for a NYC reservoir based on historical data.
- _add_ensemble_inflow_scenarios(inflow_ensemble_indices)#
Adds ensemble inflow scenarios to the model based on provided indices.
- add_parameter_negative_one_multiplier()#
Adds a parameter to the model that is a constant multiplier of -1.0.
- add_node_major_reservoir(reservoir_name, downstream_lag, downstream_node)#
Adds a major reservoir node to the model, including its associated nodes and edges.
- add_node_major_river(node, downstream_lag, downstream_node, has_catchment)#
Adds a major river node to the model, including its associated nodes and edges.
- add_node_final_basin_outlet()#
Adds the final basin outlet node to the model, which is the Trenton node.
- add_node_nyc_aggregated_storage_and_link()#
Adds a node for NYC aggregated storage and links it to the reservoirs.
- add_node_nyc_and_nj_deliveries()#
Adds nodes for NYC and NJ deliveries, which are the demands for the model.
- add_parameter_nyc_and_nj_demands()#
Adds parameters for NYC and NJ demands based on historical or predicted data.
- add_parameter_nyc_reservoirs_operational_regimes()#
Adds parameters for the operational regimes of NYC reservoirs.
- add_parameter_nyc_and_nj_delivery_constraints()#
Adds parameters for the delivery constraints of NYC and NJ reservoirs.
- add_parameter_nyc_reservoirs_min_require_flow()#
Adds parameters for the minimum required flow for NYC reservoirs.
- add_parameter_nyc_reservoirs_flood_control()#
Adds parameters for flood control releases from NYC reservoirs.
- add_parameter_nyc_reservoirs_variable_cost_based_on_fractional_storage()#
Adds parameters for variable costs based on fractional storage in NYC reservoirs.
- add_parameter_nyc_reservoirs_current_volume()#
Adds parameters for the current volume of NYC reservoirs.
- add_parameter_nyc_reservoirs_aggregated_info()#
Adds parameters for aggregated information of NYC reservoirs.
- add_parameter_nyc_bank_storage()#
Adds parameters for NYC bank storage, which is a storage node for NYC reservoirs.
- add_parameter_montague_trenton_flow_targets()#
Adds parameters for flow targets between Montague and Trenton.
- add_parameter_predicted_lagged_non_nyc_inflows_to_Montague_and_Trenton_and_lagged_nj_demands()#
Adds parameters for predicted lagged non-NYC inflows to Montague and Trenton, and lagged NJ demands.
- add_parameter_nyc_reservoirs_balancing_methods()#
Adds parameters for balancing methods for NYC reservoirs, including flood control and FFMP releases.
- add_parameter_temperature_model()#
Adds parameters to couple the temperature LSTM model with the reservoir model.
- add_parameter_couple_salinity_lstm()#
Adds parameters to couple the salinity LSTM model with the reservoir model.
- __init__(start_date, end_date, inflow_type, diversion_type=None, options={})#
Initialize the ModelBuilder.
- Parameters:
start_date (str) – Start date of the model simulation.
end_date (str) – End date of the model simulation.
inflow_type (str) – Type of inflow data to use. Options are ‘nhmv10_withObsScaled’, ‘nwmv21_withObsScaled’, ‘nhmv10’, ‘nwmv21’, and “wrfaorc_withObsScaled”.
diversion_type (str, optional) – Type of diversion data to use. Default is None (historical average).
options (dict, optional) – Dictionary of options to pass to the model builder. Options include: inflow_ensemble_indices (list of int): List of indices to use for inflow ensemble scenarios. use_hist_NycNjDeliveries (bool): If True, we use historical NYC/NJ deliveries as demand, else we use predicted demand. Otherwise, assume demand is equal to max allotment under FFMP. temperature_model (dict): If given, we use LSTM model to predict temperature at Lordville. salinity_model (dict): If given, we use LSTM model to predict salinity at Trenton. run_starfit_sensitivity_analysis (bool): If True, we run STARFIT sensitivity analysis. sensitivity_analysis_scenarios (list of str): List of scenarios to use for STARFIT sensitivity analysis. initial_volume_frac (float): Initial reservoir storage as a fraction of capacity. Default is 0.8.
Methods
__init__
(start_date, end_date, inflow_type)Initialize the ModelBuilder.
add_ensemble_inflow_scenarios
(...)Add ensemble inflow scenarios to the model based on provided indices.
Add a final basin outlet node to the model.
add_node_major_reservoir
(reservoir_name, ...)Add a major reservoir node to the model.
add_node_major_river
(name, downstream_lag, ...)Add a major river node to the model.
Add a node for aggregated NYC storage and links to each reservoir.
Add nodes for NYC and NJ deliveries, linking them to the respective reservoirs.
Add parameters defining flow targets at Montague and Trenton based on drought levels of NYC aggregated storage.
Add a parameter to the model that is a constant multiplier of -1.0.
Add parameters defining delivery constraints for NYC and NJ under normal and drought conditions.
Add nyc and nj demands to model parameters.
Add parameters defining NYC bank storages, specifically the IERQ remaining volume for each bank.
Add parameters defining aggregated information for NYC reservoirs, including total volume, inflows, and maximum volume.
Add parameters for balancing methods for NYC reservoirs.
Add parameters defining the current volume stored in each NYC reservoir.
Add parameters defining flood control releases from NYC reservoirs based on FFMP.
Add parameters defining minimum release flow requirements from NYC reservoirs based on FFMP.
Add parameters defining operational regimes for NYC reservoirs based on combined storage.
add_parameter_nyc_reservoirs_variable_cost_based_on_fractional_storage
()Add parameters defining variable storage cost for each NYC reservoir based on its fractional storage.
add_parameter_predicted_lagged_non_nyc_inflows_to_Montague_and_Trenton_and_lagged_nj_demands
()Add parameters for predicted lagged non-NYC inflows to Montague and Trenton, and predicted lagged NJ demands.
add_parameter_salinity_model
()Add parameters for salinity prediction using LSTM model.
Add parameters for temperature prediction using LSTM model.
Detach data from the model builder to release memory.
Make the model by adding nodes, edges, and parameters based on the DRB structure.
Reset the model dictionary to its initial state.
write_model
(model_filename)Write the model to a JSON file.