-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add NASA POWER to iotools #2500
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 6 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
794cc5d
Create nasa_power.py
IoannisSifnaios ff8d010
Updated API
IoannisSifnaios 9a99395
Update __init__.py
IoannisSifnaios 88c2efa
fixed minor typos
IoannisSifnaios 7222882
Implement Adam's feedback
IoannisSifnaios 773dfab
update metadata
IoannisSifnaios 85cc8de
Add tests
IoannisSifnaios fc3f520
fix lint
IoannisSifnaios 2775387
2nd try
IoannisSifnaios 2f127e4
update whatsnew
IoannisSifnaios 1b1793d
Apply suggestions from code review
IoannisSifnaios 0ae7346
suggestions from code review vol.2
IoannisSifnaios 095f311
Apply suggestions from code review
IoannisSifnaios d726591
lint vol.2
IoannisSifnaios 11eedcc
Apply suggestions from code review
IoannisSifnaios 7241196
Adam's corrections
IoannisSifnaios 3720b85
Update tests according to new code
IoannisSifnaios c508058
come on now linter!
IoannisSifnaios a2c9a44
minor change
IoannisSifnaios 36a337f
Apply suggestions from code review
IoannisSifnaios 9c0d58f
Kevin's suggestions (function)
IoannisSifnaios b8ff9eb
Kevin's suggestions (tests)
IoannisSifnaios aac8c69
Apply suggestions from code review
IoannisSifnaios 2625612
Apply suggestions from code review
IoannisSifnaios ea98ebe
Put URL at the end of the function
IoannisSifnaios 915d8f0
Merge branch 'main' into add_nasa_power
IoannisSifnaios 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
"""Function for reading and retrieving data from NASA POWER.""" | ||
|
||
import pandas as pd | ||
import requests | ||
|
||
|
||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
URL = 'https://power.larc.nasa.gov/api/temporal/hourly/point' | ||
|
||
VARIABLE_MAP = { | ||
'ALLSKY_SFC_SW_DWN': 'ghi', | ||
'ALLSKY_SFC_SW_DIFF': 'dhi', | ||
'ALLSKY_SFC_SW_DNI': 'dni', | ||
'CLRSKY_SFC_SW_DWN': 'ghi_clear', | ||
'T2M': 'temp_air_2m', | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'WS2M': 'wind_speed_2m', | ||
'WS10M': 'wind_speed_10m', | ||
} | ||
|
||
|
||
def get_nasa_power(latitude, longitude, start, end, parameters, | ||
time_standard='utc', community='re', elevation=None, | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wind_height=None, wind_surface=None, map_variables=True): | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Retrieve irradiance and weather data from NASA POWER. | ||
|
||
A general description of NASA POWER is given in [1]_ and the API is | ||
described in [2]_. A detailed list of the available parameters can be | ||
found in [3]_. | ||
|
||
Parameters | ||
---------- | ||
latitude: float | ||
In decimal degrees, north is positive (ISO 19115). | ||
longitude: float | ||
In decimal degrees, east is positive (ISO 19115). | ||
start: datetime like | ||
First timestamp of the requested period. If a timezone is not | ||
specified, UTC is assumed. | ||
end: datetime like | ||
Last timestamp of the requested period. If a timezone is not | ||
specified, UTC is assumed. | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parameters: str, list | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
List of parameters. Some common parameters are mentioned below; for the | ||
full list see [3]_: | ||
|
||
* ``ALLSKY_SFC_SW_DWN``: Global Horizontal Irradiance (GHI) [Wm⁻²] | ||
* ``ALLSKY_SFC_SW_DIFF``: Diffuse Horizontal Irradiance (DHI) [Wm⁻²] | ||
* ``ALLSKY_SFC_SW_DNI``: Direct Normal Irradiance (DNI) [Wm⁻²] | ||
* ``CLRSKY_SFC_SW_DWN``: Clear-sky GHI [Wm⁻²] | ||
* ``T2M``: Air temperature at 2 m [C] | ||
* ``WS2M``: Wind speed at 2 m [m/s] | ||
* ``WS10M``: Wind speed at 10 m [m/s] | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
community: str, default: ``'re'`` | ||
Can be one of the following depending on which parameters are of | ||
interest. Note that in many cases this choice might affect the units | ||
of the parameter: | ||
|
||
* ``'re'``: renewable energy | ||
* ``'sb'``: sustainable buildings | ||
* ``'ag'``: agroclimatology | ||
|
||
time_standard: str, default: ``'utc'`` | ||
Can be either ``'utc'`` or ``'lst'``: | ||
|
||
* Universal Time Coordinated (utc) | ||
* Local Solar Time (lst): A 15 Degrees swath that represents solar | ||
noon at the middle longitude of the swath | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
elevation: float, optional | ||
The custom site elevation in meters to produce the corrected | ||
atmospheric pressure adjusted for elevation. | ||
wind_height: float, optional | ||
The custom wind height in meters to produce the wind speed adjusted | ||
for height. Has to be between 10 and 300 m; see [4]_. | ||
wind_surface: str, optional | ||
The definable surface type to adjust the wind speed. For a list of the | ||
surface types see [4]_. | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
map_variables: bool, optional, default: True | ||
When true, renames columns of the Dataframe to pvlib variable names | ||
where applicable. The default is True. See variable | ||
:const:`VARIABLE_MAP`. | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Raises | ||
------ | ||
requests.HTTPError | ||
Raises an error when an incorrect request is made. | ||
|
||
Returns | ||
------- | ||
data : pd.DataFrame | ||
Time series data. The index corresponds to the start (left) of the | ||
interval. | ||
|
||
References | ||
---------- | ||
.. [1] `NASA Prediction Of Worldwide Energy Resources (POWER) | ||
<https://power.larc.nasa.gov/>`_ | ||
.. [2] `NASA POWER API | ||
<https://power.larc.nasa.gov/api/pages/>`_ | ||
.. [3] `NASA POWER API parameters | ||
<https://power.larc.nasa.gov/parameters/>`_ | ||
.. [4] `NASA POWER corrected wind speed parameters | ||
<https://power.larc.nasa.gov/docs/methodology/meteorology/wind/>`_ | ||
""" | ||
start = pd.Timestamp(start) | ||
end = pd.Timestamp(end) | ||
start = start.tz_localize('UTC') if start.tzinfo is None else start | ||
end = end.tz_localize('UTC') if end.tzinfo is None else end | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
params = { | ||
'latitude': latitude, | ||
'longitude': longitude, | ||
'start': start.strftime('%Y%m%d'), | ||
'end': end.strftime('%Y%m%d'), | ||
'community': community, | ||
'parameters': ','.join(parameters), # make parameters in a string | ||
'format': 'json', | ||
'user': None, | ||
'header': True, | ||
'time-standard': time_standard, | ||
'site-elevation': elevation, | ||
'wind-elevation': wind_height, | ||
'wind-surface': wind_surface, | ||
} | ||
|
||
response = requests.get(URL, params=params) | ||
if not response.ok: | ||
# response.raise_for_status() does not give a useful error message | ||
raise requests.HTTPError(response.json()) | ||
|
||
# Parse the data to dataframe | ||
data = response.json() | ||
hourly_data = data['properties']['parameter'] | ||
df = pd.DataFrame(hourly_data) | ||
df.index = pd.to_datetime(df.index, format='%Y%m%d%H').tz_localize('UTC') | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Make metadata dictionary | ||
meta = {key: data[key] for key in ['header', 'messages', 'parameters', | ||
'times', 'type']} | ||
IoannisSifnaios marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
meta['longitude'] = data['geometry']['coordinates'][0] | ||
meta['latitude'] = data['geometry']['coordinates'][1] | ||
meta['altitude'] = data['geometry']['coordinates'][2] | ||
|
||
# Rename according to pvlib convention | ||
if map_variables: | ||
df = df.rename(columns=VARIABLE_MAP) | ||
|
||
return df, meta |
Oops, something went wrong.
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.