DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

DIAdem script to compute the run length between samples

Solved!
Go to solution

Could you please suggest how can we compute the number of maximum continuous samples that occur between 2 threshold values using DIAdem?

I am creating 10 threshold based on the below python script:

import numpy as np
threshold_list = np.linspace(th_mean,th_max, num = 10, endpoint= False)

 

If we assume th_mean =30 and th_max = 32, it will generate threshold_list as below:

[30. 30.2 30.4 30.6 30.8 31. 31.2 31.4 31.6 31.8]

 

How can we determinate the number of maximum continuous values between each threshold interval ?
For example if we consider the interval 31.8 to 31.6 , we need to compute how many continuous samples are less than or equal to 31.8 & greater than 31.6

0 Kudos
Message 1 of 11
(2,000 Views)

Hi joshilpa,

 

I think you can use the Event-Search function for this.

Walter_Rick_0-1660639869606.pngWalter_Rick_1-1660639880504.png

 

If you entered all parameters and then press CTRL+SHIFT+C you get the script commands for it:

dd.ChnEventList1 = dd.ChnEventDetectionWindow("", "[1]/Time", 10, 30, 0, 0)
dd.ChnEventCreateStatusChn("/EventStatus", dd.ChnEventList1, "[1]/Time", 0, 1)
# TotalValueCount
TotalValueCount = dd.ChnEventStatValueCount("[1]/Time", dd.ChnEventList1)

 

Greetings

Walter

Message 2 of 11
(1,980 Views)

Hi Walter,

When trying with the below code on attached data set  here I am looking to determine the maximum contiguous set of values for which this occurs hence the output should be 7.

joshilpa_0-1660653688640.png

The script below returns all the events with output as 14

# -- Beginning of user code --
dd.ChnEventList1 = dd.ChnEventDetectionWindow("", "[1]/Signal", 30, 32, 0, 0)
dd.ChnEventCreateStatusChn("/EventStatus", dd.ChnEventList1, "[1]/Signal", 0, 1)
# TotalValueCount
TotalValueCount = dd.ChnEventStatValueCount("[1]/Signal", dd.ChnEventList1)
print(TotalValueCount)

 

0 Kudos
Message 3 of 11
(1,969 Views)

Hi joshilpa,

 

I do not understand the required algorithm. The limits are 31 and 32.
Why count 31 when it comes up twice in a row?
Why doesn't the count end when the first 32 appears?
Why does 30.5 count even though it is not in the range 31 to 32?
Why doesn't the count start at the first 31 value?

 

Greetings

Walter

0 Kudos
Message 4 of 11
(1,965 Views)

Hi Walter,

 

The problem here is we need to count the maximum number of continuous samples that occur between 30 and 32
Please find below my response in line:
Why count 31 when it comes up twice in a row?
Ans : It is a repeated sample 
Why doesn't the count end when the first 32 appears?
Ans : We are counting the continuous samples between the range 30 and 32
Why does 30.5 count even though it is not in the range 31 to 32?
Ans : The samples can lie in the range 30 to 32
Why doesn't the count start at the first 31 value?

Ans : We are counting the events when the sample occurs in range 30 and 32, here need to determine the max continuous duration for which the even occurred. In this example the event occurred continuously for 7 consecutive samples which is the maximum. 

0 Kudos
Message 5 of 11
(1,959 Views)
Solution
Accepted by topic author ebenellis

Hi josilpa,

 

For what reason ever, I thought the range was between 31 and 32. – Anyway.

Here is the script solution. It is necessary to iterate aver the ChnEventList1.

 

oSourceChn = dd.Data.GetChannel("[1]/Signal")

dd.ChnEventList1 = dd.ChnEventDetectionWindow("", oSourceChn, 30, 32, 0, 0)
dd.ChnEventCreateStatusChn("/EventStatus", dd.ChnEventList1, oSourceChn, 0, 1)
iMaxCount  = len(dd.ChnEventList1)
oResultChn = dd.Data.Root.ActiveChannelGroup.Channels.Add("Result", dd.DataTypeChnFloat64)
for iCount in range(1, iMaxCount + 1):
    oResultChn[iCount] = dd.ChnEventStatValueCount(oSourceChn, dd.ChnEventList1, iCount)

dd.ChnCharacter(oResultChn)
dd.MsgBoxDisp(oResultChn.Maximum)

 

Greetings

Walter

Message 6 of 11
(1,930 Views)

Hi Walter,

 

Thanks for sharing the working solution, could you please explain what does ChnEventList1 contain?
When checked in the help it says ChnEventList1 contains the result of the event search but how is it different from below channel:

dd.ChnEventCreateStatusChn("/EventStatus", dd.ChnEventList1, oSourceChn, 0, 1)

 

0 Kudos
Message 7 of 11
(1,901 Views)

Hi joshipa,

 

Does this explain what ChnEventList1 does?

Walter_Rick_0-1660724553240.png

 

ChnEventCreateStatusChn creates a result channel with 0 = no match and 1 = match out of it.

 

Greetings

Walter

 

Message 8 of 11
(1,898 Views)

Thank you Walter got it, ChnEventList1 basically contains the start and end index of each event. I got confused because index 2 and 3 were always none since here there is no second dimension specified.

Message 9 of 11
(1,893 Views)

Hi Walter,

 

I ran this script on a channel with 54110000 samples & its been 6hrs that the script is still running, is there any way to reduce the runtime of the script?

0 Kudos
Message 10 of 11
(1,647 Views)