def ingest_data(self, data, modeled=True, length_fit=False): self.BM = BodyModel(data) if length_fit: self.BM.fit() self.data = data if modeled: n = normalize_data({'kin': self.BM.data})['kin'] X = np.column_stack((n[key] for key in KL)) self.model_data = normalize_rows(X) times = self.data['Time'] newtimes = np.linspace(times[0], times[-1], 1000) self.times = times self.newtimes = newtimes floor = self.floor if self.floor else 0.5 * (np.mean(self.data['FootRight'].T[2]) + np.mean(self.data['FootLeft'].T[2])) #if (floor == None): floor = 0.5 * (np.mean(self.data['FootRight'].T[2]) + np.mean(self.data['FootLeft'].T[2])) vl = VL(self.BM.data, floor=floor) modeled_vl = vl + VLm(self.model_data) if modeled else vl subsampled_vl = UnivariateSpline(times, modeled_vl, s=0)(newtimes) self.smoothed_VL = UnivariateSpline(newtimes, sav_gol.savgol_filter(subsampled_vl, 31, 3), s=0) # smooth pretty hard to stop wobbling, overest? hl = HL(self.BM.data) modeled_hl = hl + HLm(self.model_data) if modeled else hl subsampled_hl = UnivariateSpline(times, modeled_hl, s=0)(newtimes) self.smoothed_HL = UnivariateSpline(newtimes, sav_gol.savgol_filter(subsampled_hl, 31, 3), s=0) # smooth pretty hard to stop wobbling, overest? aa = AA(self.BM.data) modeled_aa = aa + AAm(self.model_data) if modeled else aa subsampled_aa = UnivariateSpline(times, modeled_aa, s=0)(newtimes) self.smoothed_AA = UnivariateSpline(newtimes, sav_gol.savgol_filter(subsampled_aa, 31, 3), s=0) # smooth pretty hard to stop wobbling, overest? self.find_F() # self.find_origins() # self.find_ends() self.find_V() self.find_H() self.find_D() self.find_A()
def sg_filter_data(self): window = 33 degree = 3 times = self.data.raw['Time'] newtimes = np.linspace(times[0], times[-1], 33*(times[-1] - times[0])) for label in KIN_LABELS: # if not 'Hand' in label and not 'Foot' in label: # self.dampen_jitter(label) filtered = [] for i in range(3): temp = UnivariateSpline(times, self.data.raw[label].T[i], s=0)(newtimes) filt = sav_gol.savgol_filter(temp, window, degree) filt_spline = UnivariateSpline(newtimes, filt, s=0) filtered.append(filt_spline(times)) self.data.raw[label] = np.column_stack((filtered[i] for i in range(3))) self.smoothing = "SG"
def sg_filter_data(point): window = 33 degree = 3 if "Time" not in point: raise Exception("Need time to filter!") times = point["Time"] newtimes = np.linspace(times[0], times[-1], 33 * (times[-1] - times[0])) outpoint = {} for label in point: if not label in data_model.KIN_TREE: outpoint[label] = point[label] else: filtered = [] for i in range(3): temp = UnivariateSpline(times, point[label].T[i], s=0)(newtimes) filt = sav_gol.savgol_filter(temp, window, degree) filt_spline = UnivariateSpline(newtimes, filt, s=0) filtered.append(filt_spline(times)) outpoint[label] = np.column_stack((filtered[i] for i in range(3))) return outpoint