Skip to content

Commit 7712675

Browse files
issue693 use default option from backend in datacube.sar_backscatter
1 parent d8a4718 commit 7712675

File tree

4 files changed

+65
-42
lines changed

4 files changed

+65
-42
lines changed

openeo/internal/processes/parse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ def is_geojson_schema(schema) -> bool:
4343
return any(is_geojson_schema(s) for s in self.schema)
4444
return False
4545

46-
def get_enum_options(self,name):
46+
def get_enum_options(self):
4747
result = None
4848
if isinstance(self.schema,list):
4949
for item in self.schema:
50-
if name in item:
50+
if "enum" in item:
5151
if result is None:
52-
result = item[name]
52+
result = item["enum"]
5353
else:
54-
raise ValueError("Multiple entries found with name {v}.".format(v=name))
54+
raise ValueError("Multiple entries found for enum options.")
5555
elif isinstance(self.schema,dict):
56-
if name in self.schema:
57-
result = self.schema[name]
56+
if "enum" in self.schema:
57+
result = self.schema["enum"]
5858
return result
5959

6060

openeo/rest/datacube.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,15 +2725,15 @@ def ard_normalized_radar_backscatter(
27252725

27262726
@openeo_process
27272727
def sar_backscatter(
2728-
self,
2729-
coefficient: Union[str, None] = "gamma0-terrain",
2730-
elevation_model: Union[str, None] = None,
2731-
mask: bool = False,
2732-
contributing_area: bool = False,
2733-
local_incidence_angle: bool = False,
2734-
ellipsoid_incidence_angle: bool = False,
2735-
noise_removal: bool = True,
2736-
options: Optional[dict] = None
2728+
self,
2729+
coefficient: Union[str, None] = "default",
2730+
elevation_model: Union[str, None] = None,
2731+
mask: bool = False,
2732+
contributing_area: bool = False,
2733+
local_incidence_angle: bool = False,
2734+
ellipsoid_incidence_angle: bool = False,
2735+
noise_removal: bool = True,
2736+
options: Optional[dict] = None,
27372737
) -> DataCube:
27382738
"""
27392739
Computes backscatter from SAR input.
@@ -2769,8 +2769,13 @@ def sar_backscatter(
27692769
.. versionchanged:: 0.4.10 replace `orthorectify` and `rtc` arguments with `coefficient`.
27702770
"""
27712771
try:
2772-
schema = Process.from_dict(self.connection.describe_process("sar_backscatter")).get_parameter("coefficient").schema
2773-
coefficient_options = schema.get_enum_options("enum") + [None]
2772+
parameter = Process.from_dict(self.connection.describe_process("sar_backscatter")).get_parameter(
2773+
"coefficient"
2774+
)
2775+
schema = parameter.schema
2776+
coefficient_options = schema.get_enum_options() + [None]
2777+
if coefficient == "default":
2778+
coefficient = parameter.default
27742779
except Exception as e:
27752780
log.warning(f"Failed to extract coefficient options for process `sar_backscatter`: {e}")
27762781
coefficient_options = [
@@ -2781,6 +2786,8 @@ def sar_backscatter(
27812786
"gamma0-terrain",
27822787
None,
27832788
]
2789+
if coefficient == "default":
2790+
coefficient = "gamma0-terrain"
27842791
if coefficient not in coefficient_options:
27852792
raise OpenEoClientException("Invalid `sar_backscatter` coefficient {c!r}. Should be one of {o}".format(
27862793
c=coefficient, o=coefficient_options

tests/internal/processes/test_parse.py

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,48 @@ def test_schema_accepts_geojson(schema, expected):
3737

3838

3939
@pytest.mark.parametrize(
40-
"schema",
40+
("schema", "expected"),
41+
[
42+
(
43+
Schema(
44+
{
45+
"type": "string",
46+
"enum": [
47+
"average",
48+
"bilinear",
49+
"cubic",
50+
"cubicspline",
51+
"lanczos",
52+
"max",
53+
"med",
54+
"min",
55+
"mode",
56+
"near",
57+
],
58+
}
59+
),
60+
["average", "bilinear", "cubic", "cubicspline", "lanczos", "max", "med", "min", "mode", "near"],
61+
),
62+
(
63+
Schema([{"type": "string", "enum": ["replicate", "reflect", "reflect_pixel", "wrap"]}, {"type": "number"}]),
64+
["replicate", "reflect", "reflect_pixel", "wrap"],
65+
),
66+
],
67+
)
68+
def test_get_enum_options(schema, expected):
69+
schema.get_enum_options()
70+
assert schema.get_enum_options() == expected
71+
72+
73+
def test_get_enum_options_error():
74+
schema = Schema(
4175
[
42-
Schema([
43-
{"x1": "y1"},
44-
{"x2": "y2"},
45-
{"x3": "y3"},
46-
{"x5": "y3"},
47-
]),
48-
Schema({"x1":"y1","x2":"y2","x3": "y3","x5": "y3"})
49-
],
76+
{"type": "string", "enum": ["replicate", "reflect", "reflect_pixel", "wrap"]},
77+
{"type": "number", "enum": ["replicate", "reflect", "reflect_pixel", "wrap"]},
78+
]
5079
)
51-
@pytest.mark.parametrize(("key", "expected"), [("x1", "y1"), ("x2", "y2"), ("x4", None)])
52-
def test_get_enum_options(schema, key, expected):
53-
assert schema.get_enum_options(key) == expected
54-
55-
@pytest.mark.parametrize("key",["x2","x3",])
56-
def test_get_enum_options_error(key):
57-
schema = Schema([
58-
{"x1": "y1"},
59-
{"x2": "y2"},
60-
{"x3": "y3"},
61-
{"x3": "y4"},
62-
{"x2": "y1"},
63-
])
6480
with pytest.raises(ValueError):
65-
schema.get_enum_options(key)
81+
schema.get_enum_options()
6682

6783

6884
def test_parameter():

tests/rest/datacube/test_datacube100.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ def test_sar_backscatter_check_coefficient_backend(con100, requests_mock):
28372837
"summary": "Computes backscatter from SAR input",
28382838
"parameters": [
28392839
{
2840-
"default": "gamma0-terrain",
2840+
"default": "gamma0-ellipsoid",
28412841
"description": "Select the radiometric correction coefficient.",
28422842
"name": "coefficient",
28432843
"schema": [
@@ -2863,7 +2863,7 @@ def test_sar_backscatter_check_coefficient_backend(con100, requests_mock):
28632863
"process_id": "sar_backscatter",
28642864
"arguments": {
28652865
"data": {"from_node": "loadcollection1"},
2866-
"coefficient": "gamma0-terrain",
2866+
"coefficient": "gamma0-ellipsoid",
28672867
"elevation_model": None,
28682868
"mask": False,
28692869
"contributing_area": False,

0 commit comments

Comments
 (0)