Skip to content

Commit 0f55934

Browse files
committed
WIP, imec sync channel processing
1 parent 6f4a97c commit 0f55934

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

neo/rawio/spikeglxrawio.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,21 +300,47 @@ def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_s
300300
channel = dig_ch[event_channel_index]
301301
ch_idx = 7 - int(channel[2:]) # They are in the reverse order
302302
this_stream = event_data[:, ch_idx]
303-
this_rising = np.where(np.diff(this_stream) == 1)[0] + 1
304-
this_falling = (
305-
np.where(np.diff(this_stream) == 255)[0] + 1
306-
) # because the data is in unsigned 8 bit, -1 = 255!
307-
if len(this_rising) > 0:
308-
timestamps.extend(this_rising)
309-
labels.extend([f"{channel} ON"] * len(this_rising))
310-
if len(this_falling) > 0:
311-
timestamps.extend(this_falling)
312-
labels.extend([f"{channel} OFF"] * len(this_falling))
303+
timestamps, durations, labels = self._find_events_in_channel(this_stream, channel)
313304
timestamps = np.asarray(timestamps)
314305
if len(labels) == 0:
315306
labels = np.asarray(labels, dtype="U1")
316307
else:
317308
labels = np.asarray(labels)
309+
310+
return timestamps, durations, labels
311+
312+
def _get_sync_events(self, stream_index):
313+
#find sync events in the 'SY0' channel of imec streams
314+
channel = 'SY0'
315+
sync_data = self.get_analogsignal_chunk(channel_names = [channel], stream_index = stream_index)
316+
#uint16 word to uint8 bytes to bits
317+
sync_data_uint8 = sync_data.view(np.uint8)
318+
unpacked_sync_data = np.unpackbits(sync_data_uint8, axis=1)
319+
#sync line is the 6th bit (so 1st bit because reversed order)
320+
#https://billkarsh.github.io/SpikeGLX/Sgl_help/Metadata_30.html
321+
sync_line = unpacked_sync_data[:,1]
322+
raise NotImplementedError("Work in progress")
323+
return self._find_events_in_channel(sync_line, "SY0")
324+
325+
def _find_events_in_channel(self, channel_data, channel_name):
326+
327+
timestamps, durations, labels = [], None, []
328+
329+
this_rising = np.where(np.diff(channel_data) == 1)[0] + 1
330+
this_falling = (
331+
np.where(np.diff(channel_data) == 255)[0] + 1
332+
) # because the data is in unsigned 8 bit, -1 = 255!
333+
if len(this_rising) > 0:
334+
timestamps.extend(this_rising)
335+
labels.extend([f"{channel_name} ON"] * len(this_rising))
336+
if len(this_falling) > 0:
337+
timestamps.extend(this_falling)
338+
labels.extend([f"{channel_name} OFF"] * len(this_falling))
339+
timestamps = np.asarray(timestamps)
340+
if len(labels) == 0:
341+
labels = np.asarray(labels, dtype="U1")
342+
else:
343+
labels = np.asarray(labels)
318344
return timestamps, durations, labels
319345

320346
def _rescale_event_timestamp(self, event_timestamps, dtype, event_channel_index):

0 commit comments

Comments
 (0)