@@ -632,28 +632,32 @@ def test_detect_clearsky_missing_index(detect_clearsky_data):
632
632
clearsky .detect_clearsky (expected ['GHI' ].values , cs ['ghi' ].values )
633
633
634
634
635
- def test__line_length_windowed ():
636
- # sqt is hand-calculated assuming window=3
635
+ @ pytest . fixture
636
+ def detect_clearsky_helper_data ():
637
637
samples_per_window = 3
638
638
sample_interval = 1
639
639
x = pd .Series (np .arange (0 , 7 )** 2. )
640
640
# line length between adjacent points
641
641
sqt = pd .Series (np .sqrt (np .array ([np .nan , 2. , 10. , 26. , 50. , 82 , 122. ])))
642
642
H = hankel (np .arange (samples_per_window ),
643
643
np .arange (samples_per_window - 1 , len (sqt )))
644
+ return x , samples_per_window , sample_interval , H
645
+
646
+
647
+ def test__line_length_windowed (detect_clearsky_helper_data ):
648
+ x , samples_per_window , sample_interval , H = detect_clearsky_helper_data
649
+ # sqt is hand-calculated assuming window=3
650
+ # line length between adjacent points
651
+ sqt = pd .Series (np .sqrt (np .array ([np .nan , 2. , 10. , 26. , 50. , 82 , 122. ])))
644
652
expected = {}
645
653
expected ['line_length' ] = sqt + sqt .shift (- 1 )
646
654
result = clearsky ._line_length_windowed (
647
655
x , H , samples_per_window , sample_interval )
648
656
assert_series_equal (result , expected ['line_length' ])
649
657
650
658
651
- def test__max_diff_windowed ():
652
- samples_per_window = 3
653
- sample_interval = 1
654
- x = pd .Series (np .arange (0 , 7 )** 2. )
655
- H = hankel (np .arange (samples_per_window ),
656
- np .arange (samples_per_window - 1 , len (x )))
659
+ def test__max_diff_windowed (detect_clearsky_helper_data ):
660
+ x , samples_per_window , sample_interval , H = detect_clearsky_helper_data
657
661
expected = {}
658
662
expected ['max_diff' ] = pd .Series (
659
663
data = [np .nan , 3. , 5. , 7. , 9. , 11. , np .nan ], index = x .index )
@@ -662,19 +666,15 @@ def test__max_diff_windowed():
662
666
assert_series_equal (result , expected ['max_diff' ])
663
667
664
668
665
- def test__calc_stats ():
669
+ def test__calc_stats (detect_clearsky_helper_data ):
670
+ x , samples_per_window , sample_interval , H = detect_clearsky_helper_data
666
671
# stats are hand-computed assuming window = 3 and sample_interval = 1
667
- samples_per_window = 3
668
- sample_interval = 1
669
- x = pd .Series (np .arange (0 , 7 )** 2. )
670
672
mean_x = pd .Series (np .array ([np .nan , np .nan , 5 , 14 , 29 , 50 , 77 ]) / 3. )
671
673
max_x = pd .Series (np .array ([np .nan , np .nan , 4 , 9 , 16 , 25 , 36 ]))
672
674
diff_std = np .array ([np .nan , np .nan , np .sqrt (2 ), np .sqrt (2 ), np .sqrt (2 ),
673
675
np .sqrt (2 ), np .sqrt (2 )])
674
676
slope_nstd = diff_std / mean_x
675
677
slope = x .diff ().shift (- 1 )
676
- H = hankel (np .arange (samples_per_window ),
677
- np .arange (samples_per_window - 1 , len (x )))
678
678
expected = {}
679
679
expected ['mean' ] = mean_x
680
680
expected ['max' ] = max_x
0 commit comments