Exemplo n.º 1
0
def calc_features(frame):

    acc_x = frame["acc_x"]
    acc_y = frame["acc_y"]
    acc_z = frame["acc_z"]
    gyro_x = frame["gyro_x"]
    gyro_y = frame["gyro_y"]
    gyro_z = frame["gyro_z"]
    flex_index = frame["flex_index"]
    flex_pinky = frame["flex_pinky"]

    acc_mean_x = calc.mean(acc_x)
    acc_mean_y = calc.mean(acc_y)
    acc_mean_z = calc.mean(acc_z)

    acc_std_x = calc.std(acc_x)
    acc_std_y = calc.std(acc_y)
    acc_std_z = calc.std(acc_z)

    acc_mad_x = calc.mad(acc_x)
    acc_mad_y = calc.mad(acc_y)
    acc_mad_z = calc.mad(acc_z)

    acc_max_x = calc.max(acc_x)
    acc_max_y = calc.max(acc_y)
    acc_max_z = calc.max(acc_z)

    acc_min_x = calc.min(acc_x)
    acc_min_y = calc.min(acc_y)
    acc_min_z = calc.min(acc_z)

    acc_iqr_x = calc.iqr(acc_x)
    acc_iqr_y = calc.iqr(acc_y)
    acc_iqr_z = calc.iqr(acc_z)

    acc_correlation_1 = calc.correlation(acc_x, acc_y)
    acc_correlation_2 = calc.correlation(acc_x, acc_z)
    acc_correlation_3 = calc.correlation(acc_y, acc_z)

    gyro_mean_x = calc.mean(gyro_x)
    gyro_mean_y = calc.mean(gyro_y)
    gyro_mean_z = calc.mean(gyro_z)

    gyro_std_x = calc.std(gyro_x)
    gyro_std_y = calc.std(gyro_y)
    gyro_std_z = calc.std(gyro_z)

    gyro_mad_x = calc.mad(gyro_x)
    gyro_mad_y = calc.mad(gyro_y)
    gyro_mad_z = calc.mad(gyro_z)

    gyro_max_x = calc.max(gyro_x)
    gyro_max_y = calc.max(gyro_y)
    gyro_max_z = calc.max(gyro_z)

    gyro_min_x = calc.min(gyro_x)
    gyro_min_y = calc.min(gyro_y)
    gyro_min_z = calc.min(gyro_z)

    gyro_iqr_x = calc.iqr(gyro_x)
    gyro_iqr_y = calc.iqr(gyro_y)
    gyro_iqr_z = calc.iqr(gyro_z)

    gyro_correlation_1 = calc.correlation(gyro_x, gyro_y)
    gyro_correlation_2 = calc.correlation(gyro_x, gyro_z)
    gyro_correlation_3 = calc.correlation(gyro_y, gyro_z)

    feature_frame = [
        acc_mean_x, acc_mean_y, acc_mean_z, acc_std_x, acc_std_y, acc_std_z,
        acc_mad_x, acc_mad_y, acc_mad_z, acc_max_x, acc_max_y, acc_max_z,
        acc_min_x, acc_min_y, acc_min_z, acc_iqr_x, acc_iqr_y, acc_iqr_z,
        acc_correlation_1, acc_correlation_2, acc_correlation_3, gyro_mean_x,
        gyro_mean_y, gyro_mean_z, gyro_std_x, gyro_std_y, gyro_std_z,
        gyro_mad_x, gyro_mad_y, gyro_mad_z, gyro_max_x, gyro_max_y, gyro_max_z,
        gyro_min_x, gyro_min_y, gyro_min_z, gyro_iqr_x, gyro_iqr_y, gyro_iqr_z,
        gyro_correlation_1, gyro_correlation_2, gyro_correlation_3
    ]

    return feature_frame
Exemplo n.º 2
0
def process_raw_data(filename = None, 
    maxima = None, 
    binsize=20,
    deg=3,
    delta=.004,
    xlabel='Time (s)',
    title = None,
    **kwargs):
    '''

        Args:
        =======
        -> maxima T/F deteck peaks as maxima or minima
        -> label 

        This function is the main entry point.
        given a file it will do the whole processing... thing...
        this is mainly just to make it easier.

        this is very much dependant on the structuer of the datafile!
        If you change acquisition!!! change this!!!!

    '''
    # ASSUMPTIONS!!!!!! change these. there may be more subtle assumptions
    # further in. 
    inputV = 'Voltage_0'    # input signal, to track phase changes
    outputV = 'Voltage_1'   # output signal, to track particles
    x = 'X_Value'           # time array, 

    r = parse(filename=filename, **kwargs) # parse the datafile
    assert(inputV in r) # __ASSUMPTIONS__ we know this to be the input signal
    assert(outputV in r) # __ASSUMPTIONS__ we know this to be the output signal


    # add some useful info 

    r['input ave'] = [mean(r[inputV])] * len(r[inputV])
    r['output ave'] = [mean(r[outputV])] * len(r[outputV])

    # =============================
    ''' Smooth the output to remove large peaks resulting from rare noise events '''
    r['smoothed output'] = moving_average(r[outputV], n=binsize)
    r['bin size'] = binsize
    
    # =============================
    ''' remove instrumental drift. By fitting a polynomial to the 
        output signal, then subtracting it. '''
    r['polyfit to output'] = polyfit(r[x],r[outputV], d=deg)
    r['deg'] = deg

    r['output adjusted'] = r['smoothed output'] - r['polyfit to output']


    # ==============================
    ''' Run the detect peak algorithm to count the peaks in the datafile. '''
    mx, mn = find_peaks(r[x], r['output adjusted'], delta=delta)
    if maxima: 
        r['particles'] = mx
        r['number of particles'] = len(mx)
    else: 
        r['particles'] = mn 
        r['number of particles'] = len(mn)
    r['max'] = maxima
    r['delta'] = delta


    # =============================
    ''' The hard part is done. just plot the results. 
        I want to produce one summary graph. that displays the processing pipeline
        and one that is just the results. 
    '''
    plots = [
        ('Raw Output', r[outputV]),
        ('Smoothed Output', r['smoothed output']),
        ('Result', r['output adjusted'])
    ]
    plot(r[x], plots, x_title=xlabel, plot_title=title, measurements=[])

    # =============================
    # and we're done. return the results just for goodness sake. 
    return r