npTDMS API Reference

Reading TDMS Files

class nptdms.TdmsFile(file, memmap_dir=None)

Reads and stores data from a TDMS file.

Variables:objects – A dictionary of objects in the TDMS file, where the keys are the object paths.
__init__(file, memmap_dir=None)

Initialise a new TDMS file object, reading all data.

  • file – Either the path to the tdms file to read or an already opened file.
  • 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.
as_dataframe(time_index=False, absolute_time=False)

Converts the TDMS file to a DataFrame

  • time_index – Whether to include a time index for the dataframe.
  • absolute_time – If time_index is true, whether the time index values are absolute times or relative to the start time.

The full TDMS file data.

Return type:


as_hdf(filepath, mode='w', group='/')

Converts the TDMS file into an HDF5 file

  • filepath – The path of the HDF5 file you want to write to.
  • mode – The write mode of the HDF5 file. This can be w, a …
  • group – A group in the HDF5 file that will contain the TDMS data.
channel_data(group, channel)

Get the data for a channel

  • group – The name of the group the channel is in.
  • channel – The name of the channel to get data for.

The channel data.

Return type:

NumPy array.


Returns a list of channel objects for the given group

Parameters:group – Name of the group to get channels for.
Return type:List of TdmsObject objects.

Return the names of groups in the file

Note that there is not necessarily a TDMS object associated with each group name.

Return type:List of strings.

Get a TDMS object from the file

Parameters:path – The object group and channel. Providing no channel returns a group object, and providing no channel or group will return the root object.
Return type:TdmsObject

For example, to get the root object:


To get a group:


To get a channel:

object("group_name", "channel_name")
class nptdms.TdmsObject(path, tdms_file=None)

Represents an object in a TDMS file.

  • path – The TDMS object path.
  • properties – Dictionary of TDMS properties defined for this object, for example the start time and time increment for waveforms.
  • has_data – Boolean, true if there is data associated with the object.

Converts the TDMS object to a DataFrame

Parameters:absolute_time – Whether times should be absolute rather than relative to the start time.
Returns:The TDMS object data.
Return type:pandas.DataFrame

Returns the name of the channel for this object, or None if it is a group or the root object.


NumPy array containing data if there is data for this object, otherwise None.


Returns the name of the group for this object, or None if it is the root object.


Returns the value of a TDMS property

Parameters:property_name – The name of the property to get.
Returns:The value of the requested property.
Raises:KeyError if the property isn’t found.

For objects that contain DAQmx raw data, this is the raw, unscaled data array. For other objects this is the same as the data property.

time_track(absolute_time=False, accuracy='ns')

Return an array of time or the independent variable for this channel

This depends on the object having the wf_increment and wf_start_offset properties defined. Note that wf_start_offset is usually zero for time-series data. If you have time-series data channels with different start times, you should use the absolute time or calculate the time offsets using the wf_start_time property.

For larger timespans, the accuracy setting should be set lower. The default setting is ‘ns’, which has a timespan of [1678 AD, 2262 AD]. For the exact ranges, refer to section “Datetime Units”.

  • absolute_time – Whether the returned time values are absolute times rather than relative to the start time. If true, the wf_start_time property must be set.
  • accuracy – The accuracy of the returned datetime64 array.
Return type:

NumPy array.


KeyError if required properties aren’t found

Writing TDMS Files

class nptdms.TdmsWriter(file, mode='w')

Writes to a TDMS file.

A TdmsWriter should be used as a context manager, for example:

with TdmsWriter(path) as tdms_writer:
__init__(file, mode='w')

Initialise a new TDMS writer

  • file – Either the path to the tdms file to open or an already opened file.
  • mode – Either ‘w’ to open a new file or ‘a’ to append to an existing TDMS file.

Write a segment of data to a TDMS file

Parameters:objects – A list of TdmsObject instances to write
class nptdms.RootObject(properties=None)

The root TDMS object


Initialise a new GroupObject

Parameters:properties – A dictionary mapping property names to their value.

The string representation of the root path

class nptdms.GroupObject(group, properties=None)

A TDMS object for a group

__init__(group, properties=None)

Initialise a new GroupObject

  • group – The name of this group.
  • properties – A dictionary mapping property names to their value.

The string representation of this group’s path

class nptdms.ChannelObject(group, channel, data, properties=None)

A TDMS object for a channel with data

__init__(group, channel, data, properties=None)

Initialise a new ChannelObject

  • group – The name of the group this channel is in.
  • channel – The name of this channel.
  • data – 1-D Numpy array of data to be written.
  • properties – A dictionary mapping property names to their value.

The string representation of this channel’s path

Data Types for Property Values

class nptdms.types.Int8(value)
class nptdms.types.Int16(value)
class nptdms.types.Int32(value)
class nptdms.types.Int64(value)
class nptdms.types.Uint8(value)
class nptdms.types.Uint16(value)
class nptdms.types.Uint32(value)
class nptdms.types.Uint64(value)
class nptdms.types.SingleFloat(value)
class nptdms.types.DoubleFloat(value)
class nptdms.types.String(value)
class nptdms.types.Boolean(value)
class nptdms.types.TimeStamp(value)

Indices and Tables