neuropsychology / NeuroKit

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

ValueError when Running rsp_rvt #996

Open rcmdnk opened 5 months ago

rcmdnk commented 5 months ago

When running rsp_process on my sample, I encountered the following error:

ValueError: Number of samples, -1, must be non-negative.

This error occurs during the RVT calculation, and I discovered that fr_phase has the same values around the corresponding indexes in _rsp_rvt_harrison . By applying the following patch to _rsp_rvt_find_min, the error is resolved:

--- a/neurokit2/rsp/rsp_rvt.py
+++ b/neurokit2/rsp/rsp_rvt.py
@@ -325,7 +325,7 @@ def _rsp_rvt_find_min(increase_inds, fr_phase, smaller_index, silent):
     n_min = increase_inds[bigger_n_max]
     fr_min = fr_phase[n_min].squeeze()
     # Sometime fr_min is the same as n_max and it caused problems
-    if fr_phase[smaller_index].squeeze() < fr_min:
+    if fr_phase[smaller_index].squeeze() <= fr_min:
         if not silent:
             warn(
                 "rsp_rvt(): The next bigger increasing index has a bigger value than the chosen decreasing index, "

But the code contains the following comment:

# Sometime fr_min is the same as n_max and it caused problems
welcome[bot] commented 5 months 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