def plot_imu(self, fig=None, plot_num=1, plot_rows=2, plot_cols=2, figsize=None, **kwargs): if fig is None: fig = plt.figure(figsize=figsize) ax = fig.add_subplot(plot_rows, plot_cols, plot_num, title=self.name + ' Gyros') moveThreshGyro = pysurvive.configf(self.so.contents.ctx, "move-threshold-gyro", pysurvive.SC_GET, 0) moveThreshAcc = pysurvive.configf(self.so.contents.ctx, "move-threshold-acc", pysurvive.SC_GET, 0) axes_name = ['X', 'Y', 'Z'] gyros = np.array(self.gyros) ax.plot([self.imu_times[0], self.imu_times[-1]], [moveThreshGyro] * 2, linewidth=1) ax.plot(self.imu_times, np.linalg.norm(gyros, axis=1), linewidth=1, label='Norm') for i in range(3): ax.plot(self.imu_times, gyros[:, i], linewidth=1, label=axes_name[i]) ax.legend() ax = fig.add_subplot(plot_rows, plot_cols, plot_num + 1, title=self.name + ' Accels') ax.plot([self.imu_times[0], self.imu_times[-1]], [moveThreshAcc] * 2, linewidth=1) ax.plot(self.imu_times[1:], np.linalg.norm(np.diff(self.accels, axis=0), axis=1), linewidth=1) return 2
def plot_light_diff(self, fig=None, plot_num=1, plot_rows=1, plot_cols=1, figsize=None, norm_diff=True, **kwargs): if len(self.angles) == 0: return 0 if fig is None: fig = plt.figure(figsize=figsize_or_default(figsize)) ax = fig.add_subplot(plot_rows, plot_cols, plot_num, title=self.name + ' light diff') moveThreshAng = pysurvive.configf(self.so.contents.ctx, "move-threshold-ang", pysurvive.SC_GET, 0) ax.plot([self.imu_times[0], self.imu_times[-1]], [moveThreshAng] * 2, linewidth=1) for k, v in self.angles.items(): if len(v) <= 1: continue vv = np.array(v) norm = np.diff(vv[:, 0]) if norm_diff else 1. data = np.stack([vv[1:, 0], np.array(np.diff(vv[:, 1]) / norm)]) diff_data = insert_blanks(data) times = diff_data[:, 0] data = diff_data[:, 1] ax.plot(times, data, '-', label=k, linewidth=1) return 1
def plot_accel(self, fig=None, plot_num=1, plot_rows=1, plot_cols=1, only_avg=True, figsize=None, **kwargs): if fig is None: fig = plt.figure(figsize=figsize_or_default(figsize)) accel_running_avg = self.datalogs['accel running average'] if len(accel_running_avg) == 0: only_avg = False moveThreshAcc = pysurvive.configf(self.so.contents.ctx, "move-threshold-acc", pysurvive.SC_GET, 0) ax = fig.add_subplot(plot_rows, plot_cols, plot_num, title=self.name + ' Accels') ax.plot([self.imu_times[0], self.imu_times[-1]], [moveThreshAcc] * 2, '--', linewidth=1.5, label="Move threshold") if not only_avg: ax.plot(self.imu_times[1:], np.linalg.norm(np.diff(self.accels, axis=0), axis=1), linewidth=0.5, label="Norm diff") ax.plot(self.imu_times, np.linalg.norm(self.accels, axis=1), linewidth=1, label="Norm") accel_running_avg = self.datalogs['accel running average'] if len(accel_running_avg): plot_with_time(ax, accel_running_avg, data_fn=np.linalg.norm, label="Running accel average") start = len(self.imu_times) - len(get_data(accel_running_avg)) ax.plot(self.imu_times[start:], np.linalg.norm(self.accels[start:] - get_data(accel_running_avg), axis=1), linewidth=0.5, label="Norm diff(avg)") ax.plot(get_times(accel_running_avg)[1:], np.linalg.norm(np.diff(get_data(accel_running_avg), axis=0), axis=1), label="Running accel average diff") accels = np.array(self.accels) axes_name = ['X', 'Y', 'Z'] for i in range(3): if not only_avg: ax.plot(self.imu_times, accels[:, i], linewidth=0.5, label=axes_name[i]) ax.plot(get_times(accel_running_avg), get_data(accel_running_avg)[:, i], label="Avg" + axes_name[i]) ax.legend()