NeuroKit icon indicating copy to clipboard operation
NeuroKit copied to clipboard

fix.peaks() calling kubios does not handle RRI/peak artifacts as expected

Open martinfrasch opened this issue 2 years ago • 3 comments

When calling:

import neurokit2 as nk
fp = nk.signal_fixpeaks(fp_nofixpeaks, sampling_rate=1000,
                        iterative=False, show=False, interval_min=0.33, interval_max=0.75,
                        method="kubios")[1]

we observe that the set interval ranges are not respected in all cases. The attached example (numpy file and the output) show that the above settings of heart rate are completely ignored and almost no changes are made. The expected behavior in this case would be that the entire data would be discarded. In some other instances, we see some sort of moving average smoothing taking place even when the RRIs are below the set threshold, but seemingly only for a given short time scale (not sure there the threshold of the short/long time scale lies). Artifacts at longer time scale seem to be ignored.

The data in question the documented behavior can be viewed here: https://www.dropbox.com/sh/ekp5umyqxc2qack/AACT-st21zDK7q_4p34hhg7Ta?dl=0

Note that these are fetal heart rate data, so the normal heart rate is between 110 and 180 bpm, unlike the adult ranges of ~40-90.

These are the peaks' timestamps (in ms) for id#118, before (variable "fp_nofixpeaks") and after (variable "fp") calling the fixpeaks() function. Both variables are saved in a numpy file; I also enclosed a graph with a zoom on a region where fixpeaks() has operated (note that the y-coordinate in the representation of the peaks timestamps is arbitrarily set to 1 for the raw data, and 0.9 for the "fixpeaks"-ed data).

image

I would be most grateful for any guidance on this observation. Are our expectations incorrect? If so, how can be achieve the desired behavior?

martinfrasch avatar Apr 06 '22 18:04 martinfrasch

@martinfrasch, thanks for opening the issue! The observation is entirely correct. The reason is that the interval_min and interval_max parameters aren't propagated from signal_fixpeaks() to _signal_fixpeaks_kubios() (i.e., the kubios method).

https://github.com/neuropsychology/NeuroKit/blob/a30f76e64b4108abdc652a20391dc0288c62501d/neurokit2/signal/signal_fixpeaks.py#L149

Have you tried the neurokit method?

@DominiqueMakowski, seems like that's an API issue?

JanCBrammer avatar Apr 07 '22 13:04 JanCBrammer

There arguments only apply for the neurokit method indeed. I'll update the docs!

DominiqueMakowski avatar Apr 08 '22 00:04 DominiqueMakowski

This is great to know! Thank you! So, just to validate my understanding: if I want certain RRI durations to act as the filter, I must use the neurokit method if using fixpeaks() function?

I had trouble getting neurokit method to work with this particular dataset and switched pragmatically to kubios. I wonder if you might test this file using neurokit method, please, and see if it works. I apologize for being fuzzy here as to what failed. It was over 7 months ago ;-)

martinfrasch avatar Apr 08 '22 00:04 martinfrasch

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.

stale[bot] avatar Sep 20 '22 19:09 stale[bot]

This should be fixed now :)

DominiqueMakowski avatar Sep 21 '22 00:09 DominiqueMakowski