-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add retrieval functions for daily precip, snow, and temperature data from NOAA RCC ACIS #1767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3f03323
create acis.py and add get_acis_precipitation function
kandersolar 94a1e90
add tests
kandersolar 99fc6b5
sphinx
kandersolar 9bcac51
tweak
kandersolar 14dd598
better tests
kandersolar 60fb8ee
better whatsnew
kandersolar 2719b83
import in iotools/init
kandersolar 167d49b
fix all these broken things
kandersolar 52b4d84
edits from review
kandersolar de6333b
correct PR number
kandersolar 3201413
split up code to be one function per dataset; add station functions
kandersolar 7724618
fix tests
kandersolar 12cd83a
Apply suggestions from code review
kandersolar 16fbafd
more from review
kandersolar fa85d3a
add degree days to df descriptions
kandersolar 9cbe851
add degree day columns to variable map
kandersolar 30b3703
fix valid daterange test oversight
kandersolar 3b48739
cm -> mm for snow variables
kandersolar a03a774
revert back to cm for snow
kandersolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import requests | ||
import pandas as pd | ||
import numpy as np | ||
|
||
|
||
def get_acis_precipitation(latitude, longitude, start, end, dataset, | ||
url="https://data.rcc-acis.org/GridData", **kwargs): | ||
kandersolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Retrieve daily gridded precipitation data from the Applied Climate | ||
kandersolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Information System (ACIS). | ||
|
||
The Applied Climate Information System (ACIS) was developed and is | ||
maintained by the NOAA Regional Climate Centers (RCCs) and brings together | ||
climate data from many sources. | ||
AdamRJensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Parameters | ||
---------- | ||
latitude : float | ||
in decimal degrees, between -90 and 90, north is positive | ||
longitude : float | ||
in decimal degrees, between -180 and 180, east is positive | ||
start : datetime-like | ||
First day of the requested period | ||
end : datetime-like | ||
Last day of the requested period | ||
dataset : int | ||
A number indicating which gridded dataset to query. Options include: | ||
|
||
* 1: NRCC Interpolated | ||
* 2: Multi-Sensor Precipitation Estimates | ||
* 3: NRCC Hi-Res | ||
* 21: PRISM | ||
|
||
See [1]_ for the full list of options. | ||
|
||
url : str, default: 'https://data.rcc-acis.org/GridData' | ||
API endpoint URL | ||
kwargs: | ||
Optional parameters passed to ``requests.get``. | ||
kandersolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Returns | ||
------- | ||
data : pandas.Series | ||
Daily rainfall [mm] | ||
metadata : dict | ||
Coordinates for the selected grid cell | ||
|
||
Raises | ||
------ | ||
requests.HTTPError | ||
A message from the ACIS server if the request is rejected | ||
|
||
Notes | ||
----- | ||
The returned precipitation values are 24-hour aggregates, but | ||
the aggregation period may not be midnight to midnight in local time. | ||
For example, PRISM data is aggregated from 12:00 to 12:00 UTC, | ||
meaning PRISM data labeled May 26 reflects to the 24 hours ending at | ||
7:00am Eastern Standard Time on May 26. | ||
|
||
Examples | ||
-------- | ||
>>> prism, metadata = get_acis_precipitation(40.0, -80.0, '2020-01-01', | ||
>>> '2020-12-31', dataset=21) | ||
|
||
References | ||
---------- | ||
.. [1] `ACIS Web Services <http://www.rcc-acis.org/docs_webservices.html>`_ | ||
.. [2] `ACIS Gridded Data <http://www.rcc-acis.org/docs_gridded.html>`_ | ||
.. [3] `NRCC <http://www.nrcc.cornell.edu/>`_ | ||
.. [4] `Multisensor Precipitation Estimates | ||
<https://www.weather.gov/marfc/Multisensor_Precipitation>`_ | ||
.. [5] `PRISM <https://prism.oregonstate.edu/>`_ | ||
""" | ||
elems = [ | ||
# other variables exist, but are not of interest for PV modeling | ||
{"name": "pcpn", "interval": "dly", "units": "mm"}, | ||
] | ||
kandersolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
params = { | ||
'loc': f"{longitude},{latitude}", | ||
'sdate': pd.to_datetime(start).strftime('%Y-%m-%d'), | ||
'edate': pd.to_datetime(end).strftime('%Y-%m-%d'), | ||
AdamRJensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'grid': str(dataset), | ||
'elems': elems, | ||
'output': 'json', | ||
'meta': ["ll"], # "elev" should work, but it errors for some databases | ||
AdamRJensen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
response = requests.post(url, json=params, | ||
headers={"Content-Type": "application/json"}, | ||
**kwargs) | ||
response.raise_for_status() | ||
payload = response.json() | ||
|
||
if "error" in payload: | ||
raise requests.HTTPError(payload['error'], response=response) | ||
|
||
metadata = payload['meta'] | ||
metadata['latitude'] = metadata.pop('lat') | ||
metadata['longitude'] = metadata.pop('lon') | ||
|
||
df = pd.DataFrame(payload['data'], columns=['date', 'precipitation']) | ||
rainfall = df.set_index('date')['precipitation'] | ||
rainfall = rainfall.replace(-999, np.nan) | ||
rainfall.index = pd.to_datetime(rainfall.index) | ||
return rainfall, metadata |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
tests for :mod:`pvlib.iotools.acis` | ||
""" | ||
|
||
import pandas as pd | ||
import pytest | ||
from pvlib.iotools import get_acis_precipitation | ||
from ..conftest import (RERUNS, RERUNS_DELAY, assert_series_equal) | ||
from requests import HTTPError | ||
|
||
|
||
@pytest.mark.parametrize('dataset,expected,lat,lon', [ | ||
(1, [0.76, 1.78, 1.52, 0.76, 0.0], 40.0, -80.0), | ||
(2, [0.05, 2.74, 1.43, 0.92, 0.0], 40.0083, -79.9653), | ||
(3, [0.0, 2.79, 1.52, 1.02, 0.0], 40.0, -80.0), | ||
(21, [0.6, 1.8, 1.9, 1.2, 0.0], 40.0, -80.0), | ||
]) | ||
@pytest.mark.remote_data | ||
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) | ||
def test_get_acis_precipitation(dataset, expected, lat, lon): | ||
st = '2012-01-01' | ||
ed = '2012-01-05' | ||
precipitation, meta = get_acis_precipitation(40, -80, st, ed, dataset) | ||
idx = pd.date_range(st, ed, freq='d') | ||
idx.name = 'date' | ||
idx.freq = None | ||
expected = pd.Series(expected, index=idx, name='precipitation') | ||
assert_series_equal(precipitation, expected) | ||
assert meta == {'latitude': lat, 'longitude': lon} | ||
|
||
|
||
@pytest.mark.remote_data | ||
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY) | ||
def test_get_acis_precipitation_error(): | ||
with pytest.raises(HTTPError, match='invalid grid'): | ||
# 50 is not a valid dataset (or "grid", in ACIS lingo) | ||
get_acis_precipitation(40, -80, '2012-01-01', '2012-01-05', 50) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.