Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions core/eolearn/core/core_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ def zip_method(self, *f):


class MergeFeatureTask(ZipFeatureTask):
"""Merges multiple features together by concatenating their data along the last axis."""
"""Merges multiple features together by concatenating their data along the specified axis."""

def zip_method(self, *f: np.ndarray, dtype: Union[None, np.dtype, type] = None) -> np.ndarray:
"""Concatenates the data of features along the last axis."""
return np.concatenate(f, axis=-1, dtype=dtype) # pylint: disable=unexpected-keyword-arg
def zip_method(self, *f: np.ndarray, dtype: Union[None, np.dtype, type] = None, axis: int = -1) -> np.ndarray:
"""Concatenates the data of features along the specified axis."""
return np.concatenate(f, axis=axis, dtype=dtype) # pylint: disable=unexpected-keyword-arg


class ExtractBandsTask(MapFeatureTask):
Expand Down
9 changes: 5 additions & 4 deletions core/eolearn/tests/test_core_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def test_move_feature():
assert "MTless2" in patch_dst[FeatureType.MASK_TIMELESS]


def test_merge_features():
@pytest.mark.parametrize("axis", (0, -1))
def test_merge_features(axis):
patch = EOPatch()

shape = (10, 5, 5, 3)
Expand All @@ -332,10 +333,10 @@ def test_merge_features():
for feat, dat in zip(features, data):
patch = AddFeatureTask(feat)(patch, dat)

patch = MergeFeatureTask(features[:3], (FeatureType.MASK, "merged"))(patch)
patch = MergeFeatureTask(features[3:], (FeatureType.MASK_TIMELESS, "merged_timeless"))(patch)
patch = MergeFeatureTask(features[:3], (FeatureType.MASK, "merged"), axis=axis)(patch)
patch = MergeFeatureTask(features[3:], (FeatureType.MASK_TIMELESS, "merged_timeless"), axis=axis)(patch)

expected = np.concatenate([patch[f] for f in features[:3]], axis=-1)
expected = np.concatenate([patch[f] for f in features[:3]], axis=axis)

assert np.array_equal(patch.mask["merged"], expected)

Expand Down