From f5017fd4b470800f2e931c564b8d6ef3cc21ea8b Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 11 Jul 2016 21:24:19 +0800 Subject: fit_tprofile.py: Use a default config to allow a minimal user config --- fit_tprofile.py | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/fit_tprofile.py b/fit_tprofile.py index 88f7fa7..56f5d23 100755 --- a/fit_tprofile.py +++ b/fit_tprofile.py @@ -2,9 +2,11 @@ # # Aaron LI # Created: 2016-07-04 -# 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: # * Set default "rcut=3000" for TemperatureProfile.extrapolate() # @@ -16,15 +18,31 @@ temperature profile model, i.e., the *wang2012* model: With the fitted temperature profile model, we can interpolate and extrapolate the temperature profile for later mass profile calculation. +""" + + +import argparse +import json +from collections import OrderedDict + +import numpy as np +import astropy.units as au +import lmfit +from configobj import ConfigObj +import matplotlib.pyplot as plt +from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas +from matplotlib.figure import Figure +from fitting_models import FittingModel +from astro_params import ChandraPixel + +plt.style.use("ggplot") -Sample configuration file: ------------------------------------------------------------- +config_default = """ ## Configuration for `fit_tprofile.py` -## Date: 2016-07-04 # redshift of the object (for pixel to distance conversion) -redshift = +redshift = -1 # input temperature profile data file t_profile_data = t_profile_data.txt @@ -52,26 +70,8 @@ t_profile_image = t_profile.png #beta = 0.5, 0.1, 1.0, FIXED beta = 0.5, 0.1, 1.0 T0 = 2.0, 1.0, 5.0 ------------------------------------------------------------- """ -import argparse -import json -from collections import OrderedDict - -import numpy as np -import astropy.units as au -import lmfit -from configobj import ConfigObj -import matplotlib.pyplot as plt -from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas -from matplotlib.figure import Figure - -from fitting_models import FittingModel -from astro_params import ChandraPixel - -plt.style.use("ggplot") - class Wang2012Model(FittingModel): """ @@ -221,7 +221,10 @@ def main(): parser.add_argument("config", nargs="?", default="tprofile.conf", help="configuration (default: tprofile.conf") args = parser.parse_args() - config = ConfigObj(args.config) + + config = ConfigObj(config_default.splitlines()) + config_user = ConfigObj(args.config) + config.merge(config_user) tprofile_data = np.loadtxt(config["t_profile_data"]) redshift = config.as_float("redshift") -- cgit v1.2.2