Copy data after MultiPeak Fit
proland
I am trying to incorporate the MultiPeak fitter into my procedure for batch fitting. As part of this, I am having the user first perform the MultiPeak fit routine on a single trace so the batch fitting knows how many peaks to use (following DisplayHelpTopic "MPF2_DoMPFit()").
What I want, is to use PauseforUser to wait for the MultiPeak2Panel panel to close (user is done) and then copy the results (full datafolder) into a new folder. I have my data for each sample in it's own folder and I want to copy the multipeak fit results here.
Unfortunately, it seems that when you use PauseforUser, the right click menu used to add peaks for fitting is disabled preventing the use of the MultiPeak fitter. If I omit this line, the datafolders are copied before the fitting is performed.
string DF //string containing path to sample datafolder
multipeakfit2_initialize() //run initialize to make necessary folders
dowindow/k MultiPeak2StarterPanel //Destroy wave selection panel (we just needed the initialization for folder creation)
NVAR currentset = root:Packages:MultiPeakFit2:CurrentSetNumber
currentset=0
dowindow/k/z MultiPeakFit_Set1
killdatafolder/z root:Packages:MultiPeakFit2:MPF_SetFolder_1 //kill existing folder & waves if needed
MPF2_StartNewMPFit(0, "New Graph", max_wave, "energy", 1, 1)
pauseforuser MultipeakFit_Set1#MultiPeak2Panel //wait for MultiPeak panel to close
DF+="MPF" //duplicate MultiPeak results into Datafolder for storage/reference
killdatafolder/z $DF
duplicatedatafolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $(DF)
multipeakfit2_initialize() //run initialize to make necessary folders
dowindow/k MultiPeak2StarterPanel //Destroy wave selection panel (we just needed the initialization for folder creation)
NVAR currentset = root:Packages:MultiPeakFit2:CurrentSetNumber
currentset=0
dowindow/k/z MultiPeakFit_Set1
killdatafolder/z root:Packages:MultiPeakFit2:MPF_SetFolder_1 //kill existing folder & waves if needed
MPF2_StartNewMPFit(0, "New Graph", max_wave, "energy", 1, 1)
pauseforuser MultipeakFit_Set1#MultiPeak2Panel //wait for MultiPeak panel to close
DF+="MPF" //duplicate MultiPeak results into Datafolder for storage/reference
killdatafolder/z $DF
duplicatedatafolder root:Packages:MultiPeakFit2:MPF_SetFolder_1, $(DF)
Any advice?
May 20, 2013 at 12:09 pm - Permalink
If I understand correctly, every time interval (say 30 seconds) I will check to see if the multifit panel exists. If it does, I then call a function which 1) stops the background task and 2) copies the data I want.
Or, can these tasks be accomplished within an if-else statement within the background task itself? Can a background task stop itself?
May 21, 2013 at 11:15 am - Permalink
Yes, you should be able to do the wave/folder manipulations within the background task.
The background task cannot directly kill itself, but if you return the correct value, Igor will handle this for you.
For more information: displayhelptopic "Background Tasks"
May 21, 2013 at 11:48 am - Permalink
This would seem to be relatively immune to changes that WM might make to the procedure (short of changing the name of the startup function).
Here's an example:
//start multipeakfit
fStartMultipeakFit2()
//set a hook function to handle killing the multipeakfit panle
SetWindow MultiPeak2StarterPanel, hook(MoveFilesMPF)= MPF_Killed
End
Function MPF_Killed(s) //hook function, handles file manipulation when MPF window is killed
STRUCT WMWinHookStruct &s
switch (s.eventCode)
case 2: //"kill"
print "killed"
//do file manipulations
break
endswitch
return 0
End
May 21, 2013 at 12:29 pm - Permalink
But the hook needs to be on the MultiPeak2Panel rather than the MultiPeak2StarterPanel. And that requires knowing the name of the graph of interest. But since the OP is using PauseForUser with the relevant panel, I guess that problem is solved. So instead of
SetWindow MultiPeak2StarterPanel, hook(MoveFilesMPF)
use
SetWindow MultipeakFit_Set1#MultiPeak2Panel, hook(MoveFilesMPF)
This has the drawback that it will only work using a fresh experiment that hasn't been used with Multipeak Fit 2 before, since it assumes MultipeakFit_Set1. If that's under your control, then it should be OK.
This technique also assumes that the user will close the panel after the fit.
This will fail if sometime in the future I change the name of the panel, but I don't think that's too likely. But take warning- I consider the panel name to be an implementation detail, and not necessarily something I must preserve for backward compatibility.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 28, 2013 at 10:40 am - Permalink
I got around the panel naming by changing the global variable currentsetnumber to zero prior to running MPF2 routines. This essentially overwrites MPF_SetFolder_1 every time keeping the graph/panel names consistent. I know that this impedes the proper operation of the multi-peak fit routine but it was the only way I could see to do it. The subsequent batch fitting routine fits a large set of curves, including the one used to create MPF_SetFolder_1 so I have no concerns over loosing this data.
In order to allow users normal use of the Multi-peak fitter, I suppose i should check for the number of folders that start with "MPF_SetFolder*" and reset currentsetnumber back to an appropriate value after I am done. My code will continuously overwrite MPF_SetFolder_1 but every other MPF folder should remain untouched.
May 29, 2013 at 08:13 am - Permalink
Either set it to a very large number to guarantee that the user will never use that many data sets, or you could simply use the next set number available.
Again, the warning- this is an implementation detail, and the variable is my private package data folder, so I consider it to be something I can change without affecting backward compatibility. But again, I doubt it will change in the near future.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
May 29, 2013 at 11:25 am - Permalink