DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to select specific rows in a data table based on a condition to delete it in DIAdem ?

Solved!
Go to solution

I have a group with several channels that when the value in one channel is less than a certain value, I want that row and all the same rows in the other channels deleted.

Is there any way to programmatically achieve this through a script on DIAdem 2021?

0 Kudos
Message 1 of 6
(2,603 Views)

Hi joshilpa,

 

Sure, this is a pretty typical task in DIAdem, and it proceeds in two steps:

 

1) Identify all the rows you want to delete by setting them to NoValue in one channel

2) Deleting the same rows in other channels that have the NoValue in that one channel

 

Step 1) can be accomplished with the Channel Calculator or with the Event finding dialogs in ANALYSIS.

 

Step 2) always uses the ChnNovHandle() command.

 

If you have trouble implementing this in script based on the above, please post a sample of your data file and a description of the rows you want to delete, and I can send you a quick script that executes both steps.

 

Brad Turpin

Principal Technical Support Engineer
NI

Message 2 of 6
(2,571 Views)

Hi Brad,

 

Could you please help implementing the same with a script. Pfa an example where I want to delete all rows corresponding to channel Power less than 40kW.

Download All
0 Kudos
Message 3 of 6
(2,567 Views)

Hi Brad,

 

I tried writing the below python script but I do not get the desired results with it , could you please suggest what could be the issue here?

 

sOutput =""
oMyChannels = dd.Data.GetChannels("[1]/*")
for oMyChn in oMyChannels:
    sOutput = sOutput + "\r\n" + oMyChn.Name

ch("[1]/x")=IIF(ch("[1]/Power")>40,ch("Power"),NoValue)
ChnNovHandle(x, sOutput ,"Delete", "X", 1, 0)

 

 

Alternatively tried adding channel using below method but it doesn't evaluate on all rows:

#Formula 1
dd.Data.Root.Channelgroups.Item("Example").Channels.AddCalculationChannel("x", "= IIF(ch(""Power"")>40,ch(""Power""),NoValue)",dd.DataTypeChnFloat64,10)

# Formula 2
dd.Calculate("Ch(""x"")=IIf( Ch(""Power"" > 40),Ch(""Power""),NoValue)") 

 

0 Kudos
Message 4 of 6
(2,544 Views)
Solution
Accepted by topic author ebenellis

Hi josh,

 

It's easier to call the dd.Calculate() command if you define its 3 parameters beforehand as variables.  If you define the CalcChannels you want to remove rows from as a DIAdem ElementList, then create a Channel object variable for the row-defining PowerChannel, you only have to set the PowerChannel rows to NoValue.  You can remove the matching rows from all the CalcChannels and the NoValue rows from the PowerChannel at the same time and spare yourself the loop.

 

DataFilePath = r"C:\Users\Public\Documents\National Instruments\DIAdem 2021\Data\Example.tdm"
dd.Data.Root.Clear()
dd.DataFileLoad(DataFilePath, "TDM")
Group = dd.Data.Root.ChannelGroups(1)
PowerChannel = Group.Channels("Power")
CalcChannels = dd.Data.CreateElementList()
CalcChannels.AddElementList(Group.Channels)
CalcChannels.Remove(PowerChannel)
dd.ChnValExpand(PowerChannel)
Symbols = ["P"]
Formula = "P = IIF(P > 100, P, NoValue)"
dd.Calculate(Formula, Symbols, [PowerChannel])
dd.ChnNovHandle(PowerChannel, CalcChannels, "Delete", "X", 1, 0)

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 5 of 6
(2,527 Views)

Thank you Brad for proposing an efficient solution & detailed explanation!

0 Kudos
Message 6 of 6
(2,475 Views)