2424
2525import datetime
2626from collections import OrderedDict
27+ import re
2728
2829import numpy as np
2930
@@ -231,6 +232,7 @@ def _parse_header(self):
231232 # signals channels
232233 sig_channels = []
233234 all_sig_length = []
235+ source_id = []
234236 if self .progress_bar :
235237 chan_loop = trange (nb_sig_chan , desc = "Parsing signal channels" , leave = True )
236238 else :
@@ -242,6 +244,7 @@ def _parse_header(self):
242244 length = self ._data_blocks [5 ][chan_id ]["size" ].sum () // 2
243245 if length == 0 :
244246 continue # channel not added
247+ source_id .append (h ["SrcId" ])
245248 all_sig_length .append (length )
246249 sampling_rate = float (h ["ADFreq" ])
247250 sig_dtype = "int16"
@@ -267,8 +270,9 @@ def _parse_header(self):
267270 # Detect streams
268271 all_sig_length = np .asarray (all_sig_length )
269272
270- # names are WBX, FPX, SPKCX, AI, etc
271- channels_prefixes = np .asarray ([x [:2 ] for x in sig_channels ["name" ]])
273+ # names are WB{number}, FPX{number}, SPKCX{number}, AI{number}, etc
274+ pattern = r"^\D+" # Match any non-digit character at the beginning of the string
275+ channels_prefixes = np .asarray ([re .match (pattern , name ).group (0 ) for name in sig_channels ["name" ]])
272276 buffer_stream_groups = set (zip (channels_prefixes , sig_channels ["sampling_rate" ], all_sig_length ))
273277
274278 # There are explanations of the streams bassed on channel names
@@ -279,7 +283,6 @@ def _parse_header(self):
279283 "FP" : "FPl-Low Pass Filtered " ,
280284 "SP" : "SPKC-High Pass Filtered" ,
281285 "AI" : "AI-Auxiliary Input" ,
282- "V1" : "V1" , # TODO determine, possible video
283286 }
284287
285288 # Using a mapping to ensure consistent order of stream_index
@@ -288,15 +291,14 @@ def _parse_header(self):
288291 "FP" : "1" ,
289292 "SP" : "2" ,
290293 "AI" : "3" ,
291- "V1" : "4" ,
292294 }
293295
294296 signal_streams = []
295297 self ._signal_length = {}
296298 self ._sig_sampling_rate = {}
297299
298300 for stream_index , (channel_prefix , sr , length ) in enumerate (buffer_stream_groups ):
299- stream_name = channel_prefix_to_stream_name [ channel_prefix ]
301+ stream_name = channel_prefix_to_stream_name . get ( channel_prefix , channel_prefix )
300302 stream_id = channel_prefix_to_stream_id [channel_prefix ]
301303
302304 mask = (sig_channels ["sampling_rate" ] == sr ) & (all_sig_length == length )
@@ -389,7 +391,7 @@ def _segment_t_start(self, block_index, seg_index):
389391 def _segment_t_stop (self , block_index , seg_index ):
390392 t_stop = float (self ._last_timestamps ) / self ._global_ssampling_rate
391393 if hasattr (self , "_signal_length" ):
392- for stream_index in self ._signal_length :
394+ for stream_index in self ._signal_length . keys () :
393395 t_stop_sig = self ._signal_length [stream_index ] / self ._sig_sampling_rate [stream_index ]
394396 t_stop = max (t_stop , t_stop_sig )
395397 return t_stop
0 commit comments