jgliss / pyplis

Python toolbox for the analysis of UV SO2 camera data
GNU General Public License v3.0
7 stars 5 forks source link

scipy.optimize.curve_fit stuck in local minimum for cell calibration? #37

Open twVolc opened 3 years ago

twVolc commented 3 years ago

This might be a very niche error but I'm just recording it in case anyone else experiences the same issue, and for my own reference if it happens again.

I've found that the curve_fit() used in calib_base.CalibData.fit_calib_data() is not producing a good fit for a dataset of mine. One possible reason for the issue is that I use an empty cell for calibration, so essentially 0 cm-2 and when this is used as the initial guess for curve_fit() it doesn't seem to change with the fitting procedure and all fits are driven through this point, or very close too it (almost like forcing the fit through the origin). Line 467 in calib_base.py is where this guess is defined guess[-1] = min(cds) . I have found that changing this to avoid using the smallest value as the first guess resulted in the fits looking much more like they should: guess[-1] = max(cds). Perhaps this isn't ideal, but I didn't notice any detrimental impact on speed. This may also only be an issue in this specific case (or another possibility is that I have done something wrong elsewhere which is creating this issue...), so I don't know whether it is worth changing in the pyplis code..