Skip to content

Commit 56b9460

Browse files
committed
Merge branch 'devel'
2 parents 5316587 + fdab3eb commit 56b9460

File tree

7 files changed

+105
-26
lines changed

7 files changed

+105
-26
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
master-v1.2
1+
master-v1.2.2

corrections/ensemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def do_correction(self, lc):
211211

212212
# Clean up the lightcurve by removing nans and ignoring data points with bad quality flags
213213
# these values need to be removed, or they will affect the ensemble later
214-
lc_quality_mask = TESSQualityFlags.filter(lc.quality, TESSQualityFlags.HARDEST_BITMASK)
214+
lc_quality_mask = ~TESSQualityFlags.filter(lc.quality, TESSQualityFlags.HARDEST_BITMASK)
215215
lc.flux[lc_quality_mask] = np.NaN
216216
lc_corr = lc.copy()
217217

-508 KB
Binary file not shown.
-4.93 MB
Binary file not shown.

tests/test_cbvcorrector.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Tests of CBV Corrector.
5+
6+
.. codeauthor:: Rasmus Handberg <rasmush@phys.au.dk>
7+
"""
8+
9+
import pytest
10+
import numpy as np
11+
import sys
12+
import os.path
13+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
14+
import corrections
15+
#from corrections.plots import plt
16+
17+
INPUT_DIR = os.path.join(os.path.dirname(__file__), 'input')
18+
starid = 29281992
19+
camera = 1
20+
ccd = 4
21+
sector = 1
22+
23+
#--------------------------------------------------------------------------------------------------
24+
def test_cbvcorrector_basics():
25+
"""Check that the Ensemblecorrector can be initiated at all"""
26+
with corrections.CBVCorrector(INPUT_DIR, plot=True) as ec:
27+
assert ec.__class__.__name__ == 'CBVCorrector', "Did not get the correct class name back"
28+
assert ec.input_folder == INPUT_DIR, "Incorrect input folder"
29+
assert ec.plot, "Plot parameter passed appropriately"
30+
31+
#--------------------------------------------------------------------------------------------------
32+
@pytest.mark.parametrize('datasource', ['tpf', 'ffi'])
33+
def test_cbvcorrector_returned_values(datasource):
34+
""" Check that the ensemble returns values that are reasonable and within expected bounds """
35+
with corrections.TaskManager(INPUT_DIR) as tm:
36+
task = tm.get_task(starid=starid, camera=camera, ccd=ccd, datasource=datasource)
37+
38+
#Initiate the class
39+
CorrClass = corrections.corrclass('cbv')
40+
with CorrClass(INPUT_DIR, plot=False) as corr:
41+
inlc = corr.load_lightcurve(task)
42+
outlc, status = corr.do_correction(inlc.copy())
43+
44+
# Check status
45+
assert outlc is not None, "CBV Corrector fails"
46+
print(status)
47+
assert status in (corrections.STATUS.OK, corrections.STATUS.WARNING), "STATUS was not set appropriately"
48+
49+
# Check input validation
50+
#with pytest.raises(ValueError) as err:
51+
# outlc, status = corr.do_correction('hello world')
52+
# assert('The input to `do_correction` is not a TessLightCurve object!' in err.value.args[0])
53+
54+
print( inlc.show_properties() )
55+
print( outlc.show_properties() )
56+
57+
# Plot lightcurves:
58+
#plt.switch_backend('TkAgg')
59+
#inlc.plot(normalize=False)
60+
#outlc.plot(ylabel='Relative Flux [ppm]', normalize=False)
61+
#plt.show(block=True)
62+
63+
# Check contents
64+
assert len(outlc) == len(inlc), "Input flux ix different length to output flux"
65+
assert all(inlc.time == outlc.time), "Input time is nonidentical to output time"
66+
assert all(outlc.flux != inlc.flux), "Input and output flux are identical."
67+
assert np.sum(np.isnan(outlc.flux)) < 0.5*len(outlc), "More than half the lightcurve is NaN"
68+
69+
assert len(outlc.flux) == len(outlc.time), "Check TIME and FLUX have same length"
70+
assert len(outlc.flux_err) == len(outlc.time), "Check TIME and FLUX_ERR have same length"
71+
assert len(outlc.quality) == len(outlc.time), "Check TIME and QUALITY have same length"
72+
assert len(outlc.pixel_quality) == len(outlc.time), "Check TIME and QUALITY have same length"
73+
assert len(outlc.cadenceno) == len(outlc.time), "Check TIME and CADENCENO have same length"
74+
assert len(outlc.centroid_col) == len(outlc.time), "Check TIME and CENTROID_COL have same length"
75+
assert len(outlc.centroid_row) == len(outlc.time), "Check TIME and CENTROID_ROW have same length"
76+
assert len(outlc.timecorr) == len(outlc.time), "Check TIME and TIMECORR have same length"
77+
78+
# Check metadata
79+
assert outlc.meta['task']['starid'] == inlc.meta['task']['starid'], "Metadata is incomplete"
80+
assert outlc.meta['task'] == inlc.meta['task'], "Metadata is incomplete"
81+
82+
#--------------------------------------------------------------------------------------------------
83+
if __name__ == "__main__":
84+
test_cbvcorrector_basics()
85+
test_cbvcorrector_returned_values('tpf')
86+
test_cbvcorrector_returned_values('ffi')

tests/test_ensemble.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
.. codeauthor:: Lindsey Carboneau <lmcarboneau@gmail.com>
99
"""
1010

11+
import pytest
12+
import numpy as np
1113
import sys
1214
import os.path
13-
import pytest
1415
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
1516
import corrections
17+
#from corrections.plots import plt
1618

1719
INPUT_DIR = os.path.join(os.path.dirname(__file__), 'input')
1820
TEST_DATA_EXISTS = os.path.exists(os.path.join(INPUT_DIR, 'test_data_available.txt'))
@@ -31,10 +33,11 @@ def test_ensemble_basics():
3133

3234
#--------------------------------------------------------------------------------------------------
3335
@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):
3538
""" Check that the ensemble returns values that are reasonable and within expected bounds """
3639
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)
3841

3942
#Initiate the class
4043
CorrClass = corrections.corrclass('ensemble')
@@ -44,6 +47,7 @@ def test_ensemble_returned_values():
4447

4548
# Check status
4649
assert outlc is not None, "Ensemble fails"
50+
print(status)
4751
assert status == corrections.STATUS.OK, "STATUS was not set appropriately"
4852

4953
# Check input validation
@@ -54,10 +58,17 @@ def test_ensemble_returned_values():
5458
print( inlc.show_properties() )
5559
print( outlc.show_properties() )
5660

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+
5767
# Check contents
5868
assert len(outlc) == len(inlc), "Input flux ix different length to output flux"
5969
assert all(inlc.time == outlc.time), "Input time is nonidentical to output time"
6070
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"
6172

6273
assert len(outlc.flux) == len(outlc.time), "Check TIME and FLUX have same length"
6374
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():
6879
assert len(outlc.centroid_row) == len(outlc.time), "Check TIME and CENTROID_ROW have same length"
6980
assert len(outlc.timecorr) == len(outlc.time), "Check TIME and TIMECORR have same length"
7081

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-
8982
# Check metadata
9083
assert outlc.meta['task']['starid'] == inlc.meta['task']['starid'], "Metadata is incomplete"
9184
assert outlc.meta['task'] == inlc.meta['task'], "Metadata is incomplete"
9285

9386
#--------------------------------------------------------------------------------------------------
9487
if __name__ == "__main__":
9588
test_ensemble_basics()
96-
test_ensemble_returned_values()
97-
test_run_metadata()
89+
#test_ensemble_returned_values('tpf')
90+
test_ensemble_returned_values('ffi')

tests/test_run_tesscorr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_run_tesscorr_cbv(datasource):
7878
#--------------------------------------------------------------------------------------------------
7979
@pytest.mark.skipif(not test_data_available,
8080
reason="This requires a sector of data. Only run if available.")
81-
@pytest.mark.parametrize("datasource", ['ffi', 'tpf'])
81+
@pytest.mark.parametrize("datasource", ['ffi']) # 'tpf'
8282
def test_run_tesscorr_ensemble(datasource):
8383
command = "python run_tesscorr.py -t -o -p --starid=29281992 -m ensemble --datasource=%s" % (
8484
datasource

0 commit comments

Comments
 (0)