Skip to content

Commit 17e6f4e

Browse files
committed
add test and better error message
1 parent 45f8c4b commit 17e6f4e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/trodes_to_nwb/convert_ephys.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def __init__(
102102
neo_io.signal_streams_count() == 4 - behavior_only
103103
for neo_io in self.neo_io
104104
]
105+
), (
106+
"Unexpected number of signal streams. "
107+
+ "Confirm whether behavior_only is set correctly for this recording"
105108
)
106109

107110
self.block_index = 0
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import pytest
2+
3+
from trodes_to_nwb.convert_ephys import RecFileDataChunkIterator
4+
from trodes_to_nwb.tests.utils import data_path
5+
6+
7+
def test_behavior_only_rec_file():
8+
file = data_path / "behavior_only.rec"
9+
# accessing trodes stream with behavior only file should fail
10+
with pytest.raises(IndexError):
11+
RecFileDataChunkIterator(
12+
rec_file_path=[file],
13+
interpolate_dropped_packets=True,
14+
stream_id="trodes",
15+
behavior_only=True,
16+
)
17+
18+
# misspecification of behavior-only should result in mismatched stream number
19+
with pytest.raises(AssertionError):
20+
RecFileDataChunkIterator(
21+
rec_file_path=[file],
22+
interpolate_dropped_packets=True,
23+
stream_id="trodes",
24+
behavior_only=False,
25+
)
26+
27+
# correctly build iterator
28+
rec_dci = RecFileDataChunkIterator(
29+
rec_file_path=[file],
30+
interpolate_dropped_packets=True,
31+
stream_id="ECU_analog",
32+
behavior_only=True,
33+
)
34+
neo_io = rec_dci.neo_io[0]
35+
36+
# check file streams
37+
stream_names = [stream[0] for stream in neo_io.header["signal_streams"]]
38+
assert all(
39+
[
40+
x in stream_names
41+
for x in ["ECU_analog", "ECU_digital", "Controller_DIO_digital"]
42+
]
43+
), "missing expected stream in iterator"
44+
assert "trodes" not in stream_names, "unexpected trodes stream in iterator"
45+
46+
# check data accesses
47+
assert rec_dci.timestamps.size == 433012
48+
assert rec_dci.timestamps[-1] == 1751195974.5656028, "unexpected last timestamp"
49+
assert set(neo_io.multiplexed_channel_xml.keys()) == set(
50+
[
51+
"Headstage_AccelX",
52+
"Headstage_AccelY",
53+
"Headstage_AccelZ",
54+
"Headstage_GyroX",
55+
"Headstage_GyroY",
56+
"Headstage_GyroZ",
57+
"Headstage_MagX",
58+
"Headstage_MagY",
59+
"Headstage_MagZ",
60+
"Controller_Ain1",
61+
]
62+
)
63+
assert neo_io._raw_memmap.shape == (433012, 54)

0 commit comments

Comments
 (0)