Skip to content

Commit 02bfcd3

Browse files
committed
add sync to stream name
1 parent b3dd09d commit 02bfcd3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

neo/rawio/openephysbinaryrawio.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def _parse_header(self):
130130
# create signals channel map: several channel per stream
131131
signal_channels = []
132132
sync_stream_id_to_buffer_id = {}
133+
normal_stream_id_to_sync_stream_id = {}
133134
for stream_index, stream_name in enumerate(sig_stream_names):
134135
# stream_index is the index in vector stream names
135136
stream_id = str(stream_index)
@@ -140,6 +141,7 @@ def _parse_header(self):
140141
chan_id = chan_info["channel_name"]
141142

142143
units = chan_info["units"]
144+
channel_stream_id = stream_id
143145
if units == "":
144146
# When units are not provided they are microvolts for neural channels and volts for ADC channels
145147
# See https://open-ephys.github.io/gui-docs/User-Manual/Recording-data/Binary-format.html#continuous
@@ -148,14 +150,19 @@ def _parse_header(self):
148150
# Special cases for stream
149151
if "SYNC" in chan_id and not self.load_sync_channel:
150152
# Every stream sync channel is added as its own stream
151-
stream_id = f"{chan_id}-{str(stream_index)}"
152-
sync_stream_id_to_buffer_id[stream_id] = buffer_id
153+
sync_stream_id = f"{stream_name}SYNC"
154+
sync_stream_id_to_buffer_id[sync_stream_id] = buffer_id
155+
156+
# We save this mapping for the buffer description protocol
157+
normal_stream_id_to_sync_stream_id[stream_id] = sync_stream_id
158+
# We then set the stream_id to the sync stream id
159+
channel_stream_id = sync_stream_id
153160

154161
if "ADC" in chan_id:
155162
# These are non-neural channels and their stream should be separated
156163
# We defined their stream_id as the stream_index of neural data plus the number of neural streams
157164
# This is to not break backwards compatbility with the stream_id numbering
158-
stream_id = str(stream_index + len(sig_stream_names))
165+
channel_stream_id = str(stream_index + len(sig_stream_names))
159166

160167
gain = float(chan_info["bit_volts"])
161168
sampling_rate = float(info["sample_rate"])
@@ -169,7 +176,7 @@ def _parse_header(self):
169176
units,
170177
gain,
171178
offset,
172-
stream_id,
179+
channel_stream_id,
173180
buffer_id,
174181
)
175182
)
@@ -274,9 +281,8 @@ def _parse_header(self):
274281
self._stream_buffer_slice[stream_id] = slice(None, -1)
275282

276283
# Add a buffer slice for the sync channel
277-
sync_channel_name = info["channels"][-1]["channel_name"]
278-
stream_name = f"{sync_channel_name}-{str(stream_id)}"
279-
self._stream_buffer_slice[stream_name] = slice(-1, None)
284+
sync_stream_id = normal_stream_id_to_sync_stream_id[stream_id]
285+
self._stream_buffer_slice[sync_stream_id] = slice(-1, None)
280286
else:
281287
self._stream_buffer_slice[stream_id] = None
282288
else:
@@ -290,8 +296,8 @@ def _parse_header(self):
290296
self._stream_buffer_slice[stream_id_non_neural] = slice(num_neural_channels, -1)
291297

292298
# Add a buffer slice for the sync channel
293-
sync_channel_name = info["channels"][-1]["channel_name"]
294-
self._stream_buffer_slice[sync_channel_name] = slice(-1, None)
299+
sync_stream_id = normal_stream_id_to_sync_stream_id[stream_id]
300+
self._stream_buffer_slice[sync_stream_id] = slice(-1, None)
295301
else:
296302
self._stream_buffer_slice[stream_id_non_neural] = slice(num_neural_channels, None)
297303

0 commit comments

Comments
 (0)