Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(hrv) intervals_process handling of **kwargs #1045

Open
afourcade opened this issue Nov 1, 2024 · 1 comment
Open

(hrv) intervals_process handling of **kwargs #1045

afourcade opened this issue Nov 1, 2024 · 1 comment

Comments

@afourcade
Copy link

afourcade commented Nov 1, 2024

Description of the bug

interval_process is defined as taking **kwargs (to be passed to :func:.signal_interpolate), and signal_interpolate is written as taking **kwargs:
In interval_process.py, line 124:
intervals = signal_interpolate(intervals_time, intervals, x_new=x_new, **kwargs)
But the definition of signal_interpolate does not allow for **kwargs:

def signal_interpolate(
    x_values, y_values=None, x_new=None, method="quadratic", fill_value=None
)

Replication

Backstory is, I was trying to use **kwargs when using hrv_frequency, to set parameters for signal_power (e.g., change the windows length for psd computation), like this for example:

hrv_frequency(rrs_dict, interpolation_rate=4, normalize=False, psd_method='welch', **{'nperseg':4*256, 'window_type':'hann'})

Though this gave me the following error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File d:\BBSIG\bbsig_hrv.py:3
      [1](file:XXX/bbsig_hrv.py:1) #%%
      [2](file:XXX/bbsig_hrv.py:2) #Test changing window type
----> [3](file:XXX/bbsig_hrv.py:3) nk.hrv_frequency(rrs_dict, interpolation_rate=4, normalize=False, psd_method='welch', **{'nperseg':4*256, 'window_type':'hann'})

File XXX\Lib\site-packages\neurokit2\hrv\hrv_frequency.py:189, in hrv_frequency(peaks, sampling_rate, ulf, vlf, lf, hf, vhf, psd_method, show, silent, normalize, order_criteria, interpolation_rate, **kwargs)
    [186](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:186) rri, rri_time, _ = _hrv_format_input(peaks, sampling_rate=sampling_rate)
    [188](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:188) # Process R-R intervals (interpolated at 100 Hz by default)
--> [189](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:189) rri, rri_time, sampling_rate = intervals_process(
    [190](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:190)     rri, intervals_time=rri_time, interpolate=True, interpolation_rate=interpolation_rate, **kwargs
    [191](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:191) )
    [193](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:193) if interpolation_rate is None:
    [194](file:XXX/Lib/site-packages/neurokit2/hrv/hrv_frequency.py:194)     t = rri_time

File XXX\Lib\site-packages\neurokit2\hrv\intervals_process.py:124, in intervals_process(intervals, intervals_time, interpolate, interpolation_rate, detrend, **kwargs)
    [117](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:117)     # Compute x-values of interpolated interval signal at requested sampling rate.
    [118](XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:118)     x_new = np.arange(
    [119](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:119)         start=intervals_time[0],
    [120](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:120)         stop=intervals_time[-1] + 1 / interpolation_rate,
    [121](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:121)         step=1 / interpolation_rate,
    [122](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:122)     )
--> [124](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:124)     intervals = signal_interpolate(intervals_time, intervals, x_new=x_new, **kwargs)
    [125](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:125)     intervals_time = x_new
    [126](file:XXX/Lib/site-packages/neurokit2/hrv/intervals_process.py:126) else:
    [127](file:XXX/site-packages/neurokit2/hrv/intervals_process.py:127)     # check if intervals appear to be already interpolated

TypeError: signal_interpolate() got an unexpected keyword argument 'nperseg'
---------------------------------------------------------------------------

Expected behaviour
In general, I think it would be useful to be able to change the parameters of the psd computation when using hrv_frequency, in case the user wants parameters similar to Kubios or Systole for example.

System Specifications

  • OS: Windows (WindowsPE 64bit)

  • Python: 3.11.9

  • NeuroKit2: 0.2.10

  • NumPy: 1.26.0

  • Pandas: 2.2.2

  • SciPy: 1.14.0

  • sklearn: 1.5.1

  • matplotlib: 3.9.1

Copy link

welcome bot commented Nov 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant