# plt.figure(1) # plt.plot(gsr_data[:,0], gsr_data[:,1]) # plt.xlabel("Time (s)") # plt.ylabel("GSR (uS)") # plt.title("Raw GSR") # t_gsr, gsr = GSR.remove_spikes(gsr_data[:,1], nFS) t_gsr = gsr_data[:, 0] gsr = gsr_data[:, 1] print gsr.shape # print t_gsr.shape, gsr.shape, gsr_data.shape t_driver, driver, phasic_d, tonic_d = GSR.estimate_drivers( t_gsr, gsr, T1, T2, MX, DELTA) outputlabels = ["timestamp", "driver", "phasic", "tonic"] tools.array_labels_to_csv( np.column_stack([t_driver, driver, phasic_d, tonic_d]), np.array(outputlabels), "./output/preproc_" + filename[7:-4] + ".csv") #-----FEATURES----- windows = win.generate_dummy_windows(t_driver, 20, 10) features = GSR.extract_features(phasic_d, t_driver, DELTA, windows) tools.dict_to_csv(features, "./output/feat_" + filename[7:-4] + ".csv") # tools.prepare_json_to_plot_time(t_driver, [driver, phasic_d, tonic_d], ["Driver", "Phasic", "Tonic"]) # plt.figure(2) # plt.plot(t_driver, np.c_[tonic_d, driver, phasic_d]) # plt.legend(["Tonic", "Driver", "Phasic"]) # plt.title("Processed GSR") # plt.xlabel("Time (s)") # plt.ylabel("GSR (uS)")
filterType=filterType) #compact timestamp, signal and labels for the next processes total_signal = filtered_signal #extraction peaks from the signal #the user selects the parameters, with default suggested delta = 1 peaks = IBI.getPeaksIBI(total_signal, SAMP_F, delta) #calculation of the IBI #the user selects the parameters, with default suggested minFr = 40 maxFr = 200 ibi = IBI.max2interval(peaks, minFr, maxFr) tools.array_labels_to_csv(ibi, np.array(["timestamp", "IBI", "lables"]), "./output/preproc_" + fileName[7:-4] + ".csv") #-----FEATURES EXTRACTION----- timestamp = ibi[:, 0] timed_vals = ibi[:, [0, 1]] lbls = ibi[:, 2] winds, lbls = windowing.get_windows_contiguos(timestamp, lbls, 100, 50) feat, lbls = IBI.extract_IBI_features(timed_vals, winds, lbls) feat_col = np.array( ['RRmean', 'RRSTD', 'pNN50', 'pNN25', 'pNN10', 'RMSSD', 'SDSD']) tools.array_labels_to_csv(feat, feat_col, "./output/feat_" + fileName[7:-4] + ".csv")
plen_aft = 1 filtered_signal = ourFilters.matched_filter(downsampled_data, SAMP_F, start_good_beats, end_good_beats, plen_bef, plen_aft) print 'filtered' ''' #extraction peaks from the signal #the user selects the parameters, with default suggested delta = 0.2 peaks = IBI.getPeaksIBI(filtered_signal,SAMP_F, delta) print 'plotting...' plt.plot(filtered_signal[:,0],filtered_signal[:,1]) plt.plot(peaks[:,0], peaks[:,1], 'o') plt.show() #calculation of the IBI #the user selects the parameters, with default suggested minFr = 40 maxFr = 200 ibi = IBI.max2interval(peaks, minFr, maxFr) ourTools.array_labels_to_csv(ibi, np.array(["timestamp", "IBI", "labels"]), "./output/preproc_"+fileName[7:-4]+".csv") #-----FEATURES EXTRACTION----- lbls = np.array([0 for i in ibi[:,0]]) winds, lbls = windowing.get_windows_contiguos(ibi[:,0], lbls, 100, 50) feat, lbls = IBI.extract_IBI_features(ibi, winds, lbls) feat_col=np.array(['RRmean', 'RRSTD', 'pNN50', 'pNN25', 'pNN10', 'RMSSD', 'SDSD']) ourTools.array_labels_to_csv(feat, feat_col, "./output/feat_"+fileName[7:-4]+".csv")
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) feats_gyr, fcol_gyr = inertial.extract_features_gyr(gyr, t, col_gyr, windows) feats_mag, fcol_mag = inertial.extract_features_mag(mag, t, col_mag, windows) feats = np.column_stack([feats_acc, feats_gyr, feats_mag, winlab]) columns_out = np.r_[fcol_acc, fcol_gyr, fcol_mag, np.array(["LAB"])] # print feats.shape # print columns.shape, columns tools.array_labels_to_csv(feats, columns_out, "./output2/feat_" + filename[7:-4] + ".csv") # # feats.to_csv("./output/feat_6.csv")
gsr_data= tools.downsampling(gsr_data, nFS) # plt.figure(1) # plt.plot(gsr_data[:,0], gsr_data[:,1]) # plt.xlabel("Time (s)") # plt.ylabel("GSR (uS)") # plt.title("Raw GSR") # t_gsr, gsr = GSR.remove_spikes(gsr_data[:,1], nFS) t_gsr = gsr_data[:,0] gsr = gsr_data[:,1] print gsr.shape # print t_gsr.shape, gsr.shape, gsr_data.shape t_driver, driver, phasic_d, tonic_d= GSR.estimate_drivers(t_gsr, gsr, T1, T2, MX, DELTA) outputlabels=["timestamp", "driver", "phasic", "tonic"] tools.array_labels_to_csv(np.column_stack([t_driver, driver, phasic_d, tonic_d]), np.array(outputlabels), "./output/preproc_"+filename[7:-4]+".csv") #-----FEATURES----- windows=win.generate_dummy_windows(t_driver, 20, 10) features = GSR.extract_features(phasic_d, t_driver, DELTA, windows) tools.dict_to_csv(features, "./output/feat_"+filename[7:-4]+".csv") # tools.prepare_json_to_plot_time(t_driver, [driver, phasic_d, tonic_d], ["Driver", "Phasic", "Tonic"]) # plt.figure(2) # plt.plot(t_driver, np.c_[tonic_d, driver, phasic_d]) # plt.legend(["Tonic", "Driver", "Phasic"]) # plt.title("Processed GSR") # plt.xlabel("Time (s)") # plt.ylabel("GSR (uS)") # plt.show()
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) feats_gyr, fcol_gyr= inertial.extract_features_gyr(gyr, t, col_gyr, windows) feats_mag, fcol_mag= inertial.extract_features_mag(mag, t, col_mag, windows) feats=np.column_stack([feats_acc, feats_gyr, feats_mag, winlab]) columns_out=np.r_[fcol_acc, fcol_gyr, fcol_mag, np.array(["LAB"])] # print feats.shape # print columns.shape, columns tools.array_labels_to_csv(feats, columns_out, "./output2/feat_"+filename[7:-4]+".csv") # # feats.to_csv("./output/feat_6.csv")