|
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. |
3 | 3 |
|
4 | 4 | import os |
5 | 5 | from functools import wraps |
|
12 | 12 | from warnings import warn |
13 | 13 |
|
14 | 14 | import fitsio |
| 15 | +import numpy as np |
15 | 16 | import pandas as pd |
16 | 17 | from fitsio import FITS |
17 | 18 | from tqdm import tqdm |
@@ -371,14 +372,37 @@ def callback(results_in): |
371 | 372 | # First two columns are skipped because they are energy limits |
372 | 373 | combos = list(set([c.split("_")[1] for c in res_table.columns[2:]])) |
373 | 374 | # 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 |
375 | 377 | 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 |
382 | 406 | elif tel == 'chandra': |
383 | 407 | # We know that only ACIS is supported by XGA currently, so we can split on it to |
384 | 408 | # get the correct ObsID (Chandra ObsIDs are not necessarily all the same |
|
0 commit comments