diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-14 23:55:31 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-17 01:16:46 +0800 |
commit | 513a63eaa53acf469e1234c4c0ae879bfb3fbf9f (patch) | |
tree | 568b9928e269d67057ecbc94c0c3e0078086389b | |
parent | b6f1902c7c767104700ea86896eed9b27d389344 (diff) | |
download | chandra-acis-analysis-513a63eaa53acf469e1234c4c0ae879bfb3fbf9f.tar.bz2 |
chandra_acis.py: Add function "get_chips()"
-rwxr-xr-x | scripts/chandra_acis.py | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/scripts/chandra_acis.py b/scripts/chandra_acis.py index 2dcc62e..6170b40 100755 --- a/scripts/chandra_acis.py +++ b/scripts/chandra_acis.py @@ -8,6 +8,8 @@ """ Determine the Chandra ACIS type for the given observation. + +TODO: move these methods to module `acis.py` """ import argparse @@ -17,15 +19,15 @@ import re from setup_pfiles import setup_pfiles -def get_acis_type(infile): +def get_acis_type(filepath): """ Determine the Chandra ACIS type (``I`` or ``S``) according the active ACIS chips. Parameters ---------- - infile : str - Filename of the FITS file + filepath : str + Path to the input FITS file Returns ------- @@ -34,7 +36,7 @@ def get_acis_type(infile): """ subprocess.check_call(["punlearn", "dmkeypar"]) detnam = subprocess.check_output([ - "dmkeypar", "infile=%s" % infile, "keyword=DETNAM", "echo=yes" + "dmkeypar", "infile=%s" % filepath, "keyword=DETNAM", "echo=yes" ]).decode("utf-8").strip() if re.match(r"^ACIS-0123", detnam): return "I" @@ -44,6 +46,31 @@ def get_acis_type(infile): raise ValueError("unknown chip combination: %s" % detnam) +def get_chips(filepath, sep=":"): + """ + Get the corresponding 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 = get_acis_type(filepath) + if acis_type == "I": + return sep.join(["0", "3"]) + elif acis_type == "S": + return "7" + else: + raise ValueError("unknown ACIS type") + + def main(): parser = argparse.ArgumentParser(description="Determine Chandra ACIS type") parser.add_argument("-b", "--brief", dest="brief", |