im-ethz / flirt

Are you ready to FLIRT with your wearable data?
https://flirt.readthedocs.io
Other
61 stars 21 forks source link

EDA features not being extracted #6

Closed TinasheMTapera closed 1 year ago

TinasheMTapera commented 1 year ago

Hello,

I'm having trouble extracting EDA features with the WESAD dataset and flirt. Here is a reprex:

import pathlib
import zipfile
import tempfile

import flirt

def test_extract_features_e4(WESAD_zip_path, subject_index=0, hrv=True, eda=True):
    '''
    args:
        WESAD_zip_path: str path to your WESAD zip file
        subject_index: int which subject to extract, between 0 and 14
        hrv: bool passed to get_features_for_empatica_archive -> hrv_features
        eda: bool passed to get_features_for_empatica_archive -> eda_features
    '''
    with zipfile.ZipFile(WESAD_zip_path, mode="r") as archive:

        e4s=[x for x in archive.namelist() if "E4_Data" in x]

        target=e4s[subject_index]

        with tempfile.TemporaryDirectory() as tmpdirname:
            print("extracting ", target)
            archive.extract(target, path=tmpdirname)

            e4_zip = [x for x in pathlib.Path(tmpdirname).rglob('*.*')].pop()
            features = flirt.simple.get_features_for_empatica_archive(e4_zip, 60, 10, hrv_features=hrv, eda_features=hrv, acc_features=False)

    archive.close()
    return features

## here, put the path to your full WESAD zip file download; no need to extract
download_path = pathlib.Path("~/Downloads/WESAD.zip").expanduser()

# run flirt
test_extract_features_e4(download_path, subject_index=0, hrv=False)

Output:

extracting  WESAD/S10/S10_E4_Data.zip
Received empty input features, returning empty df

Similarly, if I unzip the files and run the EDA module directly:

eda = flirt.reader.empatica.read_eda_file_into_df("/Users/tinashetapera/Downloads/WESAD/S8/S8_E4_Data/EDA.csv")
flirt.get_eda_features(eda['eda'], 250, 5)

image

I downloaded the dataset from here and it should be identical to the paper. Colleagues of mine have successfully extracted both HRV and EDA features with no trouble.

I believe it may be a Mac M2 issue as there doesn't seem to be any other reasonable explanation, but please let me know what configurations you'd like to check against.

Setup: Macbook Air M2 OSX Ventura 13.0 miniconda: conda 4.14.0 Python: Python 3.10.6 flirt:

pip show flirt
Name: flirt
Version: 0.0.2
Summary: Wearable Data Processing Toolkit
Home-page: https://github.com/im-ethz/flirt
Author: ETH Zurich – Chair of Information Management
Author-email: 
License: MIT
Location: /opt/homebrew/Caskroom/miniconda/base/envs/hinf5300/lib/python3.10/site-packages
Requires: astropy, cvxopt, ishneholterlib, joblib, numba, numpy, pandas, scipy, tqdm
Required-by: 

Thanks in advance for any help you can provide!

TinasheMTapera commented 1 year ago

Hi,

It seems that this is a python versioning problem. When I shifted back to Python 3.7, everything worked as intended.

I'll close the issue but hopefully it gets some eyes on it for other Python > 3.10 users.

hugodecasta commented 7 months ago

I had the same problem problem with 3.9 and 3.10. By removing the passing try catch to figure out the problem, it seems that creating the matrix with y = cvx.matrix(y) in __cvx_eda raises the buffer format not supported, simple way to counter is to make sure the y input is compatible by converting it with y = y.astype(np.double)

Will do a PR to fix this issue...