diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-04-27 18:32:26 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-04-27 18:32:26 +0800 |
commit | 266a366d70448307762a34c1ee1322b4be180719 (patch) | |
tree | 316f7b0778cafc3986896c6197e6075ac007dfb1 | |
parent | dcf2a2e1709dddb04ff0f87d5186abe14e58f76e (diff) | |
download | cexcess-266a366d70448307762a34c1ee1322b4be180719.tar.bz2 |
extract_excess.py: new; extract excess value/ratio to CSV format
-rwxr-xr-x | extract_excess.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/extract_excess.py b/extract_excess.py new file mode 100755 index 0000000..1983859 --- /dev/null +++ b/extract_excess.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Extract the excess value and ratio results. +# +# Aaron LI +# Created: 2016-04-27 +# + +import sys +import os +import json +import csv +import argparse +from collections import OrderedDict + + +def extract_excess(data): + """ + Extract the excess value and ratio as well as other misc information + from the "data" dictionary. + """ + results = OrderedDict([ + ("name", data["name"]), + ("obsid", data["obsid"]), + ("model", data["model"]), + ("brightness_obs", data["brightness_obs"]), + ("brightness_model", data["brightness_model"]), + ("excess_value", data["excess_value"]), + ("excess_ratio", data["excess_ratio"]), + ]) + return results + + +def main(): + parser = argparse.ArgumentParser( + description="Extract excess results from excess.json") + parser.add_argument("excess_json", nargs="?", default="excess.json", + help="json file conatins excess results (default: excess.json)") + args = parser.parse_args() + + excess_data = json.load(open(args.excess_json)) + results = extract_excess(excess_data) + + # output results + csv_writer = csv.writer(sys.stdout) + csv_writer.writerow(results.keys()) + csv_writer.writerow(results.values()) + + +if __name__ == "__main__": + main() + |