@@ -200,14 +200,14 @@ def open_biocam_file_header(filename):
200200 scale_factor = experiment_settings ["ValueConverter" ]["ScaleFactor" ]
201201 sampling_rate = experiment_settings ["TimeConverter" ]["FrameRate" ]
202202
203- if ' EventsBasedRawRanges' in experiment_settings [' DataSettings' ]:
203+ if " EventsBasedRawRanges" in experiment_settings [" DataSettings" ]:
204204 for key in rf :
205205 if key [:5 ] == "Well_" :
206206 num_channels = len (rf [key ]["StoredChIdxs" ])
207- num_frames = np .array (rf [' TOC' ])[- 1 ][- 1 ]
207+ num_frames = np .array (rf [" TOC" ])[- 1 ][- 1 ]
208208 break
209209 read_function = readHDF5t_brw4_event_based
210-
210+
211211 else :
212212 for key in rf :
213213 if key [:5 ] == "Well_" :
@@ -228,7 +228,6 @@ def open_biocam_file_header(filename):
228228
229229 gain = scale_factor * (max_uv - min_uv ) / (max_digital - min_digital )
230230 offset = min_uv
231-
232231
233232 return dict (
234233 file_handle = rf ,
@@ -241,10 +240,11 @@ def open_biocam_file_header(filename):
241240 offset = offset ,
242241 )
243242
243+
244244def GenerateSyntheticNoise_arr (file , wellID , startFrame , endFrame , numFrames , n_channels ):
245245 # collect the TOCs
246- toc = np .array (file [' TOC' ])
247- noiseToc = np .array (file [wellID + ' /NoiseTOC' ])
246+ toc = np .array (file [" TOC" ])
247+ noiseToc = np .array (file [wellID + " /NoiseTOC" ])
248248 # from the given start position in frames, localize the corresponding noise positions
249249 # using the TOC
250250 tocStartIdx = np .searchsorted (toc [:, 1 ], startFrame )
@@ -264,9 +264,9 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
264264 break
265265
266266 # obtain the noise info at the start position
267- noiseChIdxs = file [wellID + ' /NoiseChIdxs' ][noiseStartPosition :noiseEndPosition ]
268- noiseMean = file [wellID + ' /NoiseMean' ][noiseStartPosition :noiseEndPosition ]
269- noiseStdDev = file [wellID + ' /NoiseStdDev' ][noiseStartPosition :noiseEndPosition ]
267+ noiseChIdxs = file [wellID + " /NoiseChIdxs" ][noiseStartPosition :noiseEndPosition ]
268+ noiseMean = file [wellID + " /NoiseMean" ][noiseStartPosition :noiseEndPosition ]
269+ noiseStdDev = file [wellID + " /NoiseStdDev" ][noiseStartPosition :noiseEndPosition ]
270270 noiseLength = noiseEndPosition - noiseStartPosition
271271
272272 noiseInfo = {}
@@ -287,60 +287,65 @@ def GenerateSyntheticNoise_arr(file, wellID, startFrame, endFrame, numFrames, n_
287287
288288 for chIdx in range (n_channels ):
289289 if chIdx in noiseInfo :
290- arr [:,chIdx ] = np .array (np .random .normal (noiseInfo [chIdx ][0 ], noiseInfo [chIdx ][1 ],numFrames ), dtype = np .int16 )
290+ arr [:, chIdx ] = np .array (
291+ np .random .normal (noiseInfo [chIdx ][0 ], noiseInfo [chIdx ][1 ], numFrames ), dtype = np .int16
292+ )
291293 else :
292- arr [:,chIdx ] = np .array (np .random .normal (dataMean , dataStdDev , numFrames ),dtype = np .int16 )
294+ arr [:, chIdx ] = np .array (np .random .normal (dataMean , dataStdDev , numFrames ), dtype = np .int16 )
293295
294296 return arr
295297
298+
296299def DecodeEventBasedRawData_arr (rf , wellID , t0 , t1 , nch ):
297300
298- toc = np .array (rf [' TOC' ]) # Main table of contents
299- eventsToc = np .array (rf [wellID + ' /EventsBasedSparseRawTOC' ]) # Events table of contents
301+ toc = np .array (rf [" TOC" ]) # Main table of contents
302+ eventsToc = np .array (rf [wellID + " /EventsBasedSparseRawTOC" ]) # Events table of contents
300303
301304 # Only select the chunks in the desired range
302305 tocStartIdx = np .searchsorted (toc [:, 1 ], t0 )
303- tocEndIdx = min (np .searchsorted (toc [:, 1 ], t1 , side = ' right' ) + 1 , len (toc ) - 1 )
306+ tocEndIdx = min (np .searchsorted (toc [:, 1 ], t1 , side = " right" ) + 1 , len (toc ) - 1 )
304307 eventsStartPosition = eventsToc [tocStartIdx ]
305308 eventsEndPosition = eventsToc [tocEndIdx ]
306309
307310 numFrames = t1 - t0
308311
309- binaryData = rf [wellID + ' /EventsBasedSparseRaw' ][eventsStartPosition :eventsEndPosition ]
312+ binaryData = rf [wellID + " /EventsBasedSparseRaw" ][eventsStartPosition :eventsEndPosition ]
310313 binaryDataLength = len (binaryData )
311314
312315 synth = True
313316
314317 if synth :
315318 arr = GenerateSyntheticNoise_arr (rf , wellID , t0 , t1 , numFrames , nch )
316-
319+
317320 else :
318321 arr = np .zeros ((numFrames , nch ))
319322
320323 pos = 0
321324 while pos < binaryDataLength :
322- chIdx = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = ' little' , signed = True )
325+ chIdx = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = " little" , signed = True )
323326 pos += 4
324- chDataLength = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = ' little' , signed = True )
327+ chDataLength = int .from_bytes (binaryData [pos : pos + 4 ], byteorder = " little" , signed = True )
325328 pos += 4
326329 chDataPos = pos
327330 while pos < chDataPos + chDataLength :
328- fromInclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = ' little' , signed = True )
331+ fromInclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = " little" , signed = True )
329332 pos += 8
330- toExclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = ' little' , signed = True )
333+ toExclusive = int .from_bytes (binaryData [pos : pos + 8 ], byteorder = " little" , signed = True )
331334 pos += 8
332335 rangeDataPos = pos
333336 for j in range (fromInclusive , toExclusive ):
334- if j >= t0 + numFrames :
337+ if j >= t0 + numFrames :
335338 break
336339 if j >= t0 :
337- arr [j - t0 ,chIdx ] = int .from_bytes (
338- binaryData [rangeDataPos :rangeDataPos + 2 ], byteorder = 'little' , signed = True )
340+ arr [j - t0 , chIdx ] = int .from_bytes (
341+ binaryData [rangeDataPos : rangeDataPos + 2 ], byteorder = "little" , signed = True
342+ )
339343 rangeDataPos += 2
340344 pos += (toExclusive - fromInclusive ) * 2
341345
342346 return arr
343347
348+
344349def readHDF5t_100 (rf , t0 , t1 , nch ):
345350 return rf ["3BData/Raw" ][t0 :t1 ]
346351
@@ -361,7 +366,8 @@ def readHDF5t_brw4(rf, t0, t1, nch):
361366 for key in rf :
362367 if key [:5 ] == "Well_" :
363368 return rf [key ]["Raw" ][nch * t0 : nch * t1 ].reshape ((t1 - t0 , nch ), order = "C" )
364-
369+
370+
365371def readHDF5t_brw4_event_based (rf , t0 , t1 , nch ):
366372 for key in rf :
367373 if key [:5 ] == "Well_" :
0 commit comments