CaImAn icon indicating copy to clipboard operation
CaImAn copied to clipboard

Fixes infinite values in SNR

Open pseudomanu opened this issue 2 months ago • 6 comments

Description

SNR_comp sometimes contains inf values, probably due to some "bad" components having a trace at 0 except for one event. One problem is that it breaks Mesmerize viz' SNR sliders.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Has your PR been tested?

Yes.

The code just adds a line in estimates.py to check for inf values in SNR, in addition to NaN, and replace them by 0. Another options discussed previously is to replace by the max non-inf value of those traces. We decided against it eventually, but here's the code, just in case anyone is interested:

if np.any(np.isinf(SNR_comp)):
    logging.warning('inf values detected for trace SNR in {}'.format(np.where(np.isinf(SNR_comp))[0]) +
                    '. Changing their value to max SNR value.')
    # find the maximum SNR value that is not inf
    max_SNR = np.max(SNR_comp[np.isfinite(SNR_comp)])
    print('max non-inf SNR value: {}'.format(max_SNR))
    # replace inf values with the maximum SNR value
    SNR_comp = np.where(np.isinf(SNR_comp), max_SNR, SNR_comp)

pseudomanu avatar Apr 10 '24 14:04 pseudomanu