Automate curve fitting
elliottmclean
For the first fit the fitting cursors need to be set to disregard noise at the end of the graph; and the initial guesses must be set to check as to whether the fit actually looks okay. Is it possible to call from a procedure to open the curve fitting dialog? Once the coefficients have been found for the first, they are fed into the function to fit the second, and then the coefficients from the second are used for the third and so on.
Any help on the matter would be greatly appreciated as I'm not sure where to even start.
Cheers.
It is possible to trigger the Curve Fit menu item using DoIgorMenu, but I'm not sure it's particularly useful. You could set up your workflow to require initial guesses as an input, and then the method you use to get those initial guesses would be up to you to decide each time you do this. You would also determine the position of the start and end points at the same time. Quite likely that you would use the dialog to do the first fit and use that as the initial guess.
Yes- you can string together different procedures by simply calling one function from another. You may wish to design the pieces with the thought that they would eventually work together. If a task has multiple steps, each of which is relatively independent of the others, it is always easier to develop each step separately and then finally work out the problems associated with stringing them together. Hint- error handling is something you need to think about up front. An error in an early step can lead to chaos down the chain.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 4, 2017 at 09:09 am - Permalink
Great! Thanks John I'll check out batch curve fitting and see how I go.
October 6, 2017 at 05:25 am - Permalink
Very typical use of Igor!
1 make a wave to store the initial guesses, this wave will act as the coefficient wave.
2 make several waves to store fitted results. you can get the result from the coefficient wave after each fitting process.
3 get the name list( or wave reference list) of the waves to be fitted
4 use for loop (or do-while loop). in each loop, get the wave from the name list and fit it using funcfit. in each loop the same coefficient wave is used, so you dont need to fill in initial guess, just as you want, the coefficients (fitting results of the last fitting) are automatically used in the next fitting.
October 6, 2017 at 06:10 am - Permalink
You need to be careful, though. If a fit fails, the contents of the coefficient wave may be garbage.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 6, 2017 at 09:26 am - Permalink
October 6, 2017 at 11:06 pm - Permalink
//save the current work datafolder
string curr=getdatafolder(1)
//set the new data folder as the work datafolder
setdatafolder theFolderYouWantToLoadDataInto
//do anythings to the data just loaded
//restore previous datafolder
setdatafolder curr
October 6, 2017 at 11:32 pm - Permalink
yes, examine the fitted result is a necessary step of fitting process
October 6, 2017 at 11:36 pm - Permalink
LoadWave ...
Wave w = $StringFromList(0, S_WaveNames) // assumes you only ever load one wave, but that limitation is easily overcome.
AnalyseMyData(w)
end
Function AnalyseMyData(WAVE w) // Uses Igor 7 inline declaration style!
... Do something with the data in the wave ...
end
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 9, 2017 at 03:16 pm - Permalink
Thanks John I figured that would be the case. I'll just do what you mentioned.
In regards to the batch fitting I have 2 questions. At the moment I load up the selected files and extract the data into waves and graph the first set of data so I can do an initial fit to test initial guesses. I'm trying to feed W_coef from this inital fit into the batch fitting as the inital guesses for the fit via the Functions and Coefficients sub heading and in the "2D initial guess wave" drop menu. However when I try to run the batch fitting it does not work. It's not a huge inconvenience but it would save me individually typing the guesses into all the boxes.
Secondly, on a number of fit that I have run I keep getting an error which reads: "Error on batch X: Limit of passes without decreasing chi-square was reached" and the fit isn't applied to these sets of data and then each data set that follows has an incorrect fit. Now I'm not sure whether this was an error unique to my fitting function or whether it was common for batch fitting in general but I couldn't find a chi-square in my function.
Cheers.
October 11, 2017 at 05:04 am - Permalink
I'm not sure exactly what you mean- there is nothing in the dialog called "2D initial guess wave". You should be able to make a coefficient wave before you open the dialog, then select that wave from the Coefficient Wave menu. When you do that, the Initial Guess column in the list will be filled in with the contents of your wave. The pre-made coefficient wave must have exactly the right number of elements. Be sure you make a double-precision wave.
That means that nine iterations went by without any improvement in the fit. One way that can happen is if you are fitting fake data that has no noise- you get a "perfect" fit with no room for improvement. It could also happen if you manage to give the fit the absolute best solution to start from. The V_chisq and the current solution are probably OK. Another way this can happen is if your initial guesses are actually really bad, or the fit function simply doesn't resemble your data at all, and the chi-square can't improve.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 11, 2017 at 09:38 am - Permalink
I've attached a photo to show you what I mean. The "2D Initial Guess Wave" is on the left hand side which I assumed would be where I could input my coefficient wave from an initial seperate fit. I have a feeling the one you're directing me to is in the curve fitting however I was talking about batch fitting.
Cheers.
October 11, 2017 at 06:06 pm - Permalink
The 2D Initial Guess Wave menu is only available if you select 2D Wave, One Column Per Fit from the Initial Guess Mode menu just above 2D Initial Guess Wave.
Now that I'm on board, let's try this one again.
The author of the Batch Curve Fit package has left WaveMetrics, making support tricky... What happens if you use the Same Initial Guesses for Each Batch item in the Initial Guess Mode menu? That sounds like it shouldn't get screwed up by a failure of one of the fits.
And the mode, "Use Coefficients from Last Successful Fit" seems like it should ignore errors, using the last solution that finished without a problem. It might be a bug.
Can you post an Igor experiment with a selection of data that illustrates your problem?
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 12, 2017 at 12:38 pm - Permalink