8
8
.. codeauthor:: Lindsey Carboneau <lmcarboneau@gmail.com>
9
9
"""
10
10
11
+ import pytest
12
+ import numpy as np
11
13
import sys
12
14
import os .path
13
- import pytest
14
15
sys .path .append (os .path .join (os .path .dirname (__file__ ), '..' ))
15
16
import corrections
17
+ #from corrections.plots import plt
16
18
17
19
INPUT_DIR = os .path .join (os .path .dirname (__file__ ), 'input' )
18
20
TEST_DATA_EXISTS = os .path .exists (os .path .join (INPUT_DIR , 'test_data_available.txt' ))
@@ -31,10 +33,11 @@ def test_ensemble_basics():
31
33
32
34
#--------------------------------------------------------------------------------------------------
33
35
@pytest .mark .skipif (not TEST_DATA_EXISTS , reason = "This requires a sector of data." )
34
- def test_ensemble_returned_values ():
36
+ @pytest .mark .parametrize ('datasource' , ['ffi' ]) # 'tpf'
37
+ def test_ensemble_returned_values (datasource ):
35
38
""" Check that the ensemble returns values that are reasonable and within expected bounds """
36
39
with corrections .TaskManager (INPUT_DIR ) as tm :
37
- task = tm .get_task (starid = starid , camera = camera , ccd = ccd )
40
+ task = tm .get_task (starid = starid , camera = camera , ccd = ccd , datasource = datasource )
38
41
39
42
#Initiate the class
40
43
CorrClass = corrections .corrclass ('ensemble' )
@@ -44,6 +47,7 @@ def test_ensemble_returned_values():
44
47
45
48
# Check status
46
49
assert outlc is not None , "Ensemble fails"
50
+ print (status )
47
51
assert status == corrections .STATUS .OK , "STATUS was not set appropriately"
48
52
49
53
# Check input validation
@@ -54,10 +58,17 @@ def test_ensemble_returned_values():
54
58
print ( inlc .show_properties () )
55
59
print ( outlc .show_properties () )
56
60
61
+ # Plot lightcurves:
62
+ #plt.switch_backend('TkAgg')
63
+ #inlc.plot(normalize=False)
64
+ #outlc.plot(ylabel='Relative Flux [ppm]', normalize=False)
65
+ #plt.show(block=True)
66
+
57
67
# Check contents
58
68
assert len (outlc ) == len (inlc ), "Input flux ix different length to output flux"
59
69
assert all (inlc .time == outlc .time ), "Input time is nonidentical to output time"
60
70
assert all (outlc .flux != inlc .flux ), "Input and output flux are identical."
71
+ assert np .sum (np .isnan (outlc .flux )) < 0.5 * len (outlc ), "More than half the lightcurve is NaN"
61
72
62
73
assert len (outlc .flux ) == len (outlc .time ), "Check TIME and FLUX have same length"
63
74
assert len (outlc .flux_err ) == len (outlc .time ), "Check TIME and FLUX_ERR have same length"
@@ -68,30 +79,12 @@ def test_ensemble_returned_values():
68
79
assert len (outlc .centroid_row ) == len (outlc .time ), "Check TIME and CENTROID_ROW have same length"
69
80
assert len (outlc .timecorr ) == len (outlc .time ), "Check TIME and TIMECORR have same length"
70
81
71
- #--------------------------------------------------------------------------------------------------
72
- @pytest .mark .skipif (not TEST_DATA_EXISTS , reason = "This requires a sector of data." )
73
- def test_run_metadata ():
74
- """ Check that the ensemble returns values that are reasonable and within expected bounds """
75
- with corrections .TaskManager (INPUT_DIR ) as tm :
76
- task = tm .get_task (starid = starid , camera = camera , ccd = ccd )
77
-
78
- #Initiate the class
79
- CorrClass = corrections .corrclass ('ensemble' )
80
- with CorrClass (INPUT_DIR , plot = False ) as corr :
81
- inlc = corr .load_lightcurve (task )
82
- outlc , status = corr .do_correction (inlc .copy ())
83
-
84
- assert outlc is not None , "Ensemble fails"
85
-
86
- print ( inlc .show_properties () )
87
- print ( outlc .show_properties () )
88
-
89
82
# Check metadata
90
83
assert outlc .meta ['task' ]['starid' ] == inlc .meta ['task' ]['starid' ], "Metadata is incomplete"
91
84
assert outlc .meta ['task' ] == inlc .meta ['task' ], "Metadata is incomplete"
92
85
93
86
#--------------------------------------------------------------------------------------------------
94
87
if __name__ == "__main__" :
95
88
test_ensemble_basics ()
96
- test_ensemble_returned_values ()
97
- test_run_metadata ( )
89
+ # test_ensemble_returned_values('tpf' )
90
+ test_ensemble_returned_values ( 'ffi' )
0 commit comments