Skip to content

Commit dff7de8

Browse files
committed
test for micromed multi segment
1 parent 9f7bbda commit dff7de8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

neo/test/rawiotest/test_micromedrawio.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,50 @@
88

99
from neo.test.rawiotest.common_rawio_test import BaseTestRawIO
1010

11+
import numpy as np
1112

1213
class TestMicromedRawIO(
1314
BaseTestRawIO,
1415
unittest.TestCase,
1516
):
1617
rawioclass = MicromedRawIO
1718
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+
1955

2056

2157
if __name__ == "__main__":

0 commit comments

Comments
 (0)