Пример #1
0
    def test_read_acqknowledge(self):

        data_path = os.getcwd() + r"/tests/test_bio_data.acq"  # If running from travis
#        data_path = "test_bio_data.acq"  # If running in local
        # Read data
        df = nk.read_acqknowledge(data_path)
        # Resample to 100Hz
        df = df.resample("10L").mean()
        df.columns = ['ECG', 'EDA', 'PPG', 'Photosensor', 'RSP']
        # Check length
        self.assertEqual(len(df), 35645)
        return(df)
Пример #2
0
def test_read_acqknowledge():

    if run_tests_in_local is False:
        data_path = os.getcwd() + r"/tests/data/test_bio_data.acq"  # If running from travis
    else:
        data_path = "data/test_bio_data.acq"  # If running in local

    # Read data
    df, sampling_rate = nk.read_acqknowledge(data_path, return_sampling_rate=True)
    # Resample to 100Hz
    df = df.resample("10L").mean()
    df.columns = ['ECG', 'EDA', 'PPG', 'Photosensor', 'RSP']
    # Check length
    assert len(df) == 35645
    return(df)
Пример #3
0
def analyzeSCR(event_file, acq_file):
    import neurokit as nk
    import pandas as pd
    import numpy as np
    import seaborn as sns
    ## loading acq file
    df, sampling_rate = nk.read_acqknowledge(acq_file,
                                             return_sampling_rate=True)
    bio = nk.bio_process(eda=df["GSR100C"],
                         add=df["Script"],
                         sampling_rate=sampling_rate)

    # adding conditions
    events = pd.read_csv(event_file, sep=r'\s+')
    condition_list = events['trial_type']
    events = {
        'onset': np.array(events["onset"] * 1000),
        'duration': np.array(events["duration"] * 1000)
    }
    epochs = nk.create_epochs(
        bio["df"], events["onset"], duration=120000,
        onset=0)  # create epoch file with 120sec duration and -1sec begins

    data = {}  # Initialize an empty dict
    for epoch_index in epochs:
        data[epoch_index] = {
        }  # Initialize an empty dict for the current epoch
        epoch = epochs[epoch_index]

        # ECG
        #    baseline = epoch["ECG_RR_Interval"].ix[-100:0].mean()  # Baseline
        #    rr_max = epoch["ECG_RR_Interval"].ix[0:400].max()  # Maximum RR interval
        #    data[epoch_index]["HRV_MaxRR"] = rr_max - baseline  # Corrected for baseline

        # EDA - SCR
        scr_max = epoch["SCR_Peaks"].ix[100:15000].max(
        )  # Maximum SCR peak - now its 30sec after initiation of script
        if np.isnan(scr_max):
            scr_max = 0  # If no SCR, consider the magnitude, i.e.  that the value is 0
        data[epoch_index]["SCR_Magnitude"] = scr_max

    data = pd.DataFrame.from_dict(data,
                                  orient="index")  # Convert to a dataframe
    data["Condition"] = condition_list  # Add the conditions
    data  # Print
    return data
Пример #4
0
__author__ = "Julian Tejada"

import matplotlib.pyplot as plt
import neurokit as nk
import pandas as pd
import numpy as np
import math
import sys
# import seaborn as sns
import biosppy
from biosppy.signals import eda
from biosppy import plotting, utils

###############################
# import data from acq
df, sampling_rate = nk.read_acqknowledge(str(sys.argv[1]),
                                         return_sampling_rate=True)

# first filter
bio = biosppy.signals.eda.eda(df["EDA100C"],
                              sampling_rate=sampling_rate,
                              show=False,
                              min_amplitude=0.01)

# Create a ts vector with the time
length = len(df["EDA100C"])
T = (length - 1) / sampling_rate
ts = np.linspace(0, T, length, endpoint=False)
# Extract SCRs using Gamboa method
SCRs = biosppy.signals.eda.basic_scr(bio["filtered"], sampling_rate=2000)
#bio = biosppy.signals.eda.eda(df["EDA100C"], sampling_rate=2000)
Пример #5
0
# choose scripts channel
b = a.named_channels["GSR100C"].raw_data

import matplotlib.pyplot as plt

plt.plot(b)

#%% analyze data using NeuroKit
import neurokit as nk
import pandas as pd
import numpy as np
import seaborn as sns

# loading BioPack file
df, sampling_rate = nk.read_acqknowledge(
    '/media/Data/PTSD_KPE/physio_data/raw/kpe1223/scan_2/kpe1223.2_scripts_2017-02-06T08_39_32.acq',
    return_sampling_rate=True)
df[['GSR100C', 'Script']].plot()
# Process the signals
bio = nk.bio_process(eda=df["GSR100C"], add=df["Script"], sampling_rate=1000.)
# Plot the processed dataframe, normalizing all variables for viewing purpose
#%%
condition_list = [
    "Trauma", "Relax", "Sad", "Relax", "Trauma", "Sad", "Relax", "Trauma",
    "Sad"
]


#%%
def analyzeSCR(event_file, acq_file):
    import neurokit as nk
Пример #6
0
import neurokit as nk

df = nk.read_acqknowledge("abnormal_ECG.acq")

events = nk.find_events(df["Photosensor"], cut="lower")
df = nk.create_epochs(df, events["onsets"], duration=events["durations"])[0]

#df["Photosensor"].plot()
df = nk.ecg_process(df['ECG, X, RSPEC-R'])
ecg = df["ECG"]
df = df["df"]
#rpeaks = nk.ecg_find_peaks(df['ECG_Filtered'])
nk.plot_events_in_signal(df['ECG_Filtered'], ecg["R_Peaks"])
#df['ECG, X, RSPEC-R'].iloc[104000:140000].plot()
Пример #7
0
import neurokit as nk
import pandas as pd
import pywt


"""
https://github.com/MITMediaLabAffectiveComputing/eda-explorer
http://eda-explorer.media.mit.edu/info/
"""






df, sampling_rate = nk.read_acqknowledge("bio_data.acq", return_sampling_rate=True)
eda = df["EDA, X, PPGED-R"]
eda_processed = nk.eda_process(eda, sampling_rate=sampling_rate)
eda = eda_processed["df"]["EDA_Phasic"]


def getWaveletData(eda):
    '''
    This function computes the wavelet coefficients
    INPUT:
        data:           DataFrame, index is a list of timestamps at 8Hz, columns include EDA, filtered_eda
    OUTPUT:
        wave1Second:    DateFrame, index is a list of timestamps at 1Hz, columns include OneSecond_feature1, OneSecond_feature2, OneSecond_feature3
        waveHalfSecond: DateFrame, index is a list of timestamps at 2Hz, columns include HalfSecond_feature1, HalfSecond_feature2
    '''