Skip to content

Commit

Permalink
Issue #270 to_scl_dilation_mask: define as DriverDataCube method
Browse files Browse the repository at this point in the history
makes things easier to track
  • Loading branch information
soxofaan committed Mar 11, 2024
1 parent 8a8ebf4 commit ef1e297
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
32 changes: 14 additions & 18 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,24 +1995,20 @@ 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 hasattr(cube, "to_scl_dilation_mask"):
# 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:
raise FeatureUnsupportedException(message="to_scl_dilation_mask is not supported")
# 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}
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)


@process_registry_100.add_function(spec=read_spec("openeo-processes/experimental/mask_l1c.json"))
Expand Down
11 changes: 11 additions & 0 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ def resample_spatial(
):
self._not_implemented()

def to_scl_dilation_mask(
self,
erosion_kernel_size: int,
mask1_values: List[int],
mask2_values: List[int],
kernel1_size: int,
kernel2_size: int,
) -> DriverDataCube:
# Note: this is a non-standard process
self._not_implemented()


class VectorCubeError(InternalException):
code = "VectorCubeError"
Expand Down
8 changes: 6 additions & 2 deletions openeo_driver/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
These source constraints can then be fetched from the EvalEnv at `load_collection` time.
"""
from __future__ import annotations
import logging
from enum import Enum
from typing import List, Union, Tuple, Any, Optional
Expand Down Expand Up @@ -737,11 +738,14 @@ def atmospheric_correction(
def mask_scl_dilation(self, **kwargs) -> 'DriverDataCube':
return self._process("custom_cloud_mask", arguments={**{"method":"mask_scl_dilation"},**kwargs})

def to_scl_dilation_mask(self, erosion_kernel_size: int,
def to_scl_dilation_mask(
self,
erosion_kernel_size: int,
mask1_values: List[int],
mask2_values: List[int],
kernel1_size: int,
kernel2_size: int) -> 'DriverDataCube':
kernel2_size: int,
) -> DryRunDataCube:
cube = self._process("process_type", [ProcessType.FOCAL_SPACE])
size = kernel2_size
cube = cube._process("pixel_buffer", arguments={"buffer_size": [size/2.0,size/2.0]})
Expand Down

0 comments on commit ef1e297

Please sign in to comment.