Skip to content

Commit 5f5cda9

Browse files
committed
Add support for event in OpenEphys<0.6
1 parent 453071f commit 5f5cda9

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

neo/rawio/openephysbinaryrawio.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _parse_header(self):
164164
event_channels = []
165165
for stream_ind, stream_name in enumerate(event_stream_names):
166166
info = self._evt_streams[0][0][stream_ind]
167-
if 'states' in info:
167+
if 'states' in info or 'channel_states' in info:
168168
evt_channel_type = "epoch"
169169
else:
170170
evt_channel_type = "event"
@@ -213,31 +213,34 @@ def _parse_header(self):
213213
)
214214

215215
# # If available, use 'states' to compute event duration
216-
if 'states' in info and info["states"].size:
217-
states = info["states"]
218-
timestamps = info["timestamps"]
219-
labels = info["labels"]
220-
rising = np.where(states > 0)[0]
221-
falling = np.where(states < 0)[0]
222-
223-
# infer durations
224-
durations = None
225-
if len(states) > 0:
226-
# make sure first event is rising and last is falling
227-
if states[0] < 0:
228-
falling = falling[1:]
229-
if states[-1] > 0:
230-
rising = rising[:-1]
231-
232-
if len(rising) == len(falling):
233-
durations = timestamps[falling] - timestamps[rising]
234-
235-
info["rising"] = rising
236-
info["timestamps"] = timestamps[rising]
237-
info["labels"] = labels[rising]
238-
info["durations"] = durations
239-
else:
240-
info["durations"] = None
216+
info["durations"] = None
217+
# 'states' was introduced in OpenEphys v0.6. For previous versions, events used 'channels_states'
218+
if 'states' in info or "channel_states" in info:
219+
states = info["channel_states"] if "channel_states" in info else info["states"]
220+
if states.size > 0:
221+
timestamps = info["timestamps"]
222+
labels = info["labels"]
223+
rising = np.where(states > 0)[0]
224+
falling = np.where(states < 0)[0]
225+
226+
# infer durations
227+
durations = None
228+
if len(states) > 0:
229+
# make sure first event is rising and last is falling
230+
if states[0] < 0:
231+
falling = falling[1:]
232+
if states[-1] > 0:
233+
rising = rising[:-1]
234+
235+
if len(rising) == len(falling):
236+
durations = timestamps[falling] - timestamps[rising]
237+
if not self._use_direct_evt_timestamps:
238+
durations = durations / info['sample_rate']
239+
240+
info["rising"] = rising
241+
info["timestamps"] = timestamps[rising]
242+
info["labels"] = labels[rising]
243+
info["durations"] = durations
241244

242245
# no spike read yet
243246
# can be implemented on user demand

0 commit comments

Comments
 (0)