def est_smooth_ideal(moves, ts, stype='sparc'): """Estimates the smoothness of the ideal movements. """ sys.stdout.write('.') if stype == 'sparc': return np.array( [sparc(_m, fs=1/ts, padlevel=4, fc=10., amp_th=0.05)[0] for _m in moves]) else: return np.array([ldlj(_m, fs=1/ts) for _m in moves])
def estimate_smoothness(moves, ts, param, stype="sparc"): """Estimates the smoothness of the movements of two different scales. """ if stype == 'sparc': return np.array([[ sparc(moves[i, j], fs=1 / ts, padlevel=4, fc=10., amp_th=0.05)[0] for j in xrange(param['N_m']) ] for i in xrange(len(param['scales']))]) else: return np.array([[ldlj(moves[i, j], ts) for j in xrange(param['N_m'])] for i in xrange(len(param['scales']))])
def est_smooth_ideal(moves, ts, stype='sparc'): """Estimates the smoothness of the ideal movements. """ sys.stdout.write('.') if stype == 'sparc': return np.array([ sparc(_m, fs=1 / ts, padlevel=4, fc=10., amp_th=0.05)[0] for _m in moves ]) else: return np.array([ldlj(_m, fs=1 / ts) for _m in moves])
def estimate_smoothness(moves, ts, param, stype="sparc"): """Estimates the smoothness of the movements of two different scales. """ if stype == 'sparc': return np.array( [[sparc(moves[i, j], fs=1/ts, padlevel=4, fc=10., amp_th=0.05)[0] for j in xrange(param['N_m'])] for i in xrange(len(param['scales']))]) else: return np.array( [[ldlj(moves[i, j], ts) for j in xrange(param['N_m'])] for i in xrange(len(param['scales']))])
def est_smooth_noisy(moves, ts, param, stype='sparc'): """Estimates the smoothness of noisy movements. """ sys.stdout.write('.') if stype == 'sparc': return np.array([[[ sparc(moves[i, j, k], fs=1 / ts, padlevel=4, fc=10., amp_th=0.05)[0] for k in xrange(param['N_n']) ] for j in xrange(len(param['snr']))] for i in xrange(param['N_m'])]) else: return np.array( [[[ldlj(moves[i, j, k], ts) for k in xrange(param['N_n'])] for j in xrange(len(param['snr']))] for i in xrange(param['N_m'])])
def est_smooth_noisy(moves, ts, param, stype='sparc'): """Estimates the smoothness of noisy movements. """ sys.stdout.write('.') if stype == 'sparc': return np.array( [[[sparc(moves[i, j, k], fs=1/ts, padlevel=4, fc=10., amp_th=0.05)[0] for k in xrange(param['N_n'])] for j in xrange(len(param['snr']))] for i in xrange(param['N_m'])]) else: return np.array( [[[ldlj(moves[i, j, k], ts) for k in xrange(param['N_n'])] for j in xrange(len(param['snr']))] for i in xrange(param['N_m'])])
def estimate_smoothness_values(moves, Ns, dT, ts, m_types): # smoothness estimates # smooth_vals = {'speed': {'sparc': [], 'ldlj': []}, # 'accl': {'sparc': [], 'ldlj': []}, # 'jerk': {'sparc': [], 'ldlj': []}} _str = '\rType: {0}, Ns: {1}, dT: {2}' smooth_vals = {} for _n, _type in enumerate(m_types): _temp1 = np.zeros((len(Ns), len(dT))) _temp2 = np.zeros((len(Ns), len(dT))) for i in xrange(len(Ns)): _tmp1 = [] _tmp2 = [] for j in xrange(len(dT)): sys.stdout.write(_str.format(_type, Ns[i], dT[j])) m = np.diff(moves[i][j], n=_n) / np.power(ts, _n) _tmp1.append(sparc(np.abs(m), fs=1 / ts)[0]) _tmp2.append(ldlj2(m, 1 / ts, _type)) _temp1[i, :] = _tmp1 _temp2[i, :] = _tmp2 smooth_vals[_type] = {'sparc': _temp1, 'ldlj': _temp2} return smooth_vals
def analyse_smoothness_from_different_signals(data, fs, out_dir, diff_smooth): _cols = ('Nvia', 'Nmove', 'sparc_v', 'sparc_a', 'sparc_j', 'ldlj_v', 'ldlj_a', 'ldlj_j') smoothness_summary = pd.DataFrame(columns=_cols) _outfile = "{0}/{1}/{2}".format(out_dir, diff_smooth['dir'], diff_smooth['fig_file']) with PdfPages(_outfile) as pdf: # Go through each data file and estimate smoothness using # both SPARC and LDLJ. for Nvia, Nmove, minfo, mdata in data: # Calculate speed, acceleration and jerk magnitude v = np.linalg.norm(np.array(mdata[['vx', 'vy', 'vz']]), axis=1)[:-1] a = np.linalg.norm(np.array(mdata[['ax', 'ay', 'az']]), axis=1)[:-2] j = np.linalg.norm(np.array(mdata[['jx', 'jy', 'jz']]), axis=1)[:-3] # Estimate smoothness _sparcv, v1, v2 = sparc(v, fs=fs, fc=20., amp_th=0.05) _sparca, a1, a2 = sparc(a, fs=fs, fc=20., amp_th=0.05) _sparcj, j1, j2 = sparc(j, fs=fs, fc=20., amp_th=0.05) _ldljv = log_dimensionless_jerk(np.array(mdata[['vx', 'vy', 'vz']]), fs=fs, data_type="vel", scale="ms") _ldlja = log_dimensionless_jerk(np.array(mdata[['ax', 'ay', 'az']]), fs=fs, data_type="accl", scale="ms") _ldljj = log_dimensionless_jerk(np.array(mdata[['jx', 'jy', 'jz']]), fs=fs, data_type="jerk", scale="ms") # Update data row _datarow = { 'Nvia': [int(Nvia)], 'Nmove': [int(Nmove)], 'sparc_v': [_sparcv], 'sparc_a': [_sparca], 'sparc_j': [_sparcj], 'ldlj_v': [_ldljv], 'ldlj_a': [_ldlja], 'ldlj_j': [_ldljj] } # Update smoothness summary DF smoothness_summary = pd.concat( [smoothness_summary, pd.DataFrame.from_dict(_datarow)], ignore_index=True) # plot data generate_summary_plot_for_movement(pdf, mdata, minfo, Nvia, Nmove, fs, v, v1, v2, a, a1, a2, j, j1, j2, _sparcv, _sparca, _sparcj, _ldljv, _ldlja, _ldljj) sys.stdout.write("\r{0}".format(minfo['file'])) sys.stdout.flush() # Update PDF file details d = pdf.infodict() d['Title'] = 'Smoothness estimates for different signals' d['Author'] = u'Sivakumar Balasubramanian' d['Subject'] = 'Smoothness Analysis' d['Keywords'] = 'Smoothness Analysis' d['CreationDate'] = datetime.datetime(2017, 12, 16) d['ModDate'] = datetime.datetime.today() # Save summary data _dfile = "{0}/{1}/{2}".format(out_dir, diff_smooth['dir'], diff_smooth['data_file']) smoothness_summary.to_csv(path_or_buf=_dfile, index=False) sys.stdout.write("\rDone!")
def analyse_smoothness(params): # Initialize smoothness values variable. smoothvals = { 'sparc': np.zeros((params.Ndur, params.Ntgt)), 'ldljv': np.zeros((params.Ndur, params.Ntgt)), 'ldlja': np.zeros((params.Ndur, params.Ntgt)), 'sparcs': np.zeros((params.Ndur, params.Ntgt)), 'ldljsv': np.zeros((params.Ndur, params.Ntgt)), 'ldljsa': np.zeros((params.Ndur, params.Ntgt)), 'sparcs-wom': np.zeros((params.Ndur, params.Ntgt)), 'ldljsv-wom': np.zeros((params.Ndur, params.Ntgt)), 'ldljsa-wom': np.zeros((params.Ndur, params.Ntgt)), 'agr': np.zeros((params.Ndur, params.Ntgt)), } files = glob.glob("{0}/data_*.csv".format(params.outdir)) for i, f in enumerate(files): dinx, tinx = get_dur_tgt_index_from_fname(f) # Read accl, vel and speed data mdata = read_get_vel_accl_data(f, params) # Remove mean for each accelerometer sensor data mdata['accls-wom'] = mdata['accls'] - np.mean(mdata['accls'], axis=0) mdata['vels-wom'] = np.cumsum(mdata['accls-wom'], axis=0) * params.dt mdata['spds-wom'] = np.linalg.norm(mdata['vels-wom'], axis=1) # Estimate AGR. _g = (np.sqrt(len(mdata['accl'].T)) * 98.1) agr = 20 * np.log10(np.linalg.norm(mdata['accl']) / _g) # Calculate smoothness - SPARC _sparc, _, _ = sparc(mdata['spd'], fs=params.fs) _sparcs, _, _ = sparc(mdata['spds'], fs=params.fs) _sparcswom, _, _ = sparc(mdata['spds-wom'], fs=params.fs) # Calculate smoothness - LDLJ # From velocity _ldljv = log_dimensionless_jerk(mdata['vel'], fs=params.fs, data_type="vel") _ldljsv = log_dimensionless_jerk(mdata['vels'], fs=params.fs, data_type="vel") _ldljsvwom = log_dimensionless_jerk(mdata['vels-wom'], fs=params.fs, data_type="vel") # From velocity _ldlja = log_dimensionless_jerk(mdata['accl'], fs=params.fs, data_type="accl") _ldljsa = log_dimensionless_jerk(mdata['accls'], fs=params.fs, data_type="accl") _ldljsawom = log_dimensionless_jerk(mdata['accls-wom'], fs=params.fs, data_type="accl") # Save data. smoothvals['sparc'][dinx, tinx] = _sparc smoothvals['sparcs'][dinx, tinx] = _sparcs smoothvals['sparcs-wom'][dinx, tinx] = _sparcswom smoothvals['ldljv'][dinx, tinx] = _ldljv smoothvals['ldljsv'][dinx, tinx] = _ldljsv smoothvals['ldljsv-wom'][dinx, tinx] = _ldljsvwom smoothvals['ldlja'][dinx, tinx] = _ldlja smoothvals['ldljsa'][dinx, tinx] = _ldljsa smoothvals['ldljsa-wom'][dinx, tinx] = _ldljsawom smoothvals['agr'][dinx, tinx] = agr sys.stdout.write("\r {0:3d}/{1:3d} | {2}".format(i, len(files), f)) sys.stdout.write("\nDone!") return smoothvals
def _smoothsparc(sp, sps, spwom, spswom, fs): _ss, _, _ = sparc(sp, fs) _sss, _, _ = sparc(sps, fs) _sswom, _, _ = sparc(spwom, fs) _ssswom, _, _ = sparc(spswom, fs) return _ss, _sss, _sswom, _ssswom