diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-04-26 19:38:42 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-04-26 19:38:42 +0800 |
commit | 73d972de47ed73d14fbfd2582b166e17f39f356a (patch) | |
tree | d1ae6c471b1bc8188a91276d04aab65a74531c9b | |
parent | 8ebf6cbd48b25c1603b60d5b77cdb57083883061 (diff) | |
download | cexcess-73d972de47ed73d14fbfd2582b166e17f39f356a.tar.bz2 |
sbp_fit.py: reorder for better clearance; add new TODO items
-rwxr-xr-x | sbp_fit.py | 60 | ||||
-rw-r--r-- | sbpfit.conf | 6 |
2 files changed, 35 insertions, 31 deletions
@@ -3,9 +3,12 @@ # # Aaron LI # Created: 2016-03-13 -# Updated: 2016-04-21 +# Updated: 2016-04-26 # # Changelogs: +# 2016-04-26: +# * Reorder some methods of classes 'FitModelSBeta' and 'FitModelDBeta' +# * Change the output file extension from ".txt" to ".json" # 2016-04-21: # * Plot another X axis with unit "r500", with R500 values marked # * Adjust output image size/resolution @@ -33,6 +36,8 @@ # # TODO: # * to allow fit the outer beta component, then fix it, and fit the inner one +# * to integrate basic information of config file to the output json +# * to output the ignored radius range in the same unit as input sbp data # """ @@ -59,7 +64,7 @@ model = sbeta #model = dbeta # output file to store the fitting results -outfile = sbpfit.txt +outfile = sbpfit.json # output file to save the fitting plot imgfile = sbpfit.png @@ -70,7 +75,7 @@ imgfile = sbpfit.png [sbeta] # model-related options (OVERRIDE the upper level options) -outfile = sbpfit_sbeta.txt +outfile = sbpfit_sbeta.json imgfile = sbpfit_sbeta.png #ignore = 0.0-20.0, #ignore_r500 = 0.0-0.15, @@ -85,7 +90,7 @@ imgfile = sbpfit_sbeta.png [dbeta] -outfile = sbpfit_dbeta.txt +outfile = sbpfit_dbeta.json imgfile = sbpfit_dbeta.png #ignore = 0.0-20.0, #ignore_r500 = 0.0-0.15, @@ -100,18 +105,10 @@ imgfile = sbpfit_dbeta.png ------------------------------------------------- """ -__version__ = "0.6.1" -__date__ = "2016-04-21" +__version__ = "0.6.2" +__date__ = "2016-04-26" -import numpy as np -import lmfit -import matplotlib.pyplot as plt - -from configobj import ConfigObj -from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas -from matplotlib.figure import Figure - import os import sys import re @@ -119,6 +116,13 @@ import argparse import json from collections import OrderedDict +import numpy as np +import lmfit +import matplotlib.pyplot as plt +from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas +from matplotlib.figure import Figure +from configobj import ConfigObj + plt.style.use("ggplot") @@ -129,8 +133,8 @@ class FitModel: The supplied `func' should have the following syntax: y = f(x, params) - where the `params' is the parameters to be fitted, - and should be provided as well. + where the `params' is `lmfit.Parameters' instance which contains all + the model parameters to be fitted, and should be provided as well. """ def __init__(self, name=None, func=None, params=lmfit.Parameters()): self.name = name @@ -177,6 +181,10 @@ class FitModelSBeta(FitModel): ("beta", 0.7, True, 0.3, 1.1, None), ("bkg", 1.0e-9, True, 0.0, 1.0e-7, None)) + def __init__(self): + super(self.__class__, self).__init__(name="Single-beta", + func=self.sbeta, params=self.params) + @staticmethod def sbeta(r, params): parvals = params.valuesdict() @@ -186,10 +194,6 @@ class FitModelSBeta(FitModel): bkg = parvals["bkg"] return s0 * np.power((1 + (r/rc)**2), (0.5 - 3*beta)) + bkg - def __init__(self): - super(self.__class__, self).__init__(name="Single-beta", - func=self.sbeta, params=self.params) - def plot(self, params, xdata, ax): """ Plot the fitted model, as well as the fitted parameters. @@ -232,6 +236,14 @@ class FitModelDBeta(FitModel): params.add("beta2", value=0.7, min=0.3, max=1.1) params.add("bkg", value=1.0e-9, min=0.0, max=1.0e-7) + def __init__(self): + super(self.__class__, self).__init__(name="Double-beta", + func=self.dbeta, params=self.params) + + @classmethod + def dbeta(self, r, params): + return self.beta1(r, params) + self.beta2(r, params) + @staticmethod def beta1(r, params): """ @@ -255,14 +267,6 @@ class FitModelDBeta(FitModel): beta2 = parvals["beta2"] return s02 * np.power((1 + (r/rc2)**2), (0.5 - 3*beta2)) - @classmethod - def dbeta(self, r, params): - return self.beta1(r, params) + self.beta2(r, params) - - def __init__(self): - super(self.__class__, self).__init__(name="Double-beta", - func=self.dbeta, params=self.params) - def plot(self, params, xdata, ax): """ Plot the fitted model, and each beta component, diff --git a/sbpfit.conf b/sbpfit.conf index 4a8f50c..0d73953 100644 --- a/sbpfit.conf +++ b/sbpfit.conf @@ -21,7 +21,7 @@ model = sbeta #model = dbeta # output file to store the fitting results -outfile = sbpfit.txt +outfile = sbpfit.json # output file to save the fitting plot imgfile = sbpfit.png @@ -32,7 +32,7 @@ imgfile = sbpfit.png [sbeta] # model-related options (OVERRIDE the upper level options) -outfile = sbpfit_sbeta.txt +outfile = sbpfit_sbeta.json imgfile = sbpfit_sbeta.png #ignore = 0.0-20.0, ignore_r500 = 0.0-0.1, @@ -47,7 +47,7 @@ ignore_r500 = 0.0-0.1, [dbeta] -outfile = sbpfit_dbeta.txt +outfile = sbpfit_dbeta.json imgfile = sbpfit_dbeta.png #ignore = 0.0-20.0, #ignore_r500 = 0.0-0.15, |