Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_raw_data_index(self, f, raw_data_index_header):
if raw_data_index_header not in (FORMAT_CHANGING_SCALER, DIGITAL_LINE_SCALER):
raise ValueError(
"Unexpected raw data index for DAQmx data: 0x%08X" %
raw_data_index_header)
# This is a DAQmx raw data segment.
# 0x00001269 for segment containing Format Changing scaler.
# 0x0000126A for segment containing Digital Line scaler.
# Note that the NI docs on the TDMS format state that digital line scaler data
# has 0x00001369, which appears to be incorrect
# Read the data type
data_type_val = types.Uint32.read(f, self.endianness)
try:
self.data_type = types.tds_data_types[data_type_val]
except KeyError:
raise KeyError("Unrecognised data type: %s" % data_type_val)
daqmx_metadata = DaqMxMetadata(f, self.endianness, raw_data_index_header)
log.debug("DAQmx metadata: %r", daqmx_metadata)
self.data_type = daqmx_metadata.data_type
# DAQmx format has special chunking
self.data_size = daqmx_metadata.chunk_size * sum(daqmx_metadata.raw_data_widths)
self.number_values = daqmx_metadata.chunk_size
self.daqmx_metadata = daqmx_metadata
properties_list = ", ".join(properties)
return "%s(%s)" % (self.__class__.__name__, properties_list)
def _get_attr_repr(obj, attr_name):
val = getattr(obj, attr_name)
if isinstance(val, type):
return val.__name__
return repr(val)
# Type codes for DAQmx scalers don't match the normal TDMS type codes:
DAQMX_TYPES = {
0: types.Uint8,
1: types.Int8,
2: types.Uint16,
3: types.Int16,
4: types.Uint32,
5: types.Int32,
}
def _read_data_chunk(self, file, data_objects, chunk_index):
"""Read data from DAQmx data segment"""
log.debug("Reading DAQmx data segment")
all_daqmx = all(
o.data_type == types.DaqMxRawData for o in data_objects)
if not all_daqmx:
raise Exception("Cannot read a mix of DAQmx and "
"non-DAQmx interleaved data")
# If we have DAQmx data, we expect all objects to have matching
# raw data widths, so just use the first object:
raw_data_widths = data_objects[0].daqmx_metadata.raw_data_widths
chunk_size = data_objects[0].number_values
scaler_data = defaultdict(dict)
# Data for each set of raw data (corresponding to one card) is
# interleaved separately, so read one after another
for (raw_buffer_index, raw_data_width) in enumerate(raw_data_widths):
# Read all data into 1 byte unsigned ints first
combined_data = read_interleaved_segment_bytes(
file, raw_data_width, chunk_size)
def read_raw_data_index(self, f, raw_data_index_header):
# Metadata format is standard (non-DAQmx) TDMS format.
# raw_data_index_header gives the length of the index information.
# Read the data type
try:
self.data_type = types.tds_data_types[
types.Uint32.read(f, self.endianness)]
except KeyError:
raise KeyError("Unrecognised data type")
log.debug("Object data type: %s", self.data_type.__name__)
if (self.data_type.size is None and
self.data_type != types.String):
raise ValueError(
"Unsupported data type: %r" % self.data_type)
# Read data dimension
dimension = types.Uint32.read(f, self.endianness)
# In TDMS version 2.0, 1 is the only valid value for dimension
if dimension != 1:
raise ValueError("Data dimension is not 1")
properties_list = ", ".join(properties)
return "%s(%s)" % (self.__class__.__name__, properties_list)
def _get_attr_repr(obj, attr_name):
val = getattr(obj, attr_name)
if isinstance(val, type):
return val.__name__
return repr(val)
# Type codes for DAQmx scalers don't match the normal TDMS type codes:
DAQMX_TYPES = {
0: types.Uint8,
1: types.Int8,
2: types.Uint16,
3: types.Int16,
4: types.Uint32,
5: types.Int32,
}