From 9f6a62b80f49fd492383521bf616c708b5be10d9 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 11 Jul 2016 22:42:02 +0800 Subject: calc_overdensity.py: Use a default config to allow a minimal user config --- calc_overdensity.py | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'calc_overdensity.py') 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 = # 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"]) -- cgit v1.2.2