From 5f5cda977a67926a827f667aea96856b4af116a5 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 14 Dec 2023 15:02:33 +0100 Subject: [PATCH 1/3] Add support for event in OpenEphys<0.6 --- neo/rawio/openephysbinaryrawio.py | 55 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index a59137696..bf1ec8cb2 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -164,7 +164,7 @@ def _parse_header(self): event_channels = [] for stream_ind, stream_name in enumerate(event_stream_names): info = self._evt_streams[0][0][stream_ind] - if 'states' in info: + if 'states' in info or 'channel_states' in info: evt_channel_type = "epoch" else: evt_channel_type = "event" @@ -213,31 +213,34 @@ def _parse_header(self): ) # # If available, use 'states' to compute event duration - if 'states' in info and info["states"].size: - states = info["states"] - timestamps = info["timestamps"] - labels = info["labels"] - rising = np.where(states > 0)[0] - falling = np.where(states < 0)[0] - - # infer durations - durations = None - if len(states) > 0: - # make sure first event is rising and last is falling - if states[0] < 0: - falling = falling[1:] - if states[-1] > 0: - rising = rising[:-1] - - if len(rising) == len(falling): - durations = timestamps[falling] - timestamps[rising] - - info["rising"] = rising - info["timestamps"] = timestamps[rising] - info["labels"] = labels[rising] - info["durations"] = durations - else: - info["durations"] = None + info["durations"] = None + # 'states' was introduced in OpenEphys v0.6. For previous versions, events used 'channels_states' + if 'states' in info or "channel_states" in info: + states = info["channel_states"] if "channel_states" in info else info["states"] + if states.size > 0: + timestamps = info["timestamps"] + labels = info["labels"] + rising = np.where(states > 0)[0] + falling = np.where(states < 0)[0] + + # infer durations + durations = None + if len(states) > 0: + # make sure first event is rising and last is falling + if states[0] < 0: + falling = falling[1:] + if states[-1] > 0: + rising = rising[:-1] + + if len(rising) == len(falling): + durations = timestamps[falling] - timestamps[rising] + if not self._use_direct_evt_timestamps: + durations = durations / info['sample_rate'] + + info["rising"] = rising + info["timestamps"] = timestamps[rising] + info["labels"] = labels[rising] + info["durations"] = durations # no spike read yet # can be implemented on user demand From dee258d615c6388d4aa6194487f9bfbbc29401ca Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 14 Dec 2023 15:54:17 +0100 Subject: [PATCH 2/3] Convert timestamps to seconds --- neo/rawio/openephysbinaryrawio.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index bf1ec8cb2..272246a2f 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -235,6 +235,7 @@ def _parse_header(self): if len(rising) == len(falling): durations = timestamps[falling] - timestamps[rising] if not self._use_direct_evt_timestamps: + timestamps = timestamps / info['sample_rate'] durations = durations / info['sample_rate'] info["rising"] = rising @@ -398,9 +399,9 @@ def _event_count(self, block_index, seg_index, event_channel_index): def _get_event_timestamps(self, block_index, seg_index, event_channel_index, t_start, t_stop): info = self._evt_streams[block_index][seg_index][event_channel_index] - timestamps = info['timestamps'] + timestamps = info["timestamps"] durations = info["durations"] - labels = info['labels'] + labels = info["labels"] # slice it if needed if t_start is not None: From 20d1e364f59d5b67921cc84a3400eac6a40a0a0c Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Fri, 15 Dec 2023 20:59:23 +0100 Subject: [PATCH 3/3] Update neo/rawio/openephysbinaryrawio.py Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- neo/rawio/openephysbinaryrawio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index 272246a2f..7be1c6167 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -214,7 +214,7 @@ def _parse_header(self): # # If available, use 'states' to compute event duration info["durations"] = None - # 'states' was introduced in OpenEphys v0.6. For previous versions, events used 'channels_states' + # 'states' was introduced in OpenEphys v0.6. For previous versions, events used 'channel_states' if 'states' in info or "channel_states" in info: states = info["channel_states"] if "channel_states" in info else info["states"] if states.size > 0: