From 3f83471839616065d078dd07634dcf2f2e24a378 Mon Sep 17 00:00:00 2001 From: Jonathan Guinet Date: Fri, 1 Dec 2023 08:57:29 +0100 Subject: [PATCH] refac: moved class member init --- shareloc/geomodels/geomodel_template.py | 12 +++------ shareloc/geomodels/grid.py | 31 +++++++++++++++--------- shareloc/geomodels/rpc.py | 2 -- tests/geofunctions/test_rectification.py | 8 ++---- tests/geomodels/test_los.py | 2 +- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/shareloc/geomodels/geomodel_template.py b/shareloc/geomodels/geomodel_template.py index 9804ae7..599b406 100644 --- a/shareloc/geomodels/geomodel_template.py +++ b/shareloc/geomodels/geomodel_template.py @@ -27,14 +27,6 @@ # Standard imports from abc import ABCMeta, abstractmethod -# Global variable for optimization mode (functions in C) -# SHARELOC_OPTIM_GEOMODEL = False - -# TODO: Override functions depending on optimization or not - -# if(SHARELOC_OPTIM_GEOMODEL == True): -# GeoModelTemplate.direct_loc_dtm = GeoModelTemplate.direct_loc_dtm_optim - class GeoModelTemplate(metaclass=ABCMeta): """ @@ -102,7 +94,9 @@ def inverse_loc(self, lon, lat, alt): @classmethod @abstractmethod - def load(cls, geomodel_path): + def load(cls, geomodel_path: str): """ load function with class specific args + + :param geomodel_path: filename of geomodel """ diff --git a/shareloc/geomodels/grid.py b/shareloc/geomodels/grid.py index ae1b53c..2c513c8 100755 --- a/shareloc/geomodels/grid.py +++ b/shareloc/geomodels/grid.py @@ -38,7 +38,6 @@ # gitlab issue #58 # pylint: disable=too-many-instance-attributes -# pylint: disable=no-member @GeoModel.register("grid") class Grid(GeoModelTemplate): """ @@ -105,6 +104,17 @@ def __init__(self, geomodel_path: str): self.rowmax = None self.colmax = None self.epsg = 0 + + # inverse loc predictor attributes + self.pred_col_min = None + self.pred_row_min = None + self.pred_col_max = None + self.pred_row_max = None + self.pred_ofset_scale_lon = None + self.pred_ofset_scale_lat = None + self.pred_ofset_scale_row = None + self.pred_ofset_scale_col = None + self.read() @classmethod @@ -545,7 +555,7 @@ def estimate_inverse_loc_predictor(self, nbrow_pred=3, nbcol_pred=3): a_max[imes, 5] = glonlat[0, irow, icol] imes += 1 - # Calcul des coeffcients + # Compute coefficients mat_a_min = np.array(a_min) mat_a_max = np.array(a_max) @@ -559,16 +569,15 @@ def estimate_inverse_loc_predictor(self, nbrow_pred=3, nbcol_pred=3): coef_col_max = t_aa_max_inv @ mat_a_max.T @ b_col coef_row_max = t_aa_max_inv @ mat_a_max.T @ b_row - # TODO: refactor to have only class parameters in __init__ # seems not clear to understand with inverse_loc_predictor function ... - setattr(self, "pred_col_min", coef_col_min.flatten()) # noqa: 502 - setattr(self, "pred_row_min", coef_row_min.flatten()) # noqa: 502 - setattr(self, "pred_col_max", coef_col_max.flatten()) # noqa: 502 - setattr(self, "pred_row_max", coef_row_max.flatten()) # noqa: 502 - setattr(self, "pred_ofset_scale_lon", [lon_ofset, lon_scale]) # noqa: 502 - setattr(self, "pred_ofset_scale_lat", [lat_ofset, lat_scale]) # noqa: 502 - setattr(self, "pred_ofset_scale_row", [row_ofset, row_scale]) # noqa: 502 - setattr(self, "pred_ofset_scale_col", [col_ofset, col_scale]) # noqa: 502 + self.pred_col_min = coef_col_min.flatten() + self.pred_row_min = coef_row_min.flatten() + self.pred_col_max = coef_col_max.flatten() + self.pred_row_max = coef_row_max.flatten() + self.pred_ofset_scale_lon = [lon_ofset, lon_scale] + self.pred_ofset_scale_lat = [lat_ofset, lat_scale] + self.pred_ofset_scale_row = [row_ofset, row_scale] + self.pred_ofset_scale_col = [col_ofset, col_scale] def inverse_loc_predictor(self, lon, lat, alt=0.0): """ diff --git a/shareloc/geomodels/rpc.py b/shareloc/geomodels/rpc.py index 2f37850..d9c8373 100755 --- a/shareloc/geomodels/rpc.py +++ b/shareloc/geomodels/rpc.py @@ -49,8 +49,6 @@ class RPC(GeoModelTemplate): RPC class including direct and inverse localization instance methods """ - # gitlab issue #61 - # pylint: disable=too-many-instance-attributes # gitlab issue #61 # pylint: disable=too-many-instance-attributes def __init__(self, rpc_params): diff --git a/tests/geofunctions/test_rectification.py b/tests/geofunctions/test_rectification.py index 1a82b09..e249cb6 100644 --- a/tests/geofunctions/test_rectification.py +++ b/tests/geofunctions/test_rectification.py @@ -548,12 +548,8 @@ def test_rectification_moving_to_axis_error(): """ Test moving along axis with wrong axis """ - geom_model_left = RPC.from_any( - os.path.join(data_path(), "rectification", "left_image.geom"), topleftconvention=True - ) - geom_model_right = RPC.from_any( - os.path.join(data_path(), "rectification", "right_image.geom"), topleftconvention=True - ) + geom_model_left = GeoModel(os.path.join(data_path(), "rectification", "left_image.geom")) + geom_model_right = GeoModel(os.path.join(data_path(), "rectification", "right_image.geom")) current_coords = np.array([5000.5, 5000.5, 0.0], dtype=np.float64) mean_spacing = 1 diff --git a/tests/geomodels/test_los.py b/tests/geomodels/test_los.py index f105025..3d516dc 100644 --- a/tests/geomodels/test_los.py +++ b/tests/geomodels/test_los.py @@ -127,7 +127,7 @@ def test_los_parameters(): # Load geometrical model id_scene = "P1BP--2017092838284574CP" file_dimap = os.path.join(data_folder, f"rpc/RPC_{id_scene}.XML") - geometrical_model = RPC.from_any(file_dimap) + geometrical_model = GeoModel(file_dimap) # Create los model_los = LOS(matches_left, geometrical_model, [310, 850])