From 781b1e6d4e9bb94466a8fb38227984d913d2fd92 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Thu, 4 May 2023 18:08:56 +0200 Subject: [PATCH 1/2] Add parameter 'rs_random_state' (RANSAC random state) and set it to 0 by default. Signed-off-by: Daniel Scheffler --- arosics/CoReg_local.py | 8 +++++++- arosics/Tie_Point_Grid.py | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/arosics/CoReg_local.py b/arosics/CoReg_local.py index 1f7f865..75b47e0 100644 --- a/arosics/CoReg_local.py +++ b/arosics/CoReg_local.py @@ -84,6 +84,7 @@ def __init__(self, min_reliability: float = 60, rs_max_outlier: float = 10, rs_tolerance: float = 2.5, + rs_random_state: Optional[int] = 0, align_grids: bool = True, match_gsd: bool = False, out_gsd: float = None, @@ -181,6 +182,9 @@ def __init__(self, :param rs_tolerance: RANSAC tie point filtering: percentage tolerance for max_outlier_percentage (default: 2.5%) + :param rs_random_state: + RANSAC random state (an integer corresponds to a fixed/pseudo-random state, None randomizes the result) + :param align_grids: True: align the input coordinate grid to the reference (does not affect the output pixel size as long as input and output pixel sizes are compatible (5:30 or 10:30 but not 4:30), default = True @@ -293,6 +297,7 @@ def __init__(self, self.min_reliability = min_reliability self.rs_max_outlier = rs_max_outlier self.rs_tolerance = rs_tolerance + self.rs_random_state = rs_random_state self.align_grids = align_grids self.match_gsd = match_gsd self.out_gsd = out_gsd @@ -475,7 +480,8 @@ def calculate_spatial_shifts(self) -> None: outlDetect_settings=dict( min_reliability=self.min_reliability, rs_max_outlier=self.rs_max_outlier, - rs_tolerance=self.rs_tolerance), + rs_tolerance=self.rs_tolerance, + rs_random_state=self.rs_random_state), dir_out=self.projectDir, CPUs=self.CPUs, progress=self.progress, diff --git a/arosics/Tie_Point_Grid.py b/arosics/Tie_Point_Grid.py index 2b9fc28..4c1926d 100755 --- a/arosics/Tie_Point_Grid.py +++ b/arosics/Tie_Point_Grid.py @@ -130,7 +130,7 @@ def __init__(self, :param outlDetect_settings: a dictionary with the settings to be passed to arosics.TiePointGrid.Tie_Point_Refiner. Available keys: min_reliability, rs_max_outlier, rs_tolerance, rs_max_iter, rs_exclude_previous_outliers, - rs_timeout, q. See documentation there. + rs_timeout, rs_random_state, q. See documentation there. :param dir_out: output directory to be used for all outputs if nothing else is given to the individual methods @@ -1000,6 +1000,7 @@ def __init__(self, GDF, rs_max_iter: int = 15, rs_exclude_previous_outliers: bool = True, rs_timeout: float = 20, + rs_random_state: Optional[int] = 0, q: bool = False): """Get an instance of Tie_Point_Refiner. @@ -1016,6 +1017,8 @@ def __init__(self, GDF, :param rs_exclude_previous_outliers: RANSAC: whether to exclude points that have been flagged as outlier by earlier filtering (default:True) :param rs_timeout: RANSAC: timeout for iteration loop in seconds (default: 20) + :param rs_random_state: RANSAC random state (an integer corresponds to a fixed/pseudo-random + state, None randomizes the result) :param q: """ @@ -1026,6 +1029,7 @@ def __init__(self, GDF, self.rs_max_iter = rs_max_iter self.rs_exclude_previous_outliers = rs_exclude_previous_outliers self.rs_timeout = rs_timeout + self.rs_random_state = rs_random_state self.q = q self.new_cols = [] self.ransac_model_robust = None @@ -1198,7 +1202,8 @@ def _RANSAC_outlier_detection(self, inGDF): ), stop_residuals_sum=int( (self.rs_max_outlier_percentage - self.rs_tolerance) / - 100 * src_coords.shape[0]) + 100 * src_coords.shape[0]), + random_state=self.rs_random_state ) else: warnings.warn('RANSAC filtering could not be applied ' From ed66dd5f072e8d24340c6fb5f3ca83a4af6cb2f6 Mon Sep 17 00:00:00 2001 From: Daniel Scheffler Date: Thu, 4 May 2023 18:11:14 +0200 Subject: [PATCH 2/2] Update HISTORY.rst. Signed-off-by: Daniel Scheffler --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index 0fc289b..afc6435 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -8,6 +8,7 @@ History * Re-implemented interpolation of tie point attributes into space (!23). Three techniques are now supported: RBF, GPR, and Ordinary Kriging. Added scikit-learn to dependencies. * Fixed GDAL warning related to PROJ_DATA/PROJ_LIB environment variables (!34). +* Added parameter 'rs_random_state' (RANSAC random state) and set it to 0 by default (!35). 1.8.1 (2023-03-10)