示例#1
0
 def __cc_plot(self):
     """Plot cross correlation."""
     p = int(self.plot_joint.currentText().replace('P', ''))
     target = self.canvas2.get_target()
     ans = self.canvas2.get_path()
     dlg = DataChartDialog(self, "Cross Correlation", 3)
     ax = dlg.ax()
     c1 = curvature(ans[p])
     c2 = curvature(target[p])
     ps1 = path_signature(c1)
     ps2 = path_signature(c2)
     cc = cross_correlation(ps1, ps2, 0.1)
     ps2[:, 0] += cc.argmax() * 0.1
     ax[0].set_title(f"Cross Correlation of Point{p}")
     ax[0].plot(cc)
     ax[1].set_title("Curvature")
     ax[1].plot(c1, label=f"Point{p}")
     ax[1].plot(c2, label=f"Target Path")
     ax[1].legend()
     ax[2].set_title("Path Signature")
     ax[2].plot(ps1[:, 0], ps1[:, 1], label=f"Point{p}")
     ax[2].plot(ps2[:, 0], ps2[:, 1], label=f"Target Path")
     ax[2].legend()
     dlg.set_margin(0.2)
     dlg.show()
     dlg.exec_()
     dlg.deleteLater()
示例#2
0
 def __cc_plot(self):
     """Plot cross correlation."""
     p = int(self.plot_joint.currentText().replace('P', ''))
     target = self.canvas2.get_target()
     c1 = curvature(self.canvas2.get_path()[p])
     c2 = curvature(target[p])
     p1 = path_signature(c1)
     p2 = path_signature(c2, 100 - 100 / (len(target[p]) + 1))
     cc = cross_correlation(p1, p2, _U)
     cc_argmax = cc.argmax()
     p2[:, 0] += cc_argmax * _U
     m_p1 = p1.copy()
     m_p1[:, 0] += p1.max()
     p1 = concatenate((p1, m_p1), axis=0)
     del m_p1
     dlg = DataChartDialog(self, "Cross Correlation", 3)
     ax = dlg.ax()
     ax[0].set_title("Curvature")
     ax[0].plot(c1, label=f"Point{p}")
     ax[0].plot(c2, label=f"Target Path")
     ax[0].legend()
     ax[1].set_title("Path Signature")
     ax[1].plot(p1[:, 0], p1[:, 1], label=f"Point{p}")
     ax[1].plot(p2[:, 0], p2[:, 1], label=f"Target Path")
     ax[1].plot(cc_argmax * _U, p2[0, 1], 'ro', label=f"Shift Origin")
     ax[1].legend()
     ax[2].set_title(f"Cross Correlation of Point{p}")
     ax[2].plot(linspace(0, len(cc) * _U, len(cc)), cc)
     ax[2].plot(cc_argmax * _U, cc[cc_argmax], 'ro')
     dlg.set_margin(0.2)
     dlg.show()
     dlg.exec_()
     dlg.deleteLater()
示例#3
0
 def __plot(self) -> None:
     """Plot the data. Show the X and Y axises as two line."""
     joint = self.plot_joint.currentIndex()
     name = self.__current_path_name()
     data = self.__paths.get(name, [])
     slider_data = self.__slider_paths.get(name, {})
     if not data:
         return
     if self.plot_joint_slot.isChecked():
         pos = array(slider_data.get(joint, []))
     else:
         pos = array(data[joint])
     if self.wrt_label.isChecked():
         joint_wrt = self.wrt_joint.currentIndex()
         if self.wrt_joint_slot.isChecked():
             pos[:] -= array(slider_data.get(joint_wrt, []))
         else:
             pos[:] -= array(data[joint_wrt])
     vel = derivative(pos)
     acc = derivative(vel)
     cur = curvature(data[joint])
     plot = {}
     plot_count = 0
     if self.plot_pos.isChecked():
         plot_count += 1
         plot["Position"] = pos
     if self.plot_vel.isChecked():
         plot_count += 1
         plot["Velocity"] = vel
     if self.plot_acc.isChecked():
         plot_count += 1
         plot["Acceleration"] = acc
     if self.plot_jerk.isChecked():
         plot_count += 1
         plot["Jerk"] = derivative(acc)
     if self.plot_curvature.isChecked():
         plot_count += 1
         plot["Curvature"] = cur
     if self.plot_signature.isChecked():
         plot_count += 1
         plot["Path Signature"] = path_signature(cur)
     if plot_count < 1:
         QMessageBox.warning(self, "No target", "No any plotting target.")
         return
     polar = self.p_coord_sys.isChecked()
     row = plot_count
     col = 1
     if polar:
         row, col = col, row
     dlg = DataChartDialog(self, "Analysis", row, col, polar)
     dlg.setWindowIcon(QIcon(QPixmap(":/icons/formula.png")))
     ax = dlg.ax()
     for p, (title, xy) in enumerate(plot.items()):
         ax_i = ax[p]
         ax_i.set_title(title)
         if title == "Path Signature":
             ax_i.plot(xy[:, 0], xy[:, 1])
             ax_i.set_ylabel(r"$\kappa$")
             ax_i.set_xlabel(r"$\int|\kappa|dt$")
         elif xy.ndim == 2:
             x = xy[:, 0]
             y = xy[:, 1]
             if self.c_coord_sys.isChecked():
                 ax_i.plot(x, label='x')
                 ax_i.plot(y, label='y')
                 ax_i.legend()
             else:
                 r = hypot(x, y)
                 theta = arctan2(y, x)
                 ax_i.plot(theta, r, linewidth=5)
         else:
             ax_i.plot(xy)
     dlg.set_margin(0.2)
     dlg.show()
     dlg.exec_()
     dlg.deleteLater()