Skip to content

Commit 009861f

Browse files
committed
add test and fix buffer slice
1 parent 41d17eb commit 009861f

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

neo/rawio/openephysbinaryrawio.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,30 @@ def _parse_header(self):
223223
raise ValueError(
224224
"SYNC channel is not present in the recording. " "Set load_sync_channel to False"
225225
)
226-
227-
if has_sync_trace and not self.load_sync_channel:
228-
self._stream_buffer_slice[stream_id] = slice(None, -1)
226+
227+
num_neural_channels = sum(1 for ch in info["channels"] if "ADC" not in ch["channel_name"])
228+
num_non_neural_channels = sum(1 for ch in info["channels"] if "ADC" in ch["channel_name"])
229+
230+
231+
if num_non_neural_channels == 0:
232+
if has_sync_trace and not self.load_sync_channel:
233+
self._stream_buffer_slice[stream_id] = slice(None, -1)
234+
else:
235+
self._stream_buffer_slice[stream_id] = None
229236
else:
230-
self._stream_buffer_slice[stream_id] = None
231-
237+
# For ADC channels, we remove the last channel which is the Synch channel
238+
stream_id_neural = stream_id
239+
stream_id_non_neural = str(int(stream_id) + self._num_of_signal_streams)
240+
241+
# Note this implementation assumes that the neural channels come before the non-neural channels
242+
243+
self._stream_buffer_slice[stream_id_neural] = slice(0, num_neural_channels)
244+
self._stream_buffer_slice[stream_id_non_neural] = slice(num_neural_channels, None)
245+
246+
# It also assumes that the synch channel is the last channel in the buffer
247+
if has_sync_trace and not self.load_sync_channel:
248+
self._stream_buffer_slice[stream_id_non_neural] = slice(num_neural_channels, -1)
249+
232250
# events zone
233251
# channel map: one channel one stream
234252
event_channels = []

neo/test/rawiotest/test_openephysbinaryrawio.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class TestOpenEphysBinaryRawIO(BaseTestRawIO, unittest.TestCase):
1616
"openephysbinary/v0.6.x_neuropixels_multiexp_multistream",
1717
"openephysbinary/v0.6.x_neuropixels_with_sync",
1818
"openephysbinary/v0.6.x_neuropixels_missing_folders",
19+
"openephysbinary/neural_and_non_neural_data_mixed"
1920
]
2021

2122
def test_sync(self):
@@ -78,6 +79,16 @@ def test_multiple_ttl_events_parsing(self):
7879
assert np.allclose(ttl_events["durations"][ttl_events["labels"] == "6"], 0.025, atol=0.001)
7980
assert np.allclose(ttl_events["durations"][ttl_events["labels"] == "7"], 0.016666, atol=0.001)
8081

82+
def test_separating_stream_for_non_neural_data(self):
83+
rawio = OpenEphysBinaryRawIO(
84+
self.get_local_path("openephysbinary/neural_and_non_neural_data_mixed"), load_sync_channel=False
85+
)
86+
rawio.parse_header()
87+
# Check that the non-neural data stream is correctly separated
88+
assert len(rawio.header["signal_streams"]["name"]) == 2
89+
assert rawio.header["signal_streams"]["name"] == ["'Rhythm_FPGA-100.0", "'Rhythm_FPGA-100.0_ADC"]
90+
91+
8192

8293
if __name__ == "__main__":
8394
unittest.main()

0 commit comments

Comments
 (0)