1313from scipy .special import erf # pylint: disable=no-name-in-module
1414from sigima .tests .helpers import get_default_test_name
1515from sigima .tools .checks import check_1d_arrays
16- from sigima .tools .signal import fitmodels , fitting , fourier , peakdetection
16+ from sigima .tools .signal import fitting , fourier , peakdetection , pulse
1717
1818from datalab .config import _
1919
20+ # TODO: Use sigima.tools.signal.fitting functions for initial parameter estimates
21+
2022
2123def guifit (
2224 x ,
@@ -122,7 +124,7 @@ def gaussianfit(x, y, parent=None, name=None):
122124 dx = np .max (x ) - np .min (x )
123125 dy = np .max (y ) - np .min (y )
124126 sigma_guess = dx * 0.1
125- amp_guess = fitmodels .GaussianModel .get_amp_from_amplitude (dy , sigma_guess )
127+ amp_guess = pulse .GaussianModel .get_amp_from_amplitude (dy , sigma_guess )
126128 mu_guess = peakdetection .xpeak (x , y )
127129 b_guess = np .min (y )
128130
@@ -141,7 +143,7 @@ def gaussianfit(x, y, parent=None, name=None):
141143 params = [a , sigma , mu , b ]
142144
143145 def fitfunc (x , params ):
144- return fitmodels .GaussianModel .func (x , * params )
146+ return pulse .GaussianModel .func (x , * params )
145147
146148 values = guifit (
147149 x , y , fitfunc , params , parent = parent , wintitle = _ ("Gaussian fit" ), name = name
@@ -169,7 +171,7 @@ def lorentzianfit(x, y, parent=None, name=None):
169171 dx = np .max (x ) - np .min (x )
170172 dy = np .max (y ) - np .min (y )
171173 sigma_guess = dx * 0.1
172- amp_guess = fitmodels .LorentzianModel .get_amp_from_amplitude (dy , sigma_guess )
174+ amp_guess = pulse .LorentzianModel .get_amp_from_amplitude (dy , sigma_guess )
173175 mu_guess = peakdetection .xpeak (x , y )
174176 b_guess = np .min (y )
175177
@@ -188,7 +190,7 @@ def lorentzianfit(x, y, parent=None, name=None):
188190 params = [a , sigma , mu , b ]
189191
190192 def fitfunc (x , params ):
191- return fitmodels .LorentzianModel .func (x , * params )
193+ return pulse .LorentzianModel .func (x , * params )
192194
193195 values = guifit (
194196 x , y , fitfunc , params , parent = parent , wintitle = _ ("Lorentzian fit" ), name = name
@@ -216,7 +218,7 @@ def voigtfit(x, y, parent=None, name=None):
216218 dx = np .max (x ) - np .min (x )
217219 dy = np .max (y ) - np .min (y )
218220 sigma_guess = dx * 0.1
219- amp_guess = fitmodels .VoigtModel .get_amp_from_amplitude (dy , sigma_guess )
221+ amp_guess = pulse .VoigtModel .get_amp_from_amplitude (dy , sigma_guess )
220222 mu_guess = peakdetection .xpeak (x , y )
221223 b_guess = np .min (y )
222224
@@ -235,7 +237,7 @@ def voigtfit(x, y, parent=None, name=None):
235237 params = [a , sigma , mu , b ]
236238
237239 def fitfunc (x , params ):
238- return fitmodels .VoigtModel .func (x , * params )
240+ return pulse .VoigtModel .func (x , * params )
239241
240242 values = guifit (
241243 x , y , fitfunc , params , parent = parent , wintitle = _ ("Voigt fit" ), name = name
@@ -316,7 +318,7 @@ def multilorentzian(x, *values, **kwargs):
316318 a_x0 = kwargs ["a_x0" ]
317319 y = np .zeros_like (x ) + y0
318320 for amp , sigma , x0 in zip (a_amp , a_sigma , a_x0 ):
319- y += fitmodels .LorentzianModel .func (x , amp , sigma , x0 , 0 )
321+ y += pulse .LorentzianModel .func (x , amp , sigma , x0 , 0 )
320322 return y
321323
322324
@@ -338,7 +340,7 @@ def multilorentzianfit(
338340 dx = 0.5 * (x [iend ] - x [istart ])
339341 dy = np .max (y [istart :iend ]) - np .min (y [istart :iend ])
340342 sigma = dx * 0.1
341- amp = fitmodels .LorentzianModel .get_amp_from_amplitude (dy , sigma )
343+ amp = pulse .LorentzianModel .get_amp_from_amplitude (dy , sigma )
342344
343345 stri = f"{ index + 1 :02d} "
344346 params += [
@@ -581,7 +583,7 @@ def planckianfit(x: np.ndarray, y: np.ndarray, parent=None, name=None):
581583 params = [amp , x0 , sigma , y0 ]
582584
583585 def fitfunc (x , params ):
584- return fitmodels . PlanckianModel . func (x , * params )
586+ return fitting . PlanckianFitComputer . evaluate (x , * params )
585587
586588 values = guifit (
587589 x , y , fitfunc , params , parent = parent , wintitle = _ ("Planckian fit" ), name = name
@@ -682,7 +684,7 @@ def twohalfgaussianfit(x: np.ndarray, y: np.ndarray, parent=None, name=None):
682684 params = [amp_left , amp_right , sigma_left , sigma_right , x0 , y0_left , y0_right ]
683685
684686 def fitfunc (x , params ):
685- return fitmodels . TwoHalfGaussianModel . func (x , * params )
687+ return fitting . TwoHalfGaussianFitComputer . evaluate (x , * params )
686688
687689 values = guifit (
688690 x ,
@@ -802,7 +804,7 @@ def doubleexponentialfit(x: np.ndarray, y: np.ndarray, parent=None, name=None):
802804 params = [x_center , a_left , b_left , a_right , b_right , y0 ]
803805
804806 def fitfunc (x , params ):
805- return fitmodels . DoubleExponentialModel . func (x , * params )
807+ return fitting . DoubleExponentialFitComputer . evaluate (x , * params )
806808
807809 values = guifit (
808810 x ,
0 commit comments