Skip to content

Commit 7222882

Browse files
Implement Adam's feedback
1 parent 88c2efa commit 7222882

1 file changed

Lines changed: 41 additions & 39 deletions

File tree

pvlib/iotools/nasa_power.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
}
1818

1919

20-
def get_nasa_power(latitude, longitude, start_date, end_date,
21-
parameters, time_standard='utc', community='re',
22-
site_elevation=None, wind_elevation=None,
23-
wind_surface=None, map_variables=True):
20+
def get_nasa_power(latitude, longitude, start, end, parameters,
21+
time_standard='utc', community='re', elevation=None,
22+
wind_height=None, wind_surface=None, map_variables=True):
2423
"""
2524
Retrieve irradiance and weather data from NASA POWER.
2625
@@ -34,40 +33,46 @@ def get_nasa_power(latitude, longitude, start_date, end_date,
3433
In decimal degrees, north is positive (ISO 19115).
3534
longitude: float
3635
In decimal degrees, east is positive (ISO 19115).
37-
start_date: datetime like
36+
start: datetime like
3837
First timestamp of the requested period. If a timezone is not
3938
specified, UTC is assumed.
40-
end_date: datetime like
39+
end: datetime like
4140
Last timestamp of the requested period. If a timezone is not
4241
specified, UTC is assumed.
4342
parameters: str, list
4443
List of parameters. Some common parameters are mentioned below; for the
4544
full list see [3]_:
46-
* ALLSKY_SFC_SW_DWN: Global Horizontal Irradiance (GHI) [Wm⁻²]
47-
* ALLSKY_SFC_SW_DIFF: Diffuse Horizonatl Irradiance (DHI) [Wm⁻²]
48-
* ALLSKY_SFC_SW_DNI: Direct Normal Irradiance (DNI) [Wm⁻²]
49-
* CLRSKY_SFC_SW_DWN: Clear-sky GHI [Wm⁻²]
50-
* T2M : Air temperature at 2 m [C]
51-
* WS2M: Wind speed at 2 m [m/s]
52-
* WS10M: Wind speed at 10 m [m/s]
53-
community: str, default: 're'
45+
46+
* ``ALLSKY_SFC_SW_DWN``: Global Horizontal Irradiance (GHI) [Wm⁻²]
47+
* ``ALLSKY_SFC_SW_DIFF``: Diffuse Horizontal Irradiance (DHI) [Wm⁻²]
48+
* ``ALLSKY_SFC_SW_DNI``: Direct Normal Irradiance (DNI) [Wm⁻²]
49+
* ``CLRSKY_SFC_SW_DWN``: Clear-sky GHI [Wm⁻²]
50+
* ``T2M``: Air temperature at 2 m [C]
51+
* ``WS2M``: Wind speed at 2 m [m/s]
52+
* ``WS10M``: Wind speed at 10 m [m/s]
53+
54+
community: str, default: ``'re'``
5455
Can be one of the following depending on which parameters are of
5556
interest. Note that in many cases this choice might affect the units
5657
of the parameter:
57-
* 're': renewable energy
58-
* 'sb': sustainable buildings
59-
* 'ag': agroclimatology
60-
time_standard: str, default: 'utc'
61-
Can be either 'utc' or 'lst':
62-
* Universal Time Coordinated (utc)
63-
* Local Solar Time (lst): A 15 Degrees swath that represents solar
64-
noon at the middle longitude of the swath
65-
site_elevation: float, optional
58+
59+
* ``'re'``: renewable energy
60+
* ``'sb'``: sustainable buildings
61+
* ``'ag'``: agroclimatology
62+
63+
time_standard: str, default: ``'utc'``
64+
Can be either ``'utc'`` or ``'lst'``:
65+
66+
* Universal Time Coordinated (utc)
67+
* Local Solar Time (lst): A 15 Degrees swath that represents solar
68+
noon at the middle longitude of the swath
69+
70+
elevation: float, optional
6671
The custom site elevation in meters to produce the corrected
6772
atmospheric pressure adjusted for elevation.
68-
wind_elevation: float, optional
69-
The custom wind elevation in meters to produce the wind speed adjusted
70-
for elevation. Has to be between 10 and 300 m; see [4]_.
73+
wind_height: float, optional
74+
The custom wind height in meters to produce the wind speed adjusted
75+
for height. Has to be between 10 and 300 m; see [4]_.
7176
wind_surface: str, optional
7277
The definable surface type to adjust the wind speed. For a list of the
7378
surface types see [4]_.
@@ -80,8 +85,6 @@ def get_nasa_power(latitude, longitude, start_date, end_date,
8085
------
8186
requests.HTTPError
8287
Raises an error when an incorrect request is made.
83-
ValueError
84-
Raises an error if more than 15 parameters are requested in one call.
8588
8689
Returns
8790
-------
@@ -100,12 +103,8 @@ def get_nasa_power(latitude, longitude, start_date, end_date,
100103
.. [4] `NASA POWER corrected wind speed parameters
101104
<https://power.larc.nasa.gov/docs/methodology/meteorology/wind/>`_
102105
"""
103-
if len(parameters) > 15:
104-
raise ValueError("A maximum of 15 parameters can currently be "
105-
"requested in one submission.")
106-
107-
start = pd.Timestamp(start_date)
108-
end = pd.Timestamp(end_date)
106+
start = pd.Timestamp(start)
107+
end = pd.Timestamp(end)
109108
start = start.tz_localize('UTC') if start.tzinfo is None else start
110109
end = end.tz_localize('UTC') if end.tzinfo is None else end
111110

@@ -120,8 +119,8 @@ def get_nasa_power(latitude, longitude, start_date, end_date,
120119
'user': None,
121120
'header': True,
122121
'time-standard': time_standard,
123-
'site-elevation': site_elevation,
124-
'wind-elevation': wind_elevation,
122+
'site-elevation': elevation,
123+
'wind-elevation': wind_height,
125124
'wind-surface': wind_surface,
126125
}
127126

@@ -134,11 +133,14 @@ def get_nasa_power(latitude, longitude, start_date, end_date,
134133
data = response.json()
135134
hourly_data = data['properties']['parameter']
136135
df = pd.DataFrame(hourly_data)
137-
df.index = pd.to_datetime(df.index, format='%Y%m%d%H')
138-
df = df.sort_index()
136+
df.index = pd.to_datetime(df.index, format='%Y%m%d%H').tz_localize('UTC')
137+
138+
# Make metadata dictionary
139+
meta = {key: data[key] for key in ['geometry', 'header', 'messages',
140+
'parameters', 'times', 'type']}
139141

140142
# Rename according to pvlib convention
141143
if map_variables:
142144
df = df.rename(columns=VARIABLE_MAP)
143145

144-
return df
146+
return df, meta

0 commit comments

Comments
 (0)