How to Trim Data Based on A Reference Channel Using DIAdem

Updated Feb 7, 2024

This article will introduce how to trim data from a channel based on another reference channel using DIAdem. The method is useful when you have data in channel A and to analyze it you are required to trim the data based on channel B. The default example data loaded in DIAdem will be used in this article.

Assuming you need to analyze data of the Speed channel and RPM channel and you would like to trim both data to remove value during RPM between 1000-2000 r/min. You can manually or programmatically trim both channel data based on the condition for the RPM channel in DIAdem: Note: The data length of both channels used in this demonstration is the same. If you need to match your channels' data length, refer to this How to Match Data Length of Different XY Channels Using DIAdem.

Manually Trim

1. Select the VIEW panel in DIAdem.
2. Select the reference channel(in this example it is RPM channel)
3. Select the Band Cursor and adjust the cursor pointing area that meets your requirement. In this example adjust the Y-Cursor1 until the first value that more than 1000 and the Y-Cursor2 before the value greater than 2000.
step
4. Right-click on the graph area and select Flags >> Set(All Displayed Curves) to flag all the displayed curves that fall under the selected condition. Now the flagged curves will shown as bold curves in the graph. 
03
5. Select Flags: Delete Data Points to delete the flagged curves. Now the deleted data will shown as NOVALUE.
08.PNG
6. Select ANALYSIS panel >> Channel Functions >> Process NoValue... to trim the NoValue data in the Speed and RPM channels. Follow the setting below, when select Calculate, there will be new calculated channels created in the data portal.
000.PNG
 

Programmatically Trim

In this demonstration, we will use a Python script to achieve the objective.
1. Select the SCRIPT panel in DIAdem.
2. Select File >> New or Keyboard select ctrl+N.
3. Select Python to create a new Python script in DIAdem.
Capture.PNG
4. Replace the code below in the script and run the script. The trimmed channels should be created in the data portal after running the script.
# --------------------------------------------------------------------
# -- Python Script File
# -- Created on 01/30/2024 12:57:58
# -- Author: NI support
# -- Comment: Demonstration purpose
# --------------------------------------------------------------------
import sys
if 'DIAdem' in sys.modules:
    from DIAdem import Application as dd

# --------------------------------------------------------------------
# -- Beginning of user code --
#assign variable to change channel to process
cond_ref_ch = "RPM"  
Test_channel = "Speed"

#get channel from data portal and assign to a new array
oMyChannel1 = dd.Data.Root.ChannelGroups(1).Channels(cond_ref_ch)
Ref_ch = oMyChannel1.GetValuesBlock(1,oMyChannel1.Size) 

#loop the Test_channel and replace that data in channel to NoValue if fulfil the condition
for index in range(len(Ref_ch)):
    if Ref_ch[index] < 2000 and Ref_ch[index] > 1000:
        #depend on how many channel need to append
        dd.Data.Root.ChannelGroups(1).Channels(cond_ref_ch)[index+1]= None
        dd.Data.Root.ChannelGroups(1).Channels(Test_channel)[index+1]= None

#delete NoValue data in specific channels
dd.ChnNovHandle("[1]/Speed", "[1]/RPM", "Delete", "XY", False, False, 0)  
Note: The blue color of the code refers to the channels that are used in this demonstration, you may change it to require channels. The green color of the code refers to the trim condition of the data you may change it based on your requirements.