Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions NEWS.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
News
=====

0.2.14
-------------------
Fixes
+++++++++++++

* ``eda_process()`` now forwards a custom ``amplitude_min`` to ``eda_peaks()``
instead of hardcoding ``0.1`` (#1197).

0.2.8
-------------------
New Features
Expand Down Expand Up @@ -230,6 +238,3 @@ Fixes
-------------------

* First release on PyPI.



4 changes: 2 additions & 2 deletions neurokit2/eda/eda_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def eda_methods(
method_phasic = str(method).lower() if method_phasic == "default" else str(method_phasic).lower()
method_peaks = str(method).lower() if method_peaks == "default" else str(method_peaks).lower()

# Create dictionary with all inputs
# Unpack user kwargs so get_kwargs() can forward them (same pattern as rsp_methods).
report_info = {
"sampling_rate": sampling_rate,
"method_cleaning": method_cleaning,
"method_phasic": method_phasic,
"method_peaks": method_peaks,
"kwargs": kwargs,
**kwargs,
}

# Get arguments to be passed to underlying functions
Expand Down
10 changes: 6 additions & 4 deletions neurokit2/eda/eda_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def eda_process(eda_signal, sampling_rate=1000, method="neurokit", report=None,
should be generated. Defaults to ``None``. Can also be ``"text"`` to
just print the text in the console without saving anything.
**kwargs
Other arguments to be passed to specific methods. For more information,
see :func:`.rsp_methods`.
Other arguments to be passed to specific methods. This includes
``amplitude_min`` (relative SCR amplitude threshold, default ``0.1``)
forwarded to :func:`.eda_peaks`. For more information, see
:func:`.eda_methods`.

Returns
-------
Expand Down Expand Up @@ -96,12 +98,12 @@ def eda_process(eda_signal, sampling_rate=1000, method="neurokit", report=None,
**methods["kwargs_phasic"],
)

# Find peaks
# Find peaks. amplitude_min defaults to 0.1 inside eda_peaks(); a custom
# value passed via **kwargs is forwarded through methods["kwargs_peaks"].
peak_signal, info = eda_peaks(
eda_decomposed["EDA_Phasic"].values,
sampling_rate=sampling_rate,
method=methods["method_peaks"],
amplitude_min=0.1,
**methods["kwargs_peaks"],
)
info["sampling_rate"] = sampling_rate # Add sampling rate in dict info
Expand Down
30 changes: 30 additions & 0 deletions tests/tests_eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,36 @@ def test_eda_process():
assert peaks.shape == onsets.shape == recovery.shape == (5,)


def test_eda_process_custom_amplitude_min():
"""Custom amplitude_min must reach eda_peaks through eda_process (#1197)."""
from neurokit2.eda.eda_methods import eda_methods

methods = eda_methods(amplitude_min=0.03)
assert methods["kwargs_peaks"]["amplitude_min"] == 0.03

sampling_rate = 250
eda = nk.eda_simulate(
duration=30,
scr_number=5,
drift=0.1,
noise=0,
sampling_rate=sampling_rate,
random_state=42,
)

signals_default, _ = nk.eda_process(eda, sampling_rate=sampling_rate)
signals_strict, _ = nk.eda_process(eda, sampling_rate=sampling_rate, amplitude_min=0.9)
signals_loose, _ = nk.eda_process(eda, sampling_rate=sampling_rate, amplitude_min=0.01)

n_default = int(np.sum(signals_default["SCR_Peaks"] == 1))
n_strict = int(np.sum(signals_strict["SCR_Peaks"] == 1))
n_loose = int(np.sum(signals_loose["SCR_Peaks"] == 1))

assert n_strict <= n_default
assert n_loose >= n_default
assert n_strict < n_loose


def test_eda_plot():
sampling_rate = 1000
eda = nk.eda_simulate(
Expand Down
Loading