summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-07-11 22:42:02 +0800
committerAaron LI <aaronly.me@outlook.com>2016-07-11 22:42:02 +0800
commit9f6a62b80f49fd492383521bf616c708b5be10d9 (patch)
tree88de7ffb6040f38362402f1d4001dc6894f01251
parent20bc7a6b1d162a098055e384da9041792226f7ca (diff)
downloadcexcess-9f6a62b80f49fd492383521bf616c708b5be10d9.tar.bz2
calc_overdensity.py: Use a default config to allow a minimal user config
-rwxr-xr-xcalc_overdensity.py48
1 files changed, 26 insertions, 22 deletions
diff --git a/calc_overdensity.py b/calc_overdensity.py
index 5ae899d..562311e 100755
--- a/calc_overdensity.py
+++ b/calc_overdensity.py
@@ -2,9 +2,11 @@
#
# Aaron LI
# Created: 2016-06-30
-# Updated: 2016-07-04
+# Updated: 2016-07-11
#
# Change logs:
+# 2016-07-11:
+# * Use a default config to allow a minimal user config
# 2016-07-04:
# * Fix a bug with wrong variable
# * Update radii to unit "kpc" and mass to unit "Msun"
@@ -20,15 +22,30 @@ R_{500}).
References:
[1] Ettori et al., 2013, Space Science Review, 177, 119-154
+"""
+
+
+import argparse
+import json
+from collections import OrderedDict
+
+import numpy as np
+import scipy.optimize as optimize
+import astropy.units as au
+from astropy.cosmology import FlatLambdaCDM
+from configobj import ConfigObj
+
+import rpy2.robjects as ro
+from rpy2.robjects.packages import importr
+
+from astro_params import AstroParams
-Sample configuration file:
-------------------------------------------------------------
+config_default = """
## Configuration for `calc_overdensity.py`
-## Date: 2016-06-30
# redshift of the source (critical density)
-redshift = <REDSHIFT>
+#redshift = <REDSHIFT>
# gas mass profile
m_gas_profile = mass_gas_profile.txt
@@ -44,24 +61,8 @@ outfile = overdensity.json
# output overdensity profile
overdensity_profile = overdensity_profile.txt
-------------------------------------------------------------
"""
-import argparse
-import json
-from collections import OrderedDict
-
-import numpy as np
-import scipy.optimize as optimize
-import astropy.units as au
-from astropy.cosmology import FlatLambdaCDM
-from configobj import ConfigObj
-
-import rpy2.robjects as ro
-from rpy2.robjects.packages import importr
-
-from astro_params import AstroParams
-
class MassProfile:
"""
@@ -237,7 +238,10 @@ def main():
"etc. calculation (default: overdensity.conf)")
args = parser.parse_args()
- config = ConfigObj(args.config)
+ config = ConfigObj(config_default.splitlines())
+ config_user = ConfigObj(args.config)
+ config.merge(config_user)
+
redshift = config.as_float("redshift")
m_gas_data = np.loadtxt(config["m_gas_profile"])
m_total_data = np.loadtxt(config["m_total_profile"])