neuropsychology / NeuroKit

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

ecg_analyze() bug #919

Open dommrichmond opened 11 months ago

dommrichmond commented 11 months ago

Creating an ecg signal and using ecg analyze results in an error in Neurokit2 (Version 0.2.6)

ecg = nk.ecg_simulate(duration=60, sampling_rate=100, heart_rate=80)
signals, info = nk.ecg_process(ecg, sampling_rate=100)
epochs = nk.epochs_create(signals,sampling_rate=100, epochs_end=10)
results = nk.ecg_analyze(epochs,sampling_rate=100)

NeuroKitWarning: DFA_alpha2 related indices will not be calculated. The maximum duration of the windows provided for the long-term correlation is smaller than the minimum duration of windows. Refer to the scale argument in nk.fractal_dfa() for more information.

welcome[bot] commented 11 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

DominiqueMakowski commented 11 months ago

This is not an error but just a warning that some indices will not be calculated due to the short recordings

dommrichmond commented 11 months ago

Oops, my bad I forgot to paste everything. Following the warning, there is this error:

warn(
Traceback (most recent call last):
  File "C:\Users\domin\Documents\Dom\Misc\HRV\HRV.py", line 109, in <module>
    results = nk.ecg_analyze(epochs,sampling_rate=100)
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\ecg\ecg_analyze.py", line 116, in ecg_analyze
    features = ecg_intervalrelated(data, sampling_rate=sampling_rate)
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\ecg\ecg_intervalrelated.py", line 83, in ecg_intervalrelated
    intervals[index] = _ecg_intervalrelated_hrv(
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\ecg\ecg_intervalrelated.py", line 128, in _ecg_intervalrelated_hrv
    results = hrv(rpeaks, sampling_rate=sampling_rate)
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\hrv\hrv.py", line 107, in hrv
    out.append(hrv_nonlinear(peaks, sampling_rate=sampling_rate))
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\hrv\hrv_nonlinear.py", line 236, in hrv_nonlinear
    out["ApEn"], _ = entropy_approximate(rri, delay=1, dimension=2, tolerance=tolerance)
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\complexity\entropy_approximate.py", line 100, in entropy_approximate
    out, _ = _entropy_apen(signal, delay, dimension, info["Tolerance"], **kwargs)
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\complexity\optim_complexity_tolerance.py", line 363, in _entropy_apen
    phi, info = _phi(
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\complexity\utils.py", line 29, in _phi
    embedded1, count1, kdtree1 = _get_count(
  File "C:\Users\domin\Documents\Dom\Misc\HRV\venv\lib\site-packages\neurokit2\complexity\utils.py", line 115, in _get_count
    valid_metrics = sklearn.neighbors.KDTree.valid_metrics() + ["range"]
TypeError: 'list' object is not callable
dommrichmond commented 11 months ago

Any ideas on the above?

DominiqueMakowski commented 11 months ago

Yes, please update neurokit to the dev version and it should be fixed!

stale[bot] commented 6 months ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.