Skip to content

Commit

Permalink
Merge branch '218-bug-valueerror-setting-an-array-element-with-a-sequ…
Browse files Browse the repository at this point in the history
…ence-py39-py310' into 'master'

Resolve "Bug: ValueError: setting an array element with a sequence py39, py310"

Closes #218

See merge request 3d/shareloc!125
  • Loading branch information
duboise-cnes committed Sep 26, 2023
2 parents ebae364 + 8c3deee commit 66de89d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
20 changes: 15 additions & 5 deletions shareloc/geofunctions/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,30 @@ 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]:
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]

# 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
)
Expand Down
17 changes: 13 additions & 4 deletions shareloc/geofunctions/rectification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 66de89d

Please sign in to comment.