Esempio n. 1
0
def saveSignalFeatures():
    """
    This function saves all the features for each signal into a giant dataframe
    This is so we don't have to re-derive the peaks, intervals, etc. for each signal

    Parameters
    ----------
    None

    Returns
    -------
    Saves dataframe as hardcoded_features.csv where each row is a filtered signal with the getFeatures() features
    """

    records = wave.getRecords('All')[0]
    returnMatrix = []

    for i in records:
        sig = Signal(i, wave.load(i))

        features = getFeatures(sig)

        returnMatrix.append(features)

    df = pd.DataFrame(returnMatrix, )
    df.to_csv('hardcoded_features.csv')
Esempio n. 2
0
def getFeaturesNames():
    records = wave.getRecords('All')[0]
    returnMatrix = []

    sig = Signal(records[0], wave.load(records[0]))

    features_names = getFeatures(sig, names=True)
    return features_names
Esempio n. 3
0
def feature_extract():
    """
    this function creates a feature matrix from partitioned data

    Parameters
    ----------
        None

    Returns
    -------
        A pickle dump of the following:
            tuple of tuples:
            test (1/10th of data) tuple:
                testing subset feature matrix, 2D array
                list of record labels N O A ~
                list of record names
            training (9/10th of data) tuple:
                training subset feature matrix, 2D array
                list of record labels N O A ~

    """

    records_labels = wave.getRecords('All')
    partitioned = wave.getPartitionedRecords(0)  # partition nth 10th, 0-9
    testing = partitioned[0]
    training = partitioned[1]

    testMatrix = np.array([getFeaturesHardcoded("A00001")])
    trainMatrix = np.array([getFeaturesHardcoded("A00001")])

    for i in records_labels[0]:
        if i in testing[0]:
            testMatrix = np.concatenate(
                (testMatrix, [getFeaturesHardcoded(i)]))
        elif i in training[0]:
            trainMatrix = np.concatenate(
                (trainMatrix, [getFeaturesHardcoded(i)]))

    testMatrix = np.delete(testMatrix, (0),
                           axis=0)  # get rid of A00001 initialization array
    trainMatrix = np.delete(trainMatrix, (0), axis=0)

    featureMatrix = ((testMatrix, testing[1], testing[0]), (trainMatrix,
                                                            training[1]))

    pickle.dump(featureMatrix, open("feature_matrices", 'wb'))
Esempio n. 4
0
records_train = pd.read_csv(path + 'REFERENCE.csv', names=['file', 'answer'])
records_validation = pd.read_csv('validation/' + 'REFERENCE.csv',
                                 names=['file', 'answer'])

new_validation = []
for index, row in records_validation.iterrows():
    record = records_train.ix[records_train['file'] == row['file']]
    filename = record['file'].tolist()
    answer = record['answer'].tolist()
    new_validation.append([filename[0], answer[0]])

#print(len(records))
#print(records)

records = wave.getRecords('All')

wired_list = []

feat_list = []
for record in records:
    #    try:
    data = wave.load(record)
    print('running record: ' + record)
    #sig = challenge.Signal(record, data)
    noise_features = challenge.noise_feature_extract(data)
    feat_list.append(noise_features)
    print('the number of records in the feature list: ' + str(len(feat_list)))
#    except:
#        wired_list.append(record)
#        print ('stupid one found: ' + record)
Esempio n. 5
0
def pointDetection():
    records = wave.getRecords('N') # N O A ~
    data = wave.load(records[0])
    sig = Signal(records[0], data)
    fig = plt.figure(figsize=(200, 6)) # I used figures to customize size
    ax = fig.add_subplot(211)
    ax.plot(sig.data)
    ax.plot(*zip(*sig.Ppeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.Tpeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.RPeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.QPoints), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.SPoints), marker='o', color='r', ls='')
    ax.axhline(sig.baseline)
    ax.set_title(sig.name)
    fig.savefig('/Users/samy/Downloads/{0}.png'.format(sig.name))
    plt.show()
    
    records = wave.getRecords('A') # N O A ~
    data = wave.load(records[0])
    sig = Signal(records[0], data)
    fig = plt.figure(figsize=(200, 6)) # I used figures to customize size
    ax = fig.add_subplot(211)
    ax.plot(sig.data)
    ax.plot(*zip(*sig.Ppeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.Tpeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.RPeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.QPoints), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.SPoints), marker='o', color='r', ls='')
    ax.axhline(sig.baseline)
    ax.set_title(sig.name)
    fig.savefig('/Users/samy/Downloads/{0}.png'.format(sig.name))
    plt.show()
    
    records = wave.getRecords('O') # N O A ~
    data = wave.load(records[0])
    sig = Signal(records[0], data)
    fig = plt.figure(figsize=(200, 6)) # I used figures to customize size
    ax = fig.add_subplot(211)
    ax.plot(sig.data)
    ax.plot(*zip(*sig.Ppeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.Tpeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.RPeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.QPoints), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.SPoints), marker='o', color='r', ls='')
    ax.axhline(sig.baseline)
    ax.set_title(sig.name)
    fig.savefig('/Users/samy/Downloads/{0}.png'.format(sig.name))
    plt.show()
    
    
    records = wave.getRecords('~') # N O A ~
    data = wave.load(records[0])
    sig = Signal(records[0], data)
    fig = plt.figure(figsize=(200, 6)) # I used figures to customize size
    ax = fig.add_subplot(211)
    ax.plot(sig.data)
    ax.plot(*zip(*sig.Ppeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.Tpeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.RPeaks), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.QPoints), marker='o', color='r', ls='')
    ax.plot(*zip(*sig.SPoints), marker='o', color='r', ls='')
    ax.axhline(sig.baseline)
    ax.set_title(sig.name)
    fig.savefig('/Users/samy/Downloads/{0}.png'.format(sig.name))
    plt.show()