Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BlockwiseCoreg.stats() KeyError and improved tests. #192

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/test_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))




Expand Down
7 changes: 6 additions & 1 deletion xdem/coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
erikmannerfelt marked this conversation as resolved.
Show resolved Hide resolved
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]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand Down