flatironinstitute / CaImAn-MATLAB

Complete Matlab pipeline for large scale calcium imaging data analysis
GNU General Public License v2.0
252 stars 147 forks source link

Error in CNM.fitPatches #77

Closed JSignoretGenest closed 6 years ago

JSignoretGenest commented 6 years ago

Hi,

I've encountered an error while trying to run the demo_patches_class on a motion corrected endoscope movie (300x300x1000 frames), and more precisely:

Error using kde>fixed_point (line 114)
Matrix dimensions must agree.

Error in kde>@(t)fixed_point(t,N,I,a2) (line 82)
t_star=root(@(t)fixed_point(t,N,I,a2),N);

Error in kde>@(x)abs(f(x)) (line 166)
        t=fminbnd(@(x)abs(f(x)),0,.1); flag=1;

Error in fminbnd (line 228)
x= xf; fx = funfcn(x,varargin{:});

Error in kde>root (line 166)
        t=fminbnd(@(x)abs(f(x)),0,.1); flag=1;

Error in kde (line 82)
t_star=root(@(t)fixed_point(t,N,I,a2),N);

Error in trace_fit_extreme (line 12)
    [~,density,xmesh] = kde(C(i,:));

Error in classify_components (line 43)
max_pr = trace_fit_extreme(full(traces),fr,t_int,sn_fac);

Error in CNMF/evaluateComponents (line 255)
            [obj.rval_space,obj.rval_time,obj.max_pr,obj.sizeA,obj.keep_eval] = classify_components(...

Error in CNMF/fit (line 395)
            obj.evaluateComponents();

Error in run_CNMF_patches>process_patch_object (line 386)
    CNM.fit(Y,options,K);

Error in run_CNMF_patches (line 105)
    parfor i = 1:n_patches

Error in CNMF/fitPatches (line 416)
                run_CNMF_patches(obj.Y,obj.K,obj.patches,obj.gSig,obj.p,obj.options);

The error was in kde, but the problem seems to be the "data" input: in the faulty calls, there are some Inf values inside (kde runs just fine on some patches, but displays the error on some others, and it changes depending on the patch size).

As far as I could check by looking at the data size and the presence of Inf/NaN values along the chain, the problem seems to appear during a call to detrend_df_f (after the call, the matrices contain NaN and Inf values), but I am unable to solve the issue.

Thank you for your help!

epnev commented 6 years ago

@JeSiggen I looked into it. kde will fail if your traces contain Inf values but it can tolerate a moderate amount of NaN values. the problem is more general with the df/f in micro-endoscopic data. In general this should be avoided since the background signal is very strong there and dominated from out of focus fluorescence (and not baseline fluorescence where a DF/F transformation would make change). I suggest you omit this step in your analysis.

JSignoretGenest commented 6 years ago

Thanks for the answer. I disabled both the DF/F and the corresponding "trace_fit_extreme", it now reaches the end (the results are a bit strange, but I'll play with the parameters to see if it gets better).

epnev commented 6 years ago

@JeSiggen Thanks. Bear in mind that the CNMF-E package from Pengcheng Zhou is better suited for micro-endoscopic data although several people have reported good results with this package as well.