Skip to content

Commit 92f046c

Browse files
committed
Issue #346 Some more ProcessArgs porting
for less boilerplate code and better/earlier error messages
1 parent a02d321 commit 92f046c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

openeo_driver/ProcessGraphDeserializer.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,10 @@ def mask_polygon(args: ProcessArgs, env: EvalEnv) -> DriverDataCube:
15241524
return cube
15251525

15261526

1527-
def _extract_temporal_extent(args: dict, field="extent", process_id="filter_temporal") -> Tuple[str, str]:
1527+
def _extract_temporal_extent(
1528+
args: Union[dict, ProcessArgs], field="extent", process_id="filter_temporal"
1529+
) -> Tuple[str, str]:
1530+
# TODO #346: make this a ProcessArgs method?
15281531
extent = extract_arg(args, name=field, process_id=process_id)
15291532
if len(extent) != 2:
15301533
raise ProcessParameterInvalidException(
@@ -1554,13 +1557,8 @@ def _extract_temporal_extent(args: dict, field="extent", process_id="filter_temp
15541557

15551558

15561559
@process
1557-
def filter_temporal(args: dict, env: EvalEnv) -> DriverDataCube:
1558-
cube = extract_arg(args, 'data')
1559-
if not isinstance(cube, DriverDataCube):
1560-
raise ProcessParameterInvalidException(
1561-
parameter="data", process="filter_temporal",
1562-
reason=f"Invalid data type {type(cube)!r} expected raster-cube."
1563-
)
1560+
def filter_temporal(args: ProcessArgs, env: EvalEnv) -> DriverDataCube:
1561+
cube: DriverDataCube = args.get_required("data", expected_type=DriverDataCube)
15641562
start, end = _extract_temporal_extent(args, field="extent", process_id="filter_temporal")
15651563
return cube.filter_temporal(start=start, end=end)
15661564

@@ -1576,7 +1574,10 @@ def filter_labels(args: ProcessArgs, env: EvalEnv) -> DriverDataCube:
15761574
return cube.filter_labels(condition=condition, dimension=dimension, context=context, env=env)
15771575

15781576

1579-
def _extract_bbox_extent(args: dict, field="extent", process_id="filter_bbox", handle_geojson=False) -> dict:
1577+
def _extract_bbox_extent(
1578+
args: Union[dict, ProcessArgs], field="extent", process_id="filter_bbox", handle_geojson=False
1579+
) -> dict:
1580+
# TODO #346: make this a ProcessArgs method?
15801581
extent = extract_arg(args, name=field, process_id=process_id)
15811582
# TODO #114: support vector cube
15821583
if handle_geojson and extent.get("type") in [

0 commit comments

Comments
 (0)