Closed timvlaer closed 2 years ago
Hi, can you update neurokit to the latest version (1.4.1) and try again? Thanks
Hi @timvlaer
I was able to replicate your errors with the latest version of NeuroKit. However, a particular problem that I noticed is in the ECG signal you provided.
import neurokit2 as nk
ecg = pd.read_csv('sample_ecg.csv')['channel'].values
clean_ecg_engz = nk.ecg_clean(ecg, sampling_rate=250, method="engzeemod2012")
clean_ecg_default = nk.ecg_clean(ecg, sampling_rate=250)
import matplotlib.pyplot as plt
fig= plt.figure()
plt.plot(ecg, label = 'raw')
plt.plot(clean_ecg_engz, label = 'engzeemod2012 cleaning')
plt.plot(clean_ecg_default, label = 'neurokit cleaning')
plt.legend()
The ECG signal here is simply too noisy to be cleaned as you can see in the outputs of both engzeemod2012
and neurokit
methods.
clean_ecg_engz = nk.ecg_clean(ecg, sampling_rate=250, method="engzeemod2012")
rp, rpeaks_engz = nk.ecg_peaks(clean_ecg_engz, sampling_rate=250)
Note that the input of rpeaks_engz
causes all delineate methods to fail as the problem lies upstream. Only 3 rpeaks were detected and they are too few to detect reliable heart rate and thus the nk.ecg_segment()
returns Nans. The problem here is that the rpeaks detected might not be at all reliable, looking at the state of the signal.
Even though using the neurokit
cleaning method might not cause an error in the delineation, I don't think the output can be used reliably.
clean_ecg_default = nk.ecg_clean(ecg, sampling_rate=250)
rp, rpeaks_default = nk.ecg_peaks(clean_ecg_default, sampling_rate=250)
wv, waves_peak = nk.ecg_delineate(clean_ecg_default, rpeaks_default["ECG_R_Peaks"], sampling_rate=250, show=True, method="peak")
Hi @Tam-Pham , thanks for reviewing. I share your thoughts, the signal is indeed complete rubbish. I was supprised to see the code crash on this particular example while I did expect an empty result in this case (no waves at all). Does that reasoning makes sense?
I'm reporting this bug to make the internals of the library robust against these weird cases. I'm fine with closing this ticket as 'won't fix' as this is a corner case.
I will definitely check the signals before trying to find peaks with Neurokit.
Hello, same issue is happening with me
This issue has been automatically marked as inactive because it has not had recent activity. It will eventually be closed if no further activity occurs.
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.
This is a template for reporting a bug. You can remove it and write from scratch. These sections are a rough guide, but the important thing is to give enough details so that the developers can reproduce the bug on their machine and then investigate.
Describe the bug See dataset attached, ecg_delineator fails with ValueError. I don't know what exactly is going on but two things seems crucial to trigger the bug:
peak
See sample code below
To Reproduce
Expected behaviour Expected array with detected waves but instead fails with ValueError
System Specifications
It's important that you give us some information about the system you are using. For that you can run:
sample_ecg.csv