MultiPeakBatchFit question

I am looking to automate some fitting via multi peak 2.0 and am examining the MultiPreakBatchFit function. It has three input parameters:datafoldername,ywavelist,xwavelist.

What should the the xwavelist look like for calculated values?

Andy
What version of Igor are you running? I don't have a MultiPeakBatchFit() function. I have MPF2_AutoMPFit(). The help file for Multipeak Fit 2 includes documentation of the inputs for MPF2_AutoMPFit(). It says:

xWaveList list of the X waves with peak data to be fit. Any entry in the list that doesn't name an actual wave causes the fit to use "_calculated_"; that is, the X values will be taken from the corresponding Y wave's X scaling.
If xWaveList is set to "", all X waves will be "_calculated_".

Note that last line.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Hi John,

I am running 6.34a.

The multiPeakBatchFit function is in the help file and I am trying to use it to automate some batch processing. (and you didn't think people actually read the help files did you?)

Ah, I see. I wrote it, but had forgotten about it.

Your right- we tend to assume that people don't read the help. I think we're mostly right, so it's nice to be proven wrong sometimes!

The key is this line:
                Wave/Z MPStruct.xWave = $StringFromList(i, xwavelist)
The list could be just "" (an empty list) or it could be a list of words that simply aren't names of waves, like "_calculated_". The /Z flag in Wave/Z indicates to Igor's compiler that it's not a mistake for the wave reference to be NULL. The MPF2_DoMPFit() function will interpret the NULL wave reference for the X wave to mean that it should use the Y wave's X scaling for the X data.

Is there some reason to not use MPF2_AutoMPFit()? It's a lot more sophisticated than the example function.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
hegedus wrote:
I am looking to automate some fitting via multi peak 2.0 and am examining the MultiPreakBatchFit function. It has three input parameters:datafoldername,ywavelist,xwavelist.

What should the the xwavelist look like for calculated values?

Andy


Hi, could you show me a typical experiment to use the multipeakbatchfit function, I have been trying to use it, but I don't know how. Thank you.
lingxiaoabc wrote:
hegedus wrote:
I am looking to automate some fitting via multi peak 2.0 and am examining the MultiPreakBatchFit function. It has three input parameters:datafoldername,ywavelist,xwavelist.

What should the the xwavelist look like for calculated values?

Andy


Hi, could you show me a typical experiment to use the multipeakbatchfit function, I have been trying to use it, but I don't know how. Thank you.



Attached is a an example of what I am working on.

There are a set of small spectra files (Auger spectra) that I loaded up. I have set the wave scaling to set the energy range and I do not need a separate x-wave.

I create a list of the waves to be fit using wavelist. Note: the documentation is not specific but it appears in my fumbling through that a semi-colon delimited string is expected. When I used a comma delimited string nothing would happen nor was there an error message.

To do the batch fit, I use the function included in multi-peak fitting V.2 (make sure it is loaded) and I run the command
MPF2_AuotMPFit("RDF","ExpModGauss","PC%d","Cubic","Fred",ywavelist,"",5) and you can look into the help file for the definitions. I create a string called ywavelist with the wave names.

You can delete the fit folders and rerun the command to see it work.
@ John Weeks. I am trying to do some batch processing with the MPF2_AutoMPFit() function to fit chromatograms with 19 peaks. My approach has been to do a careful manual multi peak fit to develop the peak coefficients and constraints. I know the peak coefficients and constraints text waves are now listed under root:Packages:MultiPeakFit2:MPF_SetFolder_2 along with a number of back up coefficients and various strings/variables. I have gone through and figured out the inputs for the MPF2_AutoMPFit function (shown below).

MPF2_AutoMPFit(resultDFBase, peakType, PeakCoefWaveFormat, BLType, BLCoefWaveName, yWaveList, xWaveList, InitialGuessOptions [, noiseEst, smFact, noiseEstMult, smFactMult, minAutoFindFraction])

I believe I would like to use initialOptionsGuess 0 "Do not run the automatic peak picker. Initial guesses will be pre-loaded in coefficient waves in the data folder resultDFBase+"_0". Use those values for every data set." I just am a bit lost on how I should set up a data folder containing the required information, and then how to feed that to the function inputs.
That means that the first of the result data folders must exist before you call MPF2_AutoMPFit(), and you need to copy the coefficient waves from your manual run into that data folder. You might have something like
    String resultDFBase = "MyResults"
    String newDFName = resultDFBase+"_0"
    String PeakCoefWaveFormat = "myPeak%d"
    DuplicateDataFolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $newDFName
    DFREF newdf = $newDFName
    Variable i
    for (i = 0; i < 19; i += 1)
        String wname
        sprintf(wname, "Peak %d Coefs", i)
        String newname
        sprintf(newname, PeakCoefWaveFormat, i)
        Rename newdf:$wname, $newname
    endfor
    MPF2_AutoMPFit(resultDFBase, ..., PeakCoefWaveFormat, ...)

In that code (which is completely untested!) the complete data folder for a manual multipeak fit is duplicated, giving the duplicate the appropriate name ending in "_0". The the looop renames the coefficients waves from the names used by the MPF2 user interface, to names corresponding to the names specified by the PeakCoefWaveFormat input string.

If you have a baseline as part of the fit, you need to do the same for the baseline coefficient wave. To avoid the loop and renaming waves, you could just use
    String resultDFBase = "MyResults"
    String newDFName = resultDFBase+"_0"
    DuplicateDataFolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $newDFName
    MPF2_AutoMPFit(resultDFBase, ..., "Peak %d Coefs", ..., "Baseline Coefs", ...)

This simplifies the problem by using the same names as the GUI for MPF2 uses, so you only need to duplicate the data folder, you don't need to rename the waves.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
I was able to get it all working. Thanks for the help. I am curious about something. When I go in and do a manual multi-Peak fit to determine the coefficient parameters I can set constraints for the location of each peak. Is that at all incorporated into the MPF2_AutoMPFit function? And if not, how could I incorporate the constraints?
Constraints were added to Multi Peak fit 2 well after MPF2_AutoMPFit() was written. Looking into it how to do it now, its not hard but not quite as easy as it should be. The MPF2 package does not store constraints in the same format used by FuncFit (the foundation of MPF2) to do the fitting. But it shouldn't be difficult to get your constraints to apply to the batch.

You will have to add a parameter to MPF2_AutoMPFit(). I suggest you copy MPF2_AutoMPFit() from Multi-peak Fitting 2.0.ipf, rename it something like MPF2_AutoMPFitCustom() and add a constraints argument. The constraints argument would be in the format that MPF2_DoMPFit() expects in the MPFitInfoStruct structure argument. For details on the constraint text wave format see the help for Fitting With Constraints.

DisplayHelpTopic "Fitting With Constraints"

The custom MPF2AutoPMFitCustom() function defintion would look like the following:
Function MPF2_AutoMPFitCustom(resultDFBase, peakType, PeakCoefWaveFormat, BLType, BLCoefWaveName, yWaveList, xWaveList, InitialGuessOptions [, noiseEst, smFact, noiseEstMult, smFactMult, minAutoFindFraction, constraints])
    String resultDFBase
    String peakType, PeakCoefWaveFormat
    String BLType, BLCoefWaveName
    String yWaveList, xWaveList
    Variable InitialGuessOptions
    Variable noiseEst, smFact
    Variable noiseEstMult, smFactMult
    Variable minAutoFindFraction
    Wave /T constraints
...

Then, after the MPFs struct is declared (the "STRUCT MPFitInfoStruct MPFs" line), add the following lines:
STRUCT MPFitInfoStruct MPFs
if (!ParamIsDefault(constraints))
    Wave /T MPFs.constraints=constraints
endif

That should be all you need to make MPF2_AutoMPFitCustom work with constraints. Now you just need to define the constraints. You can do it by hand by creating a text wave and defining one constraint per row - following the Constraint Expressions syntax described in Fitting With Constraints. Or you can copy the constraint text wave used by the Multi Peak Fit 2 package. The MPF2 UI text wave is part of a structure, so its scope is limited to the function in which it is instantiated. If, however, you have the MPF2 UI open and the constraints set you can call the following function to make a copy of the constraints wave.
Function getConstraintsWaveCopy(setNumber)
    Variable setNumber
   
    Wave /T constraints = getGlobalConstraintsWave(setNumber)
    String conWaveName = "W_Set"+num2str(setNumber)+"_Constraints"
    Duplicate /O constraints, $conWaveName
End

Pass the resulting wave to your MPF2_AutoMPFitCustom() function and you should be in business:
MPF2_AutoMPFitCustom(..., constraints=W_Set1_Constraints)

Note that I have not tested any of this. If you have trouble getting this to work email me at Wavemetrics support. I will be adding constraint functionality to MPF2_AutoMPFit() in the manner I described here, as well as making MPF2_DoMPFit() write reference constraint text waves, for the next Igor version 6 update.

Good Luck!

Nate Hyde
WaveMetrics
support@wavemetrics.com
Does this still apply (the need to make my own MPF2_AutoMPFitCustom())? The MPF2 help currently gives me this:

"MPF2_AutoMPFit(resultDFBase, peakType, PeakCoefWaveFormat, BLType, BLCoefWaveName, yWaveList, xWaveList, InitialGuessOptions [, noiseEst, smFact, noiseEstMult, smFactMult, minAutoFindFraction, constraints])"

So can I call it like this? is this the right syntax? (i'm getting an error if I use square parentheses and it is asking for an equal sign)
Make/O/T T_Constraints
T_Constraints[0] ={"K3>11.08","K3<11.08"}

variable ret = MPF2_AutoMPFit("peaksframe","Gauss","PeakCoefs%d","Constant","BaselineCoefs",trynamelist,xwaveslist,0, constraints=T_Constraints)

Thank you for any help.