Skip to content

Commit

Permalink
Issue #270 to_scl_dilation_mask: raise error when input has multiple …
Browse files Browse the repository at this point in the history
…bands
  • Loading branch information
soxofaan committed Mar 26, 2024
1 parent 4b76b09 commit 6670bb5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and start a new "In Progress" section above it.

## In progress

# 0.94.2

- `to_scl_dilation_mask`: raise error when input cube has more than one band ([#270](https://github.com/Open-EO/openeo-python-driver/issues/270))

## 0.94.1

- Improve resilience by retrying EJR search requests ([Open-EO/openeo-geopyspark-driver#720](https://github.com/Open-EO/openeo-geopyspark-driver/issues/720)).
Expand Down
10 changes: 9 additions & 1 deletion openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)
from openeo_driver.datastructs import SarBackscatterArgs, ResolutionMergeArgs
from openeo_driver.delayed_vector import DelayedVector
from openeo_driver.dry_run import DryRunDataTracer, SourceConstraint
from openeo_driver.dry_run import DryRunDataTracer, SourceConstraint, DryRunDataCube
from openeo_driver.errors import (
ProcessParameterRequiredException,
ProcessParameterInvalidException,
Expand Down Expand Up @@ -2005,6 +2005,14 @@ def mask_scl_dilation(args: Dict, env: EvalEnv):
@process_registry_2xx.add_function(spec=read_spec("openeo-processes/experimental/to_scl_dilation_mask.json"))
def to_scl_dilation_mask(args: ProcessArgs, env: EvalEnv):
cube: DriverDataCube = args.get_required("data", expected_type=DriverDataCube)
if not isinstance(cube, DryRunDataCube) and len(cube.metadata.band_names) != 1:
# TODO: make sure `len(cube.metadata.band_names)` check also works in the DryRunDataTracer phase
raise ProcessParameterInvalidException(
parameter="data",
process="to_scl_dilation_mask",
reason=f"The source data cube should only contain a single (SCL) band, but got {cube.metadata.band_names}.",
)

# Get default values for other args from spec
spec = read_spec("openeo-processes/experimental/to_scl_dilation_mask.json")
defaults = {param["name"]: param["default"] for param in spec["parameters"] if "default" in param}
Expand Down
2 changes: 1 addition & 1 deletion openeo_driver/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.94.1a1"
__version__ = "0.94.2a1"
3 changes: 2 additions & 1 deletion openeo_driver/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def filter_spatial(self, geometries):
cube = self.filter_bbox(**bbox, operation="_weak_spatial_extent")
return cube._process(operation="filter_spatial", arguments={"geometries": geometries})

def filter_bands(self, bands) -> 'DryRunDataCube':
def filter_bands(self, bands) -> DryRunDataCube:
# TODO: Ideally, bands in metadata are filtered here, but this breaks too many tests at the moment
return self._process("bands", bands)

def filter_properties(self, properties) -> 'DryRunDataCube':
Expand Down
5 changes: 5 additions & 0 deletions openeo_driver/dummy/dummy_backend.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import json
import numbers
from datetime import datetime
Expand Down Expand Up @@ -193,6 +194,10 @@ def __init__(self, metadata: CollectionMetadata = None):
for name in [n for n, m in DummyDataCube.__dict__.items() if getattr(m, '_mock_side_effect', False)]:
setattr(self, name, Mock(side_effect=getattr(self, name)))

@mock_side_effect
def filter_bands(self, bands) -> DummyDataCube:
return DummyDataCube(self.metadata.filter_bands(bands))

@mock_side_effect
def reduce_dimension(
self, reducer, *, dimension: str, context: Optional[dict] = None, env: EvalEnv
Expand Down
23 changes: 23 additions & 0 deletions tests/test_views_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4235,3 +4235,26 @@ def test_to_scl_dilation_mask_defaults(api, arguments, expected):
assert args == ()
assert kwargs == expected


def test_to_scl_dilation_mask_multiple_bands(api):
"""
input raster cube with multiple bands should raise error
"""
res = api.result(
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {"id": "SENTINEL2_L2A_SENTINELHUB", "bands": ["B02", "B03", "SCL"]},
},
"to_scl_dilation_mask": {
"process_id": "to_scl_dilation_mask",
"arguments": {"data": {"from_node": "loadcollection1"}},
"result": True,
},
}
)
res.assert_error(
400,
"ProcessParameterInvalid",
message="The source data cube should only contain a single (SCL) band, but got ['B02', 'B03', 'SCL']",
)

0 comments on commit 6670bb5

Please sign in to comment.