You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Given a short respiration signal in which only one peak is detected, a ValueError is raised by rsp_process() when interpolating the amplitude to match the signal length (since there is only one amplitude value corresponding to the single peak detected).
error log
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
[<ipython-input-4-b24b2adbbe1f>](https://localhost:8080/#) in <module>---->1nk.rsp_process(rsp, sampling_rate=sampling_rate)
[/usr/local/lib/python3.7/dist-packages/neurokit2/rsp/rsp_process.py](https://localhost:8080/#) in rsp_process(rsp_signal, sampling_rate, method)80# Get additional parameters81phase=rsp_phase(peak_signal, desired_length=len(rsp_signal))
--->82amplitude=rsp_amplitude(rsp_cleaned, peak_signal)
83rate=signal_rate(info["RSP_Troughs"], sampling_rate=sampling_rate, desired_length=len(rsp_signal))
84
[/usr/local/lib/python3.7/dist-packages/neurokit2/rsp/rsp_amplitude.py](https://localhost:8080/#) in rsp_amplitude(rsp_cleaned, peaks, troughs, interpolation_method)75# Interpolate amplitude to length of rsp_cleaned.76amplitude=signal_interpolate(
--->77peaks, amplitude, x_new=np.arange(len(rsp_cleaned)), method=interpolation_method78 )
79
[/usr/local/lib/python3.7/dist-packages/neurokit2/signal/signal_interpolate.py](https://localhost:8080/#) in signal_interpolate(x_values, y_values, x_new, method, fill_value)95ifmethod=="monotone_cubic":
96interpolation_function=scipy.interpolate.PchipInterpolator(
--->97x_values, y_values, extrapolate=True98 )
99else:
[/usr/local/lib/python3.7/dist-packages/scipy/interpolate/_cubic.py](https://localhost:8080/#) in __init__(self, x, y, axis, extrapolate)230 """
231 def __init__(self, x, y, axis=0, extrapolate=None):
--> 232 x, _, y, axis, _ = prepare_input(x, y, axis)
233 xp = x.reshape((x.shape[0],) + (1,)*(y.ndim-1))
234 dk = self._find_derivatives(xp, y)
[/usr/local/lib/python3.7/dist-packages/scipy/interpolate/_cubic.py](https://localhost:8080/#) in prepare_input(x, y, axis, dydx)
44 raise ValueError("`x` must be 1-dimensional.")
45 if x.shape[0] < 2:
---> 46 raise ValueError("`x` must contain at least 2 elements.")
47 if x.shape[0] != y.shape[axis]:
48 raise ValueError("The length of `y` along `axis`={0} doesn't "
ValueError: `x`mustcontainatleast2elements.
Expected behaviour
I assume that rather than raising an error, we would like to return the single amplitude value, just repeated so that it matched the signal length.
Describe the bug
Given a short respiration signal in which only one peak is detected, a ValueError is raised by
rsp_process()
when interpolating the amplitude to match the signal length (since there is only one amplitude value corresponding to the single peak detected).error log
To Reproduce
System Specifications
Expected behaviour
I assume that rather than raising an error, we would like to return the single amplitude value, just repeated so that it matched the signal length.
Suggestion
Modify the following lines in
rsp_amplitude()
such that if there is only one peak detected, the amplitude value will be repeated:https://github.com/neuropsychology/NeuroKit/blob/dev/neurokit2/rsp/rsp_amplitude.py#L75-L78
Let me know your thoughts & I'll submit a PR!
The text was updated successfully, but these errors were encountered: