Skip to content

Commit a26f39e

Browse files
Change return signature, more comments
1 parent b3911d6 commit a26f39e

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

neo/rawio/spikeglxrawio.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def _parse_header(self):
204204
# This is true only in case of 'nidq' stream
205205
for stream_name in stream_names:
206206
if "nidq" in stream_name:
207+
#TODO: loop over all segments to add nidq events to _events_memmap
207208
info = self.signals_info_dict[0, stream_name]
208209
if len(info["digital_channels"]) > 0:
209210
# add event channels
@@ -292,6 +293,7 @@ def _event_count(self, event_channel_idx, block_index=None, seg_index=None):
292293
return timestamps.size
293294

294295
def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_start=None, t_stop=None):
296+
#TODO: fix seg_index usage, currently hardcoded for first segment
295297
timestamps, durations, labels = [], None, []
296298
info = self.signals_info_dict[0, "nidq"] # There are no events that are not in the nidq stream
297299
dig_ch = info["digital_channels"]
@@ -312,17 +314,23 @@ def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_s
312314
def _get_sync_events(self, stream_index, seg_index = 0):
313315
'''
314316
Find sync events in the stream.
315-
For imec streams, the sync events are found in the 'SY0' channel,
316-
which should be the 6th bit in the last 'analog' channel in the stream.
317+
318+
For imec streams, the sync events are found in the 6th bit
319+
of the'SY0' channel, which should be the last 'analog' channel in the stream.
320+
317321
For nidq streams, the sync events are found in the channel specified by the metadata fields
318322
'syncNiChanType' and 'syncNiChan'.
319323
320324
Meta file descriptions taken from:
321325
https://billkarsh.github.io/SpikeGLX/Sgl_help/Metadata_30.html
322326
323-
Returns timestamps, durations, labels of rising or falling edges in these channels
327+
Returns (timestamps, labels)
328+
timestamps in samples of each edge
329+
labels is a list of ('channel_name ON') or OFF for rising or falling edges
324330
'''
325-
331+
if stream_index > len(self.header["signal_streams"]):
332+
raise ValueError("stream_index out of range")
333+
326334
stream_name = self.header["signal_streams"][stream_index]["name"]
327335
info = self.signals_info_dict[seg_index, stream_name]
328336

@@ -342,14 +350,14 @@ def _get_sync_events(self, stream_index, seg_index = 0):
342350
sync_data_uint8 = sync_data.view(np.uint8)
343351
unpacked_sync_data = np.unpackbits(sync_data_uint8, axis=1)
344352
sync_line = unpacked_sync_data[:,1]
345-
return self._find_events_in_channel(sync_line, channel)
346-
elif 'nidq' in self.header['signal_streams'][stream_index]['name']:
353+
timestamps, _, labels = self._find_events_in_channel(sync_line, channel)
354+
elif 'nidq' in stream_name:
347355
#find channel from metafile
348356
meta = info['meta']
349357
niChanType = int(meta['syncNiChanType'])
350358
niChan = int(meta['syncNiChan'])
351-
if niChanType == 0: #digital channel
352-
return self._get_event_timestamps(0, seg_index, niChan)
359+
if niChanType == 0: #digital channel
360+
timestamps, _, labels = self._get_event_timestamps(0, seg_index, niChan)
353361
elif niChanType == 1: #analog channel
354362
niThresh = float(meta['syncNiThresh']) #volts
355363
sync_line = self.get_analogsignal_chunk(channel_names = [f'XA{niChan}'],
@@ -358,12 +366,16 @@ def _get_sync_events(self, stream_index, seg_index = 0):
358366
#Does this need to be scaled by channel gain before threshold?
359367
sync_line = sync_line > niThresh
360368
raise NotImplementedError("Analog sync events not yet implemented")
361-
return self._find_events_in_channel(sync_line, f'XA{niChan}')
369+
timestamps, _, labels = self._find_events_in_channel(sync_line, f'XA{niChan}')
362370
else:
363-
raise ValueError("Unknown stream type, cannot find sync events")
364-
371+
raise ValueError(f"Unknown stream type '{stream_name}', cannot find sync events")
372+
return (timestamps, labels)
365373

366374
def _find_events_in_channel(self, channel_data, channel_name):
375+
'''
376+
Finds rising and falling edges in channel_data and returns
377+
timestamps (in samples), duration (not implemented) and label with channel_name
378+
'''
367379

368380
timestamps, durations, labels = [], None, []
369381

0 commit comments

Comments
 (0)