|
8 | 8 |
|
9 | 9 | from neo.test.rawiotest.common_rawio_test import BaseTestRawIO |
10 | 10 |
|
| 11 | +import numpy as np |
11 | 12 |
|
12 | 13 | class TestMicromedRawIO( |
13 | 14 | BaseTestRawIO, |
14 | 15 | unittest.TestCase, |
15 | 16 | ): |
16 | 17 | rawioclass = MicromedRawIO |
17 | 18 | entities_to_download = ["micromed"] |
18 | | - entities_to_test = ["micromed/File_micromed_1.TRC"] |
| 19 | + entities_to_test = [ |
| 20 | + "micromed/File_micromed_1.TRC", |
| 21 | + "micromed/File_mircomed2.TRC", |
| 22 | + "micromed/File_mircomed2_2segments.TRC", |
| 23 | + ] |
| 24 | + |
| 25 | + def test_micromed_multi_segments(self): |
| 26 | + file_full = self.get_local_path("micromed/File_mircomed2.TRC") |
| 27 | + file_splitted = self.get_local_path("micromed/File_mircomed2_2segments.TRC") |
| 28 | + |
| 29 | + # the second file contains 2 pieces of the first file |
| 30 | + # so it is 2 segments with the same traces but reduced |
| 31 | + # note that traces in the splited can differ at the very end of the cut |
| 32 | + |
| 33 | + reader1 = MicromedRawIO(file_full) |
| 34 | + reader1.parse_header() |
| 35 | + assert reader1.segment_count(block_index=0) == 1 |
| 36 | + assert reader1.get_signal_t_start(block_index=0, seg_index=0, stream_index=0) == 0. |
| 37 | + traces1 = reader1.get_analogsignal_chunk(stream_index=0) |
| 38 | + |
| 39 | + reader2 = MicromedRawIO(file_splitted) |
| 40 | + reader2.parse_header() |
| 41 | + print(reader2) |
| 42 | + assert reader2.segment_count(block_index=0) == 2 |
| 43 | + |
| 44 | + # check that pieces of the second file is equal to the first file (except a truncation at the end) |
| 45 | + for seg_index in range(2): |
| 46 | + t_start = reader2.get_signal_t_start(block_index=0, seg_index=seg_index, stream_index=0) |
| 47 | + assert t_start > 0 |
| 48 | + sr = reader2.get_signal_sampling_rate(stream_index=0) |
| 49 | + ind_start = int(t_start * sr) |
| 50 | + traces1_chunk = traces1[ind_start: ind_start+traces2.shape[0]] |
| 51 | + traces2 = reader2.get_analogsignal_chunk(block_index=0, seg_index=seg_index, stream_index=0) |
| 52 | + # we remove the last 100 sample because tools that cut traces is truncating the last buffer |
| 53 | + assert np.array_equal(traces2[:-100], traces1_chunk[:-100]) |
| 54 | + |
19 | 55 |
|
20 | 56 |
|
21 | 57 | if __name__ == "__main__": |
|
0 commit comments