def get_features_dict_ex(signals, filename):
    """
       ts : array
        Signal time axis reference (seconds).
    filtered : array
        Filtered ECG signal.
    rpeaks : array
        R-peak location indices.
    templates_ts : array
        Templates time axis reference (seconds).
    templates : array
        Extracted heartbeat templates.
    heart_rate_ts : array
        Heart rate time axis reference (seconds).
    heart_rate : array
        Instantaneous heart rate (bpm).
    :param x:
    :return:
    """
    out, rpeaks = ecg.ecgex(signals=signals,
                            sampling_rate=loader.FREQUENCY,
                            show=False,
                            filename=filename)

    result = []
    for i in range(len(out)):
        x = signals.iloc[:, [i]].values.reshape(-1)
        [ts, fts, new_rpeaks, tts, thb, hrts, hr] = out[i]
        import neurokit as nk
        rsa = nk.respiratory_sinus_arrhythmia(rpeaks, rsp_cycles, rsp_signal)
        fx = dict()
        fx.update(add_suffix(frequency_powers(fts), "fil"))
        fx.update(frequency_powers_summary(fts))
        fx.update(heart_beats_features(thb, np.median(np.diff(new_rpeaks))))
        fx.update(fft_features(heartbeats.median_heartbeat(thb)))
        # fx.update(heart_beats_features3(thb))
        # gloal feature
        fx.update(frequency_powers(x, n_power_features=60))
        fx.update(heart_rate_features(hr))
        fx.update(r_features(fts, new_rpeaks))

        fx['PRbyST'] = fx['PR_interval'] * fx['ST_interval']
        fx['P_form'] = fx['P_kurt'] * fx['P_skew']
        fx['T_form'] = fx['T_kurt'] * fx['T_skew']

        for key, value in fx.items():
            if np.math.isnan(value):
                value = 0
            fx[key] = value
        from time_domain_feature import psfeatureTime
        result += psfeatureTime(x)
        result += list(
            np.array([fx[key] for key in sorted(list(fx.keys()))],
                     dtype=np.float32))

    rx = r_features(rpeaks)
    result += list(
        np.array([rx[key] for key in sorted(list(rx.keys()))],
                 dtype=np.float32))
    return result
Beispiel #2
0
def get_features_dict_ex(signals, filename):
    """
       ts : array
        Signal time axis reference (seconds).
    filtered : array
        Filtered ECG signal.
    rpeaks : array
        R-peak location indices.
    templates_ts : array
        Templates time axis reference (seconds).
    templates : array
        Extracted heartbeat templates.
    heart_rate_ts : array
        Heart rate time axis reference (seconds).
    heart_rate : array
        Instantaneous heart rate (bpm).
    :param x:
    :return:
    """
    out, rpeaks = ecg.ecgex(signals=signals,
                            sampling_rate=loader.FREQUENCY,
                            show=False,
                            filename=filename)

    result = []
    templates = []
    for i in range(len(out)):
        x = signals.iloc[:, [i]].values.reshape(-1)
        [ts, fts, new_rpeaks, tts, thb, hrts, hr] = out[i]
        fx = dict()
        fx.update(heart_rate_features(hr))
        fx.update(frequency_powers(x, n_power_features=60))
        fx.update(add_suffix(frequency_powers(fts), "fil"))
        fx.update(frequency_powers_summary(fts))
        fx.update(heart_beats_features2(thb, rpeaks))
        #fx.update(fft_features(heartbeats.median_heartbeat(thb)))
        templates.append(heartbeats.median_heartbeat(thb))

        fx['PRbyST'] = fx['PR_interval'] * fx['ST_interval']
        fx['P_form'] = fx['P_kurt'] * fx['P_skew']
        fx['T_form'] = fx['T_kurt'] * fx['T_skew']

        for key, value in fx.items():
            if np.math.isnan(value):
                value = 0
            fx[key] = value
        from time_domain_feature import psfeatureTime
        result += psfeatureTime(x)
        result += list(
            np.array([fx[key] for key in sorted(list(fx.keys()))],
                     dtype=np.float32))
    rx = r_features(rpeaks)
    result += list(
        np.array([rx[key] for key in sorted(list(rx.keys()))],
                 dtype=np.float32))
    import os
    #path = os.path.join('data', filename)
    #pd.DataFrame(np.array(templates).T).to_csv(path,index=None,header=None)
    return result
Beispiel #3
0
def get_more_featrues(index_list):
    df_info = get_train_info()
    train_dir = config.train_dir
    level = 9
    count = 50
    resamples = 2048
    columns = [str(i) for i in range(1*(count+8)+1)]
    x = pd.DataFrame(columns=columns)
    x_index = 0
    for i in tqdm(range(len(index_list))):
        index = index_list[i]
        # print(i, index)
        file_name = os.path.join(train_dir, df_info.loc[index,'file'])
        from test1 import load_data
        raw_df = load_data(file_name)

        #print(df.columns.values[:1])
        df_list = create_data(raw_df,win_size=2500,move=500)

        for df in df_list:
            row_features = []
            for column in df.columns.values[:1]:
                data = df.loc[:, column].values
                from scipy import signal
                # data = signal.resample(data, resamples)
                # data = fiter_wave(data)
                # 每列都计算
                from time_domain_feature import psfeatureTime
                time_features = psfeatureTime(data)
                #wavelet_features = calc_energy(data, 'db10', level, "freq", count)
                #row_features = row_features + time_features + wavelet_features0000
                fxx, pxx = signal.welch(data, 500)
                row_features = row_features + time_features+ list(pxx[:count])
            x.loc[x_index] = [index]+row_features
            x_index += 1

    return x
Beispiel #4
0
def get_sub_featrues(df_info,train_dir):
    level = 9
    count = 247
    columns = [str(i) for i in range(10*count+1)]
    x = pd.DataFrame(columns=columns)
    index_list = df_info.index.values
    for i in tqdm(range(len(index_list))):
        index = index_list[i]
        # print(i, index)
        file_name = os.path.join(train_dir, df_info.loc[index,'file'])
        #print(file_name)
        df = load_data(file_name)

        row_features = []
        #print(df.columns.values[:1])
        for column in df.columns.values:
            #print(column)
            data = df.loc[:, column].values
            from scipy import signal
            #data = signal.resample(data, resamples)

            # 每列都计算
            time_features = psfeatureTime(data)
            #wavelet_features = calc_energy(data, 'db10', level, "freq", count)
            row_features = row_features + time_features
            import features.feature_extractor6 as extractor
            from loading import loader
            from preprocessing import categorizer, balancer, normalizer
            from utils import logger, parallel
            #data = signal.resample(data, resamples)
            # wave filtering
            data = normalizer.normalize_ecg(data)
            new_feature = extractor.features_for_row(data)
            row_features += list(new_feature)

        x.loc[i] = [index]+row_features
    return x