Skip to content

Commit bb3ad5b

Browse files
authored
Merge pull request #548 from sentinel-hub/develop
Release version 1.4.0
2 parents 55cfb24 + 04bebaa commit bb3ad5b

File tree

98 files changed

+1796
-2491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1796
-2491
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[flake8]
2-
ignore = E203, W503, C408
2+
# B028 is ignored because !r flags cannot be used in python < 3.8
3+
ignore = E203, W503, C408, B028
34
exclude = .git, __pycache__, build, dist
45
max-line-length= 120
56
max-complexity = 15

.github/workflows/ci_action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
- "master"
88
- "develop"
99
schedule:
10-
- cron: "0 0 * * *"
10+
# Schedule events are triggered by whoever last changed the cron schedule
11+
- cron: "5 0 * * *"
1112

1213
env:
1314
# The only way to simulate if-else statement
@@ -60,7 +61,14 @@ jobs:
6061
run: make pylint
6162

6263
- name: Run mypy
63-
run: mypy core/eolearn/core
64+
run: |
65+
mypy core/eolearn/core
66+
mypy coregistration/eolearn/coregistration
67+
mypy geometry/eolearn/geometry
68+
mypy features/eolearn/features
69+
mypy mask/eolearn/mask
70+
mypy ml_tools/eolearn/ml_tools
71+
mypy visualization/eolearn/visualization
6472
6573
test-on-github:
6674
runs-on: ubuntu-latest

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ run_sh_integration_tests:
1212
script:
1313
- pip install -r requirements-dev.txt --upgrade
1414
- python install_all.py
15-
- sentinelhub.config --sh_client_id "$SH_CLIENT_ID" --sh_client_secret "$SH_CLIENT_SECRET" > /dev/null # Gitlab can't mask SH_CLIENT_SECRET in logs
15+
- sentinelhub.config --sh_client_id "$SH_CLIENT_ID" --sh_client_secret "$SH_CLIENT_SECRET" > /dev/null # Gitlab can't mask SH_CLIENT_SECRET in logs
1616
- pytest -m sh_integration

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v4.4.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: requirements-txt-fixer
@@ -13,19 +13,19 @@ repos:
1313
- id: debug-statements
1414

1515
- repo: https://github.com/psf/black
16-
rev: 22.8.0
16+
rev: 22.12.0
1717
hooks:
1818
- id: black
1919
language_version: python3
2020

2121
- repo: https://github.com/pycqa/isort
22-
rev: 5.10.1
22+
rev: 5.11.4
2323
hooks:
2424
- id: isort
2525
name: isort (python)
2626

2727
- repo: https://github.com/PyCQA/autoflake
28-
rev: v1.5.3
28+
rev: v2.0.0
2929
hooks:
3030
- id: autoflake
3131
args:
@@ -36,7 +36,7 @@ repos:
3636
]
3737

3838
- repo: https://github.com/pycqa/flake8
39-
rev: 5.0.4
39+
rev: 6.0.0
4040
hooks:
4141
- id: flake8
4242
additional_dependencies:
@@ -46,7 +46,7 @@ repos:
4646
- flake8-typing-imports
4747

4848
- repo: https://github.com/nbQA-dev/nbQA
49-
rev: 1.4.0
49+
rev: 1.6.0
5050
hooks:
5151
- id: nbqa-black
5252
- id: nbqa-isort

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## [Version 1.4.0] - 2023-1-20
2+
3+
- (**codebreaking**) Complete overhaul of `eolearn.coregistration`. See documentation for details.
4+
- (**codebreaking**) Removed non-working HVPlot backend for `eolearn.visualization`.
5+
- (**codebreaking**) The `SpatialResizeTask` had a bug when resizing w.r.t resolution. The issue was fixed and the signature of the task was redesigned to better avoid mistakes. See documentation for details.
6+
- (**codebreaking**) The `EOPatch` methods `get_features` and `get_feature_list` were recombined into a new `get_features` method. The method `get_time_series` was removed. See documentation for details.
7+
- (**codebreaking**) Removed unsound `use_int_coords` option in `eolearn.ml_tools.sampling.random_point_in_triangle`.
8+
- Added ability to specify query in execute method of `MeteoblueTask`.
9+
- `SentinelHubInputTask` no longer saves redundant data into meta-features.
10+
- Module `eolearn.core.utils.types` was moved to `eolearn.core.types`. Old one will be removed in the future.
11+
- Switched `opencv-contrib-python-headless` requirement to `opencv-python-headless`
12+
- Added type annotations to most of the code base.
13+
- Various improvements to tests and code.
14+
15+
116
## [Version 1.3.1] - 2022-11-23
217

318
- Sentinel Hub IO tasks now support a custom timestamp filtration via `timestamp_filter` parameter.

core/eolearn/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
from .utils.parallelize import execute_with_mp_lock, join_futures, join_futures_iter, parallelize
3333
from .utils.parsing import FeatureParser
3434

35-
__version__ = "1.3.1"
35+
__version__ = "1.4.0"

core/eolearn/core/core_tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from .constants import FeatureType
2727
from .eodata import EOPatch
2828
from .eotask import EOTask
29+
from .types import FeatureSpec, FeaturesSpecification, SingleFeatureSpec
2930
from .utils.fs import get_filesystem, pickle_fs, unpickle_fs
30-
from .utils.parsing import FeatureSpec, FeaturesSpecification
3131

3232

3333
class CopyTask(EOTask):
@@ -313,7 +313,7 @@ def execute(self, eopatch: EOPatch) -> EOPatch:
313313
"""
314314
shape = eopatch[self.shape_feature].shape if self.shape_feature else self.shape
315315

316-
add_features = set(self.features) - set(self.parse_features(eopatch.get_feature_list()))
316+
add_features = set(self.features) - set(self.parse_features(eopatch.get_features()))
317317

318318
for feature in add_features:
319319
eopatch[feature] = np.ones(shape, dtype=self.dtype) * self.init_value
@@ -472,7 +472,7 @@ def zip_method(self, *f):
472472
def __init__(
473473
self,
474474
input_features: FeaturesSpecification,
475-
output_feature: FeaturesSpecification,
475+
output_feature: SingleFeatureSpec,
476476
zip_function: Optional[Callable] = None,
477477
**kwargs: Any,
478478
):

core/eolearn/core/eodata.py

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
from .constants import FeatureType, OverwritePermission
3131
from .eodata_io import FeatureIO, load_eopatch, save_eopatch
3232
from .eodata_merge import merge_eopatches
33+
from .types import EllipsisType, FeatureSpec, FeaturesSpecification, Literal
3334
from .utils.common import deep_eq, is_discrete_type
3435
from .utils.fs import get_filesystem
35-
from .utils.parsing import FeatureSpec, FeaturesSpecification, parse_features
36-
from .utils.types import EllipsisType, Literal
36+
from .utils.parsing import parse_features
3737

3838
_T = TypeVar("_T")
3939
_Self = TypeVar("_Self")
@@ -352,19 +352,22 @@ def __setitem__(
352352

353353
return self.__setattr__(FeatureType(feature_type).value, value, feature_name=feature_name)
354354

355-
def __delitem__(self, feature: Tuple[FeatureType, str]) -> None:
355+
def __delitem__(self, feature: FeatureSpec) -> None:
356356
"""Deletes the selected feature.
357357
358358
:param feature: EOPatch feature
359359
"""
360360
self._check_tuple_key(feature)
361361
feature_type, feature_name = feature
362-
del self[feature_type][feature_name]
362+
if feature_type in [FeatureType.BBOX, FeatureType.TIMESTAMP]:
363+
self.reset_feature_type(feature_type)
364+
else:
365+
del self[feature_type][feature_name]
363366

364367
@staticmethod
365368
def _check_tuple_key(key: tuple) -> None:
366369
"""A helper function that checks a tuple, which should hold (feature_type, feature_name)."""
367-
if len(key) != 2:
370+
if not isinstance(key, (tuple, list)) or len(key) != 2:
368371
raise ValueError(f"Given element should be a tuple of (feature_type, feature_name), but {key} found.")
369372

370373
def __eq__(self, other: object) -> bool:
@@ -520,21 +523,6 @@ def reset_feature_type(self, feature_type: FeatureType) -> None:
520523
else:
521524
self[feature_type] = []
522525

523-
def get_features(self) -> Dict[FeatureType, Union[Set[str], Literal[True]]]:
524-
"""Returns a dictionary of all non-empty features of EOPatch.
525-
526-
The elements are either sets of feature names or a boolean `True` in case feature type has no dictionary of
527-
feature names.
528-
529-
:return: A dictionary of features
530-
"""
531-
feature_dict: Dict[FeatureType, Union[Set[str], Literal[True]]] = {}
532-
for feature_type in FeatureType:
533-
if self[feature_type]:
534-
feature_dict[feature_type] = set(self[feature_type]) if feature_type.has_dict() else True
535-
536-
return feature_dict
537-
538526
def get_spatial_dimension(self, feature_type: FeatureType, feature_name: str) -> Tuple[int, int]:
539527
"""
540528
Returns a tuple of spatial dimension (height, width) of a feature.
@@ -552,20 +540,19 @@ def get_spatial_dimension(self, feature_type: FeatureType, feature_name: str) ->
552540
"FeatureType used to determine the width and height of raster must be time dependent or spatial."
553541
)
554542

555-
def get_feature_list(self) -> List[Union[FeatureType, Tuple[FeatureType, str]]]:
543+
def get_features(self) -> List[FeatureSpec]:
556544
"""Returns a list of all non-empty features of EOPatch.
557545
558-
The elements are either only FeatureType or a pair of FeatureType and feature name.
559-
560-
:return: list of features
546+
:return: List of non-empty features
561547
"""
562-
feature_list: List[Union[FeatureType, Tuple[FeatureType, str]]] = []
548+
feature_list: List[FeatureSpec] = []
563549
for feature_type in FeatureType:
564-
if feature_type.has_dict():
550+
if feature_type is FeatureType.BBOX or feature_type is FeatureType.TIMESTAMP:
551+
if feature_type in self:
552+
feature_list.append((feature_type, None))
553+
else:
565554
for feature_name in self[feature_type]:
566555
feature_list.append((feature_type, feature_name))
567-
elif self[feature_type]:
568-
feature_list.append(feature_type)
569556
return feature_list
570557

571558
def save(
@@ -661,27 +648,6 @@ def merge(
661648

662649
return merged_eopatch
663650

664-
def get_time_series(self, ref_date: Optional[dt.datetime] = None, scale_time: int = 1) -> np.ndarray:
665-
"""Returns a numpy array with seconds passed between the reference date and the timestamp of each image.
666-
667-
An array is constructed as time_series[i] = (timestamp[i] - ref_date).total_seconds().
668-
If reference date is None the first date in the EOPatch's timestamp is taken.
669-
If EOPatch timestamp attribute is empty the method returns None.
670-
671-
:param ref_date: reference date relative to which the time is measured
672-
:param scale_time: scale seconds by factor. If `60`, time will be in minutes, if `3600` hours
673-
"""
674-
675-
if not self.timestamp:
676-
return np.zeros(0, dtype=np.int64)
677-
678-
if ref_date is None:
679-
ref_date = self.timestamp[0]
680-
681-
return np.asarray(
682-
[round((timestamp - ref_date).total_seconds() / scale_time) for timestamp in self.timestamp], dtype=np.int64
683-
)
684-
685651
def consolidate_timestamps(self, timestamps: List[dt.datetime]) -> Set[dt.datetime]:
686652
"""Removes all frames from the EOPatch with a date not found in the provided timestamps list.
687653

core/eolearn/core/eodata_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
from sentinelhub.exceptions import SHUserWarning
5454

5555
from .constants import FeatureType, FeatureTypeSet, OverwritePermission
56-
from .utils.parsing import FeatureParser, FeaturesSpecification
57-
from .utils.types import EllipsisType
56+
from .types import EllipsisType, FeaturesSpecification
57+
from .utils.parsing import FeatureParser
5858
from .utils.vector_io import infer_schema
5959

6060
_T = TypeVar("_T")

core/eolearn/core/eodata_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
from .constants import FeatureType
2727
from .exceptions import EORuntimeWarning
28-
from .utils.parsing import FeatureParser, FeatureSpec, FeaturesSpecification
29-
from .utils.types import Literal
28+
from .types import FeatureSpec, FeaturesSpecification, Literal
29+
from .utils.parsing import FeatureParser
3030

3131
if TYPE_CHECKING:
3232
from .eodata import EOPatch

0 commit comments

Comments
 (0)