@@ -121,8 +121,9 @@ def _parse_header(self):
121121 # signals zone
122122 # create signals channel map: several channel per stream
123123 signal_channels = []
124+
124125 for stream_index , stream_name in enumerate (sig_stream_names ):
125- # stream_index is the index in vector sytream names
126+ # stream_index is the index in vector stream names
126127 stream_id = str (stream_index )
127128 buffer_id = stream_id
128129 info = self ._sig_streams [0 ][0 ][stream_index ]
@@ -132,37 +133,66 @@ def _parse_header(self):
132133 if "SYNC" in chan_id and not self .load_sync_channel :
133134 # the channel is removed from stream but not the buffer
134135 stream_id = ""
136+
135137 if chan_info ["units" ] == "" :
136138 # in some cases for some OE version the unit is "", but the gain is to "uV"
137139 units = "uV"
138140 else :
139141 units = chan_info ["units" ]
142+
143+ if "ADC" in chan_id :
144+ # These are non-neural channels and their stream should be separated
145+ # We defined their stream_id as the stream_index of neural data plus the number of neural streams
146+ # This is to not break backwards compatbility with the stream_id numbering
147+ stream_id = str (stream_index + len (sig_stream_names ))
148+ # For ADC channels multiplying by the bit_volts whe un units are not provided converts to Volts
149+ units = "V" if units == "" else units
150+
151+ gain = chan_info ["bit_volts" ]
152+ offset = 0.0
140153 new_channels .append (
141154 (
142155 chan_info ["channel_name" ],
143156 chan_id ,
144157 float (info ["sample_rate" ]),
145158 info ["dtype" ],
146159 units ,
147- chan_info [ "bit_volts" ] ,
148- 0.0 ,
160+ gain ,
161+ offset ,
149162 stream_id ,
150163 buffer_id ,
151164 )
152165 )
153166 signal_channels .extend (new_channels )
167+
154168 signal_channels = np .array (signal_channels , dtype = _signal_channel_dtype )
155169
156170 signal_streams = []
157171 signal_buffers = []
158- for stream_index , stream_name in enumerate (sig_stream_names ):
159- stream_id = str (stream_index )
160- buffer_id = str (stream_index )
161- signal_buffers .append ((stream_name , buffer_id ))
172+
173+ unique_streams_ids = np .unique (signal_channels ["stream_id" ])
174+ for stream_id in unique_streams_ids :
175+ # Handle special case of Synch channel having stream_id empty
176+ if stream_id == "" :
177+ continue
178+ stream_index = int (stream_id )
179+ # Neural signal
180+ if stream_index < len (sig_stream_names ):
181+ stream_name = sig_stream_names [stream_index ]
182+ buffer_id = stream_id
183+ # We add the buffers here as both the neural and the ADC channels are in the same buffer
184+ signal_buffers .append ((stream_name , buffer_id ))
185+ else : # This names the ADC streams
186+ neural_stream_index = stream_index - len (sig_stream_names )
187+ neural_stream_name = sig_stream_names [neural_stream_index ]
188+ stream_name = f"{ neural_stream_name } _ADC"
189+ buffer_id = str (neural_stream_index )
162190 signal_streams .append ((stream_name , stream_id , buffer_id ))
191+
163192 signal_streams = np .array (signal_streams , dtype = _signal_stream_dtype )
164193 signal_buffers = np .array (signal_buffers , dtype = _signal_buffer_dtype )
165194
195+
166196 # create memmap for signals
167197 self ._buffer_descriptions = {}
168198 self ._stream_buffer_slice = {}
@@ -431,6 +461,8 @@ def _channels_to_group_id(self, channel_indexes):
431461 return group_id
432462
433463 def _get_signal_t_start (self , block_index , seg_index , stream_index ):
464+ if stream_index >= len (self ._sig_streams [block_index ][seg_index ]):
465+ stream_index = stream_index - len (self ._sig_streams [block_index ][seg_index ])
434466 t_start = self ._sig_streams [block_index ][seg_index ][stream_index ]["t_start" ]
435467 return t_start
436468
0 commit comments