neuropsychology / NeuroKit

NeuroKit2: The Python Toolbox for Neurophysiological Signal Processing
https://neuropsychology.github.io/NeuroKit
MIT License
1.46k stars 397 forks source link

NumPy DeprecationWarning thrown in `neurokit2.signal.signal_filter._signal_filter_butterworth` #997

Open MarcBalle opened 3 weeks ago

MarcBalle commented 3 weeks ago

Describe the bug When running neurokit2.ecg_clean there is the following numpy deprecation warning: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

Debugging into it, I suspect that the error happens when calling scipy.signal.butter in neurokit2.signal.signal_filter._signal_filter_butterworth. The Wn argument in scipy.signal.butter should be a scalar when btype is lowpass or highpass, but in this case freqs is a list.

To Reproduce

  1. Install neurokit2==0.2.9, scipy==1.13.1, numpy==1.26.4
  2. Run neurokit2.ecg_clean(ecg_signal=np.random.rand(20), sampling_rate=300.0, method="neurokit") (I use a random sequence here, but it is enough to reproduce the error. It also happens with an actual ecg signal)

System Specifications

Running on Windows 10, python 3.9.18. Example:

import neurokit2 as nk
nk.ecg_clean(np.random.rand(20), sampling_rate=300.0, method="neurokit")

Warning: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)

welcome[bot] commented 3 weeks ago

Hi 👋 Thanks for reaching out and opening your first issue here! We'll try to come back to you as soon as possible. ❤️ kenobi

DominiqueMakowski commented 3 weeks ago

Hi @MarcBalle thanks! Would you mind making a PR to address this?

MarcBalle commented 3 weeks ago

@DominiqueMakowski Done :)