Example #1
0
def noiseRemoval():

    data = wave.load('A00269')
    wave.plot(data, title="A00269")
    data = wave.discardNoise(data)
    wave.plot(data, title="A00269 - After noise removal")
    
    level = 6
    omission = ([1,2], True) # 5-40 hz
    rebuilt = wave.decomp(data, 'sym5', level, omissions=omission)
    wave.plot(rebuilt, title="A00269 - After wavelet decompisition") 
    
    data = wave.load('A00420')
    wave.plot(data, title="A00420")
    data = wave.discardNoise(data)
    wave.plot(data, title="A00420 - After noise removal")
    rebuilt = wave.decomp(data, 'sym5', level, omissions=omission)
    wave.plot(rebuilt, title="A00420 - After wavelet decompisition") 
    
    data = wave.load('A00550')
    wave.plot(data, title="A00550")
    data = wave.discardNoise(data)
    wave.plot(data, title="A00550 - After noise removal")
    rebuilt = wave.decomp(data, 'sym5', level, omissions=omission)
    wave.plot(rebuilt, title="A00420 - After wavelet decompisition") 
Example #2
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')
Example #3
0
 def write(self, data: ndarray) -> None:
     with load(self.path, 'wb') as file:
         file.setnchannels(self.channels)
         file.setsampwidth(self.bitdepth // 8)
         file.setframerate(self.samprate)
         file.writeframesraw(data)
     self.load()
Example #4
0
 def load(self) -> None:
     with load(self.path, 'rb') as file:
         self.channels, self.bitdepth, self.samprate, self.size, self.comptype, self.compname = file.getparams(
         )
         self.bitdepth *= 8
         self.content = fromstring(file.readframes(self.size),
                                   dtype=f'int{self.bitdepth}')
Example #5
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
Example #6
0
    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)
#
#
feat_list = np.array(feat_list)

#feat_list=[]
#for record in records:
##    try:
Example #7
0
    cb_lrf.set_label("1/day")

    cb_eig = common.add_wavelength_colorbar(fig,
                                            eig_im,
                                            ax=row_eig.tolist(),
                                            pad=0.01)
    cb_eig.set_label("Wavenumber (1/k)")

    return fig


INPUT = sys.argv[1]
OUTPUT = sys.argv[2]

with open(INPUT) as f:
    lrfs = wave.load(f)

if OUTPUT == 'figs/fig10.pdf':
    items = ["Stable 1%", "Unstable 1%", "Unstable 10%", "Unstable 20%"]
elif OUTPUT == "figs/S2.pdf":
    items = ["Stable", "Unstable"]
    kwargs = {'eig_xlim': (-300, 300)}
else:
    raise ValueError("Output not allowed.")

print(f"Plotting {items}")
print(f"Saving to {OUTPUT}")

couplers = {key: WaveCoupler.from_tom_data(lrfs[key]) for key in items}
logging.info("Computing the spectra")
plot_data = {
Example #8
0
import matplotlib.pyplot as plt
import numpy as np
import wave
import common
import sys

with open(sys.argv[1]) as f:
    S = wave.load(f)

maxstep = S['maxstep']
Input_reg = S['Input_reg']

YMAX = 45  # Upper limit for y-axis
themean = np.mean(maxstep, axis=0) / 48
thestd = np.std(maxstep, axis=0) / 48

fig, ax = plt.subplots(figsize=(3.5, 3.5 / 1.61), constrained_layout=True)
ax2 = ax.twinx()

# Shading goes in the back
ax.fill_between(100 * Input_reg,
                themean - thestd,
                themean + thestd,
                color='silver')
ax.plot(100 * Input_reg, themean, color='k')
ax.scatter(100 * Input_reg, themean, color='k')
ax.set_ylabel('Time to actual\nprognostic failure (days)')
ax.set_xlabel('Regularization $\sigma$ (%)')
ax.set_xlim((-1, 26))
ax.set_ylim((0, YMAX))
Example #9
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()