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

Downsampling cnmfe parameters in initialization #1219

Open zhouyi0812 opened 1 year ago

zhouyi0812 commented 1 year ago

Hello!

I have a question about the downsampling parameters. I wonder if it is always good to select 1 when my computer has enough memory? Since each time if I choose parameters=1 it took so long to run per movie maybe 2 hours.

I also tried to downsampling to 2 and the different between 1 and 2 I saw is the number of ROIs. Will it impact the quality of the traces?

Thank you!

kushalkolar commented 1 year ago

Are you talking about spatial downsample? You might have to adjust your gSig accordingly as well if you downsample (caiman might do it automatically, I haven't dug into it), and I don't think it's a direct linear downscale w.r.t. gSig, i.e. performing a downscale factor of 2 for both the movie and gSig doesn't give the same results as without downscaling.

EricThomson commented 10 months ago

This is a bit of an art with no one-size-fits-all answer.

If things are too slow on your system, then try some tricks to speed it up. First, I often recommend doing subsampling outside of caiman first on the movie you give to caiman, so you don't have to mess with subsampling params within caiman in which case you have to think about how all the different spatial parameters are related to each other. Then, tweak n_processes and the patch parameters (but watch out for k which is patch-dependent!).

After all this, if cnmf is really slow you can subsample in space/time. if you change ssub then you will need to change gSig.

It could influence the quality of the traces, but generally they will probably be fine (it depends how many pixels you have per component in the subsampled data). This is something you have to test with your data. It has been discussed in a paper: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005685

We need to better document all this, as brought up in another context in #1158

zhouyi0812 commented 10 months ago

Hello! I have a follow up question. I want to downsampling my data and check the contour of the ROI before and after, and may I ask if you know what kind of tool does this plot used to plot all the ROI in this way? Thank you! Screenshot 2024-01-29 171944

EricThomson commented 8 months ago

@zhouyi0812 I thought you had resolved this in #1105 is there something else different here you mean? I think you should be able to plot the spatial footprints with subsampling, and without -- compare them (and compare the results more generally) and see if they look similar enough/good enough for them to be good to work with.