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

Handle problem with dff auto-percentile calculation #1288

Closed EricThomson closed 9 months ago

EricThomson commented 9 months ago

Description

When flag_auto was set to True in dff calculation, there was a significant chance that things could end up in an infinite while loop.

In the kernel density estimator, an exception which was rarely thrown was exposed recently with some scipy deprecations, so this has started happening a lot lately. It was handled previously with printing 'oops' and returning None. This PR fixes that, stops the while loop from recurring indefinitely. The basic logic wasn't terrible it's fine to use try/except blocks as control elements in Python, it's just a bad idea to let them go on indefintely. I patched that up, found the explicit exception, and tried to make the logic a little more clear.

Fixes # (issue)

1262 , #1274 , #1283

Type of change

Has your PR been tested?

caimanmanager test ran fine (demotest is currently running will report back if any problems).

I pushed pretty hard against the detrend_df_f() function in the two main demo notebooks with different permutations of the kwargs. It behaved as expected with the logger outputting reasonable warnings (e.g., when using short time windows for percentiles).