diff --git a/xdem/coreg/base.py b/xdem/coreg/base.py index 73bbc48e..aa241a33 100644 --- a/xdem/coreg/base.py +++ b/xdem/coreg/base.py @@ -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) @@ -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 @@ -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()