aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/chandra_json2csv_v3.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/chandra_json2csv_v3.py')
-rwxr-xr-xscripts/chandra_json2csv_v3.py270
1 files changed, 270 insertions, 0 deletions
diff --git a/scripts/chandra_json2csv_v3.py b/scripts/chandra_json2csv_v3.py
new file mode 100755
index 0000000..cf69cf9
--- /dev/null
+++ b/scripts/chandra_json2csv_v3.py
@@ -0,0 +1,270 @@
+#!/usr/bin/python
+# avoid using `/usr/bin/env python'
+#
+# convert JSON to CSV format
+# Ref: http://stackoverflow.com/questions/1871524/convert-from-json-to-csv-using-python
+## Ref: http://json.parser.online.fr/
+#
+# LIweitiaNux <liweitianux@gmail.com>
+# August 31, 2012
+#
+# ChangeLogs:
+# v3.1, 2013/05/18, LIweitiaNux
+# add key `Feature', corresponding to `collectdata_v3.1'
+# v3.2, 2013/05/29, LIweitiaNux
+# add key `XCNTRD_RA, XCNTRD_DEC'
+# v3.3, 2013/10/14, LIweitiaNux
+# add key `Unified Name'
+#
+
+import sys
+import csv
+import json
+
+argc = len(sys.argv)
+if (argc != 3):
+ print("usage:")
+ print(" "+ sys.argv[0]+ " <input_json> <output_csv>")
+ sys.exit(255)
+
+infile = open(sys.argv[1], 'r')
+data = json.load(infile)
+infile.close()
+
+outfile = csv.writer(open(sys.argv[2], "wb+"))
+
+# write header {{{
+outfile.writerow([
+ "Obs. ID",
+ "Source Name",
+ "Unified Name",
+ "Obs. Date",
+ "Detector",
+ "Exposure (ks)",
+ "Clean Exposure (ks)",
+ "R. A.",
+ "Dec.",
+ "XCNTRD_RA",
+ "XCNTRD_DEC",
+ "nH (10^22 cm^-2)",
+ "redshift",
+ "E(z)",
+ "T_ref (keV)",
+ "Z_ref (solar)",
+ "Rmax_SBP (pixel)",
+ "Rmax_Tpro (pixel)",
+ "Rmax_SBP (kpc)",
+ "Rmax_Tpro (kpc)",
+ "NFW_Rmin (kpc)",
+ "Model_SBP",
+ "n01",
+ "beta1",
+ "rc1",
+ "rc1_kpc",
+ "n02",
+ "beta2",
+ "rc2",
+ "rc2_kpc",
+ "bkg",
+ "R200 (kpc)",
+ "R200_err_lower (1sigma)",
+ "R200_err_upper (1sigma)",
+ "M200 (M_sun)",
+ "M200_err_lower (1sigma)",
+ "M200_err_upper (1sigma)",
+ "L200 (erg/s)",
+ "L200_err (1sigma)",
+ "M_gas200 (M_sun)",
+ "M_gas200_err_lower (1sigma)",
+ "M_gas200_err_upper (1sigma)",
+ "F_gas200",
+ "F_gas200_err_lower (1sigma)",
+ "F_gas200_err_upper (1sigma)",
+ "R500 (kpc)",
+ "R500_err_lower (1sigma)",
+ "R500_err_upper (1sigma)",
+ "M500 (M_sun)",
+ "M500_err_lower (1sigma)",
+ "M500_err_upper (1sigma)",
+ "L500 (erg/s)",
+ "L500_err (1sigma)",
+ "M_gas500 (M_sun)",
+ "M_gas500_err_lower (1sigma)",
+ "M_gas500_err_upper (1sigma)",
+ "F_gas500",
+ "F_gas500_err_lower (1sigma)",
+ "F_gas500_err_upper (1sigma)",
+ "R1500",
+ "R1500_err_lower",
+ "R1500_err_upper",
+ "M1500",
+ "M1500_err_lower",
+ "M1500_err_upper",
+ "L1500",
+ "L1500_err",
+ "M_gas1500",
+ "M_gas1500_err_lower",
+ "M_gas1500_err_upper",
+ "F_gas1500",
+ "F_gas1500_err_lower",
+ "F_gas1500_err_upper",
+ "R2500",
+ "R2500_err_lower",
+ "R2500_err_upper",
+ "M2500",
+ "M2500_err_lower",
+ "M2500_err_upper",
+ "L2500",
+ "L2500_err",
+ "M_gas2500",
+ "M_gas2500_err_lower",
+ "M_gas2500_err_upper",
+ "F_gas2500",
+ "F_gas2500_err_lower",
+ "F_gas2500_err_upper",
+ "T(0.1-0.5 R500)",
+ "T_err(0.1-0.5 R500)",
+ "T_err_l(0.1-0.5 R500)",
+ "T_err_u(0.1-0.5 R500)",
+ "Z(0.1-0.5 R500)",
+ "Z_err(0.1-0.5 R500)",
+ "Z_err_l(0.1-0.5 R500)",
+ "Z_err_u(0.1-0.5 R500)",
+ "T(0.2-0.5 R500)",
+ "T_err(0.2-0.5 R500)",
+ "T_err_l(0.2-0.5 R500)",
+ "T_err_u(0.2-0.5 R500)",
+ "Z(0.2-0.5 R500)",
+ "Z_err(0.2-0.5 R500)",
+ "Z_err_l(0.2-0.5 R500)",
+ "Z_err_u(0.2-0.5 R500)",
+ "F_gas(R2500-R500)",
+ "F_gas_err_l(R2500-R500)",
+ "F_gas_err_u(R2500-R500)",
+ "R_cool (kpc)",
+ "Cooling_time (Gyr)",
+ "Cool_core",
+ "Feature",
+ "NOTE"
+])
+## header }}}
+
+# write data {{{
+for item in data:
+ outfile.writerow([
+ item["Obs. ID"],
+ item["Source Name"],
+ item["Unified Name"],
+ item["Obs. Date"],
+ item["Detector"],
+ item["Exposure (ks)"],
+ item["Clean Exposure (ks)"],
+ item["R. A."],
+ item["Dec."],
+ item["XCNTRD_RA"],
+ item["XCNTRD_DEC"],
+ item["nH (10^22 cm^-2)"],
+ item["redshift"],
+ item["E(z)"],
+ item["T_ref (keV)"],
+ item["Z_ref (solar)"],
+ item["Rmax_SBP (pixel)"],
+ item["Rmax_Tpro (pixel)"],
+ item["Rmax_SBP (kpc)"],
+ item["Rmax_Tpro (kpc)"],
+ item["NFW_Rmin (kpc)"],
+ item["Model_SBP"],
+ item["n01"],
+ item["beta1"],
+ item["rc1"],
+ item["rc1_kpc"],
+ item["n02"],
+ item["beta2"],
+ item["rc2"],
+ item["rc2_kpc"],
+ item["bkg"],
+ item["R200 (kpc)"],
+ item["R200_err_lower (1sigma)"],
+ item["R200_err_upper (1sigma)"],
+ item["M200 (M_sun)"],
+ item["M200_err_lower (1sigma)"],
+ item["M200_err_upper (1sigma)"],
+ item["L200 (erg/s)"],
+ item["L200_err (1sigma)"],
+ item["M_gas200 (M_sun)"],
+ item["M_gas200_err_lower (1sigma)"],
+ item["M_gas200_err_upper (1sigma)"],
+ item["F_gas200"],
+ item["F_gas200_err_lower (1sigma)"],
+ item["F_gas200_err_upper (1sigma)"],
+ item["R500 (kpc)"],
+ item["R500_err_lower (1sigma)"],
+ item["R500_err_upper (1sigma)"],
+ item["M500 (M_sun)"],
+ item["M500_err_lower (1sigma)"],
+ item["M500_err_upper (1sigma)"],
+ item["L500 (erg/s)"],
+ item["L500_err (1sigma)"],
+ item["M_gas500 (M_sun)"],
+ item["M_gas500_err_lower (1sigma)"],
+ item["M_gas500_err_upper (1sigma)"],
+ item["F_gas500"],
+ item["F_gas500_err_lower (1sigma)"],
+ item["F_gas500_err_upper (1sigma)"],
+ item["R1500"],
+ item["R1500_err_lower"],
+ item["R1500_err_upper"],
+ item["M1500"],
+ item["M1500_err_lower"],
+ item["M1500_err_upper"],
+ item["L1500"],
+ item["L1500_err"],
+ item["M_gas1500"],
+ item["M_gas1500_err_lower"],
+ item["M_gas1500_err_upper"],
+ item["F_gas1500"],
+ item["F_gas1500_err_lower"],
+ item["F_gas1500_err_upper"],
+ item["R2500"],
+ item["R2500_err_lower"],
+ item["R2500_err_upper"],
+ item["M2500"],
+ item["M2500_err_lower"],
+ item["M2500_err_upper"],
+ item["L2500"],
+ item["L2500_err"],
+ item["M_gas2500"],
+ item["M_gas2500_err_lower"],
+ item["M_gas2500_err_upper"],
+ item["F_gas2500"],
+ item["F_gas2500_err_lower"],
+ item["F_gas2500_err_upper"],
+ item["T(0.1-0.5 R500)"],
+ item["T_err(0.1-0.5 R500)"],
+ item["T_err_l(0.1-0.5 R500)"],
+ item["T_err_u(0.1-0.5 R500)"],
+ item["Z(0.1-0.5 R500)"],
+ item["Z_err(0.1-0.5 R500)"],
+ item["Z_err_l(0.1-0.5 R500)"],
+ item["Z_err_u(0.1-0.5 R500)"],
+ item["T(0.2-0.5 R500)"],
+ item["T_err(0.2-0.5 R500)"],
+ item["T_err_l(0.2-0.5 R500)"],
+ item["T_err_u(0.2-0.5 R500)"],
+ item["Z(0.2-0.5 R500)"],
+ item["Z_err(0.2-0.5 R500)"],
+ item["Z_err_l(0.2-0.5 R500)"],
+ item["Z_err_u(0.2-0.5 R500)"],
+ item["F_gas(R2500-R500)"],
+ item["F_gas_err_l(R2500-R500)"],
+ item["F_gas_err_u(R2500-R500)"],
+ item["R_cool (kpc)"],
+ item["Cooling_time (Gyr)"],
+ item["Cool_core"],
+ item["Feature"],
+ item["NOTE"]
+ ])
+## write data }}}
+
+## EOF
+