Updates to normalisation matrix

This commit is contained in:
2022-08-16 16:51:00 +02:00
parent 88f85607be
commit b626ef3ae8
+45 -13
View File
@@ -976,6 +976,8 @@ class CalibrateMagnetometer(Frame):
self.residual_result_vars = [StringVar(), StringVar(), StringVar()]
self.calibration_raw_results = None # Cached raw experiment data to allow for saving to csv.
self.clipboard = "" # Clipboard string containing results
self.cos_trans_matrix_clipboard = "" # Clipboard string containing coordinate transformation matrix
self.mgm_to_helmholtz_cos_trans = [[DoubleVar(value=1), DoubleVar(value=0), DoubleVar(value=0)],
[DoubleVar(value=0), DoubleVar(value=1), DoubleVar(value=0)],
[DoubleVar(value=0), DoubleVar(value=0), DoubleVar(value=1)]]
@@ -1113,7 +1115,7 @@ class CalibrateMagnetometer(Frame):
save_calibration_results_frame.grid(row=6, column=0, columnspan=5)
# Save and apply
self.export_calibration_button = Button(save_calibration_results_frame, text="Export raw to CSV",
command=self.export_csv,
command=self.export_csv_calibration_raw_results,
state="disabled",
pady=5, padx=5)
self.export_calibration_button.grid(row=0, column=0, padx=5, pady=5)
@@ -1124,7 +1126,7 @@ class CalibrateMagnetometer(Frame):
self.copy_calibration_button.grid(row=0, column=1, padx=5, pady=5)
row_counter += 1
# RIGHT Bottom COLUMN
# LEFT COLUMN
# Input coordinate system conversion matrix
row_counter = 0
input_cos_frame = LabelFrame(self.right_column, text="Input MGM to Helmholtz COS Transformation Matrix")
@@ -1194,13 +1196,13 @@ class CalibrateMagnetometer(Frame):
save_input_cos_frame = Frame(input_cos_frame)
save_input_cos_frame.grid(row=6, column=0, columnspan=5)
# Save and apply
self.export_cos_trans_button = Button(save_input_cos_frame, text="Export raw to CSV",
command=self.export_csv,
self.export_cos_trans_button = Button(save_input_cos_frame, text="Export to CSV",
command=self.export_csv_cos_trans_matrix,
state="normal",
pady=5, padx=5)
self.export_cos_trans_button.grid(row=0, column=0, padx=5, pady=5)
self.copy_cos_trans_matrix_button = Button(save_input_cos_frame, text="Copy to clipboard",
command=self.copy_to_clipboard,
command=self.copy_to_clipboard_cos_trans_matrix,
state="normal",
pady=5, padx=5)
self.copy_cos_trans_matrix_button.grid(row=0, column=1, padx=5, pady=5)
@@ -1209,8 +1211,10 @@ class CalibrateMagnetometer(Frame):
state="normal",
pady=5, padx=5)
self.normalize_matrix_button.grid(row=0, column=2, padx=5, pady=5)
row_counter += 1
# This starts an endless polling loop
self.update_view()
@@ -1312,29 +1316,57 @@ class CalibrateMagnetometer(Frame):
except (DeviceAccessError, TclError) as e:
messagebox.showwarning("Calibration failed", "Failed to start calibration:\n{}".format(e))
def export_csv(self):
def export_csv_calibration_raw_results(self):
if self.calibration_raw_results is None:
ui_print("Error: Failed to export non-existent calibration data.")
return
save_dict_list_to_csv('magnetometer_calibration.csv', self.calibration_raw_results, query_path=True)
ui_print("Saved calibration results to magnetometer_calibration.csv.")
def export_csv_cos_trans_matrix(self):
if self.mgm_to_helmholtz_cos_trans is None:
ui_print("Error: Failed to export non-existent coordinate transformation matrix.")
return
# Populate clipboard for coordinate transformation matrix
cos_trans_matrix_message = "X, Y, Z\n"
cos_trans_matrix_message += "X, {:.5f}".format(self.mgm_to_helmholtz_cos_trans[0][0].get())
cos_trans_matrix_message += ", {:.5f}".format(self.mgm_to_helmholtz_cos_trans[0][1].get())
cos_trans_matrix_message += ", {:.5f}\n".format(self.mgm_to_helmholtz_cos_trans[0][2].get())
cos_trans_matrix_message += "Y, {:.5f}".format(self.mgm_to_helmholtz_cos_trans[1][0].get())
cos_trans_matrix_message += ", {:.5f}".format(self.mgm_to_helmholtz_cos_trans[1][1].get())
cos_trans_matrix_message += ", {:.5f}\n".format(self.mgm_to_helmholtz_cos_trans[1][2].get())
cos_trans_matrix_message += "Z, {:.5f}".format(self.mgm_to_helmholtz_cos_trans[2][0].get())
cos_trans_matrix_message += ", {:.5f}".format(self.mgm_to_helmholtz_cos_trans[2][1].get())
cos_trans_matrix_message += ", {:.5f}\n".format(self.mgm_to_helmholtz_cos_trans[2][2].get())
save_dict_list_to_csv('magnetometer_cos_trans_matrix.csv', cos_trans_matrix_message, query_path=True)
ui_print("Saved MGM to Helmholtz coordinate transformation matrix to magnetometer_cos_trans_matrix.csv.")
def copy_to_clipboard(self):
self.clipboard_clear()
self.clipboard_append(self.clipboard)
self.update()
def copy_to_clipboard_cos_trans_matrix(self):
# Populate clipboard for coordinate transformation matrix
self.cos_trans_matrix_clipboard = "\tX\tY\tZ\n"
self.cos_trans_matrix_clipboard += "X\t{:.5f}".format(self.mgm_to_helmholtz_cos_trans[0][0].get())
self.cos_trans_matrix_clipboard += "\t{:.5f}".format(self.mgm_to_helmholtz_cos_trans[0][1].get())
self.cos_trans_matrix_clipboard += "\t{:.5f}\n".format(self.mgm_to_helmholtz_cos_trans[0][2].get())
self.cos_trans_matrix_clipboard += "Y\t{:.5f}".format(self.mgm_to_helmholtz_cos_trans[1][0].get())
self.cos_trans_matrix_clipboard += "\t{:.5f}".format(self.mgm_to_helmholtz_cos_trans[1][1].get())
self.cos_trans_matrix_clipboard += "\t{:.5f}\n".format(self.mgm_to_helmholtz_cos_trans[1][2].get())
self.cos_trans_matrix_clipboard += "Z\t{:.5f}".format(self.mgm_to_helmholtz_cos_trans[2][0].get())
self.cos_trans_matrix_clipboard += "\t{:.5f}".format(self.mgm_to_helmholtz_cos_trans[2][1].get())
self.cos_trans_matrix_clipboard += "\t{:.5f}\n".format(self.mgm_to_helmholtz_cos_trans[2][2].get())
self.clipboard_clear()
self.clipboard_append(self.cos_trans_matrix_clipboard)
self.update()
def matrix_normalize(self):
try:
ui_print("Input matrix to be normalized:")
# Normalize Matrix
matrix = [[self.mgm_to_helmholtz_cos_trans[0][0].get(), self.mgm_to_helmholtz_cos_trans[0][1].get(),
self.mgm_to_helmholtz_cos_trans[0][2].get()],
[self.mgm_to_helmholtz_cos_trans[1][0].get(), self.mgm_to_helmholtz_cos_trans[1][1].get(),
self.mgm_to_helmholtz_cos_trans[1][2].get()],
[self.mgm_to_helmholtz_cos_trans[2][0].get(), self.mgm_to_helmholtz_cos_trans[2][1].get(),
self.mgm_to_helmholtz_cos_trans[2][2].get()]]
matrix = [[x.get() for x in row] for row in self.mgm_to_helmholtz_cos_trans]
matrix = np.array(matrix)
ui_print(matrix)
matrix_max = matrix.max()