forked from pvlib/pvlib-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathacis.py
More file actions
105 lines (90 loc) · 3.58 KB
/
Copy pathacis.py
File metadata and controls
105 lines (90 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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):
"""
Retrieve daily gridded precipitation data from the Applied Climate
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.
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``.
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"},
]
params = {
'loc': f"{longitude},{latitude}",
'sdate': pd.to_datetime(start).strftime('%Y-%m-%d'),
'edate': pd.to_datetime(end).strftime('%Y-%m-%d'),
'grid': str(dataset),
'elems': elems,
'output': 'json',
'meta': ["ll"], # "elev" should work, but it errors for some databases
}
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