@@ -164,7 +164,7 @@ def _parse_header(self):
164
164
event_channels = []
165
165
for stream_ind , stream_name in enumerate (event_stream_names ):
166
166
info = self ._evt_streams [0 ][0 ][stream_ind ]
167
- if 'states' in info :
167
+ if 'states' in info or 'channel_states' in info :
168
168
evt_channel_type = "epoch"
169
169
else :
170
170
evt_channel_type = "event"
@@ -213,31 +213,35 @@ def _parse_header(self):
213
213
)
214
214
215
215
# # 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 'channel_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
+ timestamps = timestamps / info ['sample_rate' ]
239
+ durations = durations / info ['sample_rate' ]
240
+
241
+ info ["rising" ] = rising
242
+ info ["timestamps" ] = timestamps [rising ]
243
+ info ["labels" ] = labels [rising ]
244
+ info ["durations" ] = durations
241
245
242
246
# no spike read yet
243
247
# can be implemented on user demand
@@ -395,9 +399,9 @@ def _event_count(self, block_index, seg_index, event_channel_index):
395
399
396
400
def _get_event_timestamps (self , block_index , seg_index , event_channel_index , t_start , t_stop ):
397
401
info = self ._evt_streams [block_index ][seg_index ][event_channel_index ]
398
- timestamps = info [' timestamps' ]
402
+ timestamps = info [" timestamps" ]
399
403
durations = info ["durations" ]
400
- labels = info [' labels' ]
404
+ labels = info [" labels" ]
401
405
402
406
# slice it if needed
403
407
if t_start is not None :
0 commit comments