Skip to content

Use more ProcessArgs #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,10 @@ def mask_polygon(args: dict, env: EvalEnv) -> DriverDataCube:
return image_collection


def _extract_temporal_extent(args: dict, field="extent", process_id="filter_temporal") -> Tuple[str, str]:
def _extract_temporal_extent(
args: Union[dict, ProcessArgs], field="extent", process_id="filter_temporal"
) -> Tuple[str, str]:
# TODO #346: make this a ProcessArgs method?
extent = extract_arg(args, name=field, process_id=process_id)
if len(extent) != 2:
raise ProcessParameterInvalidException(
Expand All @@ -1416,13 +1419,8 @@ def _extract_temporal_extent(args: dict, field="extent", process_id="filter_temp


@process
def filter_temporal(args: dict, env: EvalEnv) -> DriverDataCube:
cube = extract_arg(args, 'data')
if not isinstance(cube, DriverDataCube):
raise ProcessParameterInvalidException(
parameter="data", process="filter_temporal",
reason=f"Invalid data type {type(cube)!r} expected raster-cube."
)
def filter_temporal(args: ProcessArgs, env: EvalEnv) -> DriverDataCube:
cube: DriverDataCube = args.get_required("data", expected_type=DriverDataCube)
extent = _extract_temporal_extent(args, field="extent", process_id="filter_temporal")
return cube.filter_temporal(start=extent[0], end=extent[1])

Expand All @@ -1438,7 +1436,10 @@ def filter_labels(args: ProcessArgs, env: EvalEnv) -> DriverDataCube:
return cube.filter_labels(condition=condition, dimension=dimension, context=context, env=env)


def _extract_bbox_extent(args: dict, field="extent", process_id="filter_bbox", handle_geojson=False) -> dict:
def _extract_bbox_extent(
args: Union[dict, ProcessArgs], field="extent", process_id="filter_bbox", handle_geojson=False
) -> dict:
# TODO #346: make this a ProcessArgs method?
extent = extract_arg(args, name=field, process_id=process_id)
if handle_geojson and extent.get("type") in [
"Polygon",
Expand Down Expand Up @@ -1655,20 +1656,17 @@ def run_udf(args: dict, env: EvalEnv):


@process
def linear_scale_range(args: dict, env: EvalEnv) -> DriverDataCube:
image_collection = extract_arg(args, 'x')

inputMin = extract_arg(args, "inputMin")
inputMax = extract_arg(args, "inputMax")
outputMax = args.get("outputMax", 1.0)
outputMin = args.get("outputMin", 0.0)
if not isinstance(image_collection, DriverDataCube):
raise ProcessParameterInvalidException(
parameter="data", process="linear_scale_range",
reason=f"Invalid data type {type(image_collection)!r} expected raster-cube."
)

return image_collection.linear_scale_range(inputMin, inputMax, outputMin, outputMax)
def linear_scale_range(args: ProcessArgs, env: EvalEnv) -> DriverDataCube:
# TODO: eliminate this top-level linear_scale_range process implementation (should be used as `apply` callback)
_log.warning("DEPRECATED: linear_scale_range usage directly on cube is deprecated/non-standard.")
cube: DriverDataCube = args.get_required("x", expected_type=DriverDataCube)
# Note: non-standard camelCase parameter names (https://github.com/Open-EO/openeo-processes/issues/302)
input_min = args.get_required("inputMin")
input_max = args.get_required("inputMax")
output_min = args.get_optional("outputMin", default=0.0)
output_max = args.get_optional("outputMax", default=1.0)
# TODO linear_scale_range is defined on GeopysparkDataCube, but not on DriverDataCube
return cube.linear_scale_range(input_min, input_max, output_min, output_max)


@process
Expand Down