woutergins / satlas

Statistical Analysis Toolbox for Laser Spectroscopy
Other
6 stars 4 forks source link

Pandas issue #36

Closed cricketts497 closed 4 years ago

cricketts497 commented 4 years ago

Issue with satlas.chisquare_fit() in the profiles.py line 481 with pandas v1.0.5, throws an attribute error when looking for wofz(z).real

File "C:\Users\crick\OneDrive\Documents\analysis_files\analysis_project\Scan_clean.py", line 1172, in fit_model success, message = sat.chisquare_fit(self.model, self.binned['frequency'], self.binned['rate'], yerr=self.binned['err_rate'], xerr=self.binned['err_freq']) File "C:\Users\crick\Miniconda3\lib\site-packages\satlas\stats\fitting.py", line 183, in chisquare_fit result = lm.minimize(chisquare_model, params, args=(f, x, np.hstack(y), np.hstack(yerr), xerr, func), iter_cb=iter_cb, method=method) File "C:\Users\crick\Miniconda3\lib\site-packages\lmfit\minimizer.py", line 2505, in minimize return fitter.minimize(method=method) File "C:\Users\crick\Miniconda3\lib\site-packages\lmfit\minimizer.py", line 2285, in minimize return function(kwargs) File "C:\Users\crick\Miniconda3\lib\site-packages\lmfit\minimizer.py", line 1646, in leastsq lsout = scipy_leastsq(self.__residual, variables, lskws) File "C:\Users\crick\Miniconda3\lib\site-packages\scipy\optimize\minpack.py", line 388, in leastsq shape, dtype = _check_func('leastsq', 'func', func, x0, args, n) File "C:\Users\crick\Miniconda3\lib\site-packages\scipy\optimize\minpack.py", line 26, in _check_func res = atleast_1d(thefunc(((x0[:numinputs],) + args))) File "C:\Users\crick\Miniconda3\lib\site-packages\lmfit\minimizer.py", line 576, in __residual out = self.userfcn(params, self.userargs, *self.userkws) File "C:\Users\crick\Miniconda3\lib\site-packages\satlas\stats\fitting.py", line 76, in chisquare_model model = np.hstack(f(x)) File "C:\Users\crick\Miniconda3\lib\site-packages\satlas\models\hfsmodel.py", line 631, in call s = self.params['Scale'].value sum([prof(x) for prof in self.parts]) File "C:\Users\crick\Miniconda3\lib\site-packages\satlas\models\hfsmodel.py", line 631, in s = self.params['Scale'].value sum([prof(x) for prof in self.parts]) File "C:\Users\crick\Miniconda3\lib\site-packages\satlas\profiles.py", line 481, in call top = wofz(z).real / (self.sigma sqrt2pi) File "C:\Users\crick\Miniconda3\lib\site-packages\pandas\core\generic.py", line 5274, in getattr return object.getattribute(self, name) AttributeError: 'Series' object has no attribute 'real'

cricketts497 commented 4 years ago

Only a problem when passing pd.Series() objects as x input to satlas.chisquare_fit()

woutergins commented 4 years ago

The issue is indeed that the function expects Numpy arrays as input. Using the ".values" attribute of the Series/Dataframe should solve the problem.