DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Chanel Event function

Solved!
Go to solution

Hi all, 

 

I have a dataset with two channels: (1) a signal which has boolean values (1/0) and (2) time. I want to eliminate the noise of this signal, so I mean giving a value of 0 to the signals which last less than 2 minutes. I guess that first of all, I need to calculate the delta X when Y=1 and once I have that I can eliminate the smallest values. I was recommended in a previous post to use the Event Search function for calculating this in diadem 2015, but I do not know how to use it in a script. 

 

 

Capture.JPGCapture.PNG

 

Thanks

 

Estefania M

0 Kudos
Message 1 of 12
(5,332 Views)

Hi Estefania,

 

Would you please post your data set?  We need to create a script that does what you request, and it would help to save the time to try to create a similar data set.  I agree that the ChnEvent...() functions in DIAdem 2015 are the right tool to use here.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 2 of 12
(5,322 Views)

Hi Brad, 

 

Thanks for your reply. What i want to do is ignoring the signals which last less than two minutes from the variables which are called "Gas valve open"; so when I plot this Gas valve open I do not see the noise. 

 

Thanks

 

Regards

 

Estefania

0 Kudos
Message 3 of 12
(5,311 Views)

Hi Estefania,

 

Thanks for the data file.  I'm puzzled, though, that the Time channel jumps "backwards" from "12/01/2016 23:58:00" (index 3942) to "01/01/2016 00:00:00" (index 3943).

 

Should I sort the rows by ascending Time value before analyzing?

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 12
(5,304 Views)

Hi Estefania,

 

I decided to analyze just the first 3942 values of the file you sent me-- the Time channel values are well behaved up to that point.

 

MinDuration = 5*60 ' seconds
DataFilePath = "D:\NICS\Discussion Forums\emendezcampa\P35 - Lloyds - St Williams - datadump.csv"
Call Data.Root.Clear
Call DataFileLoad(DataFilePath, "CSV")
Set Group = Data.Root.ChannelGroups(1)
FOR Each Channel In Group.Channels
ChnLength(Channel) = 3942
NEXT ' Channel
Set TimeChannel = Group.Channels(1)
Set BoolChannel = Group.Channels(7)
EventList = ChnEventDetectionWindow(TimeChannel, BoolChannel, 0.5, 1.5)
nMax = UBound(EventList)
FOR n = 0 TO nMax
P1 = EventList(n, 0)
P2 = EventList(n, 1)
Duration = TimeChannel.dValues(P2) - TimeChannel.dValues(P1)
IF Duration < MinDuration THEN
Call ChnAreaDel(BoolChannel, P1, P2-P1+1)
Call ChnAreaInsert0(BoolChannel, P1, P2-P1+1)
END IF
NEXT ' n

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 5 of 12
(5,299 Views)

Hi Brad, 

 

Thanks for your help. Actually I couldn't make it work. When I run it, I get an error saying that Eventlist is not defined. Then I changed it to:

' Dim Eventlist

' Set Eventlist = EventList = ChnEventDetectionWindow(TimeChannel, SavingsBoiler1, 0.5, 1.5)

 

And I got another error, which says I need an object? Am I doing anything wrong?

The same happens to me with MinDuration variable and nmax.

 

Another question, is what does mean the 0.5 and 1.5 you include in the code. It is not clear to me. 

 

Thanks

 

Regards

 

 

 

0 Kudos
Message 6 of 12
(5,278 Views)

Hi Estefania,

 

I did, in fact, send you code that I had tested to make sure it ran on my computer.  If you leave out OPTION EXPLICIT, you don't have to declare the variables.  I'm including below a version that uses OPTION EXPLICIT.  In that case you just need to declare all the variables, you don't need to insert "Set" operators, and you really don't need 2 different "=" operators for the same assignment.  The ChnEventDetectionWindow() command returns an array, not an object, so trying to "Set" its return is incorrect.

OPTION EXPLICIT
Dim n, nMax, MinDuration, DataFilePath, Group, Channel, TimeChannel, BoolChannel, EventList, P1, P2, Duration
MinDuration = 5*60 ' seconds
DataFilePath = "D:\NICS\Discussion Forums\emendezcampa\P35 - Lloyds - St Williams - datadump.csv"
Call Data.Root.Clear
Call DataFileLoad(DataFilePath, "CSV")
Set Group = Data.Root.ChannelGroups(1)
FOR Each Channel In Group.Channels
  ChnLength(Channel) = 3942
NEXT ' Channel
Set TimeChannel = Group.Channels(1)
Set BoolChannel = Group.Channels(7)
EventList = ChnEventDetectionWindow(TimeChannel, BoolChannel, 0.5, 1.5)
nMax = UBound(EventList)
FOR n = 0 TO nMax
  P1 = EventList(n, 0)
  P2 = EventList(n, 1)
  Duration = TimeChannel.dValues(P2) - TimeChannel.dValues(P1)
  IF Duration < MinDuration THEN
    Call ChnAreaDel(BoolChannel, P1, P2-P1+1)
    Call ChnAreaInsert0(BoolChannel, P1, P2-P1+1)
  END IF
NEXT ' n

The 0.5 to 1.5 range is one way to indicate that the region/window of interest is 1.0 values.

 

Please do comment on your Time channel values going backwards.  Should the data set be sorted chronologically?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 7 of 12
(5,241 Views)

 Hi Brad, 

 

many thanks for your help.

i cannot se the time change backwards on line 3942. It actually shouldn't be there anyways. I believe that's an issue from the format when I send it to you? I attach another file to check that again. 

 

I am trying to include the script you have sent to me within mine but I am not able to plot the signals without the noise.

The channel that I am trying to plot (without noise) is called "SavingsBoiler1". It has been calculated from a substraction of "boiler 1 Terminal 1" and "Boiler 1 Gas valve open". Do I maybe need to create another channel with the same signal without the noise? I am asking this because I need to do the same process in the same file a few more times with different columns (different boilers). 

 

Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim oMySheet, oNewArea, Channel, Channels
Call View.Sheets.RemoveAll
Set oMySheet = View.Sheets.Add("Savings")
Set oNewArea = oMySheet.ActiveArea
oNewArea.DisplayObjType ("CurveChart2D")
Set Channels = Data.GetChannels("[1]/*ALL*")
FOR Each Channel In Channels
Dim oVista
Set oVista = View.Sheets("Savings").Areas("Area : 1").DisplayObj.Curves.Add("[1]/Time", Channel.GetReference(eRefTypeIndexName))
oVista.Type = "Step Curve"
' Savings Boiler1
If CNo("[1]/*Boiler 1 M2G Terminal*") = 0 Then
Call ChnSub(Data.GetChannels("[1]/*Boiler 1 M2G Terminal*"),Data.GetChannels("[1]/*Boiler 1*Gas*"), "/Subt")
Call Calculate ("Ch(""[1]/SavingsBoiler1"")= Abs(Ch(""[1]/Subt""))")
Call Data.Root.ChannelGroups(1).Channels.Remove("Subt")
Else If CNo("[1]/*Boiler 1 M2G Terminal*") = 0 Then
End If
End If
Dim n, nMax, MinDuration, DataFilePath, Group, TimeChannel, BoolChannel, EventList, P1, P2, Duration, oVista1
MinDuration = 2*60 ' seconds
Set Group = Data.Root.ChannelGroups(1)
Set BoolChannel = Data.GetChannels("[1]/SavingsBoiler1")
Set TimeChannel = Group.Channels(1)
EventList = ChnEventDetectionWindow(TimeChannel, BoolChannel, 0.5, 1.5)
nMax = UBound (EventList)
For n=0 to nMax
P1 = EventList(n,0)
P2 = EventList (n,1)
Duration = TimeChannel.dValues(P2) - TimeChannel.dValues(P1)
If Duration < MinDuration Then
Call ChnAreaDel (BoolChannel, P1, P2-P1+1)
Call ChnAreaInsert0 (BoolChannel, P2-P1+1)
Dim oVista4
Set oVista4 = View.Sheets("Savings").Areas("Area : 1").DisplayObj.Curves.Add("[1]/Time", Channel.GetReference(eRefTypeIndexName))
oVista.Type = "Step Curve"
End If
Next
View.Sheets("Savings").Areas("Area : 1").DisplayObj.YScaling = "n systems [phys.]"
Call WndShow("VIEW","Open")
Next

 

 

Your help is much appreciated.

Many thanks

Estefania

0 Kudos
Message 8 of 12
(5,217 Views)

Hi Estefania,

 

The Time channel jumping backward was a result of a bad assumtion of mine.  Normally when I see "/" delimiters in a datetime, I assume it's the "American" MM/DD/YYYY convention, but your Time channel used "DD/MM/YYYY hh:mm" syntax.  I therefore created a DataPlugin that uses that datetime convention and also puts the units in the channel names into the channel unit property.  Please register and use the attached DataPlugin (emendezcampa_CSV.uri) to load your CSV file into DIAdem.  Then make any additional channel calculations your need to, such as the substraction of "boiler 1 Terminal 1" and "Boiler 1 Gas valve open".  Then run the below VBScript in the DIAdem SCRIPT panel.  It will remove all 0=>1 and 1=>0 transitions that are of duration shorter than MinDuration (in seconds).  The below VBScript has MinDuration set to 10 minutes.  The VBScript will filter out these short duration transitions in all channels in the default (bold) Group in the Data Portal which have a unit property of the empty string ("").  The 2 data files you've sent so far had a Time channel first, followed by temperature channels with a "°C" unit and boolean channels with a "" unit, so the empty unit is what I keyed on.  When you run this VBScript, any channels in the default (bold) Group in the DataPortal which have a unit of "" will be filtered in place for short duration boolean transitions.

 

MinDuration = 10*60 ' seconds
Set Group = Data.Root.ActiveChannelGroup
Set TimeChannel = Group.Channels(1)
FOR Each BoolChannel In Group.Channels
  IF ChnDim(BoolChannel) = "" THEN
    EventList = ChnEventDetectionWindow(TimeChannel, BoolChannel, 0.5, 1.5)
    nMax = UBound(EventList)
    FOR n = 0 TO nMax
      P1 = EventList(n, 0)
      P2 = EventList(n, 1)
      Duration = TimeChannel.dValues(P2) - TimeChannel.dValues(P1)
      IF Duration < MinDuration THEN
        Call ChnAreaDel(BoolChannel, P1, P2-P1+1)
        Call ChnAreaInsert0(BoolChannel, P1, P2-P1+1)
      END IF
    NEXT ' n
    EventList = ChnEventDetectionWindow(TimeChannel, BoolChannel, -0.5, 0.5)
    nMax = UBound(EventList)
    FOR n = 0 TO nMax
      P1 = EventList(n, 0)
      P2 = EventList(n, 1)
      Duration = TimeChannel.dValues(P2) - TimeChannel.dValues(P1)
      IF Duration < MinDuration THEN
        FOR i = P1 TO P2
          BoolChannel(i) = 1.0
        NEXT ' i
      END IF
    NEXT ' n
  END IF ' BoolChannel
NEXT ' BoolChannel

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 9 of 12
(5,197 Views)

Hi Brad, 

 

Many thanks for your reply. 

Unfortunattely, I am not able to make it work. I did exactly what you said but got an error message which says -Type mismatch;"UBOUND" (Refering to Line 7) -.

 

Nonetheless, I don't want to run this script for all the channels which have a unit property of the empty script; but all the channels which contains the word "savings" on the string name. I do not want the rest of channels to be modified. 

I assume that after running this script I only need to plot this channels as it is normally done?

 

Thanks again

 

Regards

 

Estefania

 

0 Kudos
Message 10 of 12
(5,154 Views)