Closed raphaelvallat closed 2 years ago
If the EEG data is flat (at any point) for at least 300 ms, the yasa.spindles_detect function will throw a ZeroDivisionError. This is because of the call to yasa.moving_transform:
yasa.spindles_detect
yasa.moving_transform
https://github.com/raphaelvallat/yasa/blob/a281d556749b3a968f9858b4db9f803186dfabcd/yasa/detection.py#L750-L759
which in turn calls the lower-level numba function yasa.numba._corr:
yasa.numba._corr
https://github.com/raphaelvallat/yasa/blob/a281d556749b3a968f9858b4db9f803186dfabcd/yasa/numba.py#L16-L30
An easy fix for this is to add the following lines to the _corr function:
_corr
if r_den == 0: return np.nan
We then need to make sure that the resulting NaN are correctly handled here:
https://github.com/raphaelvallat/yasa/blob/a281d556749b3a968f9858b4db9f803186dfabcd/yasa/detection.py#L779-L782
If the EEG data is flat (at any point) for at least 300 ms, the
yasa.spindles_detect
function will throw a ZeroDivisionError. This is because of the call toyasa.moving_transform
:https://github.com/raphaelvallat/yasa/blob/a281d556749b3a968f9858b4db9f803186dfabcd/yasa/detection.py#L750-L759
which in turn calls the lower-level numba function
yasa.numba._corr
:https://github.com/raphaelvallat/yasa/blob/a281d556749b3a968f9858b4db9f803186dfabcd/yasa/numba.py#L16-L30
An easy fix for this is to add the following lines to the
_corr
function:We then need to make sure that the resulting NaN are correctly handled here:
https://github.com/raphaelvallat/yasa/blob/a281d556749b3a968f9858b4db9f803186dfabcd/yasa/detection.py#L779-L782