aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-16 16:40:45 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-17 01:16:46 +0800
commit9d415275efdbdd49bcdb827a314f3b42ec5a269a (patch)
tree2e643a7aa15f101fa0a55f310ef4391495af00c3 /scripts
parent90eb3cf2b94650ce470bdf215b9b977f1e6a0a06 (diff)
downloadchandra-acis-analysis-9d415275efdbdd49bcdb827a314f3b42ec5a269a.tar.bz2
Integrate 'chandra_acis.py' into 'acis.py'
Diffstat (limited to 'scripts')
-rw-r--r--scripts/acis.py56
-rwxr-xr-xscripts/chandra_acis.py89
-rwxr-xr-xscripts/event2image.py4
3 files changed, 58 insertions, 91 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")
diff --git a/scripts/chandra_acis.py b/scripts/chandra_acis.py
deleted file mode 100755
index 6170b40..0000000
--- a/scripts/chandra_acis.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/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.
-
-TODO: move these methods to module `acis.py`
-"""
-
-import argparse
-import subprocess
-import re
-
-from setup_pfiles import setup_pfiles
-
-
-def get_acis_type(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(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",
- 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()
diff --git a/scripts/event2image.py b/scripts/event2image.py
index 832f8c6..76d8297 100755
--- a/scripts/event2image.py
+++ b/scripts/event2image.py
@@ -15,7 +15,7 @@ import subprocess
from manifest import get_manifest
from setup_pfiles import setup_pfiles
-from chandra_acis import get_chips
+from acis import ACIS
def make_image(infile, outfile, chips, erange, fov, clobber=False):
@@ -74,7 +74,7 @@ def main():
manifest = get_manifest()
fov = manifest.getpath("fov")
infile = args.infile if args.infile else manifest.getpath("evt2_clean")
- chips = get_chips(infile, sep="-")
+ chips = ACIS.get_chips_str(infile, sep="-")
erange = "{elow}-{ehigh}".format(elow=args.elow, ehigh=args.ehigh)
if args.outfile:
outfile = args.outfile