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
44import os
55from copy import copy
99
1010import numpy as np
1111from astropy .units import Quantity
12+ from packaging .version import Version
1213
1314from ._common import region_setup , _gen_detmap_cmd
1415from .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
1719from ..samples .base import BaseSample
1820from ..sas .run import sas_call
1921from ..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+
0 commit comments