diff --git a/parallax/__init__.py b/parallax/__init__.py index 18cb2af3..67bd916d 100644 --- a/parallax/__init__.py +++ b/parallax/__init__.py @@ -4,7 +4,7 @@ import os -__version__ = "0.37.19" +__version__ = "0.37.20" # allow multiple OpenMP instances os.environ["KMP_DUPLICATE_LIB_OK"] = "True" diff --git a/parallax/bundle_adjustment.py b/parallax/bundle_adjustment.py index 5ee215f2..600c142e 100644 --- a/parallax/bundle_adjustment.py +++ b/parallax/bundle_adjustment.py @@ -87,7 +87,6 @@ def _average_3D_points(self): # Write the updated DataFrame back to the CSV file self.df.to_csv(self.file_path, index=False) - def _remove_duplicates(self): # Drop duplicate rows based on 'ts_local_coords', 'global_x', 'global_y', 'global_z' columns logger.debug(f"Original rows: {self.df.shape[0]}") diff --git a/parallax/probe_calibration.py b/parallax/probe_calibration.py index fd83cc22..002730c3 100644 --- a/parallax/probe_calibration.py +++ b/parallax/probe_calibration.py @@ -11,9 +11,8 @@ import numpy as np import pandas as pd from PyQt5.QtCore import QObject, pyqtSignal -from sklearn.linear_model import LinearRegression from .coords_transformation import RotationTransformation -from .bundle_adjustmnet import BALProblem, BALOptimizer +from .bundle_adjustment import BALProblem, BALOptimizer # Set logger name logger = logging.getLogger(__name__) @@ -485,7 +484,7 @@ def _is_enough_points(self): self.transM_LR_prev = self.transM_LR return False - def _update_info_ui(self, disp_avg_error=False, save_to_csv=False): + def _update_info_ui(self, disp_avg_error=False, save_to_csv=False, file_name=None): sn = self.stage.sn if sn is not None and sn in self.stages: stage_data = self.stages[sn] @@ -508,7 +507,6 @@ def _update_info_ui(self, disp_avg_error=False, save_to_csv=False): ) if save_to_csv: - file_name = f"transM_{sn}.csv" self._save_transM_to_csv(file_name) def _save_df_to_csv(self, df, file_name): @@ -567,6 +565,24 @@ def reshape_array(self): global_points = np.array(self.global_points) return local_points.reshape(-1, 1, 3), global_points.reshape(-1, 1, 3) + def _print_formatted_transM(self): + R = self.transM_LR[:3, :3] + # Extract the translation vector (top 3 elements of the last column) + T = self.transM_LR[:3, 3] + S = self.scale[:3] + + print("stage sn: ", self.stage.sn) + print("Rotation matrix:") + print(f" [[{R[0][0]:.5f}, {R[0][1]:.5f}, {R[0][2]:.5f}],") + print(f" [{R[1][0]:.5f}, {R[1][1]:.5f}, {R[1][2]:.5f}],") + print(f" [{R[2][0]:.5f}, {R[2][1]:.5f}, {R[2][2]:.5f}]]") + print("Translation vector:") + print(f" [{T[0]:.1f}, {T[1]:.1f}, {T[2]:.1f}]") + print("Scale:") + print(f" [{S[0]:.5f}, {S[1]:.5f}, {S[2]:.5f}]") + print("==> Average L2 between stage and global: ", self.avg_err) + + def update(self, stage, debug_info=None): """ Main method to update calibration with a new stage position and check if calibration is complete. @@ -601,23 +617,23 @@ def update(self, stage, debug_info=None): # TODO - Bundle Adjustment print("\n\n=========================================================") print("Before BA") - print(" Average L2 between stage and global: ", self.avg_err) - print(self.stage.sn, self.transM_LR, self.scale) + self._print_formatted_transM() print("=========================================================") - + self._update_info_ui(disp_avg_error=True, save_to_csv=True, \ + file_name = f"transM_{self.stage.sn}.csv") + if self.model.bundle_adjustment: ret = self.run_bundle_adjustment(self.file_name) if ret: print("\n=========================================================") print("After BA") - print(" Average L2 between stage and global: ", self.avg_err) - print(self.stage.sn, self.transM_LR, self.scale) + self._print_formatted_transM() print("=========================================================") + self._update_info_ui(disp_avg_error=True, save_to_csv=True, \ + file_name = f"transM_BA_{self.stage.sn}.csv") else: return - self._update_info_ui(disp_avg_error=True, save_to_csv=True) # update transformation matrix and overall LR in UI - # Emit the signal to indicate that calibration is complete self.calib_complete.emit(self.stage.sn, self.transM_LR, self.scale) logger.debug(