From .tdms

Sanity check of file/path location


In [1]:
import os

In [3]:
# os.path.dirname(os.path.abspath(__file__)) # directory of the script being run


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-daa1e3bc904f> in <module>
----> 1 os.path.dirname(os.path.abspath(__file__)) # directory of the script being run

NameError: name '__file__' is not defined

In [4]:
os.getcwd()


Out[4]:
'/home/mobicfd/ReacCFD/masters/Propulsion/T1000/playground'

In [10]:
print(os.path.abspath("../../../../"))
# os.listdir(os.path.abspath("../../../../"))


/home/mobicfd/ReacCFD

In [12]:
print(os.path.isdir(os.path.abspath("../../../../") + "/tdms/"))
os.listdir(os.path.abspath("../../../../") + "/tdms/")


True
Out[12]:
['doc',
 'lib',
 'test',
 'LICENSE.txt',
 '.travis.yml',
 'tdms.gemspec',
 'README.md',
 'Rakefile',
 '.git',
 'demo.rb']

In [5]:
tdms_test_fixtures_path = os.path.abspath("../../../../") + "/tdms/test/fixtures/"

In [17]:
for file in os.listdir(tdms_test_fixtures_path):
    if file.endswith(".tdms"):
        print(file)


type_44_timestamp_one_segment.tdms
type_20_string_three_segments.tdms
type_09_single_two_channels_one_segment.tdms
type_07_uint32_two_channels_one_segment.tdms
type_21_boolean_two_channels_one_segment.tdms
type_03_int32_one_segment.tdms
type_05_uint8_one_segment.tdms
type_04_int64_two_channels_one_segment.tdms
type_19_single_with_unit_two_channels_one_segment.tdms
type_1a_double_with_unit_one_segment.tdms
type_06_uint16_one_segment.tdms
type_21_boolean_three_segments.tdms
type_1a_double_with_unit_three_segments.tdms
type_03_int32_two_channels_one_segment.tdms
type_09_single_three_segments.tdms
type_06_uint16_three_segments.tdms
type_08_uint64_two_channels_one_segment.tdms
type_08_uint64_three_segments.tdms
type_08_uint64_one_segment.tdms
type_04_int64_one_segment.tdms
type_04_int64_three_segments.tdms
type_03_int32_three_segments.tdms
type_02_int16_three_segments.tdms
type_05_uint8_three_segments.tdms
type_44_timestamp_three_segments.tdms
type_02_int16_two_channels_one_segment.tdms
type_01_int8_two_channels_one_segment.tdms
type_19_single_with_unit_one_segment.tdms
type_21_boolean_one_segment.tdms
type_0a_double_one_segment.tdms
type_1a_double_with_unit_two_channels_one_segment.tdms
type_01_int8_one_segment.tdms
type_07_uint32_three_segments.tdms
type_0a_double_two_channels_one_segment.tdms
type_19_single_with_unit_three_segments.tdms
type_20_double_two_channels_one_segment.tdms
type_0a_double_three_segments.tdms
type_06_uint16_two_channels_one_segment.tdms
type_01_int8_three_segments.tdms
example.tdms
type_44_timestamp_two_channels_one_segment.tdms
type_02_int16_one_segment.tdms
type_07_uint32_one_segment.tdms
type_05_uint8_two_channels_one_segment.tdms
type_20_string_two_channels_one_segment.tdms
type_09_single_one_segment.tdms
type_20_string_two_segments.tdms
type_20_string_one_segment.tdms

Typical read usage


In [2]:
import nptdms
from nptdms import TdmsFile

In [5]:
example_tdms_file = TdmsFile(tdms_test_fixtures_path + "example.tdms")
print(type(example_tdms_file))
print(dir(example_tdms_file))
#example_channel = example_tdms_file.object('Group', 'Channel1')
#data = channel.data


<class 'nptdms.tdms.TdmsFile'>
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_path', '_read_segments', 'as_dataframe', 'as_hdf', 'channel_data', 'group_channels', 'groups', 'memmap_dir', 'object', 'objects', 'segments']

cf. https://nptdms.readthedocs.io/en/latest/apireference.html

objects – A dictionary of objects in the TDMS file, where the keys are the object paths.


In [12]:
print(type(example_tdms_file.objects))
print(dir(example_tdms_file.objects))
print(example_tdms_file.objects.keys())


<class 'collections.OrderedDict'>
['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'move_to_end', 'pop', 'popitem', 'setdefault', 'update', 'values']
odict_keys(["/'EXAMPLE'/'Time'", "/'EXAMPLE'/'Speed'", "/'EXAMPLE'/'Revs'", "/'EXAMPLE'/'Torque'", "/'EXAMPLE'", "/'Noise data'/'Noise_1'", "/'Noise data'", '/', "/'Noise data'/'Noise_2'", "/'Noise data'/'Noise_3'", "/'Noise data results'/'StatisticsText'", "/'Noise data results'/'Res_Noise_1'", "/'Noise data results'/'Res_Noise_2'", "/'Noise data results'/'Res_Noise_3'", "/'Noise data results'", "/'Room temperatures'/'Temperature_1'", "/'Room temperatures'/'Temperature_2'", "/'Room temperatures'/'Temperature_3'", "/'Room temperatures'"])

With memmap

 __init__(file, memmap_dir=None)

Initialise a new TDMS file object, reading all data.

memmap_dir – The directory to store memmapped data files in, or None to read data into memory. The data files are created as temporary files and are deleted when the channel data is no longer used. tempfile.gettempdir() can be used to get the default temporary file directory.


In [3]:
print(os.path.abspath(os.getcwd()))


/home/mobicfd/ReacCFD/masters/Propulsion/T1000/playground

In [6]:
example_tdms_file = TdmsFile(tdms_test_fixtures_path + "example.tdms", os.path.abspath(os.getcwd()) + "/tempdata/")

In [7]:
print(example_tdms_file.memmap_dir)


/home/mobicfd/ReacCFD/masters/Propulsion/T1000/playground/tempdata/

cf. https://nptdms.readthedocs.io/en/latest/apireference.html

object(*path)

Get a TDMS object from a file.

.groups Return the names of groups in the file.


In [8]:
print(example_tdms_file.groups())


['EXAMPLE', 'Noise data', 'Noise data results', 'Room temperatures']

In [ ]: