aboutsummaryrefslogtreecommitdiffstats
path: root/bin/analyze_path.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-02-21 20:17:39 +0800
committerAaron LI <aaronly.me@outlook.com>2017-02-21 20:17:39 +0800
commitf50d166f80adcfaaa30a62c1e0b25bfc9d76a2a4 (patch)
tree54634903ef011cdce197820a06289971fe7bb297 /bin/analyze_path.py
parentde1fe6cd2a98201cce609f456d0145f6b8c4a8fa (diff)
downloadchandra-acis-analysis-f50d166f80adcfaaa30a62c1e0b25bfc9d76a2a4.tar.bz2
Move various Python tools from 'scripts/' to 'bin/'
Diffstat (limited to 'bin/analyze_path.py')
-rwxr-xr-xbin/analyze_path.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/bin/analyze_path.py b/bin/analyze_path.py
new file mode 100755
index 0000000..d2acd42
--- /dev/null
+++ b/bin/analyze_path.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2017 Weitian LI <liweitianux@live.com>
+# MIT license
+#
+# Weitian LI
+# 2017-02-06
+
+"""
+Extract the object name and observation ID from the directory path.
+
+The root directory of the object data has the format:
+ <name>_oi<obsid>
+"""
+
+import os
+import argparse
+
+from _context import acispy
+from acispy.analyze_path import get_name, get_obsid
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Extract object name and ObsID from data directory")
+ parser.add_argument("-b", "--brief", dest="brief",
+ action="store_true", help="Be brief")
+ parser.add_argument("-n", "--name", dest="name",
+ action="store_true", help="Only get object name")
+ parser.add_argument("-i", "--obsid", dest="obsid",
+ action="store_true", help="Only get observation ID")
+ parser.add_argument("path", nargs="?", default=os.getcwd(),
+ help="Path to the data directory " +
+ "(default: current working directory)")
+ args = parser.parse_args()
+ path = os.path.abspath(args.path)
+
+ b_get_name = False if args.obsid else True
+ b_get_obsid = False if args.name else True
+
+ if b_get_name:
+ if not args.brief:
+ print("Name:", end=" ")
+ print(get_name(path))
+ if b_get_obsid:
+ if not args.brief:
+ print("ObsID:", end=" ")
+ print(get_obsid(path))
+
+
+if __name__ == "__main__":
+ main()