Esempio n. 1
0
def preproc(data,
            cols,
            T1=0.75,
            T2=2,
            MX=1,
            DELTA_PEAK=0.02,
            k_near=5,
            grid_size=5,
            s=0.2):
    gsr = selectCol(data, cols, "GSR")
    t_gsr = selectCol(data, cols, "TIME")
    print "T_GSR", t_gsr.shape
    try:
        labs = selectCol(data, cols, "LAB")
    except IndexError as e:
        print "NO LAB:", e.message
        labs = np.zeros(data.shape[0])

    output_cols = ["TIME", "DRV", "PHA", "TNC", "LAB"]
    TIME_DRV, DRV, PH_DRV, TN_DRV, labs = estimate_drivers(
        t_gsr, gsr, labs, T1, T2, MX, DELTA_PEAK, k_near, grid_size, s)
    print "T_DRV", TN_DRV.shape
    print "LAB", labs.shape
    result = np.column_stack((TIME_DRV, DRV, PH_DRV, TN_DRV, labs))
    return result, output_cols
Esempio n. 2
0
def preproc(data, cols, coeffAcc=1, coeffGyr=1, coeffMag=1):
    '''
    :param data: the data
    :param cols: the olumns in input
    :param coeff: the conversion rate
    :param data_type: ACC, GYR or MAG
    :return: aray and columns
    '''
    col_acc=["ACCX", "ACCY", "ACCZ"]
    col_gyr=["GYRX", "GYRY", "GYRZ"]
    col_mag=["MAGX", "MAGY", "MAGZ"]
    time=selectCol(data, cols, "TIME")
    try:
        data_acc=selectCol(data, cols, col_acc)
        present_acc=True
    except IndexError as e:
        print "NO ACC:", e.message
        present_acc=False
    try:
        data_gyr=selectCol(data, cols, col_gyr)
        present_gyr=True
    except IndexError as e:
        print "NO GYR:", e.message
        present_gyr=False
    try:
        data_mag=selectCol(data, cols, col_mag)
        present_mag=True
    except IndexError as e:
        print "NO MAG:", e.message
        present_mag=False

    try:
        labs=selectCol(data, cols, "LAB")
    except IndexError as e:
        print "NO LAB:", e.message
        print cols
        labs=np.zeros(data.shape[0])
        pass

    result=time
    columns=["TIME"]
    if present_acc:
        data_acc=convert_units(data_acc, coeffAcc)
        result=np.column_stack((result,data_acc))
        columns += col_acc
    if present_gyr:
        data_gyr=convert_units(data_gyr, coeffGyr)
        result=np.column_stack((result,data_gyr))
        columns += col_gyr
    if present_mag:
        data_mag=convert_units(data_mag, coeffMag)
        result=np.column_stack((result,data_mag))
        columns += col_mag
    result=np.column_stack((result, labs))
    columns += ["LAB"]
    return result, columns
Esempio n. 3
0
def preproc(data, cols, coeffAcc=1, coeffGyr=1, coeffMag=1):
    '''
    :param data: the data
    :param cols: the olumns in input
    :param coeff: the conversion rate
    :param data_type: ACC, GYR or MAG
    :return: aray and columns
    '''
    col_acc=["ACCX", "ACCY", "ACCZ"]
    col_gyr=["GYRX", "GYRY", "GYRZ"]
    col_mag=["MAGX", "MAGY", "MAGZ"]
    time=selectCol(data, cols, "TIME")
    try:
        data_acc=selectCol(data, cols, col_acc)
        present_acc=True
    except IndexError as e:
        print "NO ACC:", e.message
        present_acc=False
    try:
        data_gyr=selectCol(data, cols, col_gyr)
        present_gyr=True
    except IndexError as e:
        print "NO GYR:", e.message
        present_gyr=False
    try:
        data_mag=selectCol(data, cols, col_mag)
        present_mag=True
    except IndexError as e:
        print "NO MAG:", e.message
        present_mag=False

    try:
        labs=selectCol(data, cols, "LAB")
    except IndexError as e:
        print "NO LAB:", e.message
        print cols
        labs=np.zeros(data.shape[0])
        pass

    result=time
    columns=["TIME"]
    if present_acc:
        data_acc=convert_units(data_acc, coeffAcc)
        result=np.column_stack((result,data_acc))
        columns += col_acc
    if present_gyr:
        data_gyr=convert_units(data_gyr, coeffGyr)
        result=np.column_stack((result,data_gyr))
        columns += col_gyr
    if present_mag:
        data_mag=convert_units(data_mag, coeffMag)
        result=np.column_stack((result,data_mag))
        columns += col_mag
    result=np.column_stack((result, labs))
    columns += ["LAB"]
    return result, columns
Esempio n. 4
0
def preproc(data, cols, T1=0.75, T2=2, MX=1, DELTA_PEAK=0.02, k_near=5, grid_size=5, s=0.2):
    gsr=selectCol(data, cols, "GSR")
    t_gsr=selectCol(data, cols, "TIME")
    print "T_GSR", t_gsr.shape
    try:
        labs=selectCol(data, cols, "LAB")
    except IndexError as e:
        print "NO LAB:", e.message
        labs=np.zeros(data.shape[0])

    output_cols=["TIME", "DRV", "PHA", "TNC", "LAB"]
    TIME_DRV, DRV, PH_DRV, TN_DRV, labs = estimate_drivers(t_gsr, gsr, labs, T1, T2, MX, DELTA_PEAK, k_near, grid_size, s)
    print "T_DRV", TN_DRV.shape
    print "LAB", labs.shape
    result=np.column_stack((TIME_DRV, DRV, PH_DRV, TN_DRV, labs))
    return result, output_cols
col_gyr = ["GYRX", "GYRY", "GYRZ"]
col_mag = ["MAGX", "MAGY", "MAGZ"]

empaticaAccCoeff = 2 * 9.81 / 128
empaticafsamp = 32

sensAccCoeff = 8 * 9.81 / 32768
sensGyrCoeff = 2000 / 32768
sensMagCoeff = 0.007629
sensfsamp = 100

data = tools.load_file(filename, sep=',', header=1)

data = tools.downsampling(data, 50)

t = tools.selectCol(data, columns_in, "TIME")
acc = tools.selectCol(data, columns_in, col_acc)
gyr = tools.selectCol(data, columns_in, col_gyr)
mag = tools.selectCol(data, columns_in, col_mag)
lab = tools.selectCol(data, columns_in, "LAB")

acc = inertial.convert_units(acc, coeff=sensAccCoeff)
gyr = inertial.convert_units(gyr, coeff=sensGyrCoeff)
mag = inertial.convert_units(mag, coeff=sensMagCoeff)

# tools.array_labels_to_csv(np.column_stack([t, acc]), np.array(columns_in), "./output/preproc_"+filename[7:-4]+".csv")

#-----EXTRACT FEATURES-----

windows, winlab = win.get_windows_no_mix(t, lab, 1, 0.5)
feats_acc, fcol_acc = inertial.extract_features_acc(acc, t, col_acc, windows)
col_mag=["MAGX", "MAGY", "MAGZ"]


empaticaAccCoeff=2*9.81/128
empaticafsamp=32

sensAccCoeff=8*9.81/32768
sensGyrCoeff=2000/32768
sensMagCoeff=0.007629
sensfsamp=100

data = tools.load_file(filename, sep=',', header=1)

data=tools.downsampling(data, 50)

t=tools.selectCol(data, columns_in, "TIME")
acc=tools.selectCol(data, columns_in, col_acc)
gyr=tools.selectCol(data, columns_in, col_gyr)
mag=tools.selectCol(data, columns_in, col_mag)
lab=tools.selectCol(data, columns_in, "LAB")

acc= inertial.convert_units(acc, coeff=sensAccCoeff)
gyr= inertial.convert_units(gyr, coeff=sensGyrCoeff)
mag= inertial.convert_units(mag, coeff=sensMagCoeff)

# tools.array_labels_to_csv(np.column_stack([t, acc]), np.array(columns_in), "./output/preproc_"+filename[7:-4]+".csv")

#-----EXTRACT FEATURES-----

windows, winlab=win.get_windows_no_mix(t,lab , 1, 0.5)
feats_acc, fcol_acc= inertial.extract_features_acc(acc, t, col_acc, windows)