diff options
author | Onderwaater <onderwaa@esrf.fr> | 2015-08-18 13:40:16 +0200 |
---|---|---|
committer | Onderwaater <onderwaa@esrf.fr> | 2015-08-18 13:40:16 +0200 |
commit | c3c24c8ef7bc700c79a911579c7c436a36c758dd (patch) | |
tree | 95e67ea502c588dc446836a4796671e796a4e2f4 | |
parent | a1a9b8e60cc46bb2b3326e87039a054b694c5dea (diff) |
added fit functions to fit module
-rw-r--r-- | BINoculars/fit.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/BINoculars/fit.py b/BINoculars/fit.py index 828ec3e..2e7b8c4 100644 --- a/BINoculars/fit.py +++ b/BINoculars/fit.py @@ -131,8 +131,8 @@ def get_class_by_name(name): for k, v in globals().iteritems(): if isinstance(v, type) and issubclass(v, FitBase): options[k.lower()] = v - if name in options: - return options[name] + if name.lower() in options: + return options[name.lower()] else: raise ValueError("unsupported fit function '{0}'".format(name)) @@ -147,6 +147,26 @@ class Lorentzian1D(PeakFitBase): gamma0 = 5 * self.space.axes[0].res #estimated FWHM on 10 pixels self.guess = [maximum , argmax[0], gamma0, linparams[0], linparams[1]] +class Lorentzian1DNoBkg(PeakFitBase): + @staticmethod + def func((x,), (I, loc ,gamma)): + return I / ((x - loc)**2 + gamma**2) + + def set_guess(self, maximum , argmax, linparams): + gamma0 = 5 * self.space.axes[0].res #estimated FWHM on 10 pixels + self.guess = [maximum , argmax[0], gamma0] + +class PolarLorentzian2Dnobkg(PeakFitBase): + @staticmethod + def func((x,y), (I, loc0, loc1, gamma0, gamma1, th)): + a,b = tuple(grid - center for grid, center in zip(rot2d(x,y,th),rot2d(loc0,loc1,th))) + return (I / (1 + (a / gamma0)**2 + (b / gamma1)**2 )) + + def set_guess(self, maximum , argmax, linparams): + gamma0 = self.space.axes[0].res#estimated FWHM on 10 pixels + gamma1 = self.space.axes[1].res + self.guess = [maximum , argmax[0], argmax[1], gamma0, gamma1, 0] + class PolarLorentzian2D(PeakFitBase): @staticmethod def func((x,y), (I, loc0, loc1, gamma0, gamma1, th, slope1, slope2, offset)): @@ -158,6 +178,10 @@ class PolarLorentzian2D(PeakFitBase): gamma1 = self.space.axes[1].res self.guess = [maximum , argmax[0], argmax[1], gamma0, gamma1, 0, linparams[0], linparams[1], linparams[2]] + def integrate_signal(self): + return self.func(self.cxdata, (self.result[0], self.result[1], self.result[2], self.result[3], self.result[4], self.result[5], 0, 0, 0)).sum() + + class Lorentzian2D(PeakFitBase): @staticmethod def func((x,y), (I, loc0, loc1, gamma0, gamma1, th, slope1, slope2, offset)): @@ -169,6 +193,18 @@ class Lorentzian2D(PeakFitBase): gamma1 = 5 * self.space.axes[1].res self.guess = [maximum , argmax[0], argmax[1],gamma0, gamma1, 0, linparams[0], linparams[1], linparams[2]] +class Lorentzian2Dnobkg(PeakFitBase): + @staticmethod + def func((x,y), (I, loc0, loc1, gamma0, gamma1, th)): + a,b = tuple(grid - center for grid, center in zip(rot2d(x,y,th),rot2d(loc0,loc1,th))) + return (I / (1 + (a/gamma0)**2) * 1 / (1 + (b/gamma1)**2)) + + def set_guess(self, maximum , argmax, linparams): + gamma0 = 5 * self.space.axes[0].res #estimated FWHM on 10 pixels + gamma1 = 5 * self.space.axes[1].res + self.guess = [maximum , argmax[0], argmax[1],gamma0, gamma1, 0] + + class Lorentzian(AutoDimensionFit): dimensions = {1: Lorentzian1D, 2: PolarLorentzian2D} |