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

EDA analysis: "IndexError: arrays used as indices must be of integer (or boolean) type" #40

Closed
caisdosodre opened this issue Mar 18, 2024 · 1 comment
Assignees

Comments

@caisdosodre
Copy link

Hey,
During EDA analysis, with some datasets, I noticed that a specific error was raised:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[<ipython-input-2>](https://localhost:8080/#) in <cell line: 8>()
      6 
      7 # process it and plot
----> 8 out2 = eda.eda(signal=signal2,sampling_rate=200, show=True)

1 frames
[/usr/local/lib/python3.10/dist-packages/biosppy/signals/eda.py](https://localhost:8080/#) in eda(signal, sampling_rate, units, path, show)
     99 
    100     # get EDR and EDL
--> 101     edl_signal, edr_signal = biosppy_decomposition(signal=filtered,
    102                                                    sampling_rate=sampling_rate,
    103                                                    method="onsets",

[/usr/local/lib/python3.10/dist-packages/biosppy/signals/eda.py](https://localhost:8080/#) in biosppy_decomposition(signal, sampling_rate, method, onsets, **kwargs)
    269 
    270         # extract edl
--> 271         edl_on = np.hstack((ts[0], ts[onsets], ts[-1]))
    272         edl_amp = np.hstack((signal[0], signal[onsets], signal[-1]))
    273         f = interpolate.interp1d(edl_on, edl_amp)

IndexError: arrays used as indices must be of integer (or boolean) type

My code is below:

from biosppy import storage
from biosppy.signals import eda

# load raw eda signal
signal2, mdata2 = storage.load_txt('signal.txt')

# process it and plot
out2 = eda.eda(signal=signal2,sampling_rate=200, show=True)

The input file is attached (the sampling frequency is 200Hz):
raw_data.txt

I tried to debug the error, and until where I discovered, the error is related to the onsets' determination, using "emotiphai" method, where the onsets array returns empty (onsets=[]), causing the error. The workaround I found to determine the onsets and complete the analysis was to set the EDA events determination method to "basic".

@PatriciaBota
Copy link
Collaborator

Thanks for bringing this issue to our attention!

In PR #47, we've updated the module to provide greater flexibility in adapting the EDA events' minimum amplitude and filter size to better align with different user objectives. To take advantage of these new features, you might want to try the following configuration or similar:

from biosppy import storage
from biosppy.signals import eda
import matplotlib.pyplot as plt

# load raw eda signal
signal2, mdata2 = storage.load_txt('signal.txt')

# process it and plot
out2 = eda.eda(signal=signal2, sampling_rate=200, show=True, min_amplitude=0.01, size=0.1)

# plot peaks and onsets
plt.figure()
plt.plot(out2['ts'], out2['filtered'], 'b')
plt.plot(out2['ts'][out2['onsets']], out2['filtered'][out2['onsets']], 'ro', label='onsets')
plt.plot(out2['ts'][out2['peaks']], out2['filtered'][out2['peaks']], 'go', label='peaks')
plt.legend()
plt.show()

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

2 participants