jkrogager / VoigtFit

Python code to fit absorption lines semi-interactively
http://voigtfit.readthedocs.io/
MIT License
28 stars 12 forks source link

Error while using dataset.fit() #40

Closed nimishak-cosmos closed 2 years ago

nimishak-cosmos commented 3 years ago

Hi, I get the following error from time to time, and gets fixed by adjusting the values of input guess values of b-parameters and column densities. Are you familiar with this problem? Thanks, Nimisha

--

Traceback (most recent call last): File "Voigtfit_Lya.py", line 54, in popt, chi2 = dataset.fit() File "/user/kumari/miniconda3/envs/voigtfit_conda/lib/python3.8/site-packages/VoigtFit/dataset.py", line 1985, in fit popt = self.minimizer.minimize(kwargs) File "/user/kumari/miniconda3/envs/voigtfit_conda/lib/python3.8/site-packages/lmfit/minimizer.py", line 2363, in minimize return function(kwargs) File "/user/kumari/miniconda3/envs/voigtfit_conda/lib/python3.8/site-packages/lmfit/minimizer.py", line 1700, in leastsq lsout = scipy_leastsq(self.__residual, variables, **lskws) File "/user/kumari/miniconda3/envs/voigtfit_conda/lib/python3.8/site-packages/scipy/optimize/minpack.py", line 422, in leastsq retval = _minpack._lmdif(func, x0, args, full_output, ftol, xtol, ValueError: The array returned by a function changed size between calls

jkrogager commented 3 years ago

Indeed, the optimization done by lmfit depends critically on the initial input you use. This is always the case for chi2-minimization with a large number of free variables. Could you please send me the input that gives rise to the following error? And please send the input that fixed the error too.

nimishak-cosmos commented 3 years ago

Sorry, I missed this somehow.

Input values which fix the error:

dataset.add_component_velocity('HI', 0., 50., 20.41, var_z=0, var_b=1, var_N=0) dataset.add_component_velocity('HI', 1220.3, 3000., 16.0, var_z=0, var_b=1, var_N=1)

Input values which give error:

dataset.add_component_velocity('HI', 0., 50., 20.41, var_z=0, var_b=1, var_N=0) dataset.add_component_velocity('HI', 1220.3, 3000., 14.0, var_z=0, var_b=1, var_N=1)

jkrogager commented 3 years ago

The initial b-value of 3000 km/s seems rather high, is this physically motivated from your data? Could you send me the best-fit results as well and if possible a figure of the spectral range you're fitting, and/or the best-fit plot?

jkrogager commented 2 years ago

No update since July 2021, so I'm closing now. Let me know if you need any other feedback.