Skip to content

Commit 2cebaa2

Browse files
authored
NeuroNexusIO: Add in appropriate streams to go with buffer API (#1711)
* update streams post buffer api * update comment * fix typo * Sam's suggestion * oops * swith to neuronexus terminology
1 parent 1dad7e2 commit 2cebaa2

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

neo/rawio/neuronexusrawio.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@ def _parse_header(self):
132132
self._n_samples, self._n_channels = self.metadata["status"]["shape"]
133133
# Stored as a simple float32 binary file
134134
BINARY_DTYPE = "float32"
135+
TIMESTAMP_DTYPE = "int64" # this is from the allego sample reader timestamps are np.int64
135136
binary_file = self.binary_file
136137
timestamp_file = self.timestamp_file
137138

138-
# the will cretae a memory map with teh generic mechanism
139+
# the will cretae a memory map with the generic mechanism
139140
buffer_id = "0"
140141
self._buffer_descriptions = {0: {0: {}}}
141142
self._buffer_descriptions[0][0][buffer_id] = {
@@ -149,7 +150,7 @@ def _parse_header(self):
149150
# Make the memory map for timestamp
150151
self._timestamps = np.memmap(
151152
timestamp_file,
152-
dtype=np.int64, # this is from the allego sample reader timestamps are np.int64
153+
dtype=TIMESTAMP_DTYPE,
153154
mode="r",
154155
offset=0, # headerless binary file
155156
)
@@ -167,24 +168,28 @@ def _parse_header(self):
167168
signal_channels = []
168169
channel_info = self.metadata["sapiens_base"]["biointerface_map"]
169170

170-
# as per dicussion with the Neo/SpikeInterface teams stream_id will become buffer_id
171-
# and because all data is stored in the same buffer stream for the moment all channels
172-
# will be in stream_id = 0. In the future this will be split into sub_streams based on
173-
# type but for now it will be the end-users responsability for this.
174-
stream_id = "0" # hard-coded see note above
171+
# NeuroNexus uses a single buffer for all file types. Now that we buffer API
172+
# we divide each Allego signal into it's appropriate stream for the end-user
175173
buffer_id = "0"
176174
for channel_index, channel_name in enumerate(channel_info["chan_name"]):
177175
channel_id = channel_info["ntv_chan_name"][channel_index]
178176
# 'ai0' indicates analog data which is stored as microvolts
177+
# sometimes also called the pri data for NeuroNexus terminology
179178
if channel_info["chan_type"][channel_index] == "ai0":
180179
units = "uV"
180+
stream_id = "ai-pri"
181181
# 'd' means digital. Per discussion with neuroconv users the use of
182182
# 'a.u.' makes the units clearer
183-
elif channel_info["chan_type"][channel_index][0] == "d":
183+
elif channel_info["chan_type"][channel_index][:2] == "di":
184184
units = "a.u."
185-
# aux channel
185+
stream_id = "din"
186+
elif channel_info["chan_type"][channel_index][:2] == "do":
187+
# aux channel
188+
units = "a.u."
189+
stream_id = "dout"
186190
else:
187191
units = "V"
192+
stream_id = "aux"
188193

189194
signal_channels.append(
190195
(
@@ -212,7 +217,7 @@ def _parse_header(self):
212217
signal_streams["buffer_id"] = buffer_id
213218
self._stream_buffer_slice = {}
214219
for stream_index, stream_id in enumerate(stream_ids):
215-
name = stream_id_to_stream_name.get(int(stream_id), "")
220+
name = stream_id_to_stream_name.get(stream_id, "")
216221
signal_streams["name"][stream_index] = name
217222
chan_inds = np.flatnonzero(signal_channels["stream_id"] == stream_id)
218223
self._stream_buffer_slice[stream_id] = chan_inds
@@ -294,7 +299,10 @@ def _get_analogsignal_buffer_description(self, block_index, seg_index, buffer_id
294299
return self._buffer_descriptions[block_index][seg_index][buffer_id]
295300

296301

297-
# this is pretty useless right now, but I think after a
298-
# refactor with sub streams we could adapt this for the sub-streams
299-
# so let's leave this here for now :)
300-
stream_id_to_stream_name = {"0": "Neuronexus Allego Data"}
302+
# here we map the stream_id to the more descriptive stream_name
303+
stream_id_to_stream_name = {
304+
"ai-pri": "NeuroNexus Allego Analog (pri) Data",
305+
"din": "NeuroNexus Allego Digital-in (din) Data",
306+
"dout": "NeuroNexus Allego Digital-out (dout) Data",
307+
"aux": "NeuroNexus Allego Auxiliary (aux) Data",
308+
}

0 commit comments

Comments
 (0)