summaryrefslogtreecommitdiffstats
path: root/extract_pei.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-04-29 16:14:59 +0800
committerAaron LI <aaronly.me@outlook.com>2016-04-29 16:14:59 +0800
commite7106fdc4354bed002ec5bcfd39b8a03e96ae04e (patch)
tree64003a26c28f19018f3a73fb8666f1902d4ef734 /extract_pei.py
parent738fdcbb7b5108da820685b469f946599a526e7b (diff)
downloadcexcess-e7106fdc4354bed002ec5bcfd39b8a03e96ae04e.tar.bz2
extract_pei.py: new; extract PEI results
Diffstat (limited to 'extract_pei.py')
-rwxr-xr-xextract_pei.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/extract_pei.py b/extract_pei.py
new file mode 100755
index 0000000..5efcc0b
--- /dev/null
+++ b/extract_pei.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Extract the power excess index (PEI) results.
+#
+# Aaron LI
+# Created: 2016-04-29
+#
+
+import sys
+import os
+import json
+import csv
+import argparse
+from collections import OrderedDict
+
+
+def extract_pei(data):
+ """
+ Extract the power excess index (PEI) results from the "data" dictionary.
+ """
+ results = OrderedDict([
+ ("name", data["name"]),
+ ("obsid", data["obsid"]),
+ ("r500_kpc", data["r500_kpc"]),
+ ("r500_pix", data["r500_pix"]),
+ ("kpc_per_pix", data["kpc_per_pix"]),
+ ("area_total", data["area_total"]),
+ ("area_below", data["area_below"]),
+ ("pei", data["pei"]),
+ ("pei_err", data["pei_err"]),
+ ])
+ return results
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Extract power excess index (PEI) results")
+ parser.add_argument("pei_json", help="json file conatins PEI results")
+ args = parser.parse_args()
+
+ pei_data = json.load(open(args.pei_json))
+ results = extract_pei(pei_data)
+
+ # output results
+ csv_writer = csv.writer(sys.stdout)
+ csv_writer.writerow(results.keys())
+ csv_writer.writerow(results.values())
+
+
+if __name__ == "__main__":
+ main()
+