11-13-2014 03:05 PM
I am trying to discern max and min values from cycle data. We'll have about 20 data points for each cycle and I need to pull the max and min out of it. I've tried writing a script for it but it takes way to long to run. Our largest files (more than one million data points) don't finish with my script and crash DIAdem. I've also tried the built in peak finding functions but they come up with data points that are not max or min. Here is my script below:
Dim cyclemin
Dim cyclemax
Dim cyclecount
Dim displacementmax, displacementmin
Dim channelcount
Dim i,j,k,g,a,m
cyclemin=CMin("Cycle Count")
cyclemax=CMax("Cycle Count")
channelcount=0
Call ChnAlloc("Cycle Count Single",(cyclemax-cyclemin)+1,1, DataTypeFloat64)
Call ChnAlloc("Min Sample Pressure",(cyclemax-cyclemin)+1,1, DataTypeFloat64)
Call ChnAlloc("Max Sample Pressure",(cyclemax-cyclemin)+1,1, DataTypeFloat64)
a=1
For cyclecount=cyclemin to cyclemax
g=1
channelcount=channelcount+1
i=ChnFind("Ch(""Cycle Count"")="&str(cyclecount),a)
j=ChnFindReverse("Ch(""Cycle Count"")="&str(cyclecount),CL("Cycle Count"))
Call ChnAlloc("Data Hold Sample Pressure",(j-i)+1,1,DataTypeFloat64)
For k=i to j
ChD(g,"Data Hold Sample Pressure")=ChD(k,"Sample Pressure")
g=g+1
Next
Call ChnCharacter("Data Hold Sample Pressure")
ChD(channelcount,"Cycle Count Single")=cyclecount
ChD(channelcount,"Max Sample Pressure")=CMax("Data Hold Sample Pressure")
ChD(channelcount,"Min Sample Pressure")=CMin("Data Hold Sample Pressure")
Call ChnDelete("Data Hold Sample Pressure")
a=j
Next
Can anyone please help me find a way of doing this quickly? Thanks.
Solved! Go to Solution.
11-13-2014 05:46 PM
Would it be possible to share an example data file to run the script with ?
Andreas
11-14-2014 08:24 AM
Here is an example file in excel format. I didn't know if attaching a .tdm would work or not. Thanks for the help.
11-14-2014 08:25 AM
The file I just attached is a small part of a normal data file. When I run the normal data file, it will take more than 20 minutes to run. If I have an extremely large file, it will crash DIAdem. Please keep that in mind.
11-14-2014 08:49 AM
Hello Steinmeister85
can you please let me know wwhich version of DIAdem you are using ? There is at least one function I woul dlike to use for the solution which came with DIAdem 2012.
Andreas
11-14-2014 09:44 AM
I am using DIAdem 2012.
11-14-2014 01:21 PM
Hello Steinmeister85
so just in case you are using a more recent version of DIAdem, here is an alternative solution.
I also used your example file and concatenated it 50 times to create a file which has about 560.000 values in each channel.
I run your script versus the new one to get some benchmark number
Example file
Original script : 2.5 seconds
Optimized script : 0.2 seconds
50 x Example file
Original script : 111.493 seconds
Optimized script : 0.25 seconds
I must admit that I sorted the concatenated file. That way I have 216 cycle segments to be analyzed. If I simple concatenate the files (without sorting) I get 50x the number of segments and the new script takes about 9 seconds to execute. The original script doesn't work correctly as you woul then have repeating cycle count numbers in different areas of the channel..
Hopefully the new versions works for you.
Andreas
11-14-2014 05:22 PM
This works perfectly. It did a million data point file in less than 30 seconds. Wow. I'll be looking this over so I can understand how you did it. Thanks.
11-14-2014 05:36 PM
I am glad it works.
He is some explanation regarding the algorithm:
The main idea is to find the index in the channel where the cycle code changes
The following function creates a channel which is "0" as long as the cycle code is the same. It is "1" when cycle code changes.
Call ChnDeltaCalc(Data.GetChannel("Cycle Count"),"/__SegmentTrigger")
Take a look at the channel "__SegmentTrigger" to see the result
The next function uses this channel to find the segments:
oRanges = ChnEventDetectionValueWindow(Data.GetChannel("/__SegmentTrigger"),0,0)',0,0)
The function works extremely fast
Once you have begin and end of those segments, you use "StatBlockCalc" to calculate "min" and "max" for that segment
That way you don't have to copy the data into a separate channel to calculate mnin and max
Andreas
11-15-2014 06:41 AM
Andreas
Liked the solution 🙂
But the function "ChnEventDetectionValueWindow" is not found when I search for it in 2012 or 2014. Where can I find it!
Paul