Skip to content

Commit f84bf71

Browse files
author
David Turner
committed
Added a SAS version requirement of v21 or greater for model_particle_background. For issue #1337
1 parent 35315e4 commit f84bf71

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

xga/sas/spec.py

Lines changed: 24 additions & 5 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) 03/04/2025, 10:27. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 03/04/2025, 11:13. Copyright (c) The Contributors
33

44
import os
55
from copy import copy
@@ -9,11 +9,13 @@
99

1010
import numpy as np
1111
from astropy.units import Quantity
12+
from packaging.version import Version
1213

1314
from ._common import region_setup, _gen_detmap_cmd
1415
from .misc import cifbuild
15-
from .. import OUTPUT, NUM_CORES, xga_conf
16-
from ..exceptions import SASInputInvalid, NotAssociatedError, NoProductAvailableError, XGADeveloperError, XGAConfigError
16+
from .. import OUTPUT, NUM_CORES, xga_conf, SAS_VERSION
17+
from ..exceptions import SASInputInvalid, NotAssociatedError, NoProductAvailableError, XGADeveloperError, \
18+
XGAConfigError, SASVersionError
1719
from ..samples.base import BaseSample
1820
from ..sas.run import sas_call
1921
from ..sources import BaseSource, ExtendedSource, GalaxyCluster
@@ -864,6 +866,16 @@ def model_particle_background(sources: Union[BaseSource, BaseSample], outer_radi
864866
min_counts: int = 5, min_sn: float = None, over_sample: float = None,
865867
one_rmf: bool = True, num_cores: int = NUM_CORES, disable_progress: bool = False):
866868

869+
# Prior to SAS v21, the commands we're going to use for this bit were part of eSAS, which at the time was
870+
# sort of a separate package (although not completely) and didn't adhere to the same design/usage as pure SAS
871+
# tasks. What that means for us is that with older versions of these functions, you can't specify paths
872+
# to the various files needed for this to work, it just assumes everything is named as it would have been
873+
# by other eSAS preparatory tasks. As such, we've decided that supporting background modelling for pre-v21.0.0
874+
# versions of SAS is a poor use of our time.
875+
if Version(SAS_VERSION) <= Version("20.0.0"):
876+
raise SASVersionError("Preparing model particle backgrounds for XMM observations requires "
877+
"at least SAS v21.0.0.")
878+
867879
# It isn't a certainty that the user will have set up the files we need to model backgrounds in this manner, so
868880
# the very first thing we do is to check whether the 'FoV + corner' all good event entries in the config
869881
# have been changed from the default.
@@ -888,7 +900,11 @@ def model_particle_background(sources: Union[BaseSource, BaseSample], outer_radi
888900
" will be removed entirely from XGA in the near future.")
889901

890902
# ----------------- DEFINING THE TEMPLATES FOR THE SAS COMMANDS -----------------
891-
pn_prep_cmd = "cd {d}; cp ../ccf.cif .; export SAS_CCF={ccf}; pnspectra {evt} {oevt} {cevt} {coevt} {}; mv * ../; cd ..; rm -r {d}"
903+
904+
if Version(SAS_VERSION) <= Version("20.0.0"):
905+
pn_prep_cmd = "cd {d}; cp ../ccf.cif .; export SAS_CCF={ccf}; pn-spectra {evt} {oevt} {cevt} {coevt} {}; mv * ../; cd ..; rm -r {d}"
906+
# all_cmds = {'pn': , 'mos1': , 'mos2': }
907+
892908
# -------------------------------------------------------------------------------
893909

894910
# This is handy, it gets the inner and outer radii into a consistent format, regardless of how the user
@@ -946,9 +962,12 @@ def model_particle_background(sources: Union[BaseSource, BaseSample], outer_radi
946962
if 'pn' in cur_inst.lower():
947963
all_good_oot_evt = xga_conf['XMM_FILES']['all_good_fov+corner_pn_oot_evts'].format(obs_id=cur_oi)
948964
if not os.path.exists(all_good_oot_evt):
949-
raise FileNotFoundError("The FoV+corner out-of-time event file for {oi}-PN cannot be "
965+
raise FileNotFoundError("The FoV+corner out-of-time event file for {oi}-pn cannot be "
950966
"found - creation of model particle backgrounds cannot proceed "
951967
"without it.".format(oi=cur_oi))
952968
else:
953969
all_good_oot_evt = None
954970

971+
972+
973+

xga/utils.py

Lines changed: 2 additions & 2 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) 03/04/2025, 09:12. Copyright (c) The Contributors
2+
# Last modified by David J Turner (turne540@msu.edu) 03/04/2025, 11:13. Copyright (c) The Contributors
33

44
import json
55
import os
@@ -449,7 +449,7 @@ def find_all_wcs(hdr: FITSHDR) -> List[WCS]:
449449
"functions in xga.sas will not work.", stacklevel=2)
450450
SAS_AVAIL = False
451451

452-
# Equivelant for the XSPEC dependency
452+
# Equivalent for the XSPEC dependency
453453
XSPEC_VERSION = None
454454
# Got to make sure we can access command line XSPEC.
455455
if shutil.which("xspec") is None:

0 commit comments

Comments
 (0)