flatironinstitute / CaImAn

Computational toolbox for large scale Calcium Imaging Analysis, including movie handling, motion correction, source extraction, spike deconvolution and result visualization.
https://caiman.readthedocs.io
GNU General Public License v2.0
640 stars 370 forks source link

"ValueError: operands could not be broadcast...." in components_evaluation.py: 324 when `method_init` set to `corr_pnr` #807

Closed ajkswamy closed 4 years ago

ajkswamy commented 4 years ago

For better support, please use the template below to submit your issue. When your issue gets resolved please remember to close it.

Sometimes errors while running CNMF occur during parallel processing which prevents the log to provide a meaningful error message. Please reproduce your error with setting dview=None.

If you need to upgrade CaImAn follow the instructions given in the documentation.

Code:

import caiman
import numpy as np

fname_new = "tmpy4htcouu_d1_106_d2_153_d3_1_order_C_frames_576_.mmap"
Yr, dims, T = caiman.load_memmap(fname_new)
images = np.reshape(Yr.T, [T] + list(dims), order='F')

c, dview, n_processes = caiman.cluster.setup_cluster(
    backend='local', n_processes=None, single_thread=False)

opts = caiman.source_extraction.cnmf.params.CNMFParams(params_dict={"method_init": "corr_pnr"})

cnm = caiman.source_extraction.cnmf.CNMF(n_processes, params=opts, dview=dview)

cnm = cnm.fit(images)

cnm2 = cnm.refit(images, dview=dview)

cnm2.estimates.evaluate_components(images, cnm2.params, dview=dview)
j-friedrich commented 4 years ago

With your parameter settings no components have been detected, therefore evaluate_components fails. Please use parameters that are appropriate for your dataset. When using corr_pnr as initialization method (usually used for microendoscopic 1p data) the crucial parameters controlling the number of detected components are min_pnr and min_corr, cf. https://github.com/flatironinstitute/CaImAn/blob/master/demos/notebooks/demo_pipeline_cnmfE.ipynb

ajkswamy commented 4 years ago

Thank you for diagnosing the problem and for the advice. I will check if setting these parameters help. Otherwise, I will reopen the issue.