def get_data(fp, labels, folders):
    file_dir = folders[fp]
    datasignals = pd.read_csv(filepath_or_buffer=fp,
                              sep=',',
                              usecols=[2, 3],
                              dtype='float')
    plt.plot(datasignals)
    plt.title(file_dir)
    plt.ylabel("volts (mV)")
    plt.xlabel("time-steps")
    plt.savefig(rootFolder + file_dir + "-raw.png")
    plt.close()
    low = .2
    high = .8
    quant_df = datasignals.quantile([low, high])
    filt_df = datasignals.apply(lambda x: x[
        (x > quant_df.loc[low, x.name]) & (x < quant_df.loc[high, x.name])],
                                axis=0)
    plt.plot(filt_df)
    plt.title(file_dir + "- Min/Max Scaled")
    plt.ylabel("volts (mV)")
    plt.xlabel("time-steps")
    plt.savefig(rootFolder + file_dir + "-filtered.png")
    plt.close()
    eegdata = eeg.get_power_features(signal=filt_df,
                                     sampling_rate=200,
                                     size=.1,
                                     overlap=0.999)['all_bands_amir']
    eegdata = np.nan_to_num(eegdata)
    datasignals = norm_data(eegdata)
    one_hot = np.zeros(3)
    label = labels[file_dir]
    one_hot[label] = 1
    return datasignals, one_hot, label
def get_data(fp, colsX, colsY):
    dataTmp = np.array(np.genfromtxt(fp, delimiter=',', usecols=colsX))
    if("EEG" in fp):
        eegdata = eeg.get_power_features(signal=dataTmp, sampling_rate=150, overlap=0.99)
    yLabels = norm_data(pd.read_csv(filepath_or_buffer=fp, sep=',', usecols=colsY, dtype=np.int32))
    normed_data = norm_data(eegdata["all_bands_amir"])
    return normed_data, yLabels
示例#3
0
 def process(self, signal, label, data, sampling=256):
     prepared_signal = pd.DataFrame(signal).transpose()
     features = eeg.get_power_features(prepared_signal, sampling)
     band_order = [
         'theta', 'alpha_low', 'alpha_high', 'beta', 'gamma', 'rest'
     ]
     for band_i, band in enumerate(features[1:]):
         for i, channel in enumerate(band.transpose()):
             #it returns ~470 values (s?) and row has only 1
             data[label + f'_{i}_{band_order[band_i]}'] = channel[:]
     return features
示例#4
0
def power_features(sig, fs=128):
    """ TESTED for (nxd) matrix input, returns (nxk) = (nx35) matrix output

     Conclusion: Passinzg in signals separately is the same as passing them in together.

     """
    [_, theta, alpha_low, alpha_high, beta,
     gamma] = eeg.get_power_features(signal=sig.T, sampling_rate=fs)
    ts1 = simple_statistics(theta.T)
    al1 = simple_statistics(alpha_low.T)
    ah1 = simple_statistics(alpha_high.T)
    b1 = simple_statistics(beta.T)
    g1 = simple_statistics(gamma.T)
    return np.concatenate((ts1, al1, ah1, b1, g1), axis=1)
def EEGFeatures(raw_signal, signal_1, signal_2, fs=128):
    bio_signal = np.transpose(raw_signal)

    # Statistical Features
    [_, std1, maxv1, minv1] = StatFeature(signal_1)
    [_, std2, maxv2, minv2] = StatFeature(signal_2)

    # Power Features
    [_, theta, alpha_low, alpha_high, beta,
     gamma] = eeg.get_power_features(signal=bio_signal, sampling_rate=fs)

    [theta1_mean, theta1_std, theta1_max, theta1_min] = StatFeature(theta[:,
                                                                          0])
    [theta2_mean, theta2_std, theta2_max, theta2_min] = StatFeature(theta[:,
                                                                          1])
    [alpha_low1_mean, alpha_low1_std, alpha_low1_max,
     alpha_low1_min] = StatFeature(alpha_low[:, 0])
    [alpha_low2_mean, alpha_low2_std, alpha_low2_max,
     alpha_low2_min] = StatFeature(alpha_low[:, 1])
    [alpha_high1_mean, alpha_high1_std, alpha_high1_max,
     alpha_high1_min] = StatFeature(alpha_high[:, 0])
    [alpha_high2_mean, alpha_high2_std, alpha_high2_max,
     alpha_high2_min] = StatFeature(alpha_high[:, 1])
    [beta1_mean, beta1_std, beta1_max, beta1_min] = StatFeature(beta[:, 0])
    [beta2_mean, beta2_std, beta2_max, beta2_min] = StatFeature(beta[:, 1])
    [gamma1_mean, gamma1_std, gamma1_max, gamma1_min] = StatFeature(gamma[:,
                                                                          0])
    [gamma2_mean, gamma2_std, gamma2_max, gamma2_min] = StatFeature(gamma[:,
                                                                          1])

    # Power Spectrum
    w = np.hamming(len(signal_1))
    w, psd = periodogram(signal_1, window=w, detrend=False)
    _, _, FreqmaxP1, _, _, _ = findLFHF(psd, w)
    w = np.hamming(len(signal_2))
    w, psd = periodogram(signal_2, window=w, detrend=False)
    _, _, FreqmaxP2, _, _, _ = findLFHF(psd, w)

    # Time Series
    kurt1 = kurtosis(signal_1)
    skew1 = skew(signal_1)
    kurt2 = kurtosis(signal_2)
    skew2 = skew(signal_2)

    # Peak Features
    [peaks1, _] = find_peaks(signal_1)
    pprom1 = peak_prominences(signal_1, peaks1)[0]
    contour_heights1 = signal_1[peaks1] - pprom1
    pwid1 = peak_widths(signal_1, peaks1, rel_height=0.4)[0]
    [ppmean1, ppstd1, _, ppmin1] = StatFeature(pprom1)
    [pwmean1, pwstd1, pwmax1, pwmin1] = StatFeature(pwid1)

    [peaks2, _] = find_peaks(signal_2)
    pprom2 = peak_prominences(signal_2, peaks2)[0]
    contour_heights2 = signal_2[peaks2] - pprom2
    pwid2 = peak_widths(signal_2, peaks2, rel_height=0.4)[0]
    [ppmean2, ppstd2, _, ppmin2] = StatFeature(pprom2)
    [pwmean2, pwstd2, pwmax2, pwmin2] = StatFeature(pwid2)

    return np.array([
        theta1_mean, theta1_std, theta1_max, theta1_min, theta2_mean,
        theta2_std, theta2_max, theta2_min, alpha_low1_mean, alpha_low1_std,
        alpha_low1_max, alpha_low1_min, alpha_low2_mean, alpha_low2_std,
        alpha_low2_max, alpha_low2_min, alpha_high1_mean, alpha_high1_std,
        alpha_high1_max, alpha_high1_min, alpha_high2_mean, alpha_high2_std,
        alpha_high2_max, alpha_high2_min, beta1_mean, beta1_std, beta1_max,
        beta1_min, beta2_mean, beta2_std, beta2_max, beta2_min, gamma1_mean,
        gamma1_std, gamma1_max, gamma1_min, gamma2_mean, gamma2_std,
        gamma2_max, gamma2_min, FreqmaxP1, kurt1, skew1, ppmean1, ppstd1,
        ppmin1, pwmean1, pwstd1, pwmax1, pwmin1, FreqmaxP2, kurt2, skew2,
        ppmean2, ppstd2, ppmin2, pwmean2, pwstd2, pwmax2, pwmin2, std1, maxv1,
        minv1, std2, maxv2, minv2
    ])