Skip to content

Commit 52a21a7

Browse files
Wind Resource API Downloads (#245)
* added wip version of resource handling files * wip worked on developing wind downloads * updated river resource * updated wind resource base and nrel wtk api resource * updated solar resource base and nrel goes api resource * added goes and wtk to supported models * updated example 5 and wind plant performance model handling of resource * updated goes solar api resource model * updated examples 5,8,10,14,15 input files and changed windplant to use same hardcoded hubheight * updated windplants to use actual hub-height * added download tools and time tools * minor bugfix in resource_base for when user inputs a file and folder * updated solar resource data files * updated solar resource in pv models and example 15 * fixed bug in pysam solar plant that occurred with rolled resource data * removed model.post_process from examples and tests with resource data * removed solar resource handling * reverted changes to solar performance models * updated solar resource inputs in example 15 plant config * added doc strings to resource utilities * added docstrings and comments to new resource classes and configs * updated example 6 and 15 input files so simulation doesnt fail * added wind resource files for flatirons site downloaded from wtk v2 * updated test values for tests that use wind plant * added test for test resource file tools and updated check_resource_dir to always output absolute paths * added tests and updated make_time_profile * made tests for time_tools * made tests for time_tools * added test for wind resource component * added test __init__ file * added check in check_resource_dir to see if running Github actions * unset RESOURCE_DIR environment variable to prevent unexpected API calls * updated initialization of SiteInfo with solar as False * updated and added pytest session start and end configs to not cause issues for users that specify resource_dir environment variable * updates to resource scripts * update to time_tools * updated doc jupyter notebook to run properly * removed use of time_tools * minor updates to comments or removed commented out code * added default value for timezone to be zero * updated lco test values for example 5 and example 10 * removed commented out code from file_tools * added docstrings and inline comments to wind performance models * cleaned up example input files that use wind * added doc page for setting environment variables * minor update to output data naming * added doc pages for wind resource * Updates to resource docs, bump OM min version, restore post_processing after filtering out resource data * minor cleanups * undid changes to post_process function in h2integrate_model * Trying different valid_intervals definition * added inline comments to format_resource_data function in wind performance models * Minor review feedback * Updated readme and config * added init file to resource folder * Removed old readme portion * updated import path in conftest * updated conftest in tests/ to have same protection for user defined environment variables * Doc updates * updates based on reviewer feedback --------- Co-authored-by: John Jasa <johnjasa11@gmail.com>
1 parent fe193c3 commit 52a21a7

55 files changed

Lines changed: 19269 additions & 403 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- Made `pipe` and `cable` substance-agnostic rather than hard-coded for `hydrogen` and `electricity`
5353
- Change finance handling to use `finance_subgroups` and `finance_groups` defined in the `plant_config` rather than previous `financial_groups` in the `tech_config` and `technologies_to_include_in_metrics` in `plant_config`
5454
- Added generic storage model, useful for battery, hydrogen, CO2, or other resource storage.
55+
- Added wind resource model, API baseclasses, updated examples, and documentation.
5556

5657
## 0.3.0 [May 2 2025]
5758

README.md

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -186,48 +186,15 @@ pip install -e ".[all]"
186186

187187
[https://developer.nrel.gov/signup/](https://developer.nrel.gov/signup/)
188188

189-
6. To set up the `NREL_API_KEY` and `NREL_API_EMAIL` required for resource downloads, you can create
190-
Environment Variables called `NREL_API_KEY` and `NREL_API_EMAIL`. Otherwise, you can keep the key
191-
in a new file called ".env" in the root directory of this project.
192-
193-
Create a file ".env" that contains the single line:
194-
195-
```bash
196-
NREL_API_KEY=key
197-
NREL_API_EMAIL=your.name@email.com
198-
```
189+
6. To set up the `NREL_API_KEY` and `NREL_API_EMAIL` required for resource downloads, follow the steps
190+
outlined in [this doc page](https://h2integrate.readthedocs.io/en/latest/getting_started/environment_variables.html).
199191

200192
7. Verify setup by running tests:
201193

202194
```bash
203195
pytest
204196
```
205197

206-
207-
2. To set up `NREL_API_KEY` for resource downloads, first refer to section 7 and 8 above. But for
208-
the `.env` file method, the file should go in the working directory of your Python project, e.g.
209-
directory from where you run `python`.
210-
211-
## Parallel processing for H2Integrate finite differences and design of experiments
212-
213-
H2Integrate is set up to run in parallel using MPI and PETSc for finite differencing and for design
214-
of experiments runs through OpenMDAO. To use this capability you will need to follow the additional
215-
installation
216-
instruction below:
217-
218-
```bash
219-
conda install -c conda-forge mpi4py petsc4py
220-
```
221-
222-
For more details on implementation and installation, reference the documentation for OpenMDAO.
223-
224-
To check that your installation is working, do the following:
225-
226-
```bash
227-
cd tests/h2integrate/
228-
mpirun -n 2 pytest test_openmdao_mpi.py
229-
```
230-
231198
## Getting Started
232199

233200
The [Examples](./examples/) contain Jupyter notebooks and sample YAML files for common usage

docs/_toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ parts:
88
chapters:
99
- file: getting_started/install
1010
- file: getting_started/expected_user_knowledge
11+
- file: getting_started/environment_variables
1112

1213
- caption: User Guide
1314
chapters:
@@ -36,6 +37,13 @@ parts:
3637
- file: technology_models/co2.md
3738
- file: technology_models/simple_generic_storage.md
3839

40+
- caption: Resource Models
41+
chapters:
42+
- file: resource/resource_index
43+
sections:
44+
- file: resource/wind_index
45+
- file: resource/wind_toolkit_v2_api
46+
3947
- caption: Examples
4048
chapters:
4149
- file: examples/01-green-hydrogen
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Setting Environment Variables
2+
3+
H2Integrate can pull weather resource datasets (e.g. data needed for wind or solar generation) automatically for a user-provided location.
4+
To use resource datasets from the NREL developer network, you will need an NREL API key, which can be obtained from:
5+
[https://developer.nrel.gov/signup/](https://developer.nrel.gov/signup/).
6+
7+
You will need to set the API key and the email you used to get the API key for downloading resource data from the NREL developer network. The 40 character API key is referred to in following sections as the value for the `NREL_API_KEY` environment variable. The email used to get the API key is referred to in the following sections as the value for the `NREL_API_EMAIL` environment variable.
8+
9+
In the following sections on setting these environment variables, `'api-key-value'` should be replaced with your NREL API key and `'email-for-api-key'` should be replaced with your email address.
10+
11+
An optional environment variable is `RESOURCE_DIR`. If set, this will be used as the default folder to save resource data to that is downloaded from the API. If setting this, please set its value as the full filepath to the folder you'd like to save resource files to, and ensure that the folder exists.
12+
13+
The remaining sections outline different options for setting environment variables in H2Integrate:
14+
- [Save environment variables with conda (preferred)](#save-environment-variables-with-conda-preferred)
15+
- [Set environment variables with a .yaml file](#set-environment-variables-with-yaml-file)
16+
- [Set environment variables with a .env file](#set-environment-variables-with-env-file)
17+
18+
## Save Environment Variables with Conda (Preferred)
19+
20+
After creating the conda environment for H2Integrate, you can [save environment variables with conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables) within that environment.
21+
This is the preferred method for setting environment variables for H2Integrate.
22+
23+
### Windows Instructions
24+
25+
If you are using a Windows machine, please follow the steps documented for conda on [saving environment variables on Windows](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#win-save-env-variables).
26+
The specific variable names and values to set are listed below; use these for steps 3 and 4 from the conda installation instructions..
27+
28+
The `.\etc\conda\activate.d\env_vars.bat` file may look like below:
29+
```bash
30+
set NREL_API_KEY='api-key-value'
31+
set NREL_API_EMAIL='email-for-api-key'
32+
set RESOURCE_DIR=C:\path\to\my\resource\folder
33+
```
34+
35+
The `.\etc\conda\deactivate.d\env_vars.bat` file may look like below:
36+
```bash
37+
set NREL_API_KEY=
38+
set NREL_API_EMAIL=
39+
set RESOURCE_DIR=
40+
```
41+
42+
### macOS and Linux instructions
43+
44+
If you are using a macOS or Linux machine, please follow the steps documented for conda on [saving environment variables on macOS or Linux](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-linux-save-env-variables)
45+
46+
The `./etc/conda/activate.d/env_vars.sh` file may look like below:
47+
```bash
48+
#!/bin/sh
49+
export NREL_API_KEY='api-key-value'
50+
export NREL_API_EMAIL='email-for-api-key'
51+
export RESOURCE_DIR=/path/to/my/resource/folder/
52+
```
53+
54+
The `./etc/conda/deactivate.d/env_vars.sh` file may look like below:
55+
```bash
56+
#!/bin/sh
57+
58+
unset NREL_API_KEY
59+
unset NREL_API_EMAIL
60+
unset RESOURCE_DIR
61+
```
62+
63+
64+
## Set Environment Variables with .yaml file
65+
66+
1. In `environment.yml`, add the following lines to the bottom of the file, and replace the
67+
environment variable values with your information. Be sure that
68+
"variables" has no leading spaces.
69+
70+
```yaml
71+
variables:
72+
NREL_API_KEY='api-key-value'
73+
NREL_API_EMAIL='email-for-api-key'
74+
RESOURCE_DIR='/path/to/my/resource/folder/'
75+
```
76+
77+
2. After that, create a conda environment and install H2Integrate and all its dependencies using the modified `environment.yml` file with the command:
78+
79+
```bash
80+
conda env create -f environment.yml
81+
```
82+
83+
## Set Environment Variables with .env file
84+
85+
```{note}
86+
This method only works for setting the `NREL_API_KEY` and `NREL_API_EMAIL` environment variables; this method should not be used to set the `RESOURCE_DIR` environment variable.
87+
```
88+
89+
The ".env" file will be looked for in all of the following locations:
90+
- H2Integrate root directory (`/path/to/H2Integrate/h2integrate/`)
91+
- parent of H2Integrate root directory (`/path/to/H2Integrate/`) (preferred location to store your environment file)
92+
- current working directory (this is not a preferred location to store your environment file)
93+
1. Choose which of the above directories you want to host your .env file, and create a file named ".env" in that folder.
94+
2. Open the ".env" file and add the environment variables:
95+
```bash
96+
NREL_API_KEY='api-key-value'
97+
NREL_API_EMAIL='email-for-api-key'
98+
```
99+
3. Save and close the ".env" file.

docs/resource/resource_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Resource data
2+
3+
4+
- [Wind Resource Data](wind_resource:models)

docs/resource/wind_index.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
(wind_resource:models)=
2+
# Wind Resource: Model Overview
3+
4+
- [**"wind_toolkit_v2_api"**](wind_resource:wtk_v2_api): this requires an API key for the NREL developer network
5+
6+
7+
```{note}
8+
Please refer to the `Setting Environment Variables` doc page for information on setting up an NREL API key if you haven't yet.
9+
```
10+
11+
(windresource:overview)=
12+
# Wind Resource: Output Data
13+
14+
Wind resource models may output wind resource data, site information, information about the data source, and time information. This information is outputted as a dictionary. The following sections detail the naming convention for the dictionary keys, standardized units, and descriptions of all the output data that may be output from a wind resource model.
15+
16+
- [Wind Resource Data](#primary-data-wind-resource-timeseries)
17+
- [Site Information](#additional-data-site-information)
18+
- [Data Source Information](#additional-data-data-source)
19+
- [Time Profile Information](#additional-data-time-profile)
20+
21+
22+
```{note}
23+
Not all wind resource models will output all the data keys listed below. Please check the documentation for each wind resource model and wind performance model to ensure compatibility.
24+
```
25+
26+
## Primary Data: Wind Resource Timeseries
27+
The below variables are outputted as arrays, with a length equal to the simulation duration. In the variables listed below, `<height>` is used to indicate the height (in meters) above the ground for the resource parameter. `<height>` should be 0 for surface level wind resource data. The naming convention and standardized units of wind resource variables are listed below:
28+
- `wind_direction_<height>m`: wind direction in degrees (units are 'deg')
29+
- `wind_speed_<height>m`: wind speed in meters per second (units are 'm/s')
30+
- `temperature_<height>m`: air temperature in Celsius (units are 'C')
31+
- `pressure_<height>m`: air pressure in atm (units are 'atm')
32+
- `precipitation_rate_<height>m`: precipitation rate in millimeters per hour (units are 'mm/h')
33+
- `relative_humidity_<height>`: relative humidity represented as a percentage (units are 'percent')
34+
35+
## Additional Data: Site Information
36+
- `site_id` (int): site id
37+
- `site_tz` (int | float): local timezone for the site
38+
- `site_lat` (float): latitude of the site
39+
- `site_lon` (float): longitude of the site
40+
- `elevation` (float | int): elevation of the site in meters
41+
42+
## Additional Data: Data source
43+
- `data_tz` (int | float): timezone the data is in represented as an hour offset from UTC
44+
- `filepath` (str): filepath where the resource data was loaded from
45+
46+
## Additional Data: Time profile
47+
Time data may be outputted as arrays to represent the time profile of the resource data. These times should be represented in the timezone of `data_tz` (if outputted).
48+
- `year`: year as 4-digit value (i.e., 2019)
49+
- `month`: month of year (1-12)
50+
- `day`: day of month (1-31)
51+
- `hour`: hour of day from a 24-hour clock (0-23)
52+
- `minute`: minute of hour (0-59)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(wind_resource:wtk_v2_api)=
2+
# Wind Resource: WTK V2 API
3+
4+
This resource class downloads wind resource data from [Wind Toolkit Data V2](https://developer.nrel.gov/docs/wind/wind-toolkit/wtk-download/)
5+
and requires an NREL API key to use.
6+
7+
This dataset allows for resource data to be downloaded for:
8+
- **resource years** from 2007 to 2014.
9+
- **locations** within the continental United States.
10+
- **resource heights** from 10 to 200 meters.
11+
- **time intervals** of 5, 15, 30, and 60 minutes.
12+
13+
## Available Data
14+
15+
| Resource Data | Resource Heights (m) |
16+
| :---------------- | :---------------: |
17+
| `wind_speed` | 10, 40, 60, 80, 100, 120, 140, 160, 200 |
18+
| `wind_direction` | 10, 40, 60, 80, 100, 120, 140, 160, 200 |
19+
| `temperature` | 10, 40, 60, 80, 100, 120, 140, 160, 200 |
20+
| `pressure` | 0, 100, 200 |
21+
| `relative_humidity` | 2 |
22+
| `precipitation_rate` | 0 |
23+
24+
| Additional Data | Included |
25+
| :---------------- | :---------------: |
26+
| `site_id` | X |
27+
| `site_lat` | X |
28+
| `site_lon` | X |
29+
| `elevation` | -- |
30+
| `site_tz` | X |
31+
| `data_tz` | X |
32+
| `filepath` | X |
33+
| `year` | X |
34+
| `month` | X |
35+
| `day` | X |
36+
| `hour` | X |
37+
| `minute` | X |

0 commit comments

Comments
 (0)