@@ -122,10 +122,27 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea
122122 i_start = 0
123123 if i_stop is None :
124124 i_stop = self ._num_frames
125- if channel_indexes is None :
126- channel_indexes = slice ( None )
125+
126+
127127 data = self ._read_function (self ._filehandle , i_start , i_stop , self ._num_channels )
128- return data [:, channel_indexes ]
128+
129+ # older style data return everything
130+ if data .shape [1 ] != 1 :
131+ if channel_indexes is None :
132+ channel_indexes = slice (None )
133+ sig_chunk = data [:, channel_indexes ]
134+ # newer style data returns an initial flat array
135+ else :
136+ if channel_indexes is None :
137+ channel_indexes = [ch for ch in range (self ._num_channels )]
138+
139+ sig_chunk = np .zeros ((i_stop - i_start , len (channel_indexes )))
140+ # iterate through channels to prevent loading all channels into memory which can cause
141+ # memory exhaustion. See https://github.com/SpikeInterface/spikeinterface/issues/3303
142+ for index , channel_index in enumerate (channel_indexes ):
143+ sig_chunk [:, index ] = data [i_start + channel_index :i_stop + channel_index :self ._num_channels ]
144+
145+ return sig_chunk
129146
130147
131148def open_biocam_file_header (filename ):
@@ -230,7 +247,7 @@ def open_biocam_file_header(filename):
230247 offset = offset ,
231248 )
232249
233-
250+ # return the full array for the old datasets
234251def readHDF5t_100 (rf , t0 , t1 , nch ):
235252 return rf ["3BData/Raw" ][t0 :t1 ]
236253
@@ -239,15 +256,16 @@ def readHDF5t_100_i(rf, t0, t1, nch):
239256 return 4096 - rf ["3BData/Raw" ][t0 :t1 ]
240257
241258
259+ # return flat array that we will iterate through
242260def readHDF5t_101 (rf , t0 , t1 , nch ):
243- return rf ["3BData/Raw" ][nch * t0 : nch * t1 ]. reshape (( t1 - t0 , nch ), order = "C" )
261+ return rf ["3BData/Raw" ][nch * t0 : nch * t1 ]
244262
245263
246264def readHDF5t_101_i (rf , t0 , t1 , nch ):
247- return 4096 - rf ["3BData/Raw" ][nch * t0 : nch * t1 ]. reshape (( t1 - t0 , nch ), order = "C" )
265+ return 4096 - rf ["3BData/Raw" ][nch * t0 : nch * t1 ]
248266
249267
250268def readHDF5t_brw4 (rf , t0 , t1 , nch ):
251269 for key in rf :
252270 if key [:5 ] == "Well_" :
253- return rf [key ]["Raw" ][nch * t0 : nch * t1 ]. reshape (( t1 - t0 , nch ), order = "C" )
271+ return rf [key ]["Raw" ][nch * t0 : nch * t1 ]
0 commit comments