scientisst / BioSPPy

Biosignal Processing in Python
https://biosppy.readthedocs.io/
Other
72 stars 22 forks source link

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

Closed caisdosodre closed 6 months ago

caisdosodre commented 8 months ago

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 commented 6 months ago

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()