@@ -198,14 +198,14 @@ def open_biocam_file_header(filename):
198198 scale_factor = experiment_settings ["ValueConverter" ]["ScaleFactor" ]
199199 sampling_rate = experiment_settings ["TimeConverter" ]["FrameRate" ]
200200
201- if ' EventsBasedRawRanges' in experiment_settings [' DataSettings' ]:
201+ if " EventsBasedRawRanges" in experiment_settings [" DataSettings" ]:
202202 for key in rf :
203203 if key [:5 ] == "Well_" :
204204 num_channels = len (rf [key ]["StoredChIdxs" ])
205- num_frames = np .array (rf [' TOC' ])[- 1 ][- 1 ]
205+ num_frames = np .array (rf [" TOC" ])[- 1 ][- 1 ]
206206 break
207207 read_function = readHDF5t_brw4_event_based
208-
208+
209209 else :
210210 for key in rf :
211211 if key [:5 ] == "Well_" :
@@ -226,7 +226,6 @@ def open_biocam_file_header(filename):
226226
227227 gain = scale_factor * (max_uv - min_uv ) / (max_digital - min_digital )
228228 offset = min_uv
229-
230229
231230 return dict (
232231 file_handle = rf ,
@@ -239,10 +238,11 @@ def open_biocam_file_header(filename):
239238 offset = offset ,
240239 )
241240
241+
242242def GenerateSyntheticNoise_arr (file , wellID , startFrame , endFrame , numFrames , n_channels ):
243243 # collect the TOCs
244- toc = np .array (file [' TOC' ])
245- noiseToc = np .array (file [wellID + ' /NoiseTOC' ])
244+ toc = np .array (file [" TOC" ])
245+ noiseToc = np .array (file [wellID + " /NoiseTOC" ])
246246 # from the given start position in frames, localize the corresponding noise positions
247247 # using the TOC
248248 tocStartIdx = np .searchsorted (toc [:, 1 ], startFrame )
@@ -262,9 +262,9 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
262262 break
263263
264264 # obtain the noise info at the start position
265- noiseChIdxs = file [wellID + ' /NoiseChIdxs' ][noiseStartPosition :noiseEndPosition ]
266- noiseMean = file [wellID + ' /NoiseMean' ][noiseStartPosition :noiseEndPosition ]
267- noiseStdDev = file [wellID + ' /NoiseStdDev' ][noiseStartPosition :noiseEndPosition ]
265+ noiseChIdxs = file [wellID + " /NoiseChIdxs" ][noiseStartPosition :noiseEndPosition ]
266+ noiseMean = file [wellID + " /NoiseMean" ][noiseStartPosition :noiseEndPosition ]
267+ noiseStdDev = file [wellID + " /NoiseStdDev" ][noiseStartPosition :noiseEndPosition ]
268268 noiseLength = noiseEndPosition - noiseStartPosition
269269
270270 noiseInfo = {}
@@ -285,60 +285,65 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
285285
286286 for chIdx in range (n_channels ):
287287 if chIdx in noiseInfo :
288- arr [:,chIdx ] = np .array (np .random .normal (noiseInfo [chIdx ][0 ], noiseInfo [chIdx ][1 ],numFrames ), dtype = np .int16 )
288+ arr [:, chIdx ] = np .array (
289+ np .random .normal (noiseInfo [chIdx ][0 ], noiseInfo [chIdx ][1 ], numFrames ), dtype = np .int16
290+ )
289291 else :
290- arr [:,chIdx ] = np .array (np .random .normal (dataMean , dataStdDev , numFrames ),dtype = np .int16 )
292+ arr [:, chIdx ] = np .array (np .random .normal (dataMean , dataStdDev , numFrames ), dtype = np .int16 )
291293
292294 return arr
293295
296+
294297def DecodeEventBasedRawData_arr (rf , wellID , t0 , t1 , nch ):
295298
296- toc = np .array (rf [' TOC' ]) # Main table of contents
297- eventsToc = np .array (rf [wellID + ' /EventsBasedSparseRawTOC' ]) # Events table of contents
299+ toc = np .array (rf [" TOC" ]) # Main table of contents
300+ eventsToc = np .array (rf [wellID + " /EventsBasedSparseRawTOC" ]) # Events table of contents
298301
299302 # Only select the chunks in the desired range
300303 tocStartIdx = np .searchsorted (toc [:, 1 ], t0 )
301- tocEndIdx = min (np .searchsorted (toc [:, 1 ], t1 , side = ' right' ) + 1 , len (toc ) - 1 )
304+ tocEndIdx = min (np .searchsorted (toc [:, 1 ], t1 , side = " right" ) + 1 , len (toc ) - 1 )
302305 eventsStartPosition = eventsToc [tocStartIdx ]
303306 eventsEndPosition = eventsToc [tocEndIdx ]
304307
305308 numFrames = t1 - t0
306309
307- binaryData = rf [wellID + ' /EventsBasedSparseRaw' ][eventsStartPosition :eventsEndPosition ]
310+ binaryData = rf [wellID + " /EventsBasedSparseRaw" ][eventsStartPosition :eventsEndPosition ]
308311 binaryDataLength = len (binaryData )
309312
310313 synth = True
311314
312315 if synth :
313316 arr = GenerateSyntheticNoise_arr (rf , wellID , t0 , t1 , numFrames , nch )
314-
317+
315318 else :
316319 arr = np .zeros ((numFrames , nch ))
317320
318321 pos = 0
319322 while pos < binaryDataLength :
320- chIdx = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = ' little' , signed = True )
323+ chIdx = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = " little" , signed = True )
321324 pos += 4
322- chDataLength = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = ' little' , signed = True )
325+ chDataLength = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = " little" , signed = True )
323326 pos += 4
324327 chDataPos = pos
325328 while pos < chDataPos + chDataLength :
326- fromInclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = ' little' , signed = True )
329+ fromInclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = " little" , signed = True )
327330 pos += 8
328- toExclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = ' little' , signed = True )
331+ toExclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = " little" , signed = True )
329332 pos += 8
330333 rangeDataPos = pos
331334 for j in range (fromInclusive , toExclusive ):
332- if j >= t0 + numFrames :
335+ if j >= t0 + numFrames :
333336 break
334337 if j >= t0 :
335- arr [j - t0 ,chIdx ] = int .from_bytes (
336- binaryData [rangeDataPos :rangeDataPos + 2 ], byteorder = 'little' , signed = True )
338+ arr [j - t0 , chIdx ] = int .from_bytes (
339+ binaryData [rangeDataPos : rangeDataPos + 2 ], byteorder = "little" , signed = True
340+ )
337341 rangeDataPos += 2
338342 pos += (toExclusive - fromInclusive ) * 2
339343
340344 return arr
341345
346+
342347def readHDF5t_100 (rf , t0 , t1 , nch ):
343348 return rf ["3BData/Raw" ][t0 :t1 ]
344349
@@ -359,7 +364,8 @@ def readHDF5t_brw4(rf, t0, t1, nch):
359364 for key in rf :
360365 if key [:5 ] == "Well_" :
361366 return rf [key ]["Raw" ][nch * t0 : nch * t1 ].reshape ((t1 - t0 , nch ), order = "C" )
362-
367+
368+
363369def readHDF5t_brw4_event_based (rf , t0 , t1 , nch ):
364370 for key in rf :
365371 if key [:5 ] == "Well_" :
0 commit comments