From 345edd1da204355205a8f78c407df08d4ee71390 Mon Sep 17 00:00:00 2001 From: Emmanuel Dubois Date: Fri, 22 Sep 2023 17:04:12 +0200 Subject: [PATCH 1/3] fix: update Makefile to be able to choose python3 version --- Makefile | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 897d54a..4e5dd91 100644 --- a/Makefile +++ b/Makefile @@ -42,15 +42,22 @@ BROWSER := python -c "$$BROWSER_PYSCRIPT" # Python global variables definition PYTHON_VERSION_MIN = 3.8 -PYTHON=$(shell command -v python3) -PYTHON_VERSION_CUR=$(shell $(PYTHON) -c 'import sys; print("%d.%d"% sys.version_info[0:2])') -PYTHON_VERSION_OK=$(shell $(PYTHON) -c 'import sys; cur_ver = sys.version_info[0:2]; min_ver = tuple(map(int, "$(PYTHON_VERSION_MIN)".split("."))); print(int(cur_ver >= min_ver))') +# Set PYTHON if not defined in command line +# Example: PYTHON="python3.10" make venv to use python 3.10 for the venv +# By default the default python3 of the system. +ifndef PYTHON + PYTHON = "python3" +endif +PYTHON_CMD=$(shell command -v $(PYTHON)) + +PYTHON_VERSION_CUR=$(shell $(PYTHON_CMD) -c 'import sys; print("%d.%d"% sys.version_info[0:2])') +PYTHON_VERSION_OK=$(shell $(PYTHON_CMD) -c 'import sys; cur_ver = sys.version_info[0:2]; min_ver = tuple(map(int, "$(PYTHON_VERSION_MIN)".split("."))); print(int(cur_ver >= min_ver))') ############### Check python version supported ############ -ifeq (, $(PYTHON)) - $(error "PYTHON=$(PYTHON) not found in $(PATH)") +ifeq (, $(PYTHON_CMD)) + $(error "$(PYTHON_CMD) not found in $(PATH)") endif ifeq ($(PYTHON_VERSION_OK), 0) @@ -68,7 +75,7 @@ help: ## this help .PHONY: venv venv: ## create virtualenv in "venv" dir if not exists - @test -d ${VENV} || python3 -m venv ${VENV} + @test -d ${VENV} || $(PYTHON_CMD) -m venv ${VENV} @${VENV}/bin/python -m pip install --upgrade pip setuptools wheel # no check to upgrade each time install is run @touch ${VENV}/bin/activate From fa72f842f0c0770ffdb17b64274735bb5b889fe2 Mon Sep 17 00:00:00 2001 From: Emmanuel Dubois Date: Mon, 25 Sep 2023 11:16:55 +0200 Subject: [PATCH 2/3] fix: clean, protect inputs and add comments for coloc function --- shareloc/geofunctions/localization.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/shareloc/geofunctions/localization.py b/shareloc/geofunctions/localization.py index bd5cad4..9953b3a 100755 --- a/shareloc/geofunctions/localization.py +++ b/shareloc/geofunctions/localization.py @@ -181,20 +181,29 @@ def coloc(model1, model2, row, col, elevation=None, image1=None, image2=None, us :type image2: shareloc.image.Image :param using_geotransform: using_geotransform :type using_geotransform: boolean - :return: Corresponding sensor position [row, col, True] in the geometric model 2 + :return: Corresponding sensor position [row, col, altitude] in the geometric model 2 :rtype: Tuple(1D np.array row position, 1D np.array col position, 1D np.array alt) + using row and col input dimensions """ - geometric_model1 = Localization(model1, elevation, image=image1) - geometric_model2 = Localization(model2, elevation, image=image2) - + # Standardize row and col inputs in ndarray if not isinstance(row, (list, np.ndarray)): row = np.array([row]) col = np.array([col]) + # Check row and col + if (row.shape[0] != col.shape[0]) or (row.shape[0] <= 0) or (col.shape[0] <= 0): + raise ValueError("coloc: row and col inputs sizes are not similar or <=0") + # get input row or col shape for ndarray output shape. + output_shape = row.shape[0] + + # prepare geomodel 1 and 2 + geometric_model1 = Localization(model1, elevation, image=image1) + geometric_model2 = Localization(model2, elevation, image=image2) + # Direct loc on (row, col) with model 1 ground_coord = geometric_model1.direct(row, col, using_geotransform=using_geotransform) # Estimate sensor position (row, col, altitude) using inverse localization with model2 - sensor_coord = np.zeros((row.shape[0], 3), dtype=np.float64) + sensor_coord = np.zeros((output_shape, 3), dtype=np.float64) sensor_coord[:, 0], sensor_coord[:, 1], sensor_coord[:, 2] = geometric_model2.inverse( ground_coord[:, 0], ground_coord[:, 1], ground_coord[:, 2], using_geotransform ) From 8c3deee232b261d90a0464459883382cd4e9278c Mon Sep 17 00:00:00 2001 From: Emmanuel Dubois Date: Mon, 25 Sep 2023 11:17:33 +0200 Subject: [PATCH 3/3] fix: convert ndarray into float64 for py3.9 and py3.10 --- shareloc/geofunctions/localization.py | 5 +++-- shareloc/geofunctions/rectification.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/shareloc/geofunctions/localization.py b/shareloc/geofunctions/localization.py index 9953b3a..6739fb0 100755 --- a/shareloc/geofunctions/localization.py +++ b/shareloc/geofunctions/localization.py @@ -189,9 +189,10 @@ def coloc(model1, model2, row, col, elevation=None, image1=None, image2=None, us if not isinstance(row, (list, np.ndarray)): row = np.array([row]) col = np.array([col]) + # Check row and col - if (row.shape[0] != col.shape[0]) or (row.shape[0] <= 0) or (col.shape[0] <= 0): - raise ValueError("coloc: row and col inputs sizes are not similar or <=0") + if row.shape[0] != col.shape[0]: + raise ValueError("coloc: row and col inputs sizes are not similar") # get input row or col shape for ndarray output shape. output_shape = row.shape[0] diff --git a/shareloc/geofunctions/rectification.py b/shareloc/geofunctions/rectification.py index d7ab230..381681c 100644 --- a/shareloc/geofunctions/rectification.py +++ b/shareloc/geofunctions/rectification.py @@ -359,9 +359,15 @@ def moving_to_next_line(geom_model_left, geom_model_right, current_line, mean_sp # Find the corresponding starting point in the right image next_line_start_right = np.zeros(3, dtype=np.float64) - next_line_start_right[0], next_line_start_right[1], next_line_start_right[2] = coloc( + row, col, alt = coloc( geom_model_left, geom_model_right, next_line_start_left[0], next_line_start_left[1], elevation ) + # Convert ndarray coloc output into float 64 (Bug python3.9 et 3.10 not allowed anymore) + # TODO: clean epipolar grids generation conversion globally with refacto/optimization + next_line_start_right[0] = row[0] + next_line_start_right[1] = col[0] + next_line_start_right[2] = alt[0] + return next_line_start_left, next_line_start_right @@ -452,9 +458,12 @@ def compute_stereorectification_epipolar_grids( # Starting points are the upper-left origin of the left epipolar image, and it's correspondent in the right image start_left = np.copy(footprint[0]) start_right = np.zeros(3, dtype=start_left.dtype) - start_right[0], start_right[1], start_right[2] = coloc( - geom_model_left, geom_model_right, start_left[0], start_left[1], elevation - ) + init_row, init_col, init_alt = coloc(geom_model_left, geom_model_right, start_left[0], start_left[1], elevation) + # Convert ndarray coloc output into float 64 (Bug python3.9 et 3.10 not allowed anymore) + # TODO: clean epipolar grids generation conversion globally with refacto/optimization + start_right[0] = init_row[0] + start_right[1] = init_col[0] + start_right[2] = init_alt[0] mean_baseline_ratio = 0