Skip to content

Commit 525a82e

Browse files
authored
Merge pull request #1487 from DavidT3/refine/moveXSPECNumChanCheck
Moved the XSPEC template script's check for a minimum number of noticed channels to before model declaration
2 parents 9a6e4da + df9730f commit 525a82e

File tree

14 files changed

+600
-409
lines changed

14 files changed

+600
-409
lines changed

xga/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# 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) 16/07/2025, 12:25. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 15:20. Copyright (c) The Contributors
33
from . import _version
44
__version__ = _version.get_versions()['version']
55

66
from .utils import (xga_conf, CENSUS, OUTPUT, NUM_CORES, XGA_EXTRACT, BASE_XSPEC_SCRIPT, MODEL_PARS,
7-
MODEL_UNITS, ABUND_TABLES, XSPEC_FIT_METHOD, COUNTRATE_CONV_SCRIPT, NHC, BLACKLIST, HY_MASS, MEAN_MOL_WEIGHT,
8-
SAS_VERSION, XSPEC_VERSION, SAS_AVAIL, DEFAULT_COSMO, TELESCOPES, USABLE, DEFAULT_TELE_SEARCH_DIST, COMBINED_INSTS,
9-
eSASS_AVAIL, SRC_REGION_COLOURS, check_telescope_choices, PRETTY_TELESCOPE_NAMES, CIAO_AVAIL, CIAO_VERSION, CALDB_AVAIL,
10-
CALDB_VERSION, ESASS_VERSION, RAD_MATCH_PRECISION)
7+
MODEL_UNITS, ABUND_TABLES, XSPEC_FIT_METHOD, COUNTRATE_CONV_SCRIPT, NHC, BLACKLIST, HY_MASS, MEAN_MOL_WEIGHT,
8+
SAS_VERSION, XSPEC_VERSION, SAS_AVAIL, DEFAULT_COSMO, TELESCOPES, USABLE, DEFAULT_TELE_SEARCH_DIST, COMBINED_INSTS,
9+
ESASS_AVAIL, SRC_REGION_COLOURS, check_telescope_choices, PRETTY_TELESCOPE_NAMES, CIAO_AVAIL, CIAO_VERSION, CALDB_AVAIL,
10+
CALDB_VERSION, ESASS_VERSION, RAD_MATCH_PRECISION)

xga/generate/ciao/spec.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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) 26/03/2025, 10:57. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 10:36. Copyright (c) The Contributors
33

44
import os
55
from copy import copy
@@ -46,6 +46,15 @@ def _chandra_spec_cmds(sources: Union[BaseSource, BaseSample], outer_radius: Uni
4646
:param bool force_gen: This boolean flag will force the regeneration of spectra, even if they already exist.
4747
"""
4848

49+
# Early XGA could generate spectra within the detection regions of the source, but
50+
# that has been deprecated for quite a while, as it was a bad idea. The generation
51+
# of spectra within user-specified regions will be possible, but it will be
52+
# implemented differently. The original way was bad because the detection region
53+
# could/almost certainly would be different for each observation
54+
if outer_radius == 'region':
55+
raise ValueError("The string 'region' is no longer a valid option for "
56+
"the 'outer_radius' argument.")
57+
4958
stack = False # This tells the ciao_call routine that this command won't be part of a stack.
5059
execute = True # This should be executed immediately.
5160
# This function supports passing both individual sources and samples - but if it is a source we like to be able

xga/generate/common.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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) 08/07/2025, 17:26. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 10:39. Copyright (c) The Contributors
33

44
import os
55
import sys
@@ -45,10 +45,27 @@ def execute_cmd(cmd: str, p_type: Union[str, List[str]], p_path: list, extra_inf
4545
if "DYLD_LIBRARY_PATH" in sys_env:
4646
cmd = f"export DYLD_LIBRARY_PATH={sys_env['DYLD_LIBRARY_PATH']} && {cmd}"
4747

48+
# This runs the passed command - it captures the stdout and stderr as well
4849
out, err = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE).communicate()
50+
# Captured out/err are byte type, will decode that into str for easier use
4951
out = out.decode("UTF-8", errors='ignore')
5052
err = err.decode("UTF-8", errors='ignore')
5153

54+
# We will assume that the first entry in the product path argument is the
55+
# primary output file, and will name the log files after it
56+
log_stem = p_path[0][:p_path[0].rfind('.')]
57+
# One file for out and one for error
58+
std_out_file = log_stem + "_stdout.log"
59+
std_err_file = log_stem + "_stderr.log"
60+
61+
# Write the standard out to a log file
62+
with open(std_out_file, "w") as std_outo:
63+
std_outo.write(cmd + "\n\n" + out)
64+
# If there are standard error entries, write them to a file as well
65+
if len(err) > 0:
66+
with open(std_err_file, "w") as std_erro:
67+
std_erro.write(cmd + "\n\n" + err)
68+
5269
# Trying to make sure that any passed arrays get smoothed out into the list type we want
5370
if type(p_path) == np.ndarray:
5471
p_path = list(p_path)

xga/generate/esass/_common.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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, 11:57. Copyright (c) The Contributors
3+
4+
from astropy.units import Quantity
5+
6+
EROSITA_EXTMAP_LO_EN = Quantity(0.2, 'keV')
7+
EROSITA_EXTMAP_HI_EN = Quantity(10.0, 'keV')

xga/generate/esass/lightcurve.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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) 03/07/2025, 10:55. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 10:36. Copyright (c) The Contributors
33

44
import os
55
from copy import deepcopy
@@ -191,6 +191,15 @@ def _append_lc_info(evt_list):
191191
"hi_en": hi_en,
192192
"telescope": 'erosita'})
193193

194+
# Early XGA could generate spectra within the detection regions of the source, but
195+
# that has been deprecated for quite a while, as it was a bad idea. The generation
196+
# of spectra within user-specified regions will be possible, but it will be
197+
# implemented differently. The original way was bad because the detection region
198+
# could/almost certainly would be different for each observation
199+
if outer_radius == 'region':
200+
raise ValueError("The string 'region' is no longer a valid option for "
201+
"the 'outer_radius' argument.")
202+
194203
# We check to see whether there is an eROSITA entry in the 'telescopes' property. If sources is a Source
195204
# object, then that property contains the telescopes associated with that source, and if it is a Sample object
196205
# then 'telescopes' contains the list of unique telescopes that are associated with at least one member source.

xga/generate/esass/run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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) 08/07/2025, 10:05. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 09/12/2025, 15:20. Copyright (c) The Contributors
33

44
from functools import wraps
55
from multiprocessing.dummy import Pool
@@ -9,7 +9,7 @@
99
from tqdm import tqdm
1010

1111
from ..common import execute_cmd
12-
from ... import eSASS_AVAIL
12+
from ... import ESASS_AVAIL
1313
from ...exceptions import eSASSNotFoundError, ProductGenerationError
1414
from ...products import BaseProduct, AnnularSpectra
1515
from ...samples.base import BaseSample
@@ -27,7 +27,7 @@ def esass_call(esass_func):
2727
@wraps(esass_func)
2828
def wrapper(*args, **kwargs):
2929
# Checking eSASS is installed and available on the system
30-
if not eSASS_AVAIL:
30+
if not ESASS_AVAIL:
3131
raise eSASSNotFoundError("No eSASS installation has been found on this machine.")
3232

3333
# The first argument of all of these eSASS functions will be the source object (or a list of),

0 commit comments

Comments
 (0)