wmpy-power


Namewmpy-power JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryEstimates hydropower generation accounting for operating constraints and electricity grid operations.
upload_time2024-03-06 22:26:58
maintainer
docs_urlNone
author
requires_python<3.12,>=3.9
license{ file = "LICENSE" }
keywords hydropower water
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # wmpy_power

`wmpy_power` is a hydropower generation simulation model that uses a physically-based representation of hydropower generation. The model parameterizes production using physically-meaningful parameters that are calibrated using a reference generation dataset.

#### To Do List
* Write automated tests
* Example batch jobs for parallel BA

### Documentation
#### Introduction
`wmpy_power` simulates hydropower generation using a physically-based representation
of hydropower generation ([Zhou et al., 2018](https://doi.org/10.1088/1748-9326/aad19f)).
Hydropower generation is simulated using timeseries of inflow and storage, and plant
characteristics including nameplate capacity, average head, and reservoir storage capacity (where applicable). Model parameters are calibrated to a reference monthly hydropower
generation dataset - typically historical generation - using the shuffle complex
evolution algorithm (SCE; [Duan et al., 1993](https://doi.org/10.1007/BF00939380)).
A two-stage calibration is performed: first at the balancing authority (BA) scale, and
second at the facility scale.

The model is designed to work with inflow and storage simulated by the mosartwmpy
routing and water management model ([Thurber et al., 2021](https://doi.org/10.21105/joss.03221)),
however is agnostic to the source of these data.

#### Calculations
`wmpy_power` uses a simple hydropower generation formula to calculate hydropower generation:

$$ P=\rho ghQ \eta \ (1) $$

|     Variable    |     Variable in Code                                   |     Definition                           |     Units     |     Value                         |
|-----------------|--------------------------------------------------------|------------------------------------------|---------------|-----------------------------------|
|     ρ           |     lumped in with gravitational acceleration; 9800    |     density of water                     |     kg m-3    |     1000                          |
|     g           |     lumped in with density of water; 9800              |     gravitational acceleration           |     m3s-2     |     9.81                          |
|     h           |     plant_head_m                                       |     gross hydraulic head of the hydropower facility            |     m         |     plant-specific                |
|     Q           |     flow                                               |     turbine flow rate                    |     m3s-1     |     plant-specific timeseries     |
|     η           |     not directly used; see below                       |     non-dimensional efficiency   term    |     –         |     plant-specific                |

This general formulation (equation 1) is modified for use in the model to accommodate parameters being calibrated, and to accommodate two cases of hydropower generation, run-of-river (ROR) plants, and plants associated with reservoirs. For both cases of generation, the non-dimensional efficiency term (η) is replaced with a combined efficiency and bias correction factor f<sub>b</sub>:

$$ P=\rho ghQf_b \ (2) $$

| Variable | Variable in Code | Definition                                                   | Units | Value                                                   | Range    |
|----------|------------------|--------------------------------------------------------------|-------|---------------------------------------------------------|----------|
| fb       | efficiency_spill | non-dimensional efficiency term and bias correction factor | –     | balancing authority-specific; calibrated in step one  | 0.5-1.5  |


This efficiency term is calibrated at the BA level in step one of the calibration. NOTE: alternative groupings of plants can be used in place of BAs; the BA variable is used by the code, but values can be replaced with other grouping identifiers, for example HUC4 basins.

Q is adjusted to account for both plant-specific maximum flow limits and spill. Maximum flow limits are imposed by limiting Q to a maximum value using Q<sub>max</sub> where:

$$ Q_{max} =S_f \ (3) $$ \
$$ Q =min(Q, Q_max) \ (4) $$

|     Variable    |     Variable in Code                   |     Definition                        |     Units     |     Value                                       |     Range      |
|-----------------|----------------------------------------|---------------------------------------|---------------|-------------------------------------------------|----------------|
|     Qmax        |     max_discharge                      |     density of water                  |     kg m-3    |     1000                                        |                |
|     S           |     nameplate_capacity_MW              |     nameplate capacity                |     W         |     plant-specific; from PLEXOS                 |                |
|     fm          |     efficiency_penstock_flexibility    |     penstock   intake scale factor    |     –         |     plant-specific; calibrated   in step two    |     0.5-1.5    |
|     g           |                                        |     gravitational acceleration        |     m3s-2     |     9.81                                        |                |
|     h           |     head                               |     hydraulic head of the dam         |     m         |     plant-specific                              |                |

Q is adjusted for spill by month using plant-specific monthly spill correction factors developed in step two of the calibration. These spill correction factors are applied as:

$$ Q_sc,m =Q_m(1 -f_f,m); m = {1,2, ..., 12} \ (5) $$

| Variable | Variable in Code     | Definition                                  | Units | Value                                    | Range   |
|----------|----------------------|---------------------------------------------|-------|------------------------------------------|---------|
| fs,m     | monthly_spill        | monthly spill correction factors            | –     | plant-specific; calibrated in step   two | 0-1     |
| fp       | penstock_flexibility | penstock flexibility of handling   max flow | –     | plant-specific; calibrated in step   two | 0.5-1.5 |

##### Run-of-River (ROR) Facilities
Generation for ROR plants is calculated using the hydropower generation formula and setting the head (h) to a fixed value equal to the dam height.

##### Reservoir Facilities
Generation for hydropower plants with reservoirs is calculated using the hydropower generation formula, with the head estimated using simulated volumetric storage, total volumetric capacity, and assuming that the shape of the reservoir is a tetrahedron:

$$ h=H^3\sqrt{\frac{v}{v_{max}}} \ (6) $$

| Variable | Variable in Code    | Definition                    | Units | Value                      |
|----------|---------------------|-------------------------------|-------|----------------------------|
| h        | height              | hydraulic head of the dam     | m     | plant-specific             |
| H        | plant_head_m        | dam height                    | m     | plant-specific             |
| V        | storage             | reservoir storage             | m3    | plant-specific timeseries  |
| Vmax     | storage_capacity_m3 | reservoir volumetric capacity | m3    | plant-specific             |

##### Shuffled Complex Evolution (SCE) Implementation
SCE is used to implement a two-step multiscale calibration that produces the inputs required for the hydropower generation formula (equation 2). Step one of the calibration is to address the errors in annual hydro-meteorological biases at the scale of hydrologic regions. The objective function used in step one is to minimizes the mean absolute error between annual observed potential generation and annual simulated potential generation at the BA level:

$$ PG_{BA,sim} =  \sum_{i=1}^n \rho gh_i Q_i f_{b,i} \ (6) $$
$$ PG_{BA,obs} =  TL_{2010} \times 0.04 + \sum_{i=1}^n G_{obs,i} \ (7) $$
$$ MAE_{PG} =  \sum_{i=1}^n \lvert PG_{BA_{sim,i}} - PG_{BA_{obs,i}} \rvert \ (8) $$

Potential generation is computed as:

$$ PG = G + R \ (10) $$
$$ R = 0.04TL \ (11) $$

|     Variable    |     Definition              |     Units    |     Value                                            |
|-----------------|-----------------------------|--------------|------------------------------------------------------|
|     PG          |     potential generation    |     MWh      |     computed at the BA scale                         |
|     G           |     actual generation       |     MWh      |     input at the plant scale                         |
|     R           |     operating reserve       |     MWh      |     calculated as 4% of the TL                       |
|     TL          |     total load              |     MWh      |     mean of annual generation   of years provided    |

The operating reserve percentage is set to as default to 4% of total load in model.py (operating_reserve_percent). This can be changed in model configuration.

Step two of the calibration seeks to reflect the complexity in monthly multi-objective reservoir operations and daily generation constraints. It works to improve seasonal variation for each power plant by calibrating a penstock flexibility factor (fp) and monthly spill correction factors (fs,1, fs,2,…, fs,12). The objective function used in step two is to minimize the Kling-Gupta Efficiency between simulated monthly power generation and observed monthly power generation at the plant level:

$$ KGE=1-\sqrt{(r-1)^2 + \left(\frac{sd(G_{sim})}{sd(G_{obs})}\right)^2 + \left(\frac{mean(G_{sim})}{mean(G_{obs})}\right)^2}\ (12) $$
$$ r = cor(G_{sim}, G_{obs}) \ (13) $$


|     Variable    |     Definition                      |     Units    |     Value                          |
|-----------------|-------------------------------------|--------------|------------------------------------|
|     Gsim        |     simulated monthly generation    |     MW       |     computed at the plant scale    |
|     Gobs        |     observed monthly generation     |     MW       |     input at the plant scale       |

#### Model Setup
The model repository contains documentation and example code for setting up and running the model. It is built as a Python package and the scripts can be imported into a Python environment.

##### Model Inputs
Model inputs are specified in the run script.

| Input                                    |                                        |       Description                                                                                        |     Format      |
|------------------------------------------|----------------------------------------|----------------------------------------------------------------------------------------------------------|-----------------|
|     daily simulated flow and storage     |     simulated_flow_and_storage_glob    |     daily simulated flow and storage, typically from a MOSART   simulation, for each hydropower plant    |     .parquet    |
|     observed monthly power generation    |     observed_hydropower_glob           |     observed monthly hydropower generation for each hydropower   plant                                   |     .parquet    |
|     reservoir and plant parameters       |     reservoir_parameter_glob           |     reservoir and hydropower plant static parameters                                                     |     .parquet    |



Many configuration options are available for running the model. These options can be specified in a configuration yaml
file or passed directly to the model initialization method, or both (the latter takes precedence). Most options have
sensible defaults, but a few are required as discussed below. For the full list of configuration options, see the
`config.yaml` file in the repository root.

Dependencies are listed in the `setup.cfg` file.
To install dependencies, run `pip install -e .` from the root directory of this repository.

There are two ways to run the model. The simplest is to provide a configuration file and run the model directly:

config.yaml
```yaml
# first year of calibration data
calibration_start_year: 1984
# last year of calibration data
calibration_end_year: 2008
# balancing authority or list of balancing authorities to calibrate
balancing_authority:
  - WAPA
# glob to files with simulated daily flow and storage for plants in the balancing authorities
simulated_flow_and_storage_glob: ./inputs/**/*flow*storage*.parquet
# glob to files with observed monthly hydropower for plants in the balancing authorities
observed_hydropower_glob: ./inputs/**/*monthly*obs*.parquet
# glob to files with reservoir/plant parameters for plants in the balancing authorities
reservoir_parameter_glob: ./inputs/**/*PLEXOS*.parquet
```

```commandline
python wmpy_power/model.py config.yaml
```

Alternatively, the model can be invoked from a python script or console:
```python
from wmpy_power import Model

# you can initialize the model using the configuration file:
model = Model('config.yaml')
# or directly:
model = Model(
  calibration_start_year=1984,
  calibration_end_year=2008,
  balancing_authority=['WAPA'],
  simulated_flow_and_storage_glob='./inputs/**/*daily*flow*storage*.parquet',
  observed_hydropower_glob='./inputs/**/*monthly*obs*.parquet',
  reservoir_parameter_glob='./inputs/**/*PLEXOS*.parquet',
)
# or both (keyword arguments take precedence)
model = Model(
  'config.yaml',
  balancing_authority=['CAISO'],
  output_type='csv',
)

# run the model (this will write the calibrations to file but also return a DataFrame
calibrations = model.run()

# plot each plant's modeled hydropower versus observed hydropower
model.plot(calibrations)

# get modeled generation for the calibrations and write to file
generation = Model.get_generation(
  './**/*_plant_calibrations.csv',
  './inputs/*reservoir_parameter*.parquet',
  './inputs/**/*daily*flow*storage*.parquet',
)
```

By default, the model writes the calibrated parameters to a parquet file per balancing  in the current working
directory, but this behavior can be overridden using the `output_path` and `output_type` configuration options.
So far only "csv" and "parquet" formats are supported.

#### Input Files

Daily flow and storage parquet files are expected to have these columns:

column       | example     | units   |
-------------|-------------|---------|
date         | 1980-01-01  | date    |
eia_plant_id | 153         | integer |
flow         | 461.003906  | m^3 / s |
storage      | 1.126790e10 | m^3     |

Monthly observed hydropower parquet files are expected to have these columns:

column         | example   | units   |
---------------|-----------|---------|
year           | 1980      | integer |
month          | 1         | integer |
eia_plant_id   | 153       | integer |
generation_MWh | 38221.193 | MWh     |

Reservoir/plant parameter parquet files are expected to have these columns:

column                | example | units   |
----------------------|---------|---------|
eia_plant_id          | 153     | integer |
balancing_authority   | WAPA    | string  |
name                  | 1980    | integer |
nameplate_capacity_MW | 1       | MW      |
plant_head_m          | 5123.3  | m       |
storage_capacity_m3   | 1.5e10  | m^3     |
use_run_of_river      | True    | boolean |


#### Notebook

The `tutorial.ipynb` file provides a Jupyter notebook illustration of running the model and plotting results.

#### Working with Parquet files

It's easy to read and write parquet files from pandas, just `pip install pyarrow` or `conda install pyarrow`, then:
```python
import pandas as pd
df = pd.read_parquet('/path/to/parquet/file.parquet')
df['my_new_column'] = 42
df.to_parquet('/path/to/new/parquet/file.parquet')
```
#### Legacy Files
wmpy_power was originally developed in MATLAB. The model provides a utility to convert Excel and MATLAB files to parquet files. This functionality can also be used to build inputs in Excel and convert them into parquet.

```python
from wmpy_power import Model

Model.update_legacy_input_files(
  daily_flow_storage_path='/path/to/flow/storage/matlab/file.mat',
  reservoir_parameters_path='/path/to/plexos/parameters/excel/file.xlsx',
  monthly_observed_generation_path='/path/to/observed/generation/excel/file.xlsx',
  daily_start_date='1980-01-01', # for daily flow/storage, since this isn't mentioned in the file itself, have to assume a start date
  monthly_start_date='1980-01-01', # for monthly observed hydro, since this isn't mentioned in the file itself, have to assume a start month
  output_path=None, # defaults to the same place as the input files, but with the .parquet extension
  includes_leap_days=False, # whether or not the daily data includes entries for leap days (Tian's files don't)
)
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "wmpy-power",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.12,>=3.9",
    "maintainer_email": "",
    "keywords": "hydropower,water",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/13/98/1d710bddc937296ed055da3259568c5a5970b78b09ebd9df80058c42eaed/wmpy_power-1.0.0.tar.gz",
    "platform": null,
    "description": "# wmpy_power\n\n`wmpy_power` is a hydropower generation simulation model that uses a physically-based representation of hydropower generation. The model parameterizes production using physically-meaningful parameters that are calibrated using a reference generation dataset.\n\n#### To Do List\n* Write automated tests\n* Example batch jobs for parallel BA\n\n### Documentation\n#### Introduction\n`wmpy_power` simulates hydropower generation using a physically-based representation\nof hydropower generation ([Zhou et al., 2018](https://doi.org/10.1088/1748-9326/aad19f)).\nHydropower generation is simulated using timeseries of inflow and storage, and plant\ncharacteristics including nameplate capacity, average head, and reservoir storage capacity (where applicable). Model parameters are calibrated to a reference monthly hydropower\ngeneration dataset - typically historical generation - using the shuffle complex\nevolution algorithm (SCE; [Duan et al., 1993](https://doi.org/10.1007/BF00939380)).\nA two-stage calibration is performed: first at the balancing authority (BA) scale, and\nsecond at the facility scale.\n\nThe model is designed to work with inflow and storage simulated by the mosartwmpy\nrouting and water management model ([Thurber et al., 2021](https://doi.org/10.21105/joss.03221)),\nhowever is agnostic to the source of these data.\n\n#### Calculations\n`wmpy_power` uses a simple hydropower generation formula to calculate hydropower generation:\n\n$$ P=\\rho ghQ \\eta \\ (1) $$\n\n|     Variable    |     Variable in Code                                   |     Definition                           |     Units     |     Value                         |\n|-----------------|--------------------------------------------------------|------------------------------------------|---------------|-----------------------------------|\n|     \u03c1           |     lumped in with gravitational acceleration; 9800    |     density of water                     |     kg m-3    |     1000                          |\n|     g           |     lumped in with density of water; 9800              |     gravitational acceleration           |     m3s-2     |     9.81                          |\n|     h           |     plant_head_m                                       |     gross hydraulic head of the hydropower facility            |     m         |     plant-specific                |\n|     Q           |     flow                                               |     turbine flow rate                    |     m3s-1     |     plant-specific timeseries     |\n|     \u03b7           |     not directly used; see below                       |     non-dimensional efficiency   term    |     \u2013         |     plant-specific                |\n\nThis general formulation (equation 1) is modified for use in the model to accommodate parameters being calibrated, and to accommodate two cases of hydropower generation, run-of-river (ROR) plants, and plants associated with reservoirs. For both cases of generation, the non-dimensional efficiency term (\u03b7) is replaced with a combined efficiency and bias correction factor f<sub>b</sub>:\n\n$$ P=\\rho ghQf_b \\ (2) $$\n\n| Variable | Variable in Code | Definition                                                   | Units | Value                                                   | Range    |\n|----------|------------------|--------------------------------------------------------------|-------|---------------------------------------------------------|----------|\n| fb       | efficiency_spill | non-dimensional efficiency term and bias correction factor | \u2013     | balancing authority-specific; calibrated in step one  | 0.5-1.5  |\n\n\nThis efficiency term is calibrated at the BA level in step one of the calibration. NOTE: alternative groupings of plants can be used in place of BAs; the BA variable is used by the code, but values can be replaced with other grouping identifiers, for example HUC4 basins.\n\nQ is adjusted to account for both plant-specific maximum flow limits and spill. Maximum flow limits are imposed by limiting Q to a maximum value using Q<sub>max</sub> where:\n\n$$ Q_{max} =S_f \\ (3) $$ \\\n$$ Q =min(Q, Q_max) \\ (4) $$\n\n|     Variable    |     Variable in Code                   |     Definition                        |     Units     |     Value                                       |     Range      |\n|-----------------|----------------------------------------|---------------------------------------|---------------|-------------------------------------------------|----------------|\n|     Qmax        |     max_discharge                      |     density of water                  |     kg m-3    |     1000                                        |                |\n|     S           |     nameplate_capacity_MW              |     nameplate capacity                |     W         |     plant-specific; from PLEXOS                 |                |\n|     fm          |     efficiency_penstock_flexibility    |     penstock   intake scale factor    |     \u2013         |     plant-specific; calibrated   in step two    |     0.5-1.5    |\n|     g           |                                        |     gravitational acceleration        |     m3s-2     |     9.81                                        |                |\n|     h           |     head                               |     hydraulic head of the dam         |     m         |     plant-specific                              |                |\n\nQ is adjusted for spill by month using plant-specific monthly spill correction factors developed in step two of the calibration. These spill correction factors are applied as:\n\n$$ Q_sc,m =Q_m(1 -f_f,m); m = {1,2, ..., 12} \\ (5) $$\n\n| Variable | Variable in Code     | Definition                                  | Units | Value                                    | Range   |\n|----------|----------------------|---------------------------------------------|-------|------------------------------------------|---------|\n| fs,m     | monthly_spill        | monthly spill correction factors            | \u2013     | plant-specific; calibrated in step   two | 0-1     |\n| fp       | penstock_flexibility | penstock flexibility of handling   max flow | \u2013     | plant-specific; calibrated in step   two | 0.5-1.5 |\n\n##### Run-of-River (ROR) Facilities\nGeneration for ROR plants is calculated using the hydropower generation formula and setting the head (h) to a fixed value equal to the dam height.\n\n##### Reservoir Facilities\nGeneration for hydropower plants with reservoirs is calculated using the hydropower generation formula, with the head estimated using simulated volumetric storage, total volumetric capacity, and assuming that the shape of the reservoir is a tetrahedron:\n\n$$ h=H^3\\sqrt{\\frac{v}{v_{max}}} \\ (6) $$\n\n| Variable | Variable in Code    | Definition                    | Units | Value                      |\n|----------|---------------------|-------------------------------|-------|----------------------------|\n| h        | height              | hydraulic head of the dam     | m     | plant-specific             |\n| H        | plant_head_m        | dam height                    | m     | plant-specific             |\n| V        | storage             | reservoir storage             | m3    | plant-specific timeseries  |\n| Vmax     | storage_capacity_m3 | reservoir volumetric capacity | m3    | plant-specific             |\n\n##### Shuffled Complex Evolution (SCE) Implementation\nSCE is used to implement a two-step multiscale calibration that produces the inputs required for the hydropower generation formula (equation 2). Step one of the calibration is to address the errors in annual hydro-meteorological biases at the scale of hydrologic regions. The objective function used in step one is to minimizes the mean absolute error between annual observed potential generation and annual simulated potential generation at the BA level:\n\n$$ PG_{BA,sim} =  \\sum_{i=1}^n \\rho gh_i Q_i f_{b,i} \\ (6) $$\n$$ PG_{BA,obs} =  TL_{2010} \\times 0.04 + \\sum_{i=1}^n G_{obs,i} \\ (7) $$\n$$ MAE_{PG} =  \\sum_{i=1}^n \\lvert PG_{BA_{sim,i}} - PG_{BA_{obs,i}} \\rvert \\ (8) $$\n\nPotential generation is computed as:\n\n$$ PG = G + R \\ (10) $$\n$$ R = 0.04TL \\ (11) $$\n\n|     Variable    |     Definition              |     Units    |     Value                                            |\n|-----------------|-----------------------------|--------------|------------------------------------------------------|\n|     PG          |     potential generation    |     MWh      |     computed at the BA scale                         |\n|     G           |     actual generation       |     MWh      |     input at the plant scale                         |\n|     R           |     operating reserve       |     MWh      |     calculated as 4% of the TL                       |\n|     TL          |     total load              |     MWh      |     mean of annual generation   of years provided    |\n\nThe operating reserve percentage is set to as default to 4% of total load in model.py (operating_reserve_percent). This can be changed in model configuration.\n\nStep two of the calibration seeks to reflect the complexity in monthly multi-objective reservoir operations and daily generation constraints. It works to improve seasonal variation for each power plant by calibrating a penstock flexibility factor (fp) and monthly spill correction factors (fs,1, fs,2,\u2026, fs,12). The objective function used in step two is to minimize the Kling-Gupta Efficiency between simulated monthly power generation and observed monthly power generation at the plant level:\n\n$$ KGE=1-\\sqrt{(r-1)^2 + \\left(\\frac{sd(G_{sim})}{sd(G_{obs})}\\right)^2 + \\left(\\frac{mean(G_{sim})}{mean(G_{obs})}\\right)^2}\\ (12) $$\n$$ r = cor(G_{sim}, G_{obs}) \\ (13) $$\n\n\n|     Variable    |     Definition                      |     Units    |     Value                          |\n|-----------------|-------------------------------------|--------------|------------------------------------|\n|     Gsim        |     simulated monthly generation    |     MW       |     computed at the plant scale    |\n|     Gobs        |     observed monthly generation     |     MW       |     input at the plant scale       |\n\n#### Model Setup\nThe model repository contains documentation and example code for setting up and running the model. It is built as a Python package and the scripts can be imported into a Python environment.\n\n##### Model Inputs\nModel inputs are specified in the run script.\n\n| Input                                    |                                        |       Description                                                                                        |     Format      |\n|------------------------------------------|----------------------------------------|----------------------------------------------------------------------------------------------------------|-----------------|\n|     daily simulated flow and storage     |     simulated_flow_and_storage_glob    |     daily simulated flow and storage, typically from a MOSART   simulation, for each hydropower plant    |     .parquet    |\n|     observed monthly power generation    |     observed_hydropower_glob           |     observed monthly hydropower generation for each hydropower   plant                                   |     .parquet    |\n|     reservoir and plant parameters       |     reservoir_parameter_glob           |     reservoir and hydropower plant static parameters                                                     |     .parquet    |\n\n\n\nMany configuration options are available for running the model. These options can be specified in a configuration yaml\nfile or passed directly to the model initialization method, or both (the latter takes precedence). Most options have\nsensible defaults, but a few are required as discussed below. For the full list of configuration options, see the\n`config.yaml` file in the repository root.\n\nDependencies are listed in the `setup.cfg` file.\nTo install dependencies, run `pip install -e .` from the root directory of this repository.\n\nThere are two ways to run the model. The simplest is to provide a configuration file and run the model directly:\n\nconfig.yaml\n```yaml\n# first year of calibration data\ncalibration_start_year: 1984\n# last year of calibration data\ncalibration_end_year: 2008\n# balancing authority or list of balancing authorities to calibrate\nbalancing_authority:\n  - WAPA\n# glob to files with simulated daily flow and storage for plants in the balancing authorities\nsimulated_flow_and_storage_glob: ./inputs/**/*flow*storage*.parquet\n# glob to files with observed monthly hydropower for plants in the balancing authorities\nobserved_hydropower_glob: ./inputs/**/*monthly*obs*.parquet\n# glob to files with reservoir/plant parameters for plants in the balancing authorities\nreservoir_parameter_glob: ./inputs/**/*PLEXOS*.parquet\n```\n\n```commandline\npython wmpy_power/model.py config.yaml\n```\n\nAlternatively, the model can be invoked from a python script or console:\n```python\nfrom wmpy_power import Model\n\n# you can initialize the model using the configuration file:\nmodel = Model('config.yaml')\n# or directly:\nmodel = Model(\n  calibration_start_year=1984,\n  calibration_end_year=2008,\n  balancing_authority=['WAPA'],\n  simulated_flow_and_storage_glob='./inputs/**/*daily*flow*storage*.parquet',\n  observed_hydropower_glob='./inputs/**/*monthly*obs*.parquet',\n  reservoir_parameter_glob='./inputs/**/*PLEXOS*.parquet',\n)\n# or both (keyword arguments take precedence)\nmodel = Model(\n  'config.yaml',\n  balancing_authority=['CAISO'],\n  output_type='csv',\n)\n\n# run the model (this will write the calibrations to file but also return a DataFrame\ncalibrations = model.run()\n\n# plot each plant's modeled hydropower versus observed hydropower\nmodel.plot(calibrations)\n\n# get modeled generation for the calibrations and write to file\ngeneration = Model.get_generation(\n  './**/*_plant_calibrations.csv',\n  './inputs/*reservoir_parameter*.parquet',\n  './inputs/**/*daily*flow*storage*.parquet',\n)\n```\n\nBy default, the model writes the calibrated parameters to a parquet file per balancing  in the current working\ndirectory, but this behavior can be overridden using the `output_path` and `output_type` configuration options.\nSo far only \"csv\" and \"parquet\" formats are supported.\n\n#### Input Files\n\nDaily flow and storage parquet files are expected to have these columns:\n\ncolumn       | example     | units   |\n-------------|-------------|---------|\ndate         | 1980-01-01  | date    |\neia_plant_id | 153         | integer |\nflow         | 461.003906  | m^3 / s |\nstorage      | 1.126790e10 | m^3     |\n\nMonthly observed hydropower parquet files are expected to have these columns:\n\ncolumn         | example   | units   |\n---------------|-----------|---------|\nyear           | 1980      | integer |\nmonth          | 1         | integer |\neia_plant_id   | 153       | integer |\ngeneration_MWh | 38221.193 | MWh     |\n\nReservoir/plant parameter parquet files are expected to have these columns:\n\ncolumn                | example | units   |\n----------------------|---------|---------|\neia_plant_id          | 153     | integer |\nbalancing_authority   | WAPA    | string  |\nname                  | 1980    | integer |\nnameplate_capacity_MW | 1       | MW      |\nplant_head_m          | 5123.3  | m       |\nstorage_capacity_m3   | 1.5e10  | m^3     |\nuse_run_of_river      | True    | boolean |\n\n\n#### Notebook\n\nThe `tutorial.ipynb` file provides a Jupyter notebook illustration of running the model and plotting results.\n\n#### Working with Parquet files\n\nIt's easy to read and write parquet files from pandas, just `pip install pyarrow` or `conda install pyarrow`, then:\n```python\nimport pandas as pd\ndf = pd.read_parquet('/path/to/parquet/file.parquet')\ndf['my_new_column'] = 42\ndf.to_parquet('/path/to/new/parquet/file.parquet')\n```\n#### Legacy Files\nwmpy_power was originally developed in MATLAB. The model provides a utility to convert Excel and MATLAB files to parquet files. This functionality can also be used to build inputs in Excel and convert them into parquet.\n\n```python\nfrom wmpy_power import Model\n\nModel.update_legacy_input_files(\n  daily_flow_storage_path='/path/to/flow/storage/matlab/file.mat',\n  reservoir_parameters_path='/path/to/plexos/parameters/excel/file.xlsx',\n  monthly_observed_generation_path='/path/to/observed/generation/excel/file.xlsx',\n  daily_start_date='1980-01-01', # for daily flow/storage, since this isn't mentioned in the file itself, have to assume a start date\n  monthly_start_date='1980-01-01', # for monthly observed hydro, since this isn't mentioned in the file itself, have to assume a start month\n  output_path=None, # defaults to the same place as the input files, but with the .parquet extension\n  includes_leap_days=False, # whether or not the daily data includes entries for leap days (Tian's files don't)\n)\n```\n",
    "bugtrack_url": null,
    "license": "{ file = \"LICENSE\" }",
    "summary": "Estimates hydropower generation accounting for operating constraints and electricity grid operations.",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [
        "hydropower",
        "water"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d4ae9473e9aefb8c605fbf2951c770bc5658e803dd89b5a424ce26b93a20595",
                "md5": "cd11e97dbd0d9102968eca5d810396fe",
                "sha256": "78268618d3ab541ba337a9c3f0b8cf7e849d0ef7acee7ae2f38d36bb97ce6bd3"
            },
            "downloads": -1,
            "filename": "wmpy_power-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd11e97dbd0d9102968eca5d810396fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.9",
            "size": 23430,
            "upload_time": "2024-03-06T22:26:56",
            "upload_time_iso_8601": "2024-03-06T22:26:56.591889Z",
            "url": "https://files.pythonhosted.org/packages/0d/4a/e9473e9aefb8c605fbf2951c770bc5658e803dd89b5a424ce26b93a20595/wmpy_power-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13981d710bddc937296ed055da3259568c5a5970b78b09ebd9df80058c42eaed",
                "md5": "bb574714ab333d492b89c59ab1ce9504",
                "sha256": "9ce78dfc58728312f24ead83c82f3bf80be2def704da1cc9cb44b33ceb7e3aed"
            },
            "downloads": -1,
            "filename": "wmpy_power-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bb574714ab333d492b89c59ab1ce9504",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.9",
            "size": 27106,
            "upload_time": "2024-03-06T22:26:58",
            "upload_time_iso_8601": "2024-03-06T22:26:58.702177Z",
            "url": "https://files.pythonhosted.org/packages/13/98/1d710bddc937296ed055da3259568c5a5970b78b09ebd9df80058c42eaed/wmpy_power-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-06 22:26:58",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "wmpy-power"
}
        
Elapsed time: 0.21175s