Open ethanbb opened 3 months ago
Looking a little closer, I think there is at least one other issue with this code block. Initializing "meanImg" to 0 in the if iall == 0
block happens for the 2nd channel as well, meaning that the first 500 frames of the first channel get lost.
I think something like the following would fix it, happy to make a pull request if it makes sense:
for ichunk, onset in enumerate(iblocks[:-1]):
offset = iblocks[ichunk + 1]
im = np.array(f[onset:offset, :, :, ndeadrows:, ndeadcols:]) // 2
im = im.astype(np.int16)
im2mean = im.mean(axis=0).astype(np.float32) / len(iblocks)
for ichan in range(nchannels):
nframes = im.shape[0]
im2write = im[:, :, ichan, :, :]
for j in range(0, nplanes):
if ichan == nfunc:
if iall == 0:
ops1[j]["meanImg"] = np.zeros((im.shape[3], im.shape[4]), np.float32)
ops1[j]["nframes"] = 0
ops1[j]["meanImg"] += np.squeeze(im2mean[j, ichan, :,
ops1[j]["nframes"] += im2write.shape[0]
ops1[j]["nframes_per_folder"][ifile] += im2write.shape[0]
reg_file[j].write(bytearray(im2write[:, j, :, :].astype("int16")))
else:
if iall == 0:
ops1[j]["meanImg_chan2"] = np.zeros(
(im.shape[3], im.shape[4]), np.float32)
ops1[j]["meanImg_chan2"] += np.squeeze(im2mean[j, ichan, :, :])
reg_file_chan2[j].write(
bytearray(im2write[:, j, :, :].astype("int16")))
iall += nframes
Describe the issue:
There seems to be a bug in the way frames are counted when loading one or more Scanbox files. From sbx.py:
Note that
ops1[j]["nframes"]
(which becomesops['nframes']
) is updated with the number of frames in the current chunk once per channel, whereas it should be independent of the number of channels. The exception is for the first chunk, whereiall
is still 0 for each iteration of theichan
loop, soops1[j]["nframes"]
gets reset to 0 for each iteration of this inner loop. Thus, there is only a bug when the total number of frames is greater than the chunk size, which defaults to 500.Please use the files here to replicate with the code example: https://drive.google.com/drive/folders/1xJ6zG52rMNEKHAN5856KW8PQeeWjxFAB?usp=drive_link
Reproduce the code example:
Error message:
Version information:
suite2p v0.14.4.dev32+gf500c1a.d20240311
Context for the issue:
This doesn't cause an error message when running the pipeline, but it may cause some of the processing steps to give incorrect results (haven't looked into it). It caused an error in a script I wrote for manual cropping when I tried to use
nframes
from the returnedops
to determine how large of aBinaryFile
I needed.