Skip to content

Commit 1086016

Browse files
author
David Turner
committed
Specified the energy bounds of all the light curves to be generated and retrieved in the TestEsassLcFuncs test class, also asserted that the energy bounds of the retrieved LCs are what they should be, and polished up the final combined-Obs - combined-TM LC test to fail rather than error if the product can't be found
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent 2ac90c4 commit 1086016

1 file changed

Lines changed: 87 additions & 23 deletions

File tree

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/8/26, 5:28 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/8/26, 5:49 PM. Copyright (c) The Contributors.
33

44
import unittest
55

6+
from astropy.units import Quantity
7+
68
from xga.exceptions import NoProductAvailableError
79
from xga.generate.esass.lightcurve import srctool_lightcurve
810
from xga.products.lightcurve import LightCurve
@@ -15,16 +17,29 @@ class TestEsassLcFuncs(unittest.TestCase):
1517
def setUpClass(cls):
1618
cls.src = get_test_source('erass')
1719

20+
# Specify the lower and upper energy bounds for the light curves generated and
21+
# retrieved in these tests.
22+
cls.lc_lo_en = Quantity(0.5, 'keV')
23+
cls.lc_hi_en = Quantity(2.0, 'keV')
24+
1825
@require_esass
1926
def test_srctool_lightcurve_combine_insts_f_combine_obs_f(self):
2027
"""
2128
Testing srctool_lightcurve with the arguments combine_insts=False and combine_obs=False
2229
"""
2330
# Run the light curve generation - one light curve per eROSITA TM per Obs associated with this source
24-
srctool_lightcurve(self.src, 'r500', combine_tm=False, combine_obs=False)
31+
srctool_lightcurve(self.src,
32+
'r500',
33+
lo_en=self.lc_lo_en,
34+
hi_en=self.lc_hi_en,
35+
combine_tm=False, combine_obs=False)
2536

2637
try:
27-
lc = self.src.get_lightcurves('r500', telescope='erass', inst='tm1')
38+
lc = self.src.get_lightcurves('r500',
39+
lo_en=self.lc_lo_en,
40+
hi_en=self.lc_hi_en,
41+
telescope='erass',
42+
inst='tm1')
2843
except NoProductAvailableError:
2944
self.fail("NoProductAvailableError raised.")
3045

@@ -37,17 +52,29 @@ def test_srctool_lightcurve_combine_insts_f_combine_obs_f(self):
3752
assert cur_lc.telescope == 'erass'
3853
assert cur_lc.obs_id != 'combined'
3954
assert cur_lc.instrument == 'tm1'
55+
# Might as well test the energy bounds as well
56+
assert cur_lc.energy_bounds[0] == self.lc_lo_en
57+
assert cur_lc.energy_bounds[1] == self.lc_hi_en
4058

4159
@require_esass
4260
def test_srctool_lightcurve_combine_insts_t_combine_obs_f(self):
4361
"""
4462
Testing srctool_lightcurve with the arguments combine_insts=True and combine_obs=False
4563
"""
4664
# Run the light curve generation - one light curve per eROSITA Obs, combining all TMs
47-
srctool_lightcurve(self.src, 'r500', combine_tm=True, combine_obs=False)
65+
srctool_lightcurve(self.src,
66+
'r500',
67+
lo_en=self.lc_lo_en,
68+
hi_en=self.lc_hi_en,
69+
combine_tm=True,
70+
combine_obs=False)
4871

4972
try:
50-
lc = self.src.get_lightcurves('r500', telescope='erass', inst='combined')
73+
lc = self.src.get_lightcurves('r500',
74+
lo_en=self.lc_lo_en,
75+
hi_en=self.lc_hi_en,
76+
telescope='erass',
77+
inst='combined')
5178
except NoProductAvailableError:
5279
self.fail("NoProductAvailableError raised.")
5380

@@ -60,6 +87,9 @@ def test_srctool_lightcurve_combine_insts_t_combine_obs_f(self):
6087
assert cur_lc.telescope == 'erass'
6188
assert cur_lc.obs_id != 'combined'
6289
assert cur_lc.instrument == 'combined'
90+
# Might as well test the energy bounds as well
91+
assert cur_lc.energy_bounds[0] == self.lc_lo_en
92+
assert cur_lc.energy_bounds[1] == self.lc_hi_en
6393

6494
@require_esass
6595
def test_srctool_lightcurve_combine_insts_f_combine_obs_t(self):
@@ -68,20 +98,35 @@ def test_srctool_lightcurve_combine_insts_f_combine_obs_t(self):
6898
"""
6999
# Run the light curve generation - one light curve per eROSITA TM, combining all ObsIDs
70100
# associated with this source
71-
srctool_lightcurve(self.src, 'r500', combine_tm=False, combine_obs=True)
101+
srctool_lightcurve(self.src,
102+
'r500',
103+
lo_en=self.lc_lo_en,
104+
hi_en=self.lc_hi_en,
105+
combine_tm=False,
106+
combine_obs=True)
72107

73108
try:
74-
lc = self.src.get_combined_lightcurves('r500', telescope='erass', inst='tm1')
109+
lc = self.src.get_combined_lightcurves('r500',
110+
lo_en=self.lc_lo_en,
111+
hi_en=self.lc_hi_en,
112+
telescope='erass',
113+
inst='tm1')
75114
except NoProductAvailableError:
76115
self.fail("NoProductAvailableError raised when retrieving TM1 combined-ObsID light curve.")
77116

78117
assert isinstance(lc, LightCurve)
79118
assert lc.telescope == 'erass'
80119
assert lc.obs_id == 'combined'
81120
assert lc.instrument == 'tm1'
121+
assert lc.energy_bounds[0] == self.lc_lo_en
122+
assert lc.energy_bounds[1] == self.lc_hi_en
82123

83124
try:
84-
all_tm_lc = self.src.get_combined_lightcurves('r500', telescope='erass', inst=None)
125+
all_tm_lc = self.src.get_combined_lightcurves('r500',
126+
lo_en=self.lc_lo_en,
127+
hi_en=self.lc_hi_en,
128+
telescope='erass',
129+
inst=None)
85130
except NoProductAvailableError:
86131
self.fail("NoProductAvailableError raised when retrieving combined-ObsID "
87132
"light curves for every separate TM.")
@@ -93,25 +138,44 @@ def test_srctool_lightcurve_combine_insts_f_combine_obs_t(self):
93138
assert cur_lc.telescope == 'erass'
94139
assert cur_lc.obs_id == 'combined'
95140
assert cur_lc.instrument[:2] == 'tm'
141+
# Might as well test the energy bounds as well
142+
assert cur_lc.energy_bounds[0] == self.lc_lo_en
143+
assert cur_lc.energy_bounds[1] == self.lc_hi_en
96144

97145
@require_esass
98146
def test_srctool_lightcurve_combine_insts_t_combine_obs_t(self):
99147
"""
100148
Testing srctool_lightcurve with the arguments combine_insts=True and combine_obs=True
101149
"""
102150

103-
srctool_lightcurve(self.src, 'r500', combine_tm=True, combine_obs=True)
104-
105-
lc = self.src.get_combined_lightcurves('r500', telescope='erass', inst='combined')
106-
107-
if isinstance(lc, list):
108-
for l in lc:
109-
assert isinstance(l, LightCurve)
110-
assert l.telescope == 'erass'
111-
assert l.obs_id == 'combined'
112-
assert l.instrument == 'combined'
113-
else:
114-
assert isinstance(lc, LightCurve)
115-
assert lc.telescope == 'erass'
116-
assert lc.obs_id == 'combined'
117-
assert lc.instrument == 'combined'
151+
# Run the light curve generation - this should only result in a single light curve as
152+
# we're combining all ObsIDs and all their TMs into a single light curve.
153+
srctool_lightcurve(self.src,
154+
'r500',
155+
lo_en=self.lc_lo_en,
156+
hi_en=self.lc_hi_en,
157+
combine_tm=True,
158+
combine_obs=True)
159+
160+
try:
161+
# Specifying the lo_en and hi_en is particularly important for this test, as
162+
# we expect a single combined ObsID - combined TM light curve to be returned,
163+
# and if there have been other equivalent LC generations run but with different
164+
# energy bounds then we'll get a list returned (though given we control these
165+
# tests, and they should be run in a clean environment I'm not THAT worried).
166+
lc = self.src.get_combined_lightcurves('r500',
167+
lo_en=self.lc_lo_en,
168+
hi_en=self.lc_hi_en,
169+
telescope='erass',
170+
inst='combined')
171+
except NoProductAvailableError:
172+
self.fail("NoProductAvailableError raised.")
173+
174+
# This MUST be a single LightCurve return, if we're getting multiple instances in a
175+
# list then something has gone wrong
176+
assert type(lc) == LightCurve
177+
assert lc.telescope == 'erass'
178+
assert lc.obs_id == 'combined'
179+
assert lc.instrument == 'combined'
180+
assert lc.energy_bounds[0] == self.lc_lo_en
181+
assert lc.energy_bounds[1] == self.lc_hi_en

0 commit comments

Comments
 (0)