Skip to content

Commit f029dea

Browse files
author
David Turner
committed
Fixed issues where both inst combined and TM1, TM2, etc. spectra were being retrieved for spectral fitting.
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent bfc31e2 commit f029dea

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

xga/sources/base.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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/5/26, 1:46 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 10:40 PM. Copyright (c) The Contributors.
33

44
import gc
55
import os
@@ -2309,6 +2309,12 @@ def _get_phot_prod(self, prod_type: str, obs_id: str = None, inst: str = None, l
23092309
telescope=telescope)
23102310
matched_prods = [p[-1] for p in broad_matches if extra_key in p[-2]]
23112311

2312+
# This part of the code ensures that if inst is None (the default), only products for 'real'
2313+
# instruments are returned. To retrieve a multi-instrument combined product, the user must
2314+
# explicitly specify inst='combined'.
2315+
if inst is None:
2316+
matched_prods = [m_prod for m_prod in matched_prods if m_prod.instrument != 'combined']
2317+
23122318
if len(matched_prods) == 1:
23132319
matched_prods = matched_prods[0]
23142320
elif len(matched_prods) == 0:
@@ -2345,6 +2351,12 @@ def _get_prof_prod(self, search_key: str, obs_id: str = None, inst: str = None,
23452351
# Fetch all the matching profiles for the specified telescope
23462352
matched_prods = self.get_products(search_key, obs_id, inst, just_obj=True, telescope=telescope)
23472353

2354+
# This part of the code ensures that if inst is None (the default), only products for 'real'
2355+
# instruments are returned. To retrieve a multi-instrument combined product, the user must
2356+
# explicitly specify inst='combined'.
2357+
if inst is None:
2358+
matched_prods = [m_prod for m_prod in matched_prods if m_prod.instrument != 'combined']
2359+
23482360
matched_prods: List[BaseProfile1D]
23492361

23502362
# Matching the radii is going to take a maybe slightly (but practically not really) dangerous approach. The
@@ -2443,6 +2455,12 @@ def _get_lc_prod(self, outer_radius: Union[str, Quantity] = None, obs_id: str =
24432455
# user (None by default) - we'll then sweep through whatever list is returned and narrow them down
24442456
matched_prods = self.get_products(search_key, obs_id, inst, telescope=telescope)
24452457

2458+
# This part of the code ensures that if inst is None (the default), only products for 'real'
2459+
# instruments are returned. To retrieve a multi-instrument combined product, the user must
2460+
# explicitly specify inst='combined'.
2461+
if inst is None:
2462+
matched_prods = [m_prod for m_prod in matched_prods if m_prod.instrument != 'combined']
2463+
24462464
matched_prods: List[LightCurve]
24472465

24482466
# Checking for matching radii first - this will likely whittle down the LCs best of all. We have
@@ -3354,6 +3372,12 @@ def _get_spec_prod(self, outer_radius: Union[str, Quantity], obs_id: str = None,
33543372
else:
33553373
matched_prods = self.get_products('spectrum', obs_id=obs_id, inst=inst, telescope=telescope)
33563374

3375+
# This part of the code ensures that if inst is None (the default), only products for 'real'
3376+
# instruments are returned. To retrieve a multi-instrument combined product, the user must
3377+
# explicitly specify inst='combined'.
3378+
if inst is None:
3379+
matched_prods = [m_prod for m_prod in matched_prods if m_prod.instrument != 'combined']
3380+
33573381
# Checking for matching radii first - this will likely whittle down the spectra best of all. We have
33583382
# had matching problems sometimes because of float precision (the last digit flips and is no longer
33593383
# an exact match to the other radius)

xga/xspec/fit/_common.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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/5/26, 1:41 PM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/5/26, 10:41 PM. Copyright (c) The Contributors.
33

44
import os
55
from typing import List, Union, Tuple, Dict
@@ -293,26 +293,19 @@ def _spec_obj_setup(stacked_spectra: bool, tel: str, source: BaseSource, out_rad
293293
try:
294294
if tel in ['erosita', 'erass'] and (len(source.obs_ids[tel]) > 1):
295295
# For erosita with multiple observations, we need combined-obs spectra to avoid duplicated events
296-
# The inst parameter controls whether we want multi-instrument (stacked) or per-instrument
297-
if stacked_spectra:
298-
# Scenario 3: Multi-obs + multi-inst combined (obs_id='combined', inst='combined')
299-
search_inst = 'combined'
300-
else:
301-
# Scenario 2: Multi-obs + individual insts (obs_id='combined', inst=<specific>)
302-
# Leaving inst=None returns all per-instrument combined-obs spectra
303-
search_inst = None
296+
# The inst parameter controls whether we want multi-instrument (stacked) or per-instrument.
297+
# Due to strict instrument filtering in get_spectra, inst=None will only return 'real' TMs.
298+
search_inst = 'combined' if stacked_spectra else None
304299

305300
spec_objs = source.get_spectra(out_rad_vals[src_ind], obs_id='combined', inst=search_inst,
306301
inner_radius=inn_rad_vals[src_ind],
307302
group_spec=group_spec, min_counts=min_counts,
308303
min_sn=min_sn, telescope=tel)
309304
else:
310-
# Single observation (or non-eROSITA): use regular spectra
311-
# For multi-instrument stacking, inst='combined' retrieves Scenario 1 products
312-
# search_inst = 'combined' if stacked_spectra else None
313-
# This part of the if-else will be for missions with no implemented spectrum
314-
# stacking method I think, so search_inst must be None.
315-
search_inst = None
305+
# Single observation (or non-eROSITA): use regular spectra.
306+
# For multi-instrument stacking, inst='combined' retrieves multi-instrument products.
307+
# inst=None retrieves all individual instrument products.
308+
search_inst = 'combined' if stacked_spectra else None
316309

317310
spec_objs = source.get_spectra(out_rad_vals[src_ind], inner_radius=inn_rad_vals[src_ind],
318311
group_spec=group_spec, min_counts=min_counts, min_sn=min_sn,

0 commit comments

Comments
 (0)