Exemple #1
0
def test_ecg_intervalrelated():

    data = nk.data("bio_resting_5min_100hz")
    df, info = nk.ecg_process(data["ECG"], sampling_rate=100)
    columns = [
        'ECG_Rate_Mean', 'HRV_RMSSD', 'HRV_MeanNN', 'HRV_SDNN', 'HRV_SDSD',
        'HRV_CVNN', 'HRV_CVSD', 'HRV_MedianNN', 'HRV_MadNN', 'HRV_MCVNN',
        'HRV_pNN50', 'HRV_pNN20', 'HRV_TINN', 'HRV_HTI', 'HRV_ULF', 'HRV_VLF',
        'HRV_LF', 'HRV_HF', 'HRV_VHF', 'HRV_LFHF', 'HRV_LFn', 'HRV_HFn',
        'HRV_LnHF', 'HRV_SD1', 'HRV_SD2', 'HRV_SD2SD1', 'HRV_CSI', 'HRV_CVI',
        'HRV_CSI_Modified', 'HRV_SampEn'
    ]

    # Test with signal dataframe
    features_df = nk.ecg_intervalrelated(df)

    assert all(elem in columns
               for elem in np.array(features_df.columns.values, dtype=str))
    assert features_df.shape[0] == 1  # Number of rows

    # Test with dict
    epochs = nk.epochs_create(df,
                              events=[0, 15000],
                              sampling_rate=100,
                              epochs_end=150)
    features_dict = nk.ecg_intervalrelated(epochs, sampling_rate=100)

    assert all(elem in columns
               for elem in np.array(features_dict.columns.values, dtype=str))
    assert features_dict.shape[0] == 2  # Number of rows
def preprocessing_and_feature_extraction_ECG(raw):#(file_name_csv,raw):
    data_ECG={}
    for participant in range(0,23):
        for video in range(0,18):
            # load raw baseline and stimuli data for left and right
            basl_l=raw['DREAMER'][0,0]['Data'][0,participant]['ECG'][0,0]['baseline'][0,0][video,0][:,0]
            stim_l=raw['DREAMER'][0,0]['Data'][0,participant]['ECG'][0,0]['stimuli'][0,0][video,0][:,0]
            basl_r=raw['DREAMER'][0,0]['Data'][0,participant]['ECG'][0,0]['baseline'][0,0][video,0][:,1]
            stim_r=raw['DREAMER'][0,0]['Data'][0,participant]['ECG'][0,0]['stimuli'][0,0][video,0][:,1]
            # process with neurokit
            ecg_signals_b_l,info_b_l=nk.ecg_process(basl_l,sampling_rate=256)
            ecg_signals_s_l,info_s_l=nk.ecg_process(stim_l,sampling_rate=256)
            ecg_signals_b_r,info_b_r=nk.ecg_process(basl_r,sampling_rate=256)
            ecg_signals_s_r,info_s_r=nk.ecg_process(stim_r,sampling_rate=256)
            # divide stimuli features by baseline features
            # would be interesting to compare classification accuracy when we
            # don't do this
            features_ecg_l=nk.ecg_intervalrelated(ecg_signals_s_l)/nk.ecg_intervalrelated(ecg_signals_b_l)
            features_ecg_r=nk.ecg_intervalrelated(ecg_signals_s_r)/nk.ecg_intervalrelated(ecg_signals_b_r)
            # average left and right features
            # would be interesting to compare classification accuracy when we
            # rather include both left and right features
            features_ecg=(features_ecg_l+features_ecg_r)/2
            if not len(data_ECG):
                data_ECG=features_ecg
            else:
                data_ECG=pd.concat([data_ECG,features_ecg],ignore_index=True)
    return data_ECG
Exemple #3
0
def nothing():
    # Quality check algorithms
    # qcqrs = run_qc(signal=data.filtered, epoch_len=15, fs=fs, algorithm="averageQRS", show_plot=False)

    # Removing invalid data based on QC thresholdling
    #t = threshold_averageqrs_data(signal=data.filtered, qc_signal=qc, epoch_len=10, fs=fs, pad_val=0,
    #                              thresh=.95, method='exclusive', plot_data=False)

    p, pc = find_peaks(signal=data.filtered,
                       fs=fs,
                       show_plot=True,
                       peak_method="pantompkins1985",
                       clean_method='neurokit')
    hrv = nk.hrv_time(peaks=pc, sampling_rate=data.sample_rate, show=False)

    freq = nk.hrv_frequency(peaks=pc,
                            sampling_rate=data.sample_rate,
                            show=True)

    # df_events, info = test_ecg_process_func(signal=data.filtered[15000:15000+1250], start=0, n_samples=int(10*125), fs=fs, plot_builtin=True, plot_events=False)

    # heartbeats = segment_ecg(signal=d, fs=fs)

    waves, sigs = nk.ecg_delineate(ecg_cleaned=data.filtered,
                                   rpeaks=pc,
                                   sampling_rate=data.sample_rate,
                                   method='dwt',
                                   show=False)

    intervals, ecg_rate, ecg_hrv = nk.ecg_intervalrelated()


# TODO
# Organizing
# Signal quality in organized section --> able to pick which algorithm
Exemple #4
0
def test_ecg_intervalrelated():

    data = nk.data("bio_resting_5min_100hz")
    df, info = nk.ecg_process(data["ECG"], sampling_rate=100)

    columns = [
        'ECG_Rate_Mean', 'HRV_RMSSD', 'HRV_MeanNN', 'HRV_SDNN', 'HRV_SDSD',
        'HRV_CVNN', 'HRV_CVSD', 'HRV_MedianNN', 'HRV_MadNN', 'HRV_MCVNN',
        'HRV_IQRNN', 'HRV_pNN50', 'HRV_pNN20', 'HRV_TINN', 'HRV_HTI',
        'HRV_ULF', 'HRV_VLF', 'HRV_LF', 'HRV_HF', 'HRV_VHF', 'HRV_LFHF',
        'HRV_LFn', 'HRV_HFn', 'HRV_LnHF', 'HRV_SD1', 'HRV_SD2', 'HRV_SD1SD2',
        'HRV_S', 'HRV_CSI', 'HRV_CVI', 'HRV_CSI_Modified', 'HRV_PIP',
        'HRV_IALS', 'HRV_PSS', 'HRV_PAS', 'HRV_ApEn', 'HRV_SampEn', 'HRV_GI',
        'HRV_SI', 'HRV_AI', 'HRV_PI', 'HRV_C1d', 'HRV_C1a', 'HRV_SD1d',
        'HRV_SD1a', 'HRV_C2d', 'HRV_C2a', 'HRV_SD2d', 'HRV_SD2a', 'HRV_Cd',
        'HRV_Ca', 'HRV_SDNNd', 'HRV_SDNNa'
    ]

    # Test with signal dataframe
    features_df = nk.ecg_intervalrelated(df, sampling_rate=100)

    # https://github.com/neuropsychology/NeuroKit/issues/304
    assert all(features_df == nk.ecg_analyze(
        df, sampling_rate=100, method="interval-related"))

    assert all(elem in np.array(features_df.columns.values, dtype=str)
               for elem in columns)
    assert features_df.shape[0] == 1  # Number of rows

    # Test with dict
    epochs = nk.epochs_create(df,
                              events=[0, 15000],
                              sampling_rate=100,
                              epochs_end=150)
    features_dict = nk.ecg_intervalrelated(epochs, sampling_rate=100)

    assert all(elem in columns
               for elem in np.array(features_dict.columns.values, dtype=str))
    assert features_dict.shape[0] == 2  # Number of rows
Exemple #5
0
             0, 0]['baseline'][0, 0][j, 0][:, 1]
         stim_r = data['DREAMER'][0, 0]['Data'][0, k]['ECG'][
             0, 0]['stimuli'][0, 0][j, 0][:, 1]
         ecg_signals_b_l, info_b_l = nk.ecg_process(basl_l,
                                                    sampling_rate=256)
         ecg_signals_s_l, info_s_l = nk.ecg_process(stim_l,
                                                    sampling_rate=256)
         ecg_signals_b_r, info_b_r = nk.ecg_process(basl_r,
                                                    sampling_rate=256)
         ecg_signals_s_r, info_s_r = nk.ecg_process(stim_r,
                                                    sampling_rate=256)
         # processed_ecg_b_l = nk.ecg_intervalrelated(ecg_signals_b_l)
         # processed_ecg_s_l = nk.ecg_intervalrelated(ecg_signals_s_l)
         # processed_ecg_b_r = nk.ecg_intervalrelated(ecg_signals_b_r)
         # processed_ecg_s_r = nk.ecg_intervalrelated(ecg_signals_s_r)
         processed_ecg_l = nk.ecg_intervalrelated(
             ecg_signals_s_l) / nk.ecg_intervalrelated(ecg_signals_b_l)
         processed_ecg_r = nk.ecg_intervalrelated(
             ecg_signals_s_r) / nk.ecg_intervalrelated(ecg_signals_b_r)
         processed_ecg = (processed_ecg_l + processed_ecg_r) / 2
         if not len(ECG):
             ECG = processed_ecg
         else:
             ECG = pd.concat([ECG, processed_ecg], ignore_index=True)
         total += 1
         print("\rprogress: %d%%" % (total / (23 * 18) * 100), end="")
 # col=ECG.columns.values
 # scaler=pre.StandardScaler()
 # for i in range(len(col)):
 #     ECG[col[i][:-3]] = scaler.fit_transform(ECG[[col[i]]])
 # ECG.drop(col, axis=1, inplace=True)
 # ECG.columns=col