From ba6b7dbb8afef1aec4570d25593ff02bef1ef7c6 Mon Sep 17 00:00:00 2001 From: vschaffn Date: Tue, 10 Dec 2024 16:07:35 +0100 Subject: [PATCH] test: add test for warp_dem without z_shift --- tests/test_coreg/test_base.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_coreg/test_base.py b/tests/test_coreg/test_base.py index a6d3d976..b8b423f0 100644 --- a/tests/test_coreg/test_base.py +++ b/tests/test_coreg/test_base.py @@ -1204,6 +1204,37 @@ def test_warp_dem() -> None: # Due to the randomness, the threshold is quite high, but would be something like 10+ if it was incorrect. assert spatialstats.nmad(dem - untransformed_dem) < 0.5 + # Test with Z-correction disabled + transformed_dem_no_z = coreg.base.warp_dem( + dem=dem, + transform=transform, + source_coords=source_coords, + destination_coords=dest_coords, + resampling="linear", + apply_z_correction=False, + ) + + # Try to undo the warp by reversing the source-destination coordinates with Z-correction disabled + untransformed_dem_no_z = coreg.base.warp_dem( + dem=transformed_dem_no_z, + transform=transform, + source_coords=dest_coords, + destination_coords=source_coords, + resampling="linear", + apply_z_correction=False, + ) + + # Validate that the DEM is now more or less the same as the original, with Z-correction disabled. + # The result should be similar to the original, but with no Z-shift applied. + assert spatialstats.nmad(dem - untransformed_dem_no_z) < 0.5 + + # The difference between the two DEMs should be the vertical shift. + # We expect the difference to be approximately equal to the average vertical shift. + expected_vshift = np.mean(dest_coords[:, 2] - source_coords[:, 2]) + + # Check that the mean difference between the DEMs matches the expected vertical shift. + assert np.nanmean(transformed_dem_no_z - transformed_dem) == pytest.approx(expected_vshift, rel=0.3) + if False: import matplotlib.pyplot as plt