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 11, 2024
1 parent ef1e297 commit cdaa88c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,13 @@ 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 len(cube.metadata.band_names) != 1:
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/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def filter_spatial(self, geometries):
return cube._process(operation="filter_spatial", arguments={"geometries": geometries})

def filter_bands(self, bands) -> 'DryRunDataCube':
return self._process("bands", bands)
return self._process("bands", bands, metadata=self.metadata.filter_bands(bands))

def filter_properties(self, properties) -> 'DryRunDataCube':
return self._process("properties", properties)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_views_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4215,3 +4215,27 @@ def test_to_scl_dilation_mask_defaults(api):
"mask1_values": [2, 4, 5, 6, 7],
"mask2_values": [3, 8, 9, 10, 11],
}


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 cdaa88c

Please sign in to comment.