1
1
import numpy as np
2
- from datetime import datetime
3
-
4
- from ocf_datapipes .transform .numpy_batch import AddTrigonometricDateTime
5
2
6
3
from ocf_datapipes .transform .numpy_batch .datetime_features import _get_date_time_in_pi
7
4
8
5
9
6
def test_get_date_time_in_pi ():
10
- times = [
11
- "2020-01-01T00:00:01" ,
12
- "2020-04-01T06:00:00" ,
13
- "2020-07-01T12:00:00" ,
14
- "2020-09-30T18:00:00" ,
15
- "2020-12-31T23:59:59" ,
16
- "2021-01-01T00:00:01" ,
17
- "2021-04-02T06:00:00" ,
18
- "2021-07-02T12:00:00" ,
19
- "2021-10-01T18:00:00" ,
20
- "2021-12-31T23:59:59" ,
21
- ]
22
-
23
- expected_times_in_pi = [0 , 0.5 * np .pi , np .pi , 1.5 * np .pi , 2 * np .pi ] * 2
24
-
25
- times = np .array ([datetime .fromisoformat (time ) for time in times ], dtype = "datetime64[s]" )
7
+ times = np .array ([
8
+ "2020-01-01T00:00:00" , "2020-04-01T06:00:00" ,
9
+ "2020-07-01T12:00:00" , "2020-09-30T18:00:00" ,
10
+ "2020-12-31T23:59:59" ,
11
+ "2021-01-01T00:00:00" , "2021-04-02T06:00:00" ,
12
+ "2021-07-02T12:00:00" , "2021-10-01T18:00:00" ,
13
+ "2021-12-31T23:59:59"
14
+ ]).reshape ((2 , 5 ))
15
+
16
+ expected_times_in_pi = np .array ([0 , 0.5 * np .pi , np .pi , 1.5 * np .pi , 2 * np .pi ] * 2 ).reshape ((2 ,5 ))
17
+
18
+ times = times .astype ("datetime64[s]" )
26
19
27
20
date_in_pi , time_in_pi = _get_date_time_in_pi (times )
28
21
@@ -34,3 +27,9 @@ def test_get_date_time_in_pi():
34
27
assert np .isclose (np .sin (time_in_pi ), np .sin (expected_times_in_pi ), atol = 7.3e-05 ).all ()
35
28
assert np .isclose (np .cos (date_in_pi ), np .cos (expected_times_in_pi ), atol = 0.02182 ).all ()
36
29
assert np .isclose (np .sin (date_in_pi ), np .sin (expected_times_in_pi ), atol = 0.02182 ).all ()
30
+
31
+ # 1D array test
32
+ assert np .isclose (np .cos (time_in_pi [0 ]), np .cos (expected_times_in_pi [0 ]), atol = 7.3e-05 ).all ()
33
+ assert np .isclose (np .sin (time_in_pi [0 ]), np .sin (expected_times_in_pi [0 ]), atol = 7.3e-05 ).all ()
34
+ assert np .isclose (np .cos (date_in_pi [0 ]), np .cos (expected_times_in_pi [0 ]), atol = 0.02182 ).all ()
35
+ assert np .isclose (np .sin (date_in_pi [0 ]), np .sin (expected_times_in_pi [0 ]), atol = 0.02182 ).all ()
0 commit comments