06-26-2012 07:58 AM
Hello All,
I've modified one of the Diadem examples to return the peaks over a given threshold from a series of data. This works fine for a single data file using the script below. I now want to modify this script to individually perform the calculation on a long series of files (too large to concentenate) each time saving the results as a new data file. I attach the code I am using and a few much simplified data files. Could someone explain to me how to script this next step or perhaps post a sample code of something similar?
Thank you
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Call ScriptInclude(AutoActPath & "ThresholdPeaks.VBS")
Dim i, Xch, Ych, Threshold, MinDev, MaxMin, EndTime
Dim CursorType, CursorMode, CursorX1, CursorX2, CursorZoom
Dim MyFolders()
Call InitMyFolders
'-------------------------------------------------------------------------------
Sub InitMyFolders
ReDim MyFolders(1)
MyFolders(0)="C:\Find All Peaks\"
End Sub
'-------------------------------------------------------------------------------
Call DataFileLoad(MyFolders(0)&"Data1","TDM","Load") '... DataFilename,FileImportFilter,ImportAction
Xch = "Time" ' X channel to analyze for peaks
Ych = "1a" ' Y channel to analyze for peaks
Threshold = 20 ' Enter threshold value here
MinDev = 3 ' (0...100) % of abs(Peak - Threshold) to exlude
MaxMin = "Max" ' (Min, Max) look for local Maxima or local Minima
Call ThresholdPeaks(Xch, Ych, Threshold, MinDev, MaxMin) ' find peaks
Solved! Go to Solution.
06-27-2012 08:59 AM
Hi Mark_A -
See if the following helps you at all.
Option Explicit 'Forces the explicit declaration of all the variables in a script. Call ScriptInclude(AutoActPath & "ThresholdPeaks.VBS") Dim i, Xch, Ych, Threshold, MinDev, MaxMin, EndTime Dim CursorType, CursorMode, CursorX1, CursorX2, CursorZoom Dim vFoundFiles, iCount Xch = "Time" ' X channel to analyze for peaks Ych = "1a" ' Y channel to analyze for peaks Threshold = 20 ' Enter threshold value here MinDev = 3 ' (0...100) % of abs(Peak - Threshold) to exlude MaxMin = "Max" ' (Min, Max) look for local Maxima or local Minima If PathNameGet("Please select a folder containing TDM files:","C:\Find All Peaks\") = "IDOk" Then vFoundFiles = DirListGet(OutPutPath, "*.tdm", "filename", "FullFilenames") If IsArray(vFoundFiles) Then For iCount = Lbound(vFoundFiles) to Ubound(vFoundFiles) Call DataFileLoad(vFoundFiles(iCount),"TDM","Load") Call ThresholdPeaks(Xch, Ych, Threshold, MinDev, MaxMin) ' find peaks Next Else Call MsgBoxDisp("No TDM files found in selected directory") End If End If
I've also attached the script to this response.
07-07-2012 10:42 AM
Hi Derrick,
Thank you for your response. The script imports the files in correctly but seems to perform the calculation on the first dataset only. The resulting Y_Peak 1a channel is repeated for each time using the info from the first file. Could you suggest a possible solution? Its probably just a minor script change.
Mark
07-09-2012 10:26 AM
Hi Mark -
The code sets the Xch and Ych variables to constant channel names at the beginning of the script. When searching for channels by name in the Data Portal, DIAdem will start at the beginning (top) of the Data Portal and stop at the first channel instance it finds that matches the name for which you're searching. Therefore, since your Threshold the script is always using the "Time" and "1a" channels from the first Channel Group, even when the new data files are loaded.
To fix the script, you'll need to modify the code to reference the channels by Group Name and Channel Name, instead of just Channel Name - and you'll need to do it inside of the loop that loads each data file in turn.
e.g. Xch = "Strain2/Time"
11-08-2012 10:28 AM
Hello All,
I'm returning to an old question so I hope its ok to ask it here but it seems to make the most sense.
I have a script which works fine for a single file, single channel peaks over threshold (POT) analysis. I need to upgrade the code to provide the POT result for multiple files, saving the X_peak and Y_peak result in the original file channel each time. The problem lies in using [iCount] as a channel definition as shown below. If I replace this with 1, for example, the POT calculation is only carried out for channel 1.
How can I fix this in the code or what I need to do as an alternative? I attach some simplified sample files for testing and the relevant scripts. The "Find 1ch Peaks (Diadem)_test.VBS" is the problematic file while running the "Find 1ch Peaks (Diadem).VBS." will work but only provide the results for file 1.
Any advice or sample code would be much appreciated.
Thanks
Mark
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Call ScriptInclude(AutoActPath & "ThresholdPeaks.VBS")
Dim i, Xch, Ych, Threshold, MinDev, MaxMin, EndTime
Dim CursorType, CursorMode, CursorX1, CursorX2, CursorZoom
Dim vFoundFiles, iCount
Threshold = 20 ' Enter threshold value here
MinDev = 3 ' (0...100) % of abs(Peak - Threshold) to exlude
MaxMin = "Max" ' (Min, Max) look for local Maxima or local Minima
If PathNameGet("Please select a folder containing TDM files:","C:\Find All Peaks\") = "IDOk" Then
vFoundFiles = DirListGet(OutPutPath, "*.tdm", "filename", "FullFilenames")
If IsArray(vFoundFiles) Then
For iCount = Lbound(vFoundFiles) to Ubound(vFoundFiles)
Call DataFileLoad(vFoundFiles(iCount),"TDM","Load")
Xch = "[iCount]/Time" ' X channel to analyze for peaks
Ych = "[iCount]/1a" ' Y channel to analyze for peaks
Call ThresholdPeaks(Xch, Ych, Threshold, MinDev, MaxMin) ' find peaks
Next
Else
Call MsgBoxDisp("No TDM files found in selected directory")
End If
End If
11-09-2012 04:10 AM
Hello Mark_A
I tried to run the script and it failed in an early stage. I fixed the problem but there seem to be a few which simple prevent the script from running. I want to be careful when changing anything so that the result works on your version of DIAdem. There are a few functions in newer version of DIAdem which would make teh script a little simpler. Can you please let me know which version of DIAdem the script should work with ?
Andreas
11-09-2012 04:35 AM
Hello Andreas
I'm using the 2010 version (Service pack 1). The older functions are mainly due to the sample code I commenced with.
Thank you for looking into this
Mark
11-09-2012 05:53 AM
Hello Mark_A
I changed two things to make the script work.
In "Find 1ch Peaks (Diadem)_test.VBS"
I changed
Xch = "[iCount]/Time" ' X channel to analyze for peaks
Ych = "[iCount]/1a" ' Y channel to analyze for peaks
to
Xch = "["&iCount&"]/Time" ' X channel to analyze for peaks
Ych = "["&iCount&"]/1a" ' Y channel to analyze for peaks
DIAdem doesn't recognize that you would like to refer to the variable "iCount" if you include it in a string describing a channel name
The other thing I changed was in "ThresholdPeaks.VBS"
I replaced
L1 = CNo(ChnName(Xch))
L2 = CNo(ChnName(Ych))
with
L1 = CNo(Xch)
L2 = CNo(Ych)
ChnName() returns the name of the channel but removes the reference to the group. So the result of ChnName("[1]/1a") would be simply "1a". Then the CNO functions searches for the first match of that string and always finds "1a" in the first group which is not what you want.
Once I changed the two things, I got the peaks for each group.
In general, should you have the chance to upgrade to a newer version of DIAdem (starting with 2011) , scripts like this would a little easier. The new object oriented API for data makes the scripting for this type of algorithm more efficient.
Andreas
11-09-2012 06:48 AM
Thank you very much Andreas.It works perfectly now.
Mark
11-12-2012 10:51 AM
Hello Andreas,
From further checking, something is not quite right in the code. It seems the calculated POT for group 2 is repeating the Y calculation of group 1, group 3 is using the POT result for group 2 and so on. The only correct calculation is that of group 1.
I'm working my way through the code but can't seem to find the problem. If you had a few minutes perhaps you could take a look.
Many thanks,
Mark