summaryrefslogtreecommitdiffstats
path: root/extract_csb.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-04-29 12:59:08 +0800
committerAaron LI <aaronly.me@outlook.com>2016-04-29 12:59:08 +0800
commit744aa16e2f408f4660b2c8a143da0aa40bdf03e8 (patch)
tree4482297196ed5dd767d2eddb4200aa9b05eb2872 /extract_csb.py
parent67110575cf74d803cc5ab606a62a6439fec503bf (diff)
downloadcexcess-744aa16e2f408f4660b2c8a143da0aa40bdf03e8.tar.bz2
extract_csb.py: new; extract the C_SB results as CSV format
Diffstat (limited to 'extract_csb.py')
-rwxr-xr-xextract_csb.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/extract_csb.py b/extract_csb.py
new file mode 100755
index 0000000..c62048e
--- /dev/null
+++ b/extract_csb.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Extract the surface brightness concentration (i.e., C_{SB}) results.
+#
+# Aaron LI
+# Created: 2016-04-29
+#
+
+import sys
+import os
+import json
+import csv
+import argparse
+from collections import OrderedDict
+
+
+def extract_csb(data):
+ """
+ Extract the surface brightness concentration results
+ from the "data" dictionary.
+ """
+ results = OrderedDict([
+ ("name", data["name"]),
+ ("obsid", data["obsid"]),
+ ("csb_type", data["csb_type"]),
+ ("csb_r1", data["csb_r1"]),
+ ("csb_r2", data["csb_r2"]),
+ ("csb_s1", data["csb_s1"]),
+ ("csb_s1_err", data["csb_s1_err"]),
+ ("csb_s2", data["csb_s2"]),
+ ("csb_s2_err", data["csb_s2_err"]),
+ ("csb", data["csb"]),
+ ("csb_err", data["csb_err"]),
+ ("csb_region", data["csb_region"]),
+ ])
+ return results
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Extract surface brightness concentration results")
+ parser.add_argument("csb_json", help="json file conatins C_SB results")
+ args = parser.parse_args()
+
+ csb_data = json.load(open(args.csb_json))
+ results = extract_csb(csb_data)
+
+ # output results
+ csv_writer = csv.writer(sys.stdout)
+ csv_writer.writerow(results.keys())
+ csv_writer.writerow(results.values())
+
+
+if __name__ == "__main__":
+ main()
+