Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nptdms/test/test_example_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def tdms_files_assert_equal(tdms1: TdmsFile, tdms2: TdmsFile):

@pytest.mark.parametrize("tdms_file", [
'raw_timestamps.tdms', # Test defragmentation of a file with raw timestamps
# 'raw1.tdms', # <- cannot defragment this file (ValueError: Channel data must be a 1d array)
'raw1.tdms',
'Digital_Input.tdms',
'big_endian.tdms',
])
Expand Down
11 changes: 9 additions & 2 deletions nptdms/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ def defragment(cls, source, destination, version=4712, index_file=False):
for group in file.groups():
new_file.write_segment([GroupObject(group.name, group.properties)])
for channel in group.channels():
channel_data = channel.read_data(scaled=False)
channel_properties = channel.properties
if isinstance(channel_data, dict) and len(channel_data) == 1:
scale_id, channel_data = next(iter(channel_data.items()))
channel_properties = OrderedDict(channel_properties)
channel_properties[
"NI_Scale[%d]_Scale_Type" % scale_id] = "AdvancedAPI"
new_file.write_segment([ChannelObject(
group.name,
channel.name,
channel.read_data(scaled=False),
channel.properties
channel_data,
channel_properties
)])

def __init__(self, file, mode='w', version=4712, index_file=False):
Expand Down