diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-03-01 13:23:36 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-03-01 13:23:36 +0800 |
commit | 71b73143b0b33853a7584a8de8b8b6ddcb77286f (patch) | |
tree | 65c2ecd76070b4b11985a7bd205047da7a9d0812 | |
parent | 59fa9c0cbb21d817a8261217d5a2865dcdc422e5 (diff) | |
download | chandra-acis-analysis-71b73143b0b33853a7584a8de8b8b6ddcb77286f.tar.bz2 |
Add repro_acis.py: reprocess ACIS level=1 data and build manifest.yaml
-rwxr-xr-x | bin/repro_acis.py | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/bin/repro_acis.py b/bin/repro_acis.py new file mode 100755 index 0000000..052414c --- /dev/null +++ b/bin/repro_acis.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Weitian LI <liweitianux@live.com> +# MIT license +# +# 2017-02-27 + +""" +Reprocess Chandra ACIS raw "secondary" (level=1) data using the +CIAO contrib tool ``chandra_repro``, and build the ``manifest.yaml``. +""" + +import os +import argparse +import subprocess +import logging +from glob import glob + +from _context import acispy +from acispy.manifest import get_manifest +from acispy.pfiles import setup_pfiles + + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +def repro_acis(indir=".", outdir="repro", clobber=False): + """ + Reprocess Chandra ACIS raw level=1 data using ``chandra_repro``. + """ + logger.info("Reprocess Chandra ACIS raw level=1 data ...") + clobber = "yes" if clobber else "no" + subprocess.check_call(["punlearn", "ardlib"]) + subprocess.check_call(["punlearn", "chandra_repro"]) + subprocess.check_call([ + "chandra_repro", "indir=%s" % indir, "outdir=%s" % outdir, + "verbose=2", "clobber=%s" % clobber + ]) + logger.info("Fix asol.lis by striping the absolute directory ...") + asol_lis = glob("%s/acisf*_asol1.lis" % outdir)[0] + asol = [os.path.basename(fp) for fp in open(asol_lis).readlines()] + os.rename(asol_lis, asol_lis+".orig") + open(asol_lis, "w").writelines(asol) + + +def build_manifest(reprodir="repro", manifestfile="manifest.yaml"): + """ + Build the ``manifest.yaml`` with reprocessed products. + """ + logger.info("Build manifest with reprocessed products ...") + if os.path.exists(manifestfile): + logger.info("Use existing manifest file: %s" % manifestfile) + else: + logger.info("Create a new manifest file: %s" % manifestfile) + open(manifestfile, "w").close() + + manifest = get_manifest(manifestfile) + key = "directory" + manifest.set(key, os.path.basename(os.getcwd())) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "evt2" + manifest.setpath(key, glob("%s/acisf*_repro_evt2.fits" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "bpix" + manifest.setpath(key, glob("%s/acisf*_repro_bpix1.fits" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "asol" + manifest.setpath(key, glob("%s/pcadf*_asol1.fits" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "asol_lis" + manifest.setpath(key, glob("%s/acisf*_asol1.lis" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "fov" + manifest.setpath(key, glob("%s/acisf*_repro_fov1.fits" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "pbk" + manifest.setpath(key, glob("%s/acisf*_pbk0.fits" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + key = "msk" + manifest.setpath(key, glob("%s/acisf*_msk1.fits" % reprodir)) + logger.info("Added '%s' to manifest: %s" % (key, manifest.get(key))) + + +def main(): + parser = argparse.ArgumentParser( + description="Extract surface brightness profile (SBP)") + parser.add_argument("-C", "--clobber", dest="clobber", action="store_true", + help="overwrite existing file") + args = parser.parse_args() + + setup_pfiles(["chandra_repro", "ardlib"]) + + repro_acis(clobber=args.clobber) + build_manifest() + + +if __name__ == "__main__": + main() |