1
1
import os
2
+ import pandas as pd
2
3
3
4
import nowcasting_dataset
4
5
from nowcasting_dataset .data_sources .nwp .nwp_data_source import NWPDataSource
5
6
6
7
7
- def test_nwp_data_source_init ():
8
+ PATH = os . path . dirname ( nowcasting_dataset . __file__ )
8
9
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"
10
12
11
- # Solar PV data (test data)
12
- NWP_FILENAME = f"{ path } /../tests/data/nwp_data/test.zarr"
13
13
14
+ def test_nwp_data_source_init ():
14
15
_ = NWPDataSource (
15
16
filename = NWP_FILENAME ,
16
17
history_minutes = 30 ,
@@ -21,12 +22,6 @@ def test_nwp_data_source_init():
21
22
22
23
23
24
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
-
30
25
nwp = NWPDataSource (
31
26
filename = NWP_FILENAME ,
32
27
history_minutes = 30 ,
@@ -40,12 +35,6 @@ def test_nwp_data_source_open():
40
35
41
36
42
37
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
-
49
38
nwp = NWPDataSource (
50
39
filename = NWP_FILENAME ,
51
40
history_minutes = 30 ,
@@ -64,3 +53,20 @@ def test_nwp_data_source_batch():
64
53
batch = nwp .get_batch (t0_datetimes = t0_datetimes , x_locations = x , y_locations = y )
65
54
66
55
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