diff options
Diffstat (limited to 'scripts/acis.py')
-rw-r--r-- | scripts/acis.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/acis.py b/scripts/acis.py index 5200f4e..fb918c8 100644 --- a/scripts/acis.py +++ b/scripts/acis.py @@ -6,6 +6,8 @@ Chandra ACIS utilities """ import math +import subprocess +import re class ACIS: @@ -32,3 +34,57 @@ class ACIS: Convert energy [eV] to channel number. """ return math.floor(energy/self.echannel + 1) + + @classmethod + def get_type(self, filepath): + """ + Determine the Chandra ACIS type (``I`` or ``S``) according the + active ACIS chips. + + Parameters + ---------- + filepath : str + Path to the input FITS file + + Returns + ------- + acis_type : str + ``I`` if ACIS-I, ``S`` if ACIS-S; + otherwise, ``ValueError`` raised. + """ + subprocess.check_call(["punlearn", "dmkeypar"]) + detnam = subprocess.check_output([ + "dmkeypar", "infile=%s" % filepath, "keyword=DETNAM", "echo=yes" + ]).decode("utf-8").strip() + if re.match(r"^ACIS-0123", detnam): + return "I" + elif re.match(r"^ACIS-[0-6]*7", detnam): + return "S" + else: + raise ValueError("unknown chip combination: %s" % detnam) + + def get_chips_str(self, filepath, sep=":"): + """ + Return a string of the chips of interest according to the + active ACIS type. + + Parameters + ---------- + filepath : str + Path to the input FITS file + sep : str, optional + Separator to join the chip ranges, e.g., 0:3, 0-3 + + Returns + ------- + chips : str + ``0:3`` if ACIS-I, ``7`` if ACIS-S; + otherwise, ``ValueError`` raised. + """ + acis_type = self.get_type(filepath) + if acis_type == "I": + return sep.join(["0", "3"]) + elif acis_type == "S": + return "7" + else: + raise ValueError("unknown ACIS type") |