def processing_labeling(self, new_tracks, new_labels, filename, acq): freq = acq.GetAnalogFrequency() self.button_save.hide() self.button_processing_labeling.hide() # Estimate bone lenght and mcp angles filename_static = QtGui.QFileDialog.getOpenFileName(self, "Open Static File", "Users/jessicaabreu") static_acq, static_data, static_labels = fp.open_c3d_data(str(filename_static[0])) bone_labels, bone_lenghts, mcp_estatic_error, mcp_inner_angle, mcp_inner_angle_error, mcp_middle_angle, mcp_middle_angle_error, mcp_outer_angle = fp.hand_static_measurements(static_data, static_labels) # wrist tracks self.layout().itemAt(2).widget().deleteLater() for i in range(6): self.layout().itemAt(3).itemAt(i).widget().deleteLater() check_box_w1 = QtGui.QGroupBox("Select W1 tracks") check_box_w1_layout = QtGui.QGridLayout() check_box_w1.setLayout(check_box_w1_layout) check_box_w2 = QtGui.QGroupBox("Select W2 tracks") check_box_w2_layout = QtGui.QGridLayout() check_box_w2.setLayout(check_box_w2_layout) check_box_w3 = QtGui.QGroupBox("Select W3 tracks") check_box_w3_layout = QtGui.QGridLayout() check_box_w3.setLayout(check_box_w3_layout) for i in range(len(new_labels)): column = i / 15 line = i % 15 check_item_w1 = QtGui.QCheckBox(new_labels[i], check_box_w1) check_item_w1.setStyleSheet("font-size: 8px; font-weight: normal") check_item_w2 = QtGui.QCheckBox(new_labels[i], check_box_w2) check_item_w2.setStyleSheet("font-size: 8px; font-weight: normal") check_item_w3 = QtGui.QCheckBox(new_labels[i], check_box_w3) check_item_w3.setStyleSheet("font-size: 8px; font-weight: normal") check_box_w1_layout.addWidget(check_item_w1, line, column) check_box_w2_layout.addWidget(check_item_w2, line, column) check_box_w3_layout.addWidget(check_item_w3, line, column) self.layout().addWidget(check_box_w1, 2, 2) self.layout().addWidget(check_box_w2, 2, 3) self.layout().addWidget(check_box_w3, 2, 4) button_ok_wrist = QtGui.QPushButton("Ok") button_ok_wrist.clicked.connect(lambda: self.labelling(filename, acq, new_tracks, new_labels, freq, bone_lenghts, bone_labels, mcp_estatic_error, mcp_inner_angle, mcp_inner_angle_error, mcp_middle_angle, mcp_middle_angle_error, mcp_outer_angle)) self.layout().addWidget(button_ok_wrist, 3, 4)
def processing(self): self.button_processing.hide() filename1 = QtGui.QFileDialog.getOpenFileName(self, "Open File", "Users/jessicaabreu") acq, data, headers = fp.open_c3d_data(str(filename1[0])) split_labels, split_tracks = fp.split_wrong_tracks_by_gradient(data, headers, acq.GetAnalogFrequency()) new_tracks, new_labels = fp.join_equivalent_tracks(split_tracks, split_labels, acq.GetAnalogFrequency()) viewer = BiomecViewer(new_tracks, new_labels) viewer_widget = viewer.edit_traits(parent=self, kind='subpanel').control self.layout().addWidget(viewer_widget, 2, 1) # making checkbox and plots figurex = plt.figure() canvasx = FigureCanvas(figurex) toolbarx = NavigationToolbar(canvasx, None) toolbarx.setIconSize(QtCore.QSize(12, 12)) toolbarx.setStyleSheet("background-color: #C0C0C0 ") ax_x = figurex.add_subplot(111) ax_x.cla() plt.xlabel('Time (s)', fontsize=10) plt.ylabel('Position (mm)', fontsize=10) canvasx.draw() figurey = plt.figure() canvasy = FigureCanvas(figurey) toolbary = NavigationToolbar(canvasy, None) toolbary.setIconSize(QtCore.QSize(12, 12)) toolbary.setStyleSheet("background-color: #C0C0C0 ") ax_y = figurey.add_subplot(111) ax_y.cla() plt.xlabel('Time (s)', fontsize=10) plt.ylabel('Position (mm)', fontsize=10) canvasy.draw() figurez = plt.figure() canvasz = FigureCanvas(figurez) toolbarz = NavigationToolbar(canvasz, None) toolbarz.setIconSize(QtCore.QSize(12, 12)) toolbarz.setStyleSheet("background-color: #C0C0C0 ") ax_z = figurez.add_subplot(111) ax_z.cla() plt.xlabel('Time (s)', fontsize=10) plt.ylabel('Position (mm)', fontsize=10) canvasz.draw() check_box = QtGui.QGroupBox("Plot Tracks") check_box_layout = QtGui.QGridLayout() check_box.setLayout(check_box_layout) for i in range(len(new_labels)): column = i / 5 line = i % 5 check_item = QtGui.QCheckBox(new_labels[i]) check_item.setStyleSheet("font-size: 8px; font-weight: normal") check_item.stateChanged.connect(self.wrapper_plot(ax_x, ax_y, ax_z, new_tracks[i, :, :], new_labels[i], check_item, figurex, figurey, figurez, canvasx, canvasy, canvasz, acq )) check_box_layout.addWidget(check_item, line, column) plot_layout = QtGui.QVBoxLayout() plot_layout.addWidget(canvasx) plot_layout.addWidget(toolbarx) plot_layout.addWidget(canvasy) plot_layout.addWidget(toolbary) plot_layout.addWidget(canvasz) plot_layout.addWidget(toolbarz) self.layout().addWidget(check_box, 1, 2) self.layout().addLayout(plot_layout, 2, 2) self.button_processing_labeling.show() self.button_processing_labeling.clicked.connect(lambda: self.processing_labeling(new_tracks, new_labels, filename1[0], acq)) self.button_save.show() self.button_save.clicked.connect(lambda: self.save(new_tracks, new_labels, filename1[0], acq, "pre_processed"))
def wrist_labelling(self, tracks, labels, freq): ''' Uses UI input to label wrist trajectories. Adjusts UI after input is given. Receives: tracks: numpy array with marker trajectories. Shape (marker_number, frames, 3) labels: list with marker labels freq: acquisition frequency Returns: wrist_tracks: numpy array with wrist tracks joined and gaps interpolated with constrined cubic spline wrist_labels: list with wrist labels other_tracks: tracks excludind wrist tracks other_labels: other_tracks labels ''' list_w1 = [] list_w2 = [] list_w3 = [] indexes_wrist = [] # w1 w1_track = np.empty((tracks.shape[1], 3)) w1_track.fill(np.nan) for check_item in self.layout().itemAt(3).widget().findChildren(QtGui.QCheckBox): if check_item.isChecked(): track_index = labels.index(str(check_item.text())) indexes_wrist.append(track_index) track = tracks[track_index, :, :] index_values = np.where(np.isfinite(track[:, 0]))[0] w1_track[index_values[0]: index_values[-1] + 1, :] = track[index_values[0]: index_values[-1] + 1, :] w1 = fp.interp_constrained_spline(w1_track, freq) # w2 w2_track = np.empty((tracks.shape[1], 3)) w2_track.fill(np.nan) for check_item in self.layout().itemAt(4).widget().findChildren(QtGui.QCheckBox): if check_item.isChecked(): track_index = labels.index(str(check_item.text())) indexes_wrist.append(track_index) track = tracks[track_index, :, :] index_values = np.where(np.isfinite(track[:, 0]))[0] w2_track[index_values[0]: index_values[-1] + 1, :] = track[index_values[0]: index_values[-1] + 1, :] w2 = fp.interp_constrained_spline(w2_track, freq) # w3 w3_track = np.empty((tracks.shape[1], 3)) w3_track.fill(np.nan) for check_item in self.layout().itemAt(5).widget().findChildren(QtGui.QCheckBox): if check_item.isChecked(): track_index = labels.index(str(check_item.text())) indexes_wrist.append(track_index) track = tracks[track_index, :, :] index_values = np.where(np.isfinite(track[:, 0]))[0] w3_track[index_values[0]: index_values[-1] + 1, :] = track[index_values[0]: index_values[-1] + 1, :] w3 = fp.interp_constrained_spline(w3_track, freq) # stacking wrist_tracks = np.dstack((w1.T, w2.T, w3.T)).T wrist_labels = ['W1', 'W2', 'W3'] other_tracks = np.delete(tracks, indexes_wrist, axis=0) other_labels = list(np.delete(np.array(labels), indexes_wrist)) # adjusting ui for i in range (4): self.layout().itemAt(6-i).widget().deleteLater() return wrist_tracks, wrist_labels, other_tracks, other_labels
from file_processing import FileProcessing if __name__ == '__main__': rows_number = int(input("Please enter the number of rows: \n")) file_p = FileProcessing(rows_number) file_p.input_file() file_p.output_file()