def energy_test(self): sourcelist1 = [0.9398233871,0.9261432796,0.9179352151,0.9234072581,0.9097271505,0.9507674731,0.9398233871,0.9480314516, 0.9507674731,0.9343513441,0.9316153226,0.9288793011,0.9480314516,0.9343513441,0.9343513441,0.9234072581, 0.9343513441,0.9452954301,0.9425594086,0.9507674731,0.9398233871,0.9452954301,0.9261432796,0.9234072581, 0.9507674731,0.9370873656,0.9617115591,0.9480314516,0.9370873656,0.9343513441,0.9343513441,0.9398233871, 0.9343513441,0.9370873656,0.9234072581,0.9206712366,0.9316153226,0.9206712366,0.9206712366,0.9097271505, 0.9206712366,0.901519086,0.9042551075,0.9179352151,0.9261432796,0.9370873656,0.9425594086,0.9589755376, 0.9589755376,0.9535034946,0.9398233871,0.9343513441,0.9316153226,0.9370873656,0.9288793011,0.9699196237, 0.9726556452,0.9507674731,0.9452954301,0.9452954301,0.9562395161,0.9507674731,0.9726556452,0.9398233871, 0.9370873656,0.9452954301,0.9398233871,0.9206712366,0.9343513441,0.9261432796,0.9343513441,0.9370873656, 0.9425594086,0.9343513441,0.9398233871,0.9562395161,0.9452954301,0.9507674731,0.9507674731,0.9644475806, 0.9589755376,0.9452954301,0.9370873656,0.9343513441,0.9288793011,0.9288793011,0.9507674731,0.9452954301, 0.9617115591,0.9507674731,0.9562395161,0.9753916667,0.9562395161,0.9671836022,0.9343513441,0.9370873656, 0.9425594086,0.9507674731,0.9398233871,0.9562395161] sourceList2 = [0.1540502688,0.1331620968,0.1305510753,0.1279400538,0.1331620968,0.1253290323,0.1148849462,0.1383841398, 0.1331620968,0.1279400538,0.1357731183,0.1305510753,0.1462172043,0.1409951613,0.1201069892,0.1305510753, 0.1279400538,0.1227180108,0.1279400538,0.1174959677,0.1227180108,0.1357731183,0.1201069892,0.1174959677, 0.1279400538,0.1044408602,0.1201069892,0.1331620968,0.1122739247,0.1227180108,0.1122739247,0.1227180108, 0.1462172043,0.1357731183,0.1227180108,0.1253290323,0.1201069892,0.1122739247,0.1305510753,0.1070518817, 0.1096629032,0.1253290323,0.1201069892,0.1201069892,0.1409951613,0.1227180108,0.1462172043,0.1201069892, 0.1540502688,0.1148849462,0.1148849462,0.1227180108,0.1462172043,0.1409951613,0.1227180108,0.1096629032, 0.1070518817,0.1253290323,0.1122739247,0.1227180108,0.1227180108,0.1148849462,0.1148849462,0.1227180108, 0.1331620968,0.1018298387,0.1201069892,0.1227180108,0.1279400538,0.1122739247,0.1279400538,0.1148849462, 0.1096629032,0.1279400538,0.1122739247,0.1070518817,0.0992188172,0.0992188172,0.0887747312,0.1122739247, 0.1018298387,0.1201069892,0.0887747312,0.0835526882,0.0678865591,0.0835526882,0.1044408602,0.1044408602, 0.1122739247,0.1122739247,0.1174959677,0.1070518817,0.1018298387,0.1148849462,0.1227180108,0.1096629032, 0.1122739247,0.1122739247,0.1096629032,0.1122739247] sourceList3 = [-0.1714986559,-0.1741370968,-0.1926061828,-0.1583064516,-0.1820524194,-0.1794139785,-0.1794139785, -0.1978830645,-0.1926061828,-0.1952446237,-0.2057983871,-0.1952446237,-0.1741370968,-0.1767755376, -0.1820524194,-0.1899677419,-0.1688602151,-0.1767755376,-0.1926061828,-0.1767755376,-0.1846908602, -0.2189905914,-0.1609448925,-0.1926061828,-0.1846908602,-0.1952446237,-0.1952446237,-0.1846908602, -0.1873293011,-0.1767755376,-0.1820524194,-0.1846908602,-0.1846908602,-0.1794139785,-0.1794139785, -0.1714986559,-0.1714986559,-0.1609448925,-0.1609448925,-0.1583064516,-0.1794139785,-0.1741370968, -0.1662217742,-0.1609448925,-0.150391129,-0.1530295699,-0.1767755376,-0.1583064516,-0.1583064516, -0.1767755376,-0.1899677419,-0.1978830645,-0.1873293011,-0.2242674731,-0.1556680108,-0.2005215054, -0.1846908602,-0.1688602151,-0.1530295699,-0.1688602151,-0.1741370968,-0.1635833333,-0.1556680108, -0.1609448925,-0.1635833333,-0.1530295699,-0.1530295699,-0.1609448925,-0.1635833333,-0.1451142473, -0.1398373656,-0.1424758065,-0.1424758065,-0.131922043,-0.1371989247,-0.1530295699,-0.1556680108, -0.1424758065,-0.1213682796,-0.1820524194,-0.1345604839,-0.1108145161,-0.1292836022,-0.1451142473, -0.1530295699,-0.1556680108,-0.1424758065,-0.1424758065,-0.1662217742,-0.1556680108,-0.150391129, -0.150391129,-0.1477526882,-0.1477526882,-0.1451142473,-0.1556680108,-0.1477526882,-0.1398373656, -0.1530295699,-0.1477526882] target =0.92682144475 result = energyFeat.energyCalc(sourcelist1,sourceList2,sourceList3) self.assertAlmostEqual(result,target)
def energy_test(self): """energy_test: this function checks the energy calculation from accelerometer data""" sourcelist1 = [ 0.9398233871, 0.9261432796, 0.9179352151, 0.9234072581, 0.9097271505, 0.9507674731, 0.9398233871, 0.9480314516, 0.9507674731, 0.9343513441, 0.9316153226, 0.9288793011, 0.9480314516, 0.9343513441, 0.9343513441, 0.9234072581, 0.9343513441, 0.9452954301, 0.9425594086, 0.9507674731, 0.9398233871, 0.9452954301, 0.9261432796, 0.9234072581, 0.9507674731, 0.9370873656, 0.9617115591, 0.9480314516, 0.9370873656, 0.9343513441, 0.9343513441, 0.9398233871, 0.9343513441, 0.9370873656, 0.9234072581, 0.9206712366, 0.9316153226, 0.9206712366, 0.9206712366, 0.9097271505, 0.9206712366, 0.901519086, 0.9042551075, 0.9179352151, 0.9261432796, 0.9370873656, 0.9425594086, 0.9589755376, 0.9589755376, 0.9535034946, 0.9398233871, 0.9343513441, 0.9316153226, 0.9370873656, 0.9288793011, 0.9699196237, 0.9726556452, 0.9507674731, 0.9452954301, 0.9452954301, 0.9562395161, 0.9507674731, 0.9726556452, 0.9398233871, 0.9370873656, 0.9452954301, 0.9398233871, 0.9206712366, 0.9343513441, 0.9261432796, 0.9343513441, 0.9370873656, 0.9425594086, 0.9343513441, 0.9398233871, 0.9562395161, 0.9452954301, 0.9507674731, 0.9507674731, 0.9644475806, 0.9589755376, 0.9452954301, 0.9370873656, 0.9343513441, 0.9288793011, 0.9288793011, 0.9507674731, 0.9452954301, 0.9617115591, 0.9507674731, 0.9562395161, 0.9753916667, 0.9562395161, 0.9671836022, 0.9343513441, 0.9370873656, 0.9425594086, 0.9507674731, 0.9398233871, 0.9562395161 ] sourceList2 = [ 0.1540502688, 0.1331620968, 0.1305510753, 0.1279400538, 0.1331620968, 0.1253290323, 0.1148849462, 0.1383841398, 0.1331620968, 0.1279400538, 0.1357731183, 0.1305510753, 0.1462172043, 0.1409951613, 0.1201069892, 0.1305510753, 0.1279400538, 0.1227180108, 0.1279400538, 0.1174959677, 0.1227180108, 0.1357731183, 0.1201069892, 0.1174959677, 0.1279400538, 0.1044408602, 0.1201069892, 0.1331620968, 0.1122739247, 0.1227180108, 0.1122739247, 0.1227180108, 0.1462172043, 0.1357731183, 0.1227180108, 0.1253290323, 0.1201069892, 0.1122739247, 0.1305510753, 0.1070518817, 0.1096629032, 0.1253290323, 0.1201069892, 0.1201069892, 0.1409951613, 0.1227180108, 0.1462172043, 0.1201069892, 0.1540502688, 0.1148849462, 0.1148849462, 0.1227180108, 0.1462172043, 0.1409951613, 0.1227180108, 0.1096629032, 0.1070518817, 0.1253290323, 0.1122739247, 0.1227180108, 0.1227180108, 0.1148849462, 0.1148849462, 0.1227180108, 0.1331620968, 0.1018298387, 0.1201069892, 0.1227180108, 0.1279400538, 0.1122739247, 0.1279400538, 0.1148849462, 0.1096629032, 0.1279400538, 0.1122739247, 0.1070518817, 0.0992188172, 0.0992188172, 0.0887747312, 0.1122739247, 0.1018298387, 0.1201069892, 0.0887747312, 0.0835526882, 0.0678865591, 0.0835526882, 0.1044408602, 0.1044408602, 0.1122739247, 0.1122739247, 0.1174959677, 0.1070518817, 0.1018298387, 0.1148849462, 0.1227180108, 0.1096629032, 0.1122739247, 0.1122739247, 0.1096629032, 0.1122739247 ] sourceList3 = [ -0.1714986559, -0.1741370968, -0.1926061828, -0.1583064516, -0.1820524194, -0.1794139785, -0.1794139785, -0.1978830645, -0.1926061828, -0.1952446237, -0.2057983871, -0.1952446237, -0.1741370968, -0.1767755376, -0.1820524194, -0.1899677419, -0.1688602151, -0.1767755376, -0.1926061828, -0.1767755376, -0.1846908602, -0.2189905914, -0.1609448925, -0.1926061828, -0.1846908602, -0.1952446237, -0.1952446237, -0.1846908602, -0.1873293011, -0.1767755376, -0.1820524194, -0.1846908602, -0.1846908602, -0.1794139785, -0.1794139785, -0.1714986559, -0.1714986559, -0.1609448925, -0.1609448925, -0.1583064516, -0.1794139785, -0.1741370968, -0.1662217742, -0.1609448925, -0.150391129, -0.1530295699, -0.1767755376, -0.1583064516, -0.1583064516, -0.1767755376, -0.1899677419, -0.1978830645, -0.1873293011, -0.2242674731, -0.1556680108, -0.2005215054, -0.1846908602, -0.1688602151, -0.1530295699, -0.1688602151, -0.1741370968, -0.1635833333, -0.1556680108, -0.1609448925, -0.1635833333, -0.1530295699, -0.1530295699, -0.1609448925, -0.1635833333, -0.1451142473, -0.1398373656, -0.1424758065, -0.1424758065, -0.131922043, -0.1371989247, -0.1530295699, -0.1556680108, -0.1424758065, -0.1213682796, -0.1820524194, -0.1345604839, -0.1108145161, -0.1292836022, -0.1451142473, -0.1530295699, -0.1556680108, -0.1424758065, -0.1424758065, -0.1662217742, -0.1556680108, -0.150391129, -0.150391129, -0.1477526882, -0.1477526882, -0.1451142473, -0.1556680108, -0.1477526882, -0.1398373656, -0.1530295699, -0.1477526882 ] target = 0.92682144475 result = energyFeat.energyCalc(sourcelist1, sourceList2, sourceList3) self.assertAlmostEqual(result, target)
def calc_features(fullarray, micannot, samp_rate): #vect_c not used pre_win = [0, 100] #pre-window 1s impact_max = [50, 150] #1s imp_win = [50, 650] # impact window 6s post_win = [300, 1200] #9 s, based on the paper it should be 250-1200 datAr = [] #for vector magnitude datXa = [] #for X values datYa = [] #for Y values datZa = [] #for Z values datXg = [] datYg = [] datZg = [] for tempdata in fullarray: datAr.append(float(tempdata[6])) datXa.append(float(tempdata[0])) datYa.append(float(tempdata[1])) datZa.append(float(tempdata[2])) datXg.append(float(tempdata[3])) datYg.append(float(tempdata[4])) datZg.append(float(tempdata[5])) #if micannot == 2: # print "fall" #else: # print "non-fall" #plt.plot(datAr) #plt.show() #****************************************************************************************************************************** #minimum pre impact min_pre = min(datAr[pre_win[0]:pre_win[1]]) #minimum value impact #min_imp = min(datAr[imp_win[0]:imp_win[1]]) #minimum post imp #min_post = min(datAr[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #maximum value pre-impact #max_pre = max(datAr[pre_win[0]:pre_win[1]]) #maximum value impact max_imp = max(datAr[impact_max[0]:impact_max[1]]) #maximum value post #max_post = max(datAr[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #mean for pre-impact event meanList1 = datAr[pre_win[0]:pre_win[1]] meanVal1 = numpy.mean(meanList1) #****************************************************************************************************************************** #mean for impact meanList2 = datAr[imp_win[0]:imp_win[1]] meanVal2 = numpy.mean(meanList2) #****************************************************************************************************************************** #mean for post-impact meanList3 = datAr[post_win[0]:post_win[1]] meanVal3 = numpy.mean(meanList3) #****************************************************************************************************************************** #Root mean square for pre-impact rmsList1 = datAr[pre_win[0]:pre_win[1]] rms1 = sqrt(mean(numpy.array(rmsList1)**2)) #Root mean square for impact rmsList2 = datAr[imp_win[0]:imp_win[1]] rms2 = sqrt(mean(numpy.array(rmsList2)**2)) #Root mean square for post-impact rmsList3 = datAr[post_win[0]:post_win[1]] rms3 = sqrt(mean(numpy.array(rmsList3)**2)) #****************************************************************************************************************************** #variance for pre-impact variance1 = numpy.var(datAr[pre_win[0]:pre_win[1]], ddof=1) #variance for impact variance2 = numpy.var(datAr[imp_win[0]:imp_win[1]], ddof=1) #variance for post-impact variance3 = numpy.var(datAr[post_win[0]:post_win[1]], ddof=1) #****************************************************************************************************************************** #velocity in pre-impact velo1 = integrator.integrate(datAr[pre_win[0]:pre_win[1]]) #velocity in impact velo2 = integrator.integrate(datAr[imp_win[0]:imp_win[1]]) #velocity in post-impact velo3 = integrator.integrate(datAr[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #energy in pre-impact win1x = datXa[pre_win[0]:pre_win[1]] win1y = datYa[pre_win[0]:pre_win[1]] win1z = datZa[pre_win[0]:pre_win[1]] energy1 = energyFeat.energyCalc(win1x, win1y, win1z) #energy in impact win2x = datXa[imp_win[0]:imp_win[1]] win2y = datYa[imp_win[0]:imp_win[1]] win2z = datZa[imp_win[0]:imp_win[1]] energy2 = energyFeat.energyCalc(win2x, win2y, win2z) #energy in post-impact win3x = datXa[post_win[0]:post_win[1]] win3y = datYa[post_win[0]:post_win[1]] win3z = datZa[post_win[0]:post_win[1]] energy3 = energyFeat.energyCalc(win3x, win3y, win3z) #****************************************************************************************************************************** #signal magnitude are in pre-impact sma1 = smaFeat.smafeat(datXa[pre_win[0]:pre_win[1]], datYa[pre_win[0]:pre_win[1]], datZa[pre_win[0]:pre_win[1]]) #signal magnitude are in impact sma2 = smaFeat.smafeat(datXa[imp_win[0]:imp_win[1]], datYa[imp_win[0]:imp_win[1]], datZa[imp_win[0]:imp_win[1]]) #signal magnitude are in pre-impact sma3 = smaFeat.smafeat(datXa[post_win[0]:post_win[1]], datYa[post_win[0]:post_win[1]], datZa[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #exponential moving average in pre-impact ewma1 = emafit.ema(datAr[pre_win[0]:pre_win[1]]) #exponential moving average in impact ewma2 = emafit.ema(datAr[imp_win[0]:imp_win[1]]) #exponential moving average in post-impact ewma3 = emafit.ema(datAr[post_win[0]:post_win[1]]) #****************************************************************************************************************************** datfeat = [ min_pre, max_imp, meanVal1, meanVal2, meanVal3, rms1, rms2, rms3, variance1, variance2, variance3, velo1, velo2, velo3, energy1, energy2, energy3, sma1, sma2, sma3, ewma1, ewma2, ewma3, micannot ] return datfeat
def featurescom (fullarray, micannot,act_state): samp_rate = source_var.sampling_rate() pre_win = [0, samp_rate] #pre-window imp_win = [(samp_rate/2)-1, int(6.5 * samp_rate)] # impact window post_win = [int((2.5 * samp_rate))-1, 12 * samp_rate] #post impact window max_win = [(samp_rate/2)-1, int(1.5 * samp_rate)] # window for search max value tilt_sample_impact = [(2*samp_rate)-1, 3*samp_rate] tilt_sample_post = [(3 * samp_rate) - 1, 12 * samp_rate] # window for tilt-angle datAr = [] #for vector magnitude datXa= [] #for X values datYa= [] #for Y values datZa= [] #for Z values datXg=[] datYg=[] datZg=[] for tempdata in fullarray: datAr.append(float(tempdata[6])) datXa.append(float(tempdata[0])) datYa.append(float(tempdata[1])) datZa.append(float(tempdata[2])) datXg.append(float(tempdata[3])) datYg.append(float(tempdata[4])) datZg.append(float(tempdata[5])) #****************************************************************************************************************************** #minimum value feature minVal = min(datAr[pre_win[0]:pre_win[1]]) #****************************************************************************************************************************** #maximum value feature maxVal = max(datAr[max_win[0]:max_win[1]]) #****************************************************************************************************************************** #mean for pre-impact event meanList1 = datAr[pre_win[0]:pre_win[1]] meanVal1 = numpy.mean(meanList1) #****************************************************************************************************************************** #mean for impact meanList2 = datAr[imp_win[0]:imp_win[1]] meanVal2 = numpy.mean(meanList2) #****************************************************************************************************************************** #mean for post-impact meanList3 = datAr[post_win[0]:post_win[1]] meanVal3 = numpy.mean(meanList3) #****************************************************************************************************************************** #Root mean square for pre-impact rmsList1 = datAr[pre_win[0]:pre_win[1]] rms1 = sqrt(mean(numpy.array(rmsList1)**2)) #Root mean square for impact rmsList2 = datAr[imp_win[0]:imp_win[1]] rms2 = sqrt(mean(numpy.array(rmsList2)**2)) #Root mean square for post-impact rmsList3 = datAr[post_win[0]:post_win[1]] rms3 = sqrt(mean(numpy.array(rmsList3)**2)) #****************************************************************************************************************************** #variance for pre-impact variance1 = numpy.var(datAr[pre_win[0]:pre_win[1]],ddof=1) #variance for impact variance2 = numpy.var(datAr[imp_win[0]:imp_win[1]],ddof=1) #variance for post-impact variance3 = numpy.var(datAr[post_win[0]:post_win[1]],ddof=1) #****************************************************************************************************************************** #velocity in pre-impact velo1 = integrator.integrate(datAr[pre_win[0]:pre_win[1]]) #velocity in impact velo2 = integrator.integrate(datAr[imp_win[0]:imp_win[1]]) #velocity in post-impact velo3 = integrator.integrate(datAr[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #energy in pre-impact win1x = datXa[pre_win[0]:pre_win[1]] win1y = datYa[pre_win[0]:pre_win[1]] win1z = datZa[pre_win[0]:pre_win[1]] energy1 = energyFeat.energyCalc(win1x,win1y,win1z) #energy in impact win2x = datXa[imp_win[0]:imp_win[1]] win2y = datYa[imp_win[0]:imp_win[1]] win2z = datZa[imp_win[0]:imp_win[1]] energy2 = energyFeat.energyCalc(win2x,win2y,win2z) #energy in post-impact win3x = datXa[post_win[0]:post_win[1]] win3y = datYa[post_win[0]:post_win[1]] win3z = datZa[post_win[0]:post_win[1]] energy3 = energyFeat.energyCalc(win3x,win3y,win3z) #****************************************************************************************************************************** #signal magnitude are in pre-impact sma1 = smaFeat.smafeat(datXa[pre_win[0]:pre_win[1]],datYa[pre_win[0]:pre_win[1]],datZa[pre_win[0]:pre_win[1]]) #signal magnitude are in impact sma2 = smaFeat.smafeat(datXa[imp_win[0]:imp_win[1]],datYa[imp_win[0]:imp_win[1]],datZa[imp_win[0]:imp_win[1]]) #signal magnitude are in pre-impact sma3 = smaFeat.smafeat(datXa[post_win[0]:post_win[1]],datYa[post_win[0]:post_win[1]],datZa[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #exponential moving average in pre-impact ewma1 = emafit.ema(datAr[pre_win[0]:pre_win[1]]) #exponential moving average in impact ewma2 = emafit.ema(datAr[imp_win[0]:imp_win[1]]) #exponential moving average in post-impact ewma3 = emafit.ema(datAr[post_win[0]:post_win[1]]) #****************************************************************************************************************************** #Tilt Angle in pre-impact all_angle_1 = mytilt.mytilt(datXa[pre_win[0]:pre_win[1]],datYa[pre_win[0]:pre_win[1]],datZa[pre_win[0]:pre_win[1]], datXg[pre_win[0]:pre_win[1]],datYg[pre_win[0]:pre_win[1]],datZg[pre_win[0]:pre_win[1]]) angle_y_1 = numpy.max(numpy.abs(numpy.array(all_angle_1[0]))) angle_z_1 = numpy.max(numpy.abs(numpy.array(all_angle_1[1]))) #Tilt Angle in impact all_angle_2 = mytilt.mytilt(datXa[tilt_sample_impact[0]:tilt_sample_impact[1]],datYa[tilt_sample_impact[0]:tilt_sample_impact[1]], datZa[tilt_sample_impact[0]:tilt_sample_impact[1]],datXg[tilt_sample_impact[0]:tilt_sample_impact[1]], datYg[tilt_sample_impact[0]:tilt_sample_impact[1]],datZg[tilt_sample_impact[0]:tilt_sample_impact[1]]) angle_y_2 = numpy.max(numpy.abs(numpy.array(all_angle_2[0]))) angle_z_2 = numpy.max(numpy.abs(numpy.array(all_angle_2[1]))) #Tilt Angle in post-impact all_angle_3 = mytilt.mytilt(datXa[tilt_sample_post[0]:tilt_sample_post[1]],datYa[tilt_sample_post[0]:tilt_sample_post[1]], datZa[tilt_sample_post[0]:tilt_sample_post[1]],datXg[tilt_sample_post[0]:tilt_sample_post[1]], datYg[tilt_sample_post[0]:tilt_sample_post[1]],datZg[tilt_sample_post[0]:tilt_sample_post[1]]) angle_y_3 = numpy.max(numpy.abs(numpy.array(all_angle_3[0]))) angle_z_3 = numpy.max(numpy.abs(numpy.array(all_angle_3[1]))) #****************************************************************************************************************************** annot = micannot #datfeat = [minVal, maxVal, meanVal1, meanVal2, meanVal3, rms1, rms2, rms3, variance1, variance2, variance3, velo1, # velo2, velo3, energy1, energy2, energy3, sma1, sma2, sma3, ewma1, ewma2, ewma3, act_state, annot] datfeat = [minVal, maxVal, meanVal1, meanVal2, meanVal3, rms1, rms2, rms3, variance1, variance2, variance3, velo1, velo2, velo3, energy1, energy2, energy3, sma1, sma2, sma3, ewma1, ewma2, ewma3, angle_y_1, angle_z_1, angle_y_2, angle_z_2,angle_y_3,angle_z_3,act_state, annot] return datfeat