@@ -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,35 @@ 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 '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
241245
242246 # no spike read yet
243247 # can be implemented on user demand
@@ -395,9 +399,9 @@ def _event_count(self, block_index, seg_index, event_channel_index):
395399
396400 def _get_event_timestamps (self , block_index , seg_index , event_channel_index , t_start , t_stop ):
397401 info = self ._evt_streams [block_index ][seg_index ][event_channel_index ]
398- timestamps = info [' timestamps' ]
402+ timestamps = info [" timestamps" ]
399403 durations = info ["durations" ]
400- labels = info [' labels' ]
404+ labels = info [" labels" ]
401405
402406 # slice it if needed
403407 if t_start is not None :
0 commit comments