neuropsychology / NeuroKit

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

Eog features #850

Open VladimirR46 opened 1 year ago

VladimirR46 commented 1 year ago

Good afternoon! When I try to use the eog_features function I get the following error.

TypeError: only size-1 arrays can be converted to Python scalars

eog_cleaned = nk.eog_clean(ica0, sampling_rate=1000, method='neurokit')
peaks = nk.eog_findpeaks(eog_cleaned, sampling_rate=1000)
info = nk.eog_features(eog_cleaned, peaks,sampling_rate=1000)

But if I change sampling_rate to 100, for example, it works.

info = nk.eog_features(eog_cleaned, peaks,sampling_rate=100)

But I have a frequency of 1000 Hz.

eog_cleaned and peaks have the right data type

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

danibene commented 1 year ago

Would it be possible for you to share some example data? I ran your code with other data and did not get the same error: https://gist.github.com/danibene/595f281bc118541e49b7d4462633d8ad

VladimirR46 commented 1 year ago

Of course! You can open the file as:

with open('EOG.npy', 'rb') as f:
    eog_v = np.load(f)

sampling_rate=500

EOG.zip

danibene commented 1 year ago

But if I change sampling_rate to 100, for example, it works.

info = nk.eog_features(eog_cleaned, peaks,sampling_rate=100)

But I have a frequency of 1000 Hz.

Thanks @VladimirR46 ! Could you please clarify what you meant by a frequency of 1000 Hz / why you set the sampling_rate to 1000 in your code above if the sampling rate=500?

It would also be helpful if you could provide the error message received and the versions of your dependencies.

VladimirR46 commented 1 year ago

Hi. It's just another (new) dataset that has a sampling rate of 500 Hz. But here I get the same error message.

eog_cleaned = nk.eog_clean(eog_v, sampling_rate=500, method='mne')
peaks = nk.eog_findpeaks(eog_cleaned, method='neurokit', sampling_rate=500)
info = nk.eog_features(eog_cleaned, peaks,sampling_rate=500)

image

I also need to get the "positive amplitude velocity ratio (pAVR)" characterization as in "Robbins, K. A. (2017). BLINKER: automated extraction of ocular indices from EEG enabling large-scale analysis."

image

But the resulting values are very different, i.e. I mean the value on the X-axis.

mean (matlab) == 5.3034 mean (neurokit2) == 9715.09827

VladimirR46 commented 1 year ago

Hey, everybody! I think I've solved my problem. 1) I set threshold=0.3 for the function nk.eog_findpeaks

eog_cleaned = nk.eog_clean(eog_v, sampling_rate=500, method='mne')
peaks = nk.eog_findpeaks(eog_cleaned, method='neurokit', threshold=0.3, sampling_rate=500)
info = nk.eog_features(eog_cleaned, peaks,sampling_rate=500)

2) I changed the formula for calculating pAVR

#pAVR = abs(change_close.max() / duration_close) * 100
pAVR = abs(blink_close.max() / change_close.max())/sampling_rate * 100
pAVR_list.append(pAVR)

image

VladimirR46 commented 1 year ago

Good day! @danibene

# Neurokit2
pAVR = abs(change_close.max() / duration_close) * 100

# My Fix
pAVR = abs(blink_close.max() / change_close.max())/sampling_rate * 100  

Could you explain why the equation doesn't match the original article?

danibene commented 1 year ago

Hi @VladimirR46 thanks for sharing your solution and error, it's very appreciated!

I'm not the person who originally wrote this code and am not familiar with the article so it's hard for me to say off the top of my head (and I don't have time to look into it currently).

@DominiqueMakowski are you more familiar with this?

In any case I would suggest we keep the issue open so that we eventually either change the code for calculation or give a more informative error message.

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

VladimirR46 commented 11 months ago

Yes, this question is still relevant.

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.

VladimirR46 commented 6 months ago

Yes, this question is still relevant.