diff --git a/tests/test_coreg.py b/tests/test_coreg.py index 97cbe9da..f9fd3bc5 100644 --- a/tests/test_coreg.py +++ b/tests/test_coreg.py @@ -497,6 +497,14 @@ def test_blockwise_coreg_large_gaps(self): # This should not fail or trigger warnings as warn_failures is False blockwise.fit(reference_dem, dem_to_be_aligned) + stats = blockwise.stats() + + # We expect holes in the blockwise coregistration, so there should not be 64 "successful" blocks. + assert stats.shape[0] < 64 + + # Statistics are only calculated on finite values, so all of these should be finite as well. + assert np.all(np.isfinite(stats)) + diff --git a/xdem/coreg.py b/xdem/coreg.py index 4ec83a66..fd19c858 100644 --- a/xdem/coreg.py +++ b/xdem/coreg.py @@ -705,6 +705,10 @@ def residuals(self, reference_dem: Union[np.ndarray, np.ma.masked_array], # Calculate the DEM difference diff = ref_arr - aligned_dem + # Sometimes, the float minimum (for float32 = -3.4028235e+38) is returned. This and inf should be excluded. + if "float" in str(diff.dtype): + full_mask[(diff == np.finfo(diff.dtype).min) | np.isinf(diff)] = False + # Return the difference values within the full inlier mask return diff[full_mask] @@ -757,7 +761,6 @@ def error(self, reference_dem: Union[np.ndarray, np.ma.masked_array], f"'{error_type}'. Choices: {list(error_functions.keys())}" ) from exception - return errors if len(errors) > 1 else errors[0] @classmethod @@ -1774,6 +1777,8 @@ def stats(self) -> pd.DataFrame: statistics: list[dict[str, Any]] = [] for i in range(points.shape[0]): + if i not in chunk_meta: + continue statistics.append( { "center_x": points[i, 0, 0],