RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 800
python, random, scipy
Solution
Laser beam, by any chance? ;-)
Anyway, the problem will probably be that the rows that get selected are "hard" to fit a Gaussian curve to by scipy's curve_fit function. My first suggestion is to debug (using e.g. python's logging module) to see if the error pops up only on specific rows.
My second suggestion is to change the initial guess for the curve_fit. From rows where curve-fitting is possible, you should be able to extract a few parameters. On other rows, the mean of the Gaussian is at approximately the same position and the aplitude will not vary as much either. A good initial guess will definitely help the curve fitting.
If you want to analyze the issue, I'd definitely do both: try to find rows for which the curve fitting fails after 800 iterations. Then see if the curve fitting works by changing the initial guess.
Problem
I have an image where I pick a randow row in it and try to fit a Gaussian curve in that row. I am using scipy.optimize curve_fit method for fitting a Gaussian. Picking of the randow rows are according to an array vector [10, 20, 40, 60, 100], meaning that in the first try I pick 10 randow rows (hence, 10 Gaussian fits) in that image, then, more rows are selected and so on. Most of time, code is working, however, sometimes I get an error (especially, when the number of rows are large: around 60 or more), which says optimal parameters are not found. I have found some similar posts in stackoverflow but still can not able to solve this problem. It seems like this problem appears quite often with curve_fit method.