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 inlier masking in BlockwiseCoreg #625

Merged
merged 3 commits into from
Oct 29, 2024
Merged
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
12 changes: 9 additions & 3 deletions xdem/coreg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2944,6 +2944,12 @@ def fit(
area_or_point=area_or_point,
)

# Define inlier mask if None, before indexing subdivided array in process function below
if inlier_mask is None:
mask = np.ones(tba_dem.shape, dtype=bool)
else:
mask = inlier_mask

groups = self.subdivide_array(tba_dem.shape if isinstance(tba_dem, np.ndarray) else ref_dem.shape)

indices = np.unique(groups)
Expand All @@ -2961,10 +2967,10 @@ def process(i: int) -> dict[str, Any] | BaseException | None:
* If it fails: The associated exception.
* If the block is empty: None
"""
inlier_mask = groups == i
group_mask = groups == i

# Find the corresponding slice of the inlier_mask to subset the data
rows, cols = np.where(inlier_mask)
rows, cols = np.where(group_mask)
arrayslice = np.s_[rows.min() : rows.max() + 1, cols.min() : cols.max() + 1]

# Copy a subset of the two DEMs, the mask, the coreg instance, and make a new subset transform
Expand All @@ -2973,7 +2979,7 @@ def process(i: int) -> dict[str, Any] | BaseException | None:

if any(np.all(~np.isfinite(dem)) for dem in (ref_subset, tba_subset)):
return None
mask_subset = inlier_mask[arrayslice].copy()
mask_subset = mask[arrayslice].copy()
west, top = rio.transform.xy(transform, min(rows), min(cols), offset="ul")
transform_subset = rio.transform.from_origin(west, top, transform.a, -transform.e) # type: ignore
procstep = self.procstep.copy()
Expand Down
Loading