Skip to content

Commit f8036d9

Browse files
authored
Merge pull request #795 from sentinel-hub/develop
Release 1.5.5
2 parents c7a39ed + 34e2d1c commit f8036d9

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
language_version: python3
2020

2121
- repo: https://github.com/charliermarsh/ruff-pre-commit
22-
rev: "v0.4.4"
22+
rev: "v0.4.9"
2323
hooks:
2424
- id: ruff
2525

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [Version 1.5.5] - 2024-06-19
2+
3+
- `SnowMaskTask` now correctly handles temporally empty eopatches.
4+
15
## [Version 1.5.4] - 2024-05-13
26

37
- Minor fixes for documentation

eolearn/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Main module of the `eolearn` package."""
22

3-
__version__ = "1.5.4"
3+
__version__ = "1.5.5"
44

55
import importlib.util
66
import warnings

eolearn/coregistration/coregistration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ def register(
114114
warp_matrix,
115115
warp_mode,
116116
criteria,
117-
valid_mask, # type: ignore[arg-type]
117+
valid_mask,
118118
self.gauss_kernel_size,
119119
)
120-
except cv2.error as cv2err:
120+
except cv2.error as cv2err: # pylint: disable=catching-non-exception
121121
warnings.warn(f"Could not calculate the warp matrix: {cv2err}", EORuntimeWarning)
122122

123123
return warp_matrix

eolearn/features/utils.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ def spatially_resize_image(
162162
if resize_library is ResizeLib.CV2:
163163
resize_function = partial(cv2.resize, dsize=size, interpolation=resize_method.get_cv2_method(data.dtype))
164164
else:
165-
resize_function = partial(_pil_resize_ndarray, size=size, method=resize_method.get_pil_method())
165+
resize_function = partial(
166+
_pil_resize_ndarray, # type: ignore[arg-type]
167+
size=size,
168+
method=resize_method.get_pil_method(),
169+
)
166170

167171
resized_data = _apply_to_spatial_axes(resize_function, data, spatial_axes)
168172

eolearn/mask/snow_mask.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ 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:

tests/mask/test_snow_mask.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
import pytest
1212

13-
from eolearn.core import FeatureType
13+
from eolearn.core import EOPatch, FeatureType
1414
from eolearn.mask import SnowMaskTask
1515

1616

@@ -33,3 +33,13 @@ def test_snow_coverage(task, result, test_eopatch):
3333
snow_pixels = np.sum(output, axis=(1, 2, 3))
3434
assert np.sum(snow_pixels) == result[0], "Sum of snowy pixels does not match"
3535
assert snow_pixels[-4] == result[1], "Snowy pixels on specified frame do not match"
36+
37+
38+
def test_snow_empty_eopatch(test_eopatch):
39+
_, h, w, c = test_eopatch.data["BANDS-S2-L1C"].shape
40+
empty_eopatch = EOPatch(bbox=test_eopatch.bbox, timestamps=[])
41+
empty_eopatch.data["BANDS-S2-L1C"] = np.array([], dtype=np.float32).reshape((0, h, w, c))
42+
43+
task = SnowMaskTask((FeatureType.DATA, "BANDS-S2-L1C"), [2, 3, 7, 11], mask_name="TEST_SNOW_MASK")
44+
resulting_eopatch = task(empty_eopatch) # checks if the task runs without errors
45+
assert resulting_eopatch.mask["TEST_SNOW_MASK"].shape == (0, h, w, 1)

0 commit comments

Comments
 (0)