Skip to content

Commit 9db5efe

Browse files
author
Matic Lubej
committed
enforce shape always
1 parent 8f095cf commit 9db5efe

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

eolearn/mask/snow_mask.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,12 @@ def _apply_dilation(self, snow_masks: np.ndarray) -> np.ndarray:
6161
"""Apply binary dilation for each mask in the series"""
6262
if self.disk_size > 0:
6363
disk = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (self.disk_size, self.disk_size))
64-
snow_masks = np.array([cv2.dilate(mask.astype(np.uint8), disk) for mask in snow_masks])
64+
dilated_masks = np.array([cv2.dilate(mask.astype(np.uint8), disk) for mask in snow_masks])
65+
snow_masks = dilated_masks.reshape(snow_masks.shape) # edge case where data is empty
6566
return snow_masks.astype(bool)
6667

6768
def execute(self, eopatch: EOPatch) -> EOPatch:
6869
bands = eopatch[self.bands_feature][..., self.band_indices]
69-
if bands.shape[0] == 0:
70-
eopatch[self.mask_feature] = np.zeros((*bands.shape[:-1], 1), dtype=bool)
71-
return eopatch
72-
7370
with np.errstate(divide="ignore", invalid="ignore"):
7471
# (B03 - B11) / (B03 + B11)
7572
ndsi = (bands[..., 0] - bands[..., 3]) / (bands[..., 0] + bands[..., 3])

0 commit comments

Comments
 (0)