Skip to content

Commit 6e8a3f9

Browse files
committed
Set index to be the middle of the period
1 parent 20ec64a commit 6e8a3f9

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

pvlib/iotools/meteonorm.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_meteonorm_forecast_basic(
9191
Returns
9292
-------
9393
data : pd.DataFrame
94-
Time series data. The index corresponds to the start (left) of the
94+
Time series data. The index corresponds to the middle of the
9595
interval unless ``interval_index`` is set to True.
9696
meta : dict
9797
Metadata.
@@ -181,7 +181,7 @@ def get_meteonorm_forecast_precision(
181181
Returns
182182
-------
183183
data : pd.DataFrame
184-
Time series data. The index corresponds to the start (left) of the
184+
Time series data. The index corresponds to the middle of the
185185
interval unless ``interval_index`` is set to True.
186186
meta : dict
187187
Metadata.
@@ -270,7 +270,7 @@ def get_meteonorm_observation_realtime(
270270
Returns
271271
-------
272272
data : pd.DataFrame
273-
Time series data. The index corresponds to the start (left) of the
273+
Time series data. The index corresponds to the middle of the
274274
interval unless ``interval_index`` is set to True.
275275
meta : dict
276276
Metadata.
@@ -358,7 +358,7 @@ def get_meteonorm_observation_training(
358358
Returns
359359
-------
360360
data : pd.DataFrame
361-
Time series data. The index corresponds to the start (left) of the
361+
Time series data. The index corresponds to the middle of the
362362
interval unless ``interval_index`` is set to True.
363363
meta : dict
364364
Metadata.
@@ -473,7 +473,7 @@ def get_meteonorm_tmy(
473473
Returns
474474
-------
475475
data : pd.DataFrame
476-
Time series data. The index corresponds to the start (left) of the
476+
Time series data. The index corresponds to the middle of the
477477
interval unless ``interval_index`` is set to True.
478478
meta : dict
479479
Metadata.
@@ -513,12 +513,12 @@ def get_meteonorm_tmy(
513513
start, end = None, None
514514

515515
data, meta = _get_meteonorm(
516-
latitude, longitude, start, end,
517-
api_key, parameters,
518-
surface_tilt, surface_azimuth,
519-
time_step, horizon,
520-
interval_index, map_variables,
521-
url, endpoint, **additional_params)
516+
latitude, longitude, start, end,
517+
api_key, parameters,
518+
surface_tilt, surface_azimuth,
519+
time_step, horizon,
520+
interval_index, map_variables,
521+
url, endpoint, **additional_params)
522522
return data, meta
523523

524524

@@ -602,14 +602,14 @@ def _parse_meteonorm(response, interval_index, map_variables):
602602
data = pd.DataFrame(data_json)
603603

604604
# xxx: experimental feature - see parameter description
605-
if interval_index:
606-
data.index = pd.IntervalIndex.from_arrays(
607-
left=pd.to_datetime(response.json()["start_times"]),
608-
right=pd.to_datetime(response.json()["end_times"]),
609-
closed="left",
610-
)
611-
else:
612-
data.index = pd.to_datetime(response.json()["start_times"])
605+
data.index = pd.IntervalIndex.from_arrays(
606+
left=pd.to_datetime(response.json()["start_times"]),
607+
right=pd.to_datetime(response.json()["end_times"]),
608+
closed="left",
609+
)
610+
611+
if not interval_index:
612+
data.index = data.index.mid
613613

614614
meta = response.json()["meta"]
615615

tests/iotools/test_meteonorm.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def expected_meta():
5151
@pytest.fixture
5252
def expected_meteonorm_index():
5353
expected_meteonorm_index = \
54-
pd.date_range('2023-01-01', '2024-12-31 23:59', freq='1h', tz='UTC')
54+
pd.date_range('2023-01-01', '2024-12-31 23:59', freq='1h', tz='UTC') \
55+
+ pd.Timedelta(minutes=30)
5556
expected_meteonorm_index.freq = None
5657
return expected_meteonorm_index
5758

@@ -74,7 +75,7 @@ def expected_meteonorm_data():
7475
[210.75, 210.7458778],
7576
[221.0, 220.99278214],
7677
]
77-
index = pd.date_range('2023-01-01', periods=12, freq='1h', tz='UTC')
78+
index = pd.date_range('2023-01-01 00:30', periods=12, freq='1h', tz='UTC')
7879
index.freq = None
7980
expected = pd.DataFrame(expected, index=index, columns=columns)
8081
return expected
@@ -183,7 +184,7 @@ def test_get_meteonorm_forecast_precision(demo_api_key, demo_url):
183184
url=demo_url)
184185

185186
assert data.index[1] - data.index[0] == pd.Timedelta(minutes=15)
186-
assert data.shape == (5, 1)
187+
assert data.shape == (60/15*3+1, 1)
187188
assert meta['frequency'] == '15_minutes'
188189

189190

@@ -249,16 +250,6 @@ def expected_meteonorm_tmy_meta():
249250
return meta
250251

251252

252-
@pytest.fixture
253-
def expected_meteonorm_tmy_interval_index():
254-
index = pd.date_range(
255-
'2005-01-01', periods=8760, freq='1h', tz=3600)
256-
index.freq = None
257-
interval_index = pd.IntervalIndex.from_arrays(
258-
index, index + pd.Timedelta(hours=1), closed='left')
259-
return interval_index
260-
261-
262253
@pytest.fixture
263254
def expected_meteonorm_tmy_data():
264255
# The first 12 rows of data
@@ -290,7 +281,7 @@ def expected_meteonorm_tmy_data():
290281
@pytest.mark.flaky(reruns=RERUNS, reruns_delay=RERUNS_DELAY)
291282
def test_get_meteonorm_tmy(
292283
demo_api_key, demo_url, expected_meteonorm_tmy_meta,
293-
expected_meteonorm_tmy_data, expected_meteonorm_tmy_interval_index):
284+
expected_meteonorm_tmy_data):
294285
data, meta = pvlib.iotools.get_meteonorm_tmy(
295286
latitude=50, longitude=10,
296287
api_key=demo_api_key,
@@ -312,5 +303,3 @@ def test_get_meteonorm_tmy(
312303
url=demo_url)
313304
assert meta == expected_meteonorm_tmy_meta
314305
pd.testing.assert_frame_equal(data.iloc[:12], expected_meteonorm_tmy_data)
315-
pd.testing.assert_index_equal(
316-
data.index, expected_meteonorm_tmy_interval_index)

0 commit comments

Comments
 (0)