def export_to_tmds(meta: source.MetaData, source_file: Any, export_path: pathlib.Path) -> None: """Exports the valid data slices into a new TDMS file on disk. Don't mind the nested for loops, the sizes of the iterators of the first and second stage are very small. Arguments: meta: meta data of source file source_file: Tdms file, that passed all consistency checks export_path: File path for the corrected TDMS file. """ index_ranges = prepare_data_correction(source_file) with nptdms.TdmsWriter(export_path) as tdms_writer: for group in source_file.tdms_operator.groups(): for channel in group.channels(): if len(channel) > 0: write_chunks_to_file( tdms_writer, index_ranges, group, channel, meta.segment_size, )
def capture_chunk(self, in_data, frame_count, time_info, status): self.data = np.fromstring(in_data, dtype=np.float32) if self._has_runner: data_chunk = nptdms.ChannelObject(self.group_name, self.channel_name, self.data, properties={}) if self.filepath is not None: with nptdms.TdmsWriter(self.filepath, 'a') as writer: writer.write_segment([data_chunk]) return (self.data, pyaudio.paContinue)
def copy_tdms(nwb, in_path, out_path, nrois): num_all_rois = nwb['/processing/Acquired_ROIs/roi_spec'].shape[0] print('Copying {} of {} ROIs from {} to {}'.format( nrois, num_all_rois, in_path, out_path)) in_tdms = nptdms.TdmsFile(in_path) group_name = 'Functional Imaging Data' with nptdms.TdmsWriter(out_path) as out_tdms: root, group = in_tdms.object(), in_tdms.object(group_name) out_tdms.write_segment([root, group]) for ch, channel in {'0': 'Red', '1': 'Green'}.items(): ch_name = 'Channel {} Data'.format(ch) ch_obj = in_tdms.object(group_name, ch_name) shape = (cycles_per_trial(nwb), num_all_rois, -1) ch_data = ch_obj.data.reshape(shape) subset = ch_data[:, :nrois, :].reshape(-1) new_obj = nptdms.ChannelObject(group_name, ch_name, subset, properties={}) out_tdms.write_segment([new_obj])
def write(self): """write the tdms segment set with root object, group objects and channel objects into one tdms file""" with nptdms.TdmsWriter(self.tdms_file_path) as writer: writer.write_segment(self.tdms_object_set)