MPF2_AutoMPFit(...) in user-defined functions
I am trying to analyze data imported from an instrument using MPF2_AutoMPFit(...) . The data is a function of time and the signal is composed of zero or more gaussian peaks. I am using MPF2_AutoMPFit(...) rather than a batchfit because the data is a matrix (and a subset of the total dataset) which contains >2 million timeseries, each timeseries containing 100 points and representing a convolution gaussian peaks (0 peaks is also a possibility). Testing this function on a subset of this data (~2500 timeseries) took about 9 seconds to complete.
The error I get is described below. I appreciate any suggestions, even those saying I am approaching the problem wrong.
I get an error in MPF2_AutoMPFit(...) when no peaks are found:
nPeaks = AutoFindPeaks(yw, firstPoint, lastPoint, noiseEst, smFact, Inf)
This results in the wave
W_AutoPeakInfo
containing 0 points. The error occurs on the next line, which calls
wave wpi=w_autopeakinfo AdjustAutoPeakInfoForX(wpi, yw, xw)
and in AdjustAutoPeakInfoforX, the error occurs at:
wpi[i][0]=pnt2x(yData,wpi[i][0])
because the index (0) is out of range for the wave wpi (W_AutoPeakInfo) which contains 0 points.
These functions are non-editable, otherwise I would add a conditional statement that numpnts(wpi)>0. Is there a try-catch or something that could be used when no peaks are found?
Cheers,
James
Below is the code for AdjustAutoPeakInfoForX:
Function AdjustAutoPeakInfoForX(wpi,yData,xData)
Wave wpi,yData
WAVE/Z xData
Variable imax= DimSize(wpi,0),i=0
do
if( WaveExists(xData) )
Variable p0= wpi[i][0]
Variable pw= wpi[i][1]/2
wpi[i][0]=xData[p0]
wpi[i][1]= abs(xData[p0+pw] - xData[p0-pw])
Variable pLw = wpi[i][3]
wpi[i][3]= abs(xData[p0] - xData[p0-pLw])
Variable pRw = wpi[i][4]
wpi[i][4]= abs(xData[p0-pRw] - xData[p0])
else
wpi[i][0]=pnt2x(yData,wpi[i][0])
wpi[i][1]= abs(wpi[i][1]*deltax(yData))
wpi[i][3]= abs(wpi[i][3]*deltax(yData))
wpi[i][4]= abs(wpi[i][4]*deltax(yData))
endif
i+=1
while(i<imax)
end
Hi James,
It seems at the moment MPF2_AutoMPFit() does not support occasional skips in the data sets with no peak found. I think this can be easily fixed however. I may contact the person in charge about this. But the best way to get help here is to write the Wavemetrics support directly. It might be helpful if you could provide a test experiment where this problem can be easily reproduced. By the way, the files cannot be edited because they are inside a folder with limited write permission (I assume you are on a windows machine where Igor sits inside the Program Files folder; which Igor version?). I would not recommend to fix things yourself here anyway.
August 4, 2020 at 04:04 am - Permalink
James- chozo has been doing incredible work enhancing Multipeak Fit for Igor 9, and has transmitted to me IP9 changes that will skip a data set with no peaks to fit. I don't have a convenient way to test it, though. If you would email support@wavemetrics.com I can send you a revised procedure file with those changes. Please try it out and let me know of any further problems.
August 4, 2020 at 10:13 am - Permalink
Thanks for your response.
The code I am using is:
Attached is a text file with the wave values for temp_sc_data. The x-scaling for this data is 1. The noise estimate is based off of looking hard at a lot of timeseries and guessing the amplitude of noise. I wouldn't consider any peak less than ~1000 to be real, so 3500/20 is an estimate of the signal amplitude when there is really 0 signal. If will still come across the same error if I don't specify a noiseest, just for a different timeseries.
August 4, 2020 at 02:14 pm - Permalink
James, Thank you for the test file and your settings. I have checked that things work now- the data where no peaks are found is skipped in the updated code. You will still get an error code out (-18), both at the end and in each folder for data with no peaks. You can then decide in your code what to do next (like throwing out the bad ones). Just write to John and you will get the replacement procedure file soon.
August 4, 2020 at 08:23 pm - Permalink
Thank you for the update. I have emailed support@wavemetrics.com to make contact with John. Hope to hear back soon.
MPF2_AutoMPFit(...) crashed in a slightly different way with the attached dataset. This error occurred on line 531 of MPF_AutoMPfit which calls EstPeakNoiseandSmfact(...):
peakFindParams = EstPeakNoiseAndSmfact(yw, firstPoint, lastPoint)
The error crashes at line 219 in the function EstPeakNoiseAndSmfact(...) and the error is "error: Index out of range for wave "wsmFact"." The relevant snippet of code is:
Variable smFact= wsmFact[V_maxloc]
However, wsmdata is empty following the first cell so V_maxLoc equals -1.
Thank you again for your help.
Honestly, this particular dataset will result in a NaN or error code in my user-defined function. However, I am analyzing >2 million time series so I need a stable code avoid having to manually restart the script.
James
August 5, 2020 at 08:09 am - Permalink