Skip to content

Commit

Permalink
fix: robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
vschaffn committed Dec 3, 2024
1 parent 5fc282c commit ba50aa9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_coreg/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,19 @@ def test_dem_coregistration(self) -> None:
estimated_initial_shift=test_shift_tuple,
random_state=42,
)

# Check if the appropriate exception is raised with a wrong type initial shift
with pytest.raises(ValueError, match=r".*two numerical values.*"):
dem_coregistration(
tba_dem,
ref_dem,
estimated_initial_shift=["2", 2],
random_state=42,
)
with pytest.raises(ValueError, match=r".*two numerical values.*"):
dem_coregistration(
tba_dem,
ref_dem,
estimated_initial_shift=[2, 3, 5],
random_state=42,
)
8 changes: 8 additions & 0 deletions xdem/coreg/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ def dem_coregistration(

# Ensure that if an initial shift is provided, at least one coregistration method is affine.
if estimated_initial_shift:
if not (
isinstance(estimated_initial_shift, (list, tuple))
and len(estimated_initial_shift) == 2
and all(isinstance(val, (float, int)) for val in estimated_initial_shift)
):
raise ValueError(
"Argument `estimated_initial_shift` must be a list or tuple of exactly two numerical values."
)
if isinstance(coreg_method, CoregPipeline):
if not any(isinstance(step, AffineCoreg) for step in coreg_method.pipeline):
raise TypeError(
Expand Down

0 comments on commit ba50aa9

Please sign in to comment.