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 SnowMaskTask when dealing with empty patches #793

Merged
merged 9 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion eolearn/coregistration/coregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def register(
valid_mask, # type: ignore[arg-type]
self.gauss_kernel_size,
)
except cv2.error as cv2err:
except cv2.error as cv2err: # pylint: disable=catching-non-exception
warnings.warn(f"Could not calculate the warp matrix: {cv2err}", EORuntimeWarning)

return warp_matrix
Expand Down
4 changes: 4 additions & 0 deletions eolearn/mask/snow_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def _apply_dilation(self, snow_masks: np.ndarray) -> np.ndarray:

def execute(self, eopatch: EOPatch) -> EOPatch:
bands = eopatch[self.bands_feature][..., self.band_indices]
if bands.shape[0] == 0:
eopatch[self.mask_feature] = np.zeros((*bands.shape[:-1], 1), dtype=bool)
return eopatch

with np.errstate(divide="ignore", invalid="ignore"):
# (B03 - B11) / (B03 + B11)
ndsi = (bands[..., 0] - bands[..., 3]) / (bands[..., 0] + bands[..., 3])
Expand Down
Loading