Skip to content

Commit

Permalink
Merge pull request #795 from sentinel-hub/develop
Browse files Browse the repository at this point in the history
Release 1.5.5
  • Loading branch information
tsuligoj authored Jun 19, 2024
2 parents c7a39ed + 34e2d1c commit f8036d9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
language_version: python3

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.4.4"
rev: "v0.4.9"
hooks:
- id: ruff

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [Version 1.5.5] - 2024-06-19

- `SnowMaskTask` now correctly handles temporally empty eopatches.

## [Version 1.5.4] - 2024-05-13

- Minor fixes for documentation
Expand Down
2 changes: 1 addition & 1 deletion eolearn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Main module of the `eolearn` package."""

__version__ = "1.5.4"
__version__ = "1.5.5"

import importlib.util
import warnings
Expand Down
4 changes: 2 additions & 2 deletions eolearn/coregistration/coregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def register(
warp_matrix,
warp_mode,
criteria,
valid_mask, # type: ignore[arg-type]
valid_mask,
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
6 changes: 5 additions & 1 deletion eolearn/features/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ def spatially_resize_image(
if resize_library is ResizeLib.CV2:
resize_function = partial(cv2.resize, dsize=size, interpolation=resize_method.get_cv2_method(data.dtype))
else:
resize_function = partial(_pil_resize_ndarray, size=size, method=resize_method.get_pil_method())
resize_function = partial(
_pil_resize_ndarray, # type: ignore[arg-type]
size=size,
method=resize_method.get_pil_method(),
)

resized_data = _apply_to_spatial_axes(resize_function, data, spatial_axes)

Expand Down
3 changes: 2 additions & 1 deletion eolearn/mask/snow_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def _apply_dilation(self, snow_masks: np.ndarray) -> np.ndarray:
"""Apply binary dilation for each mask in the series"""
if self.disk_size > 0:
disk = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (self.disk_size, self.disk_size))
snow_masks = np.array([cv2.dilate(mask.astype(np.uint8), disk) for mask in snow_masks])
dilated_masks = np.array([cv2.dilate(mask.astype(np.uint8), disk) for mask in snow_masks])
snow_masks = dilated_masks.reshape(snow_masks.shape) # edge case where data is empty
return snow_masks.astype(bool)

def execute(self, eopatch: EOPatch) -> EOPatch:
Expand Down
12 changes: 11 additions & 1 deletion tests/mask/test_snow_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
import pytest

from eolearn.core import FeatureType
from eolearn.core import EOPatch, FeatureType
from eolearn.mask import SnowMaskTask


Expand All @@ -33,3 +33,13 @@ def test_snow_coverage(task, result, test_eopatch):
snow_pixels = np.sum(output, axis=(1, 2, 3))
assert np.sum(snow_pixels) == result[0], "Sum of snowy pixels does not match"
assert snow_pixels[-4] == result[1], "Snowy pixels on specified frame do not match"


def test_snow_empty_eopatch(test_eopatch):
_, h, w, c = test_eopatch.data["BANDS-S2-L1C"].shape
empty_eopatch = EOPatch(bbox=test_eopatch.bbox, timestamps=[])
empty_eopatch.data["BANDS-S2-L1C"] = np.array([], dtype=np.float32).reshape((0, h, w, c))

task = SnowMaskTask((FeatureType.DATA, "BANDS-S2-L1C"), [2, 3, 7, 11], mask_name="TEST_SNOW_MASK")
resulting_eopatch = task(empty_eopatch) # checks if the task runs without errors
assert resulting_eopatch.mask["TEST_SNOW_MASK"].shape == (0, h, w, 1)

0 comments on commit f8036d9

Please sign in to comment.