Skip to content

Commit

Permalink
to_scl_dilation_mask: use defaults from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Mar 11, 2024
1 parent d165cc9 commit 26667e7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
33 changes: 18 additions & 15 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,23 +1993,26 @@ def mask_scl_dilation(args: Dict, env: EvalEnv):

@process_registry_100.add_function(spec=read_spec("openeo-processes/experimental/to_scl_dilation_mask.json"))
@process_registry_2xx.add_function(spec=read_spec("openeo-processes/experimental/to_scl_dilation_mask.json"))
def to_scl_dilation_mask(args: Dict, env: EvalEnv):
cube: DriverDataCube = extract_arg(args, "data")
if not isinstance(cube, DriverDataCube):
raise ProcessParameterInvalidException(
parameter="data",
process="to_scl_dilation_mask",
reason=f"Invalid data type {type(cube)!r} expected raster-cube.",
)
def to_scl_dilation_mask(args: ProcessArgs, env: EvalEnv):
cube: DriverDataCube = args.get_required("data", expected_type=DriverDataCube)

if hasattr(cube, "to_scl_dilation_mask"):
erosion_kernel_size = args.get("erosion_kernel_size", 0)
mask1_values = args.get("mask1_values", [2, 4, 5, 6, 7])
mask2_values = args.get("mask2_values", [3, 8, 9, 10, 11])
kernel1_size = args.get("kernel1_size", 17)
kernel2_size = args.get("kernel2_size", 201)
return cube.to_scl_dilation_mask(erosion_kernel_size, mask1_values, mask2_values, kernel1_size, kernel2_size)
# Get default values 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}
optionals = {
arg: args.get_optional(arg, default=defaults[arg])
for arg in [
"erosion_kernel_size",
"mask1_values",
"mask2_values",
"kernel1_size",
"kernel2_size",
]
}
return cube.to_scl_dilation_mask(**optionals)
else:
return cube
raise FeatureUnsupportedException(message="to_scl_dilation_mask is not supported")


@process_registry_100.add_function(spec=read_spec("openeo-processes/experimental/mask_l1c.json"))
Expand Down
28 changes: 28 additions & 0 deletions tests/test_views_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4187,3 +4187,31 @@ def test_verify_for_synchronous_processing_failure(api, caplog):
res = api.result(pg)
res.assert_status_code(200)
assert "Unexpected error while verifying synchronous processing: Nope, catch this" in caplog.text


def test_to_scl_dilation_mask_defaults(api):
api.check_result(
{
"loadcollection1": {
"process_id": "load_collection",
"arguments": {"id": "SENTINEL2_L2A_SENTINELHUB", "bands": ["SCL"]},
},
"to_scl_dilation_mask": {
"process_id": "to_scl_dilation_mask",
"arguments": {"data": {"from_node": "loadcollection1"}},
"result": True,
},
}
)

dummy = dummy_backend.get_collection("SENTINEL2_L2A_SENTINELHUB")
assert dummy.to_scl_dilation_mask.call_count == 1
args, kwargs = dummy.to_scl_dilation_mask.call_args
assert args == ()
assert kwargs == {
"erosion_kernel_size": 0,
"kernel1_size": 17,
"kernel2_size": 201,
"mask1_values": [2, 4, 5, 6, 7],
"mask2_values": [3, 8, 9, 10, 11],
}

0 comments on commit 26667e7

Please sign in to comment.