Skip to content

Commit

Permalink
refac: moved class member init
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Guinet committed Dec 1, 2023
1 parent aa5708e commit 3f83471
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
12 changes: 3 additions & 9 deletions shareloc/geomodels/geomodel_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
"""
31 changes: 20 additions & 11 deletions shareloc/geomodels/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

# gitlab issue #58
# pylint: disable=too-many-instance-attributes
# pylint: disable=no-member
@GeoModel.register("grid")
class Grid(GeoModelTemplate):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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):
"""
Expand Down
2 changes: 0 additions & 2 deletions shareloc/geomodels/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions tests/geofunctions/test_rectification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/geomodels/test_los.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 3f83471

Please sign in to comment.