summaryrefslogtreecommitdiffstats
path: root/make_coolfunc_config.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-07-13 10:49:38 +0800
committerAaron LI <aaronly.me@outlook.com>2016-07-13 10:49:38 +0800
commitf03888f43d71835b3d2dc91073307ba267d5e2b9 (patch)
tree55e928b9e6cdeee2a6492d083eb80a9012b71f3c /make_coolfunc_config.py
parent1adb3520dcc05852e37b150d29b17a3fb85e16f1 (diff)
downloadcexcess-f03888f43d71835b3d2dc91073307ba267d5e2b9.tar.bz2
Add make_coolfunc_config.py to make config for "calc_coolfunc.py"
Diffstat (limited to 'make_coolfunc_config.py')
-rwxr-xr-xmake_coolfunc_config.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/make_coolfunc_config.py b/make_coolfunc_config.py
new file mode 100755
index 0000000..204f1fe
--- /dev/null
+++ b/make_coolfunc_config.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python3
+#
+# Make the configuration file for `calc_coolfunc.py`
+#
+# Aaron LI
+# Created: 2016-04-21
+# Updated: 2016-07-12
+#
+
+import glob
+import argparse
+import subprocess
+
+from info import get_redshift, get_nh
+
+
+sample_config = """
+## Configuration file for `calc_coolfunc.py`
+
+# redshift of the object
+redshift = %(redshift).6f
+
+# H column density (unit: 10^22 cm^-2)
+nh = %(nh)f
+
+# average abundance (unit: solar)
+abundance = %(abund)f
+"""
+
+
+def make_config(info, abund):
+ cfg_data = {
+ "abund": abund,
+ "nh": get_nh(info),
+ "redshift": get_redshift(info),
+ }
+ cfg = sample_config % cfg_data
+ return cfg
+
+
+def get_abund(infile):
+ """
+ Extract the average abundance from the input file.
+ """
+ results = subprocess.run(["grep", "^abund", infile],
+ check=True, stdout=subprocess.PIPE)
+ abund = float(results.stdout.decode("utf-8").split()[1])
+ return abund
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Make the config for 'fit_sbp.py'")
+ parser.add_argument("-j", "--json", dest="json", required=False,
+ help="the *_INFO.json file " +
+ "(default: find ../*_INFO.json)")
+ parser.add_argument("-c", "--cfg", dest="cfg",
+ required=False, default="global.cfg",
+ help="previous config file contains 'abund' " +
+ "(default: global.cfg)")
+ parser.add_argument("outfile", nargs="?", default="coolfunc.conf",
+ help="filename of the output coolfunc config " +
+ "(default: coolfunc.conf)")
+ args = parser.parse_args()
+
+ # default "*_INFO.json"
+ info_json = glob.glob("../*_INFO.json")[0]
+ if args.json:
+ info_json = args.json
+
+ abund = get_abund(args.cfg)
+ config = make_config(info_json, abund)
+ open(args.outfile, "w").write(config)
+
+
+if __name__ == "__main__":
+ main()