Skip to content

Commit c899d4e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into doc_rendering
2 parents 02ed863 + 33b1ee2 commit c899d4e

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

tests/test_coreg/test_affine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def test_tilt(self) -> None:
288288
assert np.abs(np.mean(periglacial_offset)) < np.abs(np.mean(pre_offset))
289289

290290
# Check that the mean periglacial offset is low
291-
assert np.abs(np.mean(periglacial_offset)) < 0.01
291+
assert np.abs(np.mean(periglacial_offset)) < 0.02
292292

293293
def test_icp_opencv(self) -> None:
294294
warnings.simplefilter("error")

tests/test_coreg/test_base.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,44 @@ def test_coreg_add(self) -> None:
676676
vshift5 = vshift3 + vshift3
677677
assert vshift5.to_matrix()[2, 3] == vshift * 4
678678

679+
def test_pipeline_consistency(self) -> None:
680+
"""Check that pipelines properties are respected: reflectivity, fusion of same coreg"""
681+
682+
# Test 1: Fusion of same coreg
683+
# Many vertical shifts
684+
many_vshifts = coreg.VerticalShift() + coreg.VerticalShift() + coreg.VerticalShift()
685+
many_vshifts.fit(**self.fit_params, random_state=42)
686+
aligned_dem, _ = many_vshifts.apply(self.tba.data, transform=self.ref.transform, crs=self.ref.crs)
687+
688+
# The last steps should have shifts of EXACTLY zero
689+
assert many_vshifts.pipeline[1]._meta["vshift"] == pytest.approx(0, abs=10e-5)
690+
assert many_vshifts.pipeline[2]._meta["vshift"] == pytest.approx(0, abs=10e-5)
691+
692+
# Many horizontal + vertical shifts
693+
many_nks = coreg.NuthKaab() + coreg.NuthKaab() + coreg.NuthKaab()
694+
many_nks.fit(**self.fit_params, random_state=42)
695+
aligned_dem, _ = many_nks.apply(self.tba.data, transform=self.ref.transform, crs=self.ref.crs)
696+
697+
# The last steps should have shifts of NEARLY zero
698+
assert many_nks.pipeline[1]._meta["vshift"] == pytest.approx(0, abs=0.02)
699+
assert many_nks.pipeline[1]._meta["offset_east_px"] == pytest.approx(0, abs=0.02)
700+
assert many_nks.pipeline[1]._meta["offset_north_px"] == pytest.approx(0, abs=0.02)
701+
assert many_nks.pipeline[2]._meta["vshift"] == pytest.approx(0, abs=0.02)
702+
assert many_nks.pipeline[2]._meta["offset_east_px"] == pytest.approx(0, abs=0.02)
703+
assert many_nks.pipeline[2]._meta["offset_north_px"] == pytest.approx(0, abs=0.02)
704+
705+
# Test 2: Reflectivity
706+
# Those two pipelines should give almost the same result
707+
nk_vshift = coreg.NuthKaab() + coreg.VerticalShift()
708+
vshift_nk = coreg.VerticalShift() + coreg.NuthKaab()
709+
710+
nk_vshift.fit(**self.fit_params, random_state=42)
711+
aligned_dem, _ = nk_vshift.apply(self.tba.data, transform=self.ref.transform, crs=self.ref.crs)
712+
vshift_nk.fit(**self.fit_params, random_state=42)
713+
aligned_dem, _ = vshift_nk.apply(self.tba.data, transform=self.ref.transform, crs=self.ref.crs)
714+
715+
assert np.allclose(nk_vshift.to_matrix(), vshift_nk.to_matrix(), atol=10e-1)
716+
679717

680718
class TestBlockwiseCoreg:
681719
ref, tba, outlines = load_examples() # Load example reference, to-be-aligned and mask.

xdem/coreg/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ def fit(
15161516

15171517
main_args_fit = {
15181518
"reference_dem": ref_dem,
1519-
"dem_to_be_aligned": tba_dem,
1519+
"dem_to_be_aligned": tba_dem_mod,
15201520
"inlier_mask": inlier_mask,
15211521
"transform": out_transform,
15221522
"crs": crs,

0 commit comments

Comments
 (0)