Skip to content

Commit

Permalink
Fix previously skipped tests that used to fail randomly (#280)
Browse files Browse the repository at this point in the history
* fix deramp residual and optimizer

* Unskip test that passes locally to see if passes CI

* Adjust tests with expected behaviour of skimage.warp

* Specify change in test values in comment
  • Loading branch information
rhugonnet committed Aug 12, 2022
1 parent 2d82903 commit d7ef951
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
22 changes: 11 additions & 11 deletions tests/test_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,16 +655,16 @@ def test_coreg_oneliner(_) -> None:
assert np.array_equal(dem_arr, dem_arr2_fixed)


@pytest.mark.skip('Failure triggered between 10.2021 and 04.2022, likely with warp dem, issue opened.')
def test_apply_matrix():
warnings.simplefilter("error")
ref, tba, outlines = load_examples() # Load example reference, to-be-aligned and mask.
ref_arr = gu.spatial_tools.get_array_and_mask(ref)[0]

# Test only bias (it should just apply the bias and not make anything else)
bias = 5
matrix = np.diag(np.ones(4, float))
matrix[2, 3] = bias
transformed_dem = coreg.apply_matrix(ref.data.squeeze(), ref.transform, matrix)
transformed_dem = coreg.apply_matrix(ref_arr, ref.transform, matrix)
reverted_dem = transformed_dem - bias

# Check that the reverted DEM has the exact same values as the initial one
Expand All @@ -674,7 +674,7 @@ def test_apply_matrix():
# Synthesize a shifted and vertically offset DEM
pixel_shift = 11
bias = 5
shifted_dem = ref.data.squeeze().copy()
shifted_dem = ref_arr.copy()
shifted_dem[:, pixel_shift:] = shifted_dem[:, :-pixel_shift]
shifted_dem[:, :pixel_shift] = np.nan
shifted_dem += bias
Expand All @@ -683,17 +683,17 @@ def test_apply_matrix():
matrix[0, 3] = pixel_shift * tba.res[0]
matrix[2, 3] = -bias

transformed_dem = coreg.apply_matrix(shifted_dem.data.squeeze(),
transformed_dem = coreg.apply_matrix(shifted_dem,
ref.transform, matrix, resampling="bilinear")

# Dilate the mask a bit to ensure that edge pixels are removed.
# Dilate the mask: this should remove the same edge pixels as done by skimage
transformed_dem_dilated = coreg.apply_matrix(
shifted_dem.data.squeeze(),
shifted_dem,
ref.transform, matrix, resampling="bilinear", dilate_mask=True)
# Validate that some pixels were removed.
assert np.count_nonzero(np.isfinite(transformed_dem)) > np.count_nonzero(np.isfinite(transformed_dem_dilated))
# Validate the same pixels were removed.
assert np.count_nonzero(np.isfinite(transformed_dem)) == np.count_nonzero(np.isfinite(transformed_dem_dilated))

diff = np.asarray(ref.data.squeeze() - transformed_dem)
diff = np.asarray(ref_arr - transformed_dem)

# Check that the median is very close to zero
assert np.abs(np.nanmedian(diff)) < 0.01
Expand Down Expand Up @@ -779,7 +779,6 @@ def rotation_matrix(rotation=30):
print(np.nanmedian(diff), spatialstats.nmad(diff))


@pytest.mark.skip('Failure triggered between 10.2021 and 04.2022, likely with warp dem, issue opened.')
def test_warp_dem():
"""Test that the warp_dem function works expectedly."""
warnings.simplefilter("error")
Expand Down Expand Up @@ -822,7 +821,8 @@ def test_warp_dem():
# The warped DEM should have the value 'elev_shift' in the upper left corner.
assert warped_dem[0, 0] == elev_shift
# The corner should be zero, so the corner pixel (represents the corner minus resolution / 2) should be close.
assert warped_dem[-1, -1] < 1.0
# We select the pixel before the corner (-2 in X-axis) to avoid the NaN propagation on the bottom row.
assert warped_dem[-2, -1] < 1

# Synthesise some X/Y/Z coordinates on the DEM.
source_coords = np.array(
Expand Down
1 change: 0 additions & 1 deletion tests/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def test_robust_polynomial_fit_noise_and_outliers(self):
for i in range(3):
assert coefs6[i+1] == pytest.approx(true_coefs[i+1], abs=1)

@pytest.mark.skip('This test randomly fails in CI: issue opened.')
def test_robust_sumsin_fit(self):

# Define X vector
Expand Down

0 comments on commit d7ef951

Please sign in to comment.