DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Load Data selectively in an ANP (Analysis Automation Procedure)

Solved!
Go to solution

Hi,

 

When I want to load some channels from file in a DIAdem script, I am used to writing:

dd.DataFileLoadSel(MyFile, "TDM", "*/MyChan1 | */XX | */t10", "LoadImmediately|ChnXYRelation") 

It works great, only the selected channels (MyChan1, XX, and t10 in the example above) are loaded, and it saves me a lot of time (less than a second vs 1 minute), since I'm often dealing with files with hundred of channels, most of which are not necessary for the tests I want to perform.

 

Now I want to automatise it through SystemLink; I've created a Data Index, and my acquisitions are stored there.

Of course I can load the acquisitions as follows:

def On_Run_AnalysisProcedure(oContext):

    dd = DIAdem.Application
    dd.ApplicationSetLocale("english")

#    Please enter your code sequences here.
#    --------------------------------------

    for link in oContext.DataLinks:
        elements = dd.Navigator.LoadData(link)
        oContext.LogWarning("Loaded elements: "+str(elements.Count))

 

Unfortunately, I haven't found a way to selectively load channels. I saw a procedure called dd.Navigator.LoadChannelsByName that was promising, but I'm not able to make it work.

 

Is there a way to selectively load channels from a Data Index structure? If not, any workaround?

 

Remarks. I'm working with DIAdem 2020SP1 and use Python scripts, but I can also go with VBA if requested.

0 Kudos
Message 1 of 4
(3,139 Views)

Hi panta,

 

This is not as elegant as the DataFileLoadSel() command, but it is an approach that will avoid delving into DataLink xml parsing:

 

    # -- Register Load the full data file to DIAdem Data Portal
    dd.Navigator.LoadData(oContext.DataLinks.Item(1), "Register|ChnXYRelation")
    
    # -- Expand the selected list of channels
    ExpandChannels = dd.Data.CreateElementList()
    ExpandChannels.AddElementList(dd.Data.GetChannels("*/MyChan1"))
    ExpandChannels.AddElementList(dd.Data.GetChannels("*/XX"))
    ExpandChannels.AddElementList(dd.Data.GetChannels("*/t10"))
    dd.ChnValExpand(ExpandChannels)

    # -- Delete any channels that are still registered
    DeleteChannels = dd.Data.CreateElementList()
    for Group in dd.Data.Root.ChannelGroups:
        for Channel in Group.Channels:
            if Channel.Properties("status").Value == "readonly":
                DeleteChannels.Add(Channel)
    dd.Data.Remove(DeleteChannels)

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 2 of 4
(3,098 Views)
Solution
Accepted by topic author panta1978

Hi panta,

 

If you're willing to brave the xml parsing of the DataLink, you can spare yourself the gymnastics in the Data Portal afterwards.  Also, this opens up the entire set of loading options you're used to in a regular DIAdem script:

 

    import xml.etree.ElementTree as ET

    for DataLink in oContext.DataLinks:
        root = ET.fromstring(DataLink)
        nodes = root.findall(r"./addresslist/basepoint/usistore/param")
        for item in nodes:
            param_node = ET.fromstring("<?xml version='1.0' encoding='UTF-16' standalone='no'?><param>" + item.text + "</param>")
            file_node = param_node.find(r"./filename")
            file_path = file_node.text
        exit # only analyze the first DataLink in the list
    
    # -- Load the selected channels to DIAdem Data Portal
    dd.DataFileLoadSel(file_path, "TDM", "*/MyChan1 | */XX | */t10", "LoadImmediately|ChnXYRelation")

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 3 of 4
(3,091 Views)

Hi Brad,

 

Thank you vey much for both your responses!

 

By the way, on Friday I was figuring out something similar to your second reply.

 

I realised that when I write

for link in oContext.DataLinks:

 

link is actually a string that among other things contains the whole path, and came up with some string parsing. My solution seems to be working, but yours look more robust - I feel like mine could only work on some particular cases.

 

I'll give your suggestions a try!

 

0 Kudos
Message 4 of 4
(3,053 Views)