Modules Reference

glory.model

Model interface for GLORY.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

glory.model.execute(config, basin_id, period)[source]

Execute

glory.model.run_model(config_file)[source]

Run GLORY model

glory.method.lp

Linear programming model.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

glory.method.lp.lp_model(K, Smin, Ig, Eg, f, p, z, m, solver='glpk')[source]

Construct Capacity-Yield Curve with Linear Programming Model.

Parameters:
  • K – float for reservoir storage capacity

  • Smin – int for minimum required active storage for the reservoir

  • Ig – float for annual average inflow (over GCAM 5 year time period) to reference reservoirs that has q total storage capacity of Kgref

  • Eg – float for annual average evaporation (over GCAM 5 year time period) from reference reservoirs that has q total storage capacity of Kgref

  • f – dictionary for demand fraction profile

  • p – dictionary for inflow fraction profile

  • z – dictionary for evaporation fraction profile

  • m – float for fraction of flow released from distributed reservoirs that’s reusable in the river system

Returns:

array for capacity - yield curve

glory.method.lp.lp_solution(model, K, basin_id, period)[source]
Parameters:
  • model – pyomo model object

  • K – float for storage capacity

  • basin_id – int for basin id

  • period – int for model period

Returns:

data frame for all the water balance variables

glory.method.supply_curve

Supply curves.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

class glory.method.supply_curve.SupplyCurve(config, basin_id, period, demand_gcam, capacity_gcam)[source]

Bases: object

Calculate supply curves based on Capacity-Yield curves from linear programming model

USAGE: SupplyCurve(basin_id=id,

period=period, demand_gcam=demand_gcam, capacity_gcam=capacity_gcam)

construct_maxsubresource()[source]

Construct new maxSubResource dataframe based on the max supply constrained by the max capacity.

Returns:

construct_supply_curve()[source]

Construct supply curve.

Returns:

2D numpy array

cost_per_expansion()[source]

Calculate the cost in 1975 USD per unit reservoir storage capacity expansion

Returns:

float in million 1975$

get_20_even_point_supply_curve(supply_curve_raw)[source]

This is to get 20 evenly spaced point on supply sequence to get the curve.

Parameters:

supply_curve_raw

Returns:

get_20_point_supply_curve(supply_curve_raw)[source]

This is to get 20-point sequence of yields with monotonic cubic spline.

Parameters:

supply_curve_raw – dataframe for raw supply curve without supply sequence spacing and smoothing

Returns:

get_capacity_yield_constrained()[source]

Constrain the capacity yield curve by max capacity.

Returns:

get_capacity_yield_unconstrained()[source]

Calculate capacity yield curve.

Returns:

dataframe

get_expansion_sequence()[source]

Determine the evenly spaced intervals for incremental storage capacity and get capacity expansion sequence.

Returns:

1D array

get_reservoir_evap(capacity_track)[source]

calculate reservoir surface area based on current storage capacity. Calculate reservoir ET in km3/year based on the new storage capacity in each basin.

Parameters:

capacity_track – list for reservoir capacity expansion track

Returns:

get_yield_gain_sequence()[source]

Calculate yield increments sequence based on reservoir storage capacity expansion. two segments of yield increment sequences: (1) before max capacity and (2) after max capacity

Returns:

1D array

levelized_cost()[source]

Calculate levelized cost of storage capacity (LCOSC) as 1975 USD per unit water yield.

Returns:

1D numpy array

run_lp_model(capacity, capacity_track)[source]

Run LP model.

Parameters:
  • capacity – float for target capacity

  • capacity_track – list for tracking capacity at each iteration

Returns:

value for optimized yield

set_dx()[source]

The algorithm of choosing dx in this section is to prevent the LP model running over 500 iterations, or not enough iterations (<50). However, another thing to notice is that the inflection point when reaches mean annual inflow. This requires we make sure there are enough iteration before the inflection point (20 or more). The algorithm is used to detect if the yield value with K = dx is less than 0.05 of Ig or Y0+0.05(Ig-Y0) if Y0 != 0, dx is reduced to 1/2 until dx satisfies the condition.

Returns:

none

glory.data.read_config

Module to load configuration data.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

class glory.data.read_config.ConfigReader(config_file=None)[source]

Bases: object

Read config file

static create_dir(pth)[source]

Check to see if the target path exists and create directory.

static read_config(config_file=None)[source]

Load configuration file.

Parameters:

config_file (string) – configuration file path

Returns:

glory.data.read_data

Module to load input data files.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

class glory.data.read_data.DataLoader(config, basin_id, period, base_period=2020, demand_gcam=None, capacity_gcam=None)[source]

Bases: object

Load Data

get_current_capacity()[source]

calculate if there will be expansion on storage capacity.

Returns:

float value for storage capacity

get_demand_profile()[source]

Calculate total demand profile with historical sectoral profile and sectoral demand.

Returns:

dictionary

get_max_capacity()[source]

Adjust maximum storage capacity value only if the basin have no expandable capacity. Max storage capacity input data for some basins is already adjusted based on the historical storage capacity.

Returns:

float64

static load_basin_mapping(f_basin_country, f_basin_region, header_num=7)[source]

Mapping different formats of basin names.

Parameters:
  • f_basin_country – string for full file path to basin-country mapping file

  • f_basin_region – string for full file path to basin-region mapping file

  • header_num – integer for numbers of rows to skip until the header

Returns:

dataframe

load_data(fn, header_num=0)[source]

Load data from a CSV file to pandas dataframe.

Parameters:
  • fn – string for name of file to load

  • header_num – integer for number of lines in file to skip, if text or csv file

Returns:

pandas dataframe

load_gcam_demand()[source]

Load and Format data extract from GCAM using gcamwrapper. The data should be for 235 basins, 6 demand sectors, and a single time period.

Returns:

dataframe for sectoral annual demand for selected basin

glory.data.write_outputs

Module to write output data.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

glory.data.write_outputs.write_csv(var, data, period, out_path)[source]

Write csv outputs

Parameters:
  • var – string for output variable name

  • data – df or numpy array for outputs

  • out_path – output_path

Returns:

glory.data.write_outputs.write_outputs(config, outputs)[source]

Write outputs

Parameters:

outputs – class object for outputs

Returns:

glory.utils.diagnostics

Module to create diagnostic figures.

@author: Mengqi Zhao (mengqi.zhao@pnnl.gov)

@Project: GLORY v1.0

License: BSD 3-Clause, see LICENSE and DISCLAIMER files

Copyright (c) 2023, Battelle Memorial Institute

glory.utils.diagnostics.diagnostics(config, outputs, fig_path=None)[source]

Plot capacity yield curve.