Skip to content

CaImAn with manual seed - bug in reading dimensions? #1540

@manuelbettencourt-cpu

Description

@manuelbettencourt-cpu

Hi, I've been trying to run CaImAn with manual seeding because my experiments are with nuclear-GCaMP indicators and I wanted to check wether running StarDist to segment the mean-intensity projections and then using those identified rois as a seed for caiman would work best than just running caiman. However, I keep running into a problem with how cnmf is internally reading the image dimensions for the background calculation (i believe?). Here's the error:

IndexError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_14176\2923983241.py in
35 print("Running CNMF on single plane...")
36 t0 = t.time()
---> 37 cnm_seeded.fit(imgs);
38 t1 = t.time()
39 print(f"CNMF finished in {(t1 - t0):.2f} seconds")

~\miniforge3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\cnmf.py in fit(self, images, indices)
542
543 logging.info('update spatial ...')
--> 544 self.update_spatial(Yr, use_init=True)
545
546 logging.info('update temporal ...')

~\miniforge3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\cnmf.py in update_spatial(self, Y, use_init, **kwargs)
936 update_spatial_components(Y, C=self.estimates.C, f=self.estimates.f, A_in=self.estimates.A,
937 b_in=self.estimates.b, dview=self.dview,
--> 938 sn=self.estimates.sn, dims=self.dims, **self.params.get_group('spatial'))
939
940 return self

~\miniforge3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\spatial.py in update_spatial_components(Y, C, f, A_in, sn, dims, min_size, max_size, dist, normalize_yyt_one, method_exp, expandCore, dview, n_pixels_per_process, medw, thr_method, maxthr, nrgthr, extract_cc, b_in, se, ss, nb, method_ls, update_background_components, low_rank_background, block_size_spat, num_blocks_per_run_spat)
186 # we compute the indicator from distance indicator
187 ind2_, nr, C, f, b_, A_in = computing_indicator(
--> 188 Y, A_in, b_in, C, f, nb, method_exp, dims, min_size, max_size, dist, expandCore, dview)
189
190 # remove components that are empty or have a nan

~\miniforge3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\spatial.py in computing_indicator(Y, A_in, b, C, f, nb, method, dims, min_size, max_size, dist, expandCore, dview)
1063 else:
1064 if Y.shape[-1] < 30000:
-> 1065 f = Y[not_px, :].mean(0)
1066 else:
1067 print('estimating f')

~\miniforge3\envs\caiman\lib\site-packages\numpy\core\memmap.py in getitem(self, index)
332
333 def getitem(self, index):
--> 334 res = super().getitem(index)
335 if type(res) is memmap and res._mmap is None:
336 return res.view(type=ndarray)

IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed

Originally, I was inputting it a reshaped memmap, because this was the way I got it to work in the seedless version:

Yr, dims, T = cm.load_memmap(input_memmap)
d1, d2 = dims
imgs = Yr.T.reshape((T, d1, d2),  order='F')  # (frames, height, width)

I've tried running it with many many changes in input to see if i could work around this, but unsucessfuly. These included changing the format (to tiff, caiman movie, numpy array or directly giving the memmap) and in organization ((frames, height width) or (heigh, width, frames)), giving it the dimensions directly with cnm.dims = (height, width), and several other tries. I also tried to set nb to 0 because it seems it's a background estimation related problem, but it also didn't work. Is this a bug in the source code?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions