Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 0abff22

Browse files
committed
implement simple test of DataSource.get_contiguous_time_periods() #223
1 parent 909dbc1 commit 0abff22

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

tests/data_sources/test_data_source.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
def test_image_data_source():
5-
65
_ = ImageDataSource(
76
image_size_pixels=64,
87
meters_per_pixel=2000,

tests/data_sources/test_nwp_data_source.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import os
2+
import pandas as pd
23

34
import nowcasting_dataset
45
from nowcasting_dataset.data_sources.nwp.nwp_data_source import NWPDataSource
56

67

7-
def test_nwp_data_source_init():
8+
PATH = os.path.dirname(nowcasting_dataset.__file__)
89

9-
path = os.path.dirname(nowcasting_dataset.__file__)
10+
# Solar PV data (test data)
11+
NWP_FILENAME = f"{PATH}/../tests/data/nwp_data/test.zarr"
1012

11-
# Solar PV data (test data)
12-
NWP_FILENAME = f"{path}/../tests/data/nwp_data/test.zarr"
1313

14+
def test_nwp_data_source_init():
1415
_ = NWPDataSource(
1516
filename=NWP_FILENAME,
1617
history_minutes=30,
@@ -21,12 +22,6 @@ def test_nwp_data_source_init():
2122

2223

2324
def test_nwp_data_source_open():
24-
25-
path = os.path.dirname(nowcasting_dataset.__file__)
26-
27-
# Solar PV data (test data)
28-
NWP_FILENAME = f"{path}/../tests/data/nwp_data/test.zarr"
29-
3025
nwp = NWPDataSource(
3126
filename=NWP_FILENAME,
3227
history_minutes=30,
@@ -40,12 +35,6 @@ def test_nwp_data_source_open():
4035

4136

4237
def test_nwp_data_source_batch():
43-
44-
path = os.path.dirname(nowcasting_dataset.__file__)
45-
46-
# Solar PV data (test data)
47-
NWP_FILENAME = f"{path}/../tests/data/nwp_data/test.zarr"
48-
4938
nwp = NWPDataSource(
5039
filename=NWP_FILENAME,
5140
history_minutes=30,
@@ -64,3 +53,20 @@ def test_nwp_data_source_batch():
6453
batch = nwp.get_batch(t0_datetimes=t0_datetimes, x_locations=x, y_locations=y)
6554

6655
assert batch.data.shape == (4, 1, 19, 2, 2)
56+
57+
58+
def test_nwp_get_contiguous_time_periods():
59+
nwp = NWPDataSource(
60+
filename=NWP_FILENAME,
61+
history_minutes=30,
62+
forecast_minutes=60,
63+
convert_to_numpy=True,
64+
n_timesteps_per_batch=8,
65+
channels=["t"],
66+
)
67+
68+
contiguous_time_periods = nwp.get_contiguous_time_periods()
69+
correct_time_periods = pd.DataFrame(
70+
[{"start_dt": pd.Timestamp("2019-01-01 00:00"), "end_dt": pd.Timestamp("2019-01-02 02:00")}]
71+
)
72+
pd.testing.assert_frame_equal(contiguous_time_periods, correct_time_periods)

0 commit comments

Comments
 (0)