DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Read TDM file with python module “tdm_loader”

So i am trying to read a .tdm file with python and am using tdm_loader module.

Per

import numpy
import tdm_loader as tdm
data = tdm.OpenFile('DATA.TDM')
data.channel_name(0,0)



>data.channel_name(0,0)

>Out[2]: 'Time'


But:


>data.channel(0,0)


results in:



Traceback (most recent call last):

File "<ipython-input-3-ab5f07c9eb08>", line 1, in <module>
data.channel(0,0)

File "C:\Users\sebastian\Anaconda3\lib\site-packages\tdm_loader\tdm_loader.py", line 231, in channel
data_usi = OpenFile._get_usi_from_txt(lc.findtext('values'))[0]

*IndexError: list index out of range*



> data.channel(0,1)

gives another error



Traceback (most recent call last):

File "<ipython-input-7-248c388cba15>", line 1, in <module>
data.channel(0,1)

File "C:\Users\sebastian\Anaconda3\lib\site-packages\tdm_loader\tdm_loader.py", line 238, in channel
ext_attribs = self._root.find(".//file/block[@id='{0}']".format(inc.get('external'))).attrib

AttributeError: 'NoneType' object has no attribute 'attrib'


I can access other .tdm files that go along with a .tdx file. But this .tdm file goes along with a .json and a .l03 file.
I don't know if this produces the problem? Any Advice is much appreciated.

0 Kudos
Message 1 of 6
(6,174 Views)

Hi, 

As  I know, it shouldn't both files can "work" with .tdm . It could be just syntaxes, check some examples.

Maybe You would try convert them to csv?

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

If i use any other .tdm examples that go along with a .tdx file, everything works fine. Maybe tdm_loader is only compatible with a according .tdx

If i want to convert them i need to aim to convert it with Python (i want it all to happen with python) but therefore i would need something like tdm_loader. But it does not work for my files 😕

0 Kudos
Message 3 of 6
(6,085 Views)

Hi Sebasti,

 

I'm not familiar with the tdm_loader module for python.  In general, a *.TDM header file can reference one or more binary data files of any file extension.  So I'd be surprised if the tdm_loader module hardcoded the *.TDX file lookup, since the implicitly linked binary file names are listed inside the *.TDM.

 

What I can offer you is to try to load the *.TDM file that's giving you trouble with DIAdem or LabVIEW and let you know if it's a valid TDM file, from the NI perspective.

 

One other possibility is that a few years ago DIAdem added the feature to create *.TDM files where the *.TDM file contents was zipped.  It's possible that the tdm_loader can't handle that flavor of *.TDM file.  You might try opening the *.TDM file in NotePad and see if you get XML (not pretty, no spaces or endline characters), or if you see the sort of binary characters typical of a zipped file.  If that's the case, you can just rename the file extension from *.TDM to *.zip and use 7zip or WinZip or Windows Explorer to unzip the *.TDM/*.zip file.

 

Brad Turpin

Principal Technical Support Engineer

NI

0 Kudos
Message 4 of 6
(6,073 Views)

I can open the file with DIAdem and i also used Matlab to open the file. So yea my current guess is that tdm_loader did use some hard coding but i may just ask the creators in a next step. Seems like not a lot of people use python to work with tdm files?

 

I opened it with the editor and it is given in a .XML format 😕

Nevertheless thanks for the answer.

0 Kudos
Message 5 of 6
(6,064 Views)

Hi @ sebasti_94 ,

 

we recently open-sourced our project for decoding TDM/TDX . It is available at


https://pypi.org/project/TDMtermite/

 

and

 

https://github.com/RecordEvolution/TDMtermite

 

You're welcome to check it out!

 

Best regards

0 Kudos
Message 6 of 6
(6,015 Views)