diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-06 11:15:20 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-06 11:15:20 +0800 |
commit | 72ff685c624429bc55f36739317a897156b1ccb2 (patch) | |
tree | c123972cc4679c4861057ab1895b5dffd7c307a1 /scripts | |
parent | 8628ab8cbcb185826e97af9148ec7d07861e29e7 (diff) | |
download | chandra-acis-analysis-72ff685c624429bc55f36739317a897156b1ccb2.tar.bz2 |
Add chandra_acis.py to determine ACIS type of data
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/chandra_acis.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/chandra_acis.py b/scripts/chandra_acis.py new file mode 100755 index 0000000..2dcc62e --- /dev/null +++ b/scripts/chandra_acis.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Weitian LI <liweitianux@live.com> +# MIT license +# +# Weitian LI +# 2017-02-06 + +""" +Determine the Chandra ACIS type for the given observation. +""" + +import argparse +import subprocess +import re + +from setup_pfiles import setup_pfiles + + +def get_acis_type(infile): + """ + Determine the Chandra ACIS type (``I`` or ``S``) according the + active ACIS chips. + + Parameters + ---------- + infile : str + Filename of the 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" % infile, "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 main(): + parser = argparse.ArgumentParser(description="Determine Chandra ACIS type") + parser.add_argument("-b", "--brief", dest="brief", + action="store_true", help="Be brief") + parser.add_argument("infile", help="Input FITS file") + args = parser.parse_args() + + setup_pfiles(["dmkeypar"]) + acis_type = get_acis_type(args.infile) + if not args.brief: + print("ACIS-type:", end=" ") + print(acis_type) + + +if __name__ == "__main__": + main() |