Skip to content

Commit 577bc39

Browse files
author
David Turner
committed
Added new logic to the conversion factor assignment in the xspec_call wrapper so that it can handle conversion factors calculated for combined spectra again
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent 084f278 commit 577bc39

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

xga/xspec/run.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# This code is a part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 17:27. Copyright (c) The Contributors
1+
# 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, 10:55 AM. Copyright (c) The Contributors.
33

44
import os
55
from functools import wraps
@@ -12,6 +12,7 @@
1212
from warnings import warn
1313

1414
import fitsio
15+
import numpy as np
1516
import pandas as pd
1617
from fitsio import FITS
1718
from tqdm import tqdm
@@ -371,14 +372,37 @@ def callback(results_in):
371372
# First two columns are skipped because they are energy limits
372373
combos = list(set([c.split("_")[1] for c in res_table.columns[2:]]))
373374
# Getting the spectra for each column, then assigning rates and lums
374-
# TODO this could be neater and better generalised
375+
# TODO this could be neater and better generalised - THIS WHOLE FUNCTION/SETUP
376+
# IS AWFUL AND NEEDS BURNING DOWN AND REPLACING
375377
for comb in combos:
376-
if tel in ['erosita', 'erass'] and len(s.obs_ids[tel]) == 1:
377-
spec = s.get_products("spectrum", comb[:6], comb[6:], extra_key=storage_key,
378-
telescope=tel)[0]
379-
elif tel in ['erosita', 'erass']:
380-
spec = s.get_products("combined_spectrum", comb[:6], comb[6:], extra_key=storage_key,
381-
telescope=tel)[0]
378+
379+
# Deal with peculiarities of eROSITA first
380+
if tel in ['erosita', 'erass']:
381+
# If the comb string begins and ends with combined, and is longer than just "combined" (as
382+
# if comb just equaled "combined" both startswith and endswith would return True - though
383+
# that should never happen) then we set the current ObsID and instrument accordingly.
384+
if ((np.char.startswith(comb, "combined") and np.char.endswith(comb, "combined"))
385+
and len(comb) != len("combined")):
386+
comb_oi = "combined"
387+
comb_inst = "combined"
388+
# Get this paranoid check out the way, it should never be triggered (we hope)
389+
elif ((np.char.startswith(comb, "combined") and np.char.endswith(comb, "combined"))
390+
and len(comb) == len("combined")):
391+
raise XGADeveloperError(f"The 'comb' string used for conversion factor assignment "
392+
f"somehow consists just of {comb}.")
393+
# Now we deal with the cases of one or the other of ObsID and instrument being combined
394+
else:
395+
comb_oi = "combined" if np.char.startswith(comb, "combined") else comb[:6]
396+
comb_inst = "combined" if np.char.endswith(comb, "combined") else comb[6:]
397+
398+
# Now onto retrieving spectra
399+
if len(s.obs_ids[tel]) == 1:
400+
spec = s.get_products("spectrum", comb_oi, comb_inst, extra_key=storage_key,
401+
telescope=tel)[0]
402+
else:
403+
spec = s.get_products("combined_spectrum", comb_oi, comb_inst, extra_key=storage_key,
404+
telescope=tel)[0]
405+
# Now Chandra
382406
elif tel == 'chandra':
383407
# We know that only ACIS is supported by XGA currently, so we can split on it to
384408
# get the correct ObsID (Chandra ObsIDs are not necessarily all the same

0 commit comments

Comments
 (0)