Skip to content

Commit b15a170

Browse files
committed
basic endpoint only support '1h', rename terrain_situation
1 parent 8e3b1ec commit b15a170

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

pvlib/iotools/meteonorm.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
7575
Orientation (azimuth angle) of the (fixed) plane. Clockwise from north
7676
(north=0, east=90, south=180, west=270).
7777
time_step : {'1min', '15min', '1h'}, default : '15min'
78-
Frequency of the time series.
78+
Frequency of the time series. The endpoint ``'forecast/basic'`` only
79+
supports ``time_step='1h'``.
7980
horizon : str or list, default : 'auto'
8081
Specification of the horizon line. Can be either 'flat', 'auto', or
8182
a list of 360 integer horizon elevation angles.
@@ -158,6 +159,10 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
158159

159160
if 'basic' not in endpoint:
160161
params['frequency'] = TIME_STEP_MAP.get(time_step, time_step)
162+
else:
163+
if time_step not in ['1h', '1_hour']:
164+
raise ValueError("The 'forecast/basic' api endpoint only "
165+
"supports ``time_step='1h'``.")
161166

162167
headers = {"Authorization": f"Bearer {api_key}"}
163168

@@ -180,7 +185,7 @@ def get_meteonorm(latitude, longitude, start, end, api_key, endpoint,
180185
def get_meteonorm_tmy(latitude, longitude, api_key,
181186
parameters='all', *, surface_tilt=0,
182187
surface_azimuth=180, time_step='1h', horizon='auto',
183-
terrain='open', albedo=None, turbidity='auto',
188+
terrain_situation='open', albedo=None, turbidity='auto',
184189
random_seed=None, clear_sky_radiation_model='esra',
185190
data_version='latest', future_scenario=None,
186191
future_year=None, interval_index=False,
@@ -212,7 +217,7 @@ def get_meteonorm_tmy(latitude, longitude, api_key,
212217
Specification of the horizon line. Can be either 'flat' or 'auto', or
213218
specified as a list of 360 integer horizon elevation angles.
214219
'auto'.
215-
terrain : str, default : 'open'
220+
terrain_situation : str, default : 'open'
216221
Local terrain situation. Must be one of: ['open', 'depression',
217222
'cold_air_lake', 'sea_lake', 'city', 'slope_south',
218223
'slope_west_east'].
@@ -279,7 +284,7 @@ def get_meteonorm_tmy(latitude, longitude, api_key,
279284
'frequency': TIME_STEP_MAP.get(time_step, time_step),
280285
'parameters': parameters,
281286
'horizon': horizon,
282-
'situation': terrain,
287+
'situation': terrain_situation,
283288
'turbidity': turbidity,
284289
'clear_sky_radiation_model': clear_sky_radiation_model,
285290
'data_version': data_version,

tests/iotools/test_meteonorm.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def test_get_meteonorm_forecast_basic(demo_api_key, demo_url):
162162
latitude=50, longitude=10,
163163
start=pd.Timestamp.now(tz='UTC'),
164164
end=pd.Timestamp.now(tz='UTC') + pd.Timedelta(hours=5),
165+
time_step='1h',
165166
api_key=demo_api_key,
166167
parameters='ghi',
167168
endpoint='forecast/basic',
@@ -200,6 +201,7 @@ def test_get_meteonorm_custom_horizon(demo_api_key, demo_url):
200201
end=pd.Timestamp.now(tz='UTC') + pd.Timedelta(hours=5),
201202
api_key=demo_api_key,
202203
parameters='ghi',
204+
time_step='1h',
203205
endpoint='forecast/basic',
204206
horizon=list(np.ones(360).astype(int)*80),
205207
url=demo_url)
@@ -214,12 +216,27 @@ def test_get_meteonorm_HTTPError(demo_api_key, demo_url):
214216
latitude=50, longitude=10,
215217
start=pd.Timestamp.now(tz='UTC'),
216218
end=pd.Timestamp.now(tz='UTC') + pd.Timedelta(hours=5),
219+
time_step='1h',
217220
api_key=demo_api_key,
218221
parameters='not_a_real_parameter',
219222
endpoint='forecast/basic',
220223
url=demo_url)
221224

222225

226+
def test_get_meteonorm_basic_forecast_incorrect_time_step(
227+
demo_api_key, demo_url):
228+
with pytest.raises(
229+
ValueError, match="only supports ``time_step='1h'``"):
230+
_ = pvlib.iotools.get_meteonorm(
231+
latitude=50, longitude=10,
232+
start=pd.Timestamp.now(tz='UTC'),
233+
end=pd.Timestamp.now(tz='UTC') + pd.Timedelta(hours=5),
234+
time_step='15min', # only '1h' is supported for tmy
235+
api_key=demo_api_key,
236+
endpoint='forecast/basic',
237+
url=demo_url)
238+
239+
223240
@pytest.mark.remote_data
224241
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
225242
def test_get_meteonorm_tmy_HTTPError(demo_api_key, demo_url):
@@ -305,7 +322,7 @@ def test_get_meteonorm_tmy(
305322
surface_azimuth=90,
306323
time_step='1h',
307324
horizon=list(np.ones(360).astype(int)*2),
308-
terrain='open',
325+
terrain_situation='open',
309326
albedo=0.5,
310327
turbidity=[5.2, 4, 3, 3.1, 3.0, 2.8, 3.14, 3.0, 3, 3, 4, 5],
311328
random_seed=100,

0 commit comments

Comments
 (0)