Automating Multipeak Fitting

Hi everyone,

I am currently using Igor Pro v9.01 (64-bit) with the Multipeak fit v3.01.

My goal is to automate the system with having certain parameters set for each trial that do not change. I want the code to use the waves already saved in the data browser, then picks the X and Y waves from the data browser, start new graph & start fresh then press the start button. Next, step would be to auto-locate peaks with the preset parameters already in igor then press do fit button. Lastly, press the peak results button and report in a notebook. I would like to run through the multipeak analysis procedure without having to use any of the data panels and output the results notebook and graph. I was wondering what is the best way to auto-mate the multipeak method if the data browser already has the necessary waves? 

I attempted to write my own functions based on the multipeak code in my procedure file, but unsure if this is the best way to go about automating the process.

Also, I am new to igor & wavemetrics so please let me know if I need to provide more details or explanations. Thanks for any help provided and feedback!

Thanks,

Hayley

 

I think the first step would be to figure out if the batch MPF facility already in the package will do what you want. There is a nice GUI for the batch fitting facility; to learn more execute this command on Igor's command line: DisplayHelpTopic "Automatic Multipeak Batch Fitting"

If that doesn't do what you want, you may need to do some programming of your own: DisplayHelpTopic "Multipeak Fitting for Igor Programmers"

Thank you for your help!

I continued to do more programming of my own using the multipeak fitting for igor programmers help topic. I was able to automate the process through the auto-locating peaks. However, I ran into an error that stated "expected name of target window" associated with the funcfit code line after I call the do multipeak fit procedure. I can see the graph updating and it appears to work, but at the end of the code does not apply the final fits to the graph. I have attached a snippet of the code below that uses the funcfit line. 

What should I try to get rid of this error?

Your screen capture doesn't include the end of the FuncFit command, where the /D (autodestination wave) specification will most likely be, but I assume it's there. The /D flag modifies the topmost graph *if* the Y data wave graphed there.

It might be better to copy the code as text- that makes it much easier for us to inspect it. Use the Insert Code Snippet icon above the editing window here, and paste your Igor code into the window.

In reply to by johnweeks

FuncFit/Q=1/N=(doUpdates==0?1:0)/M=2 {string=MPstruct.FuncListString} yw[xPtRgBgn,xPtRgEnd]/X=xw[xPtRgBgn,xPtRgEnd]/W=MPstruct.weightWave[xPtRgBgn,xPtRgEnd]/I=1/M=MPstruct.maskWave[xPtRgBgn,xPtRgEnd]/AD=(doAutoDest)/AR=(doAutoResid)/A=1/NWOK/C=MPstruct.constraints;AbortOnRTE

//FuncFit/N=(doUpdates==0?1:0)/M=2 {string=MPstruct.FuncListString} yw[xPtRgBgn,xPtRgEnd]/X=xw[xPtRgBgn,xPtRgEnd]/AD=1/AR=1/A=1/NWOK/C=MPstruct.constraints;AbortOnRTE
   

Here is the code snippet. 

It would be more useful if you could post your code which you wrote to interact with MPF. As mentioned before, there is less to be gained from trying to 'fix' the MPF code. Ideally, you would want to post a small experiment file, which demonstrates the problem. I have the feeling that your input to AutoMPFit might be wrong. Furthermore, I wonder if the approach described in DisplayHelpTopic "Automatic Multipeak Batch Fitting" is what you would want to try instead.

Unfortunately, the Automatic Multipeak Batch Fitting does not work with what I want to do. I have attached some of the code below that calls the different functions from the Multipeak Fitting code with modifications to not use the panels. I adapted some of the multipeak code into my own procedure files when I was eliminating the reliance on the panels. I am not using any information from the panels, only the data browser. I can provide more of that code. I am currently not using AutoMPFit, but the doMPFit after the peaks have been auto-located. From the MPF2_DoFitButtonProc(s), the MPstruct and Data Folder Path are passed to MPF2_DoFit. The code works until it reaches the funcfit line in the MPF2_DoFit. I am still familiarizing myself with the forum and will try to upload a sample file.

Thanks again for any help or feedback.

Function Combine()

MPF2_StartNewMPFit(0, "New Graph", "wave1", "wave0", 1, 0)

MPF2_AutoLocatePeaks(setnumber, RangeBegin, RangeEnd, RangeReversed)
   
    Variable listprecision = NumVarOrDefault(DFPath+":MPF2_CoefListPrecision", 5)
    Variable/G $(DFPath+":MPF2_CoefListPrecision") = listprecision
    NVAR MPF2_CoefListPrecision = $(DFPath+":MPF2_CoefListPrecision")
   
    NVAR/Z MPF2_FitTolerance = $(DFPath+":V_FitTol")               
    if (!NVAR_Exists(MPF2_FitTolerance))
        Variable/G $(DFPath+":V_FitTol")
        NVAR MPF2_FitTolerance = $(DFPath+":V_FitTol")
        MPF2_FitTolerance = 0.001                                  
    endif
   
   
    MPF2_DoFitButtonProc(s)
   
   
    MPF2_DoPeakResults(setNumber)

End

 

Unfortunately, the Automatic Multipeak Batch Fitting does not work with what I want to do.

Could you elaborate a bit on that? If Automatic Multipeak Batch Fitting will not work with your data, then your approach will not work either. Automatic Multipeak Batch Fitting was made precisely to work with MPF without the panels. I wonder if you are simply missing something, and believe that trying to force the MPF user interface to do what you want is a lot harder.

I think the code you posted is not complete and it is difficult to judge what you have changed, but I see what you are trying to do better now. I tried to replicate these steps, and came up with the following function:

Function Combine(Wave inY, Wave inX)
    STRUCT WMButtonAction s; s.eventCode=2
    MultiPeakFit2_Initialize()
    MPF2_StartNewMPFit(0, "New Graph", GetWavesDataFolder(inY,2), GetWavesDataFolder(inX,2), 1, 0)
    MPF2_AutoLocatePeaksButtonProc(s)
    MPF2_DoFitButtonProc(s)
    NVAR setNumber = root:Packages:MultiPeakFit2:currentSetNumber
    MPF2_DoPeakResults(setNumber)
End

This 'presses' all relevant buttons to complete the fit for the two input waves (the code would need additional checks if you want to omit the x Wave). I tested it with the demo experiment and it runs just fine. Maybe you are omitting one of the necessary steps here. Again, this approach is not recommended, but I am of course happy to support you in getting this to work.

Thank you for the feedback and help!!

This could be a user error problem, but automatic batch fitting does not show the peak results in a table like the multipeak start/resume program does. The goal of the program is to use the already loaded wave1 and wave0, auto-locate and do multipeak fit, then output the peak results into a report notebook. Using the multipeak start/resume program, I would load the x and y wave then start fresh and create a new graph. Next, I would auto-locate the peaks with already defined/given parameters. Then, I would click do the multipeak fit button. Lastly, I would click peak results button and report in a notebook. I would like to have all the results from the notebook such as peak numbers, location, full width half max, etc. 

I will add the changes to the code you suggested and see how the program responds. 

Thanks again for all the helpful input and suggestions!!

Yes, automatic batch fitting does not show you a ready made table or notebook. The idea is that you use this in your own code, so you need to grab and present the results yourself as well. You would 'just' need to invest some time to write code for generating a nice notebook in the way you want from the results of automatic batch fitting. May I ask for what purpose you want a table / notebook? Printing, as a log, or ...? The benefit is that automatic batch fitting is much more flexible to adapt to your needs. For example, it is easy to define the background type, which would be a difficult task to do via code the way you are currently trying to do things with the UI.

Here is a screenshot where I set up the Automatic Multipeak Batch Fitting UI to fit data from the Multipeak Fit demo, which took me only seconds. Note that I have checked the checkbox 'I Want Derived Values', which create these '...DER' waves in the output folder. These hold then the standard parameters like location, fwhm, area etc., just like you are used to see in the MPF table / notebook. It would then only be a relatively small task to create an output / summary of your liking from these.

In reply to by chozo

I was able to use the AutoMPFit function to generate the data; however, I am struggling to output the results in a notebook like the regular multipeak fitting program. I was wondering where I can find resources to help output the data the same way. 

Thanks for all the help!!

Yes, I see that it is not trivial to completely replicate the notebook output from MPF. Thus, I have written a small procedure which generates a notebook closely resembling the MPF one from a result folder of AutoMPFit (see the attachment). In essence, I took the existing notebook function and adapted it for AutoMPFit. Note also that this function does not rely on the presence of the "..DER" waves, as all derived values are generated separately. So it should work with AutoMPFit without any additional set up. This makes the code probably a bit more complicated and less beginner-friendly.

Run it like this:

AutoMPFit_ResultsNotebook(FullPathToOneResultFolder)

It should be not so difficult to create a notebook for each result folder by calling this function in a loop (should you have more than one). I didn't test it too much, so there might be bugs. Let me know if you find some problem.

If you want to dive in more yourself, you should first read up on notebooks, and then go over to the NewNotebook and Notebook commands:

DisplayHelpTopic "Notebooks"