aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-05-25 14:27:24 +0800
committerAaron LI <aaronly.me@outlook.com>2017-05-25 14:27:24 +0800
commitedab67684381c53ddd74748f541dde56f825dbe0 (patch)
treec5be6a3ded4d10ea075b8c8ab13456840660f503 /bin
parent18e6b1f1b9a28688c90f101d0c79b61fcf996aa5 (diff)
downloadchandra-acis-analysis-edab67684381c53ddd74748f541dde56f825dbe0.tar.bz2
Add bin/update_manifest.py with support of "repro" products
TODO: support updating other products to manifest.yaml
Diffstat (limited to 'bin')
-rwxr-xr-xbin/update_manifest.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/update_manifest.py b/bin/update_manifest.py
new file mode 100755
index 0000000..ca1cf27
--- /dev/null
+++ b/bin/update_manifest.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2017 Weitian LI <weitian@aaronly.me>
+# MIT license
+
+"""
+Update the manifest.yaml with generated products.
+"""
+
+import os
+import argparse
+import logging
+from glob import glob
+from collections import OrderedDict
+
+from _context import acispy
+from acispy.manifest import get_manifest
+
+
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
+
+def get_path(pglob, pdir=None):
+ if pdir is not None:
+ pglob = os.path.join(pdir, pglob)
+ p = glob(pglob)
+ if len(p) == 0:
+ return None
+ elif len(p) == 1:
+ return p[0]
+ else:
+ return p
+
+
+def add_repro(reprodir, manifest):
+ """
+ Add the generated products by ``chandra_repro`` to the manifest.
+ """
+ logging.info("Adding repro products from: {0}".format(reprodir))
+ keyglobs = OrderedDict([
+ ("evt2", "acisf*_repro_evt2.fits"),
+ ("bpix", "acisf*_repro_bpix1.fits"),
+ ("fov", "acisf*_repro_fov1.fits"),
+ ("asol", "pcadf*_asol?.fits"), # maybe multiple
+ ("pbk", "acisf*_pbk0.fits"),
+ ("msk", "acisf*_msk1.fits"),
+ ])
+ for k, g in keyglobs.items():
+ p = get_path(g, pdir=reprodir)
+ manifest.setpath(k, p)
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Update manifest.yaml with generated products")
+ parser.add_argument("-r", "--repro", dest="reprodir", default=None,
+ help="path to the repro directory; add the " +
+ "reprocessed products to manifest if specified")
+ args = parser.parse_args()
+ manifest = get_manifest()
+
+ if args.reprodir:
+ add_repro(reprodir=args.reprodir, manifest=manifest)
+
+
+if __name__ == "__main__":
+ main()