08-25-2021 10:01 AM - edited 08-25-2021 10:03 AM
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?
Solved! Go to Solution.
08-27-2021 09:09 AM
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
08-27-2021 09:17 AM - edited 08-27-2021 09:23 AM
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.
08-30-2021 03:27 PM - edited 08-30-2021 03:43 PM
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)")
09-01-2021 06:29 PM - edited 09-01-2021 06:31 PM
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
09-11-2021 11:08 AM - edited 09-11-2021 11:09 AM
Thank you Brad for proposing an efficient solution & detailed explanation!