Skip to content

Commit 7d540bb

Browse files
committed
EP-3981 Add #71 #114 references to vector cube todo's
1 parent aa5ec2c commit 7d540bb

File tree

7 files changed

+31
-28
lines changed

7 files changed

+31
-28
lines changed

openeo_driver/ProcessGraphDeserializer.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ def vector_buffer(args: Dict, env: EvalEnv) -> dict:
521521
input_crs = 'epsg:4326'
522522
buffer_resolution = 3
523523

524-
# TODO EP-3981 convert `geometry` to vector cube and move buffer logic to there
524+
# TODO #114 EP-3981 convert `geometry` to vector cube and move buffer logic to there
525525
if isinstance(geometry, str):
526526
# TODO: assumption here that `geometry` is a path/url
527527
geoms = list(DelayedVector(geometry).geometries)
@@ -664,7 +664,7 @@ def chunk_polygon(args: dict, env: EvalEnv) -> DriverDataCube:
664664
data_cube = extract_arg(args, 'data')
665665

666666
# Chunks parameter check.
667-
# TODO EP-3981 normalize first to vector cube and simplify logic
667+
# TODO #114 EP-3981 normalize first to vector cube and simplify logic
668668
if isinstance(chunks, DelayedVector):
669669
polygons = list(chunks.geometries)
670670
for p in polygons:
@@ -705,7 +705,7 @@ def fit_class_random_forest(args: dict, env: EvalEnv) -> DriverMlModel:
705705

706706
predictors = extract_arg(args, 'predictors')
707707
if not isinstance(predictors, AggregatePolygonSpatialResult):
708-
# TODO EP-3981 add support for real vector cubes.
708+
# TODO #114 EP-3981 add support for real vector cubes.
709709
raise ProcessParameterInvalidException(
710710
parameter="predictors", process="fit_class_random_forest",
711711
reason=f"should be non-temporal vector-cube (got `{type(predictors)}`)."
@@ -716,7 +716,7 @@ def fit_class_random_forest(args: dict, env: EvalEnv) -> DriverMlModel:
716716
and target.get("type") == "FeatureCollection"
717717
and isinstance(target.get("features"), list)
718718
):
719-
# TODO EP-3981 vector cube support
719+
# TODO #114 EP-3981 vector cube support
720720
raise ProcessParameterInvalidException(
721721
parameter="target", process="fit_class_random_forest",
722722
reason='only GeoJSON FeatureCollection is currently supported.',
@@ -949,7 +949,7 @@ def aggregate_spatial(args: dict, env: EvalEnv) -> DriverDataCube:
949949
target_dimension = args.get('target_dimension', None)
950950

951951
geoms = extract_arg(args, 'geometries')
952-
# TODO: convert all cases to DriverVectorCube first and just work with that
952+
# TODO #114: convert all cases to DriverVectorCube first and just work with that
953953
if isinstance(geoms, DriverVectorCube):
954954
geoms = geoms
955955
elif isinstance(geoms, dict):
@@ -993,11 +993,11 @@ def mask_polygon(args: dict, env: EvalEnv) -> DriverDataCube:
993993
replacement = args.get('replacement', None)
994994
inside = args.get('inside', False)
995995

996-
# TODO: instead of if-elif-else chain: generically "cast" to VectorCube first (e.g. for wide input
996+
# TODO #114: instead of if-elif-else chain: generically "cast" to VectorCube first (e.g. for wide input
997997
# support: GeoJSON, WKT, ...) and then convert to MultiPolygon?
998998
if isinstance(mask, DelayedVector):
999999
# TODO: avoid reading DelayedVector twice due to dry-run?
1000-
# TODO EP-3981 embed DelayedVector in VectorCube implementation
1000+
# TODO #114 EP-3981 embed DelayedVector in VectorCube implementation
10011001
polygon = shapely.ops.unary_union(list(mask.geometries))
10021002
elif isinstance(mask, DriverVectorCube):
10031003
polygon = mask.to_multipolygon()
@@ -1073,7 +1073,7 @@ def filter_spatial(args: Dict, env: EvalEnv) -> DriverDataCube:
10731073
geometries = extract_arg(args, 'geometries')
10741074

10751075
if not isinstance(geometries, dict):
1076-
# TODO: support DelayedVector
1076+
# TODO #114: support DriverDataCube
10771077
raise NotImplementedError("filter_spatial only supports dict but got {g!r}".format(g=geometries))
10781078

10791079
geometries = geojson_to_geometry(geometries)
@@ -1173,6 +1173,7 @@ def run_udf(args: dict, env: EvalEnv):
11731173
if dry_run_tracer and isinstance(data, AggregatePolygonResult):
11741174
return JSONResult({})
11751175

1176+
# TODO #114 add support for DriverVectorCube
11761177
if isinstance(data, AggregatePolygonResult):
11771178
pass
11781179
if isinstance(data, (DelayedVector, dict)):
@@ -1346,15 +1347,15 @@ def apply_process(process_id: str, args: dict, namespace: Union[str, None], env:
13461347
.returns("TODO", schema={"type": "object", "subtype": "vector-cube"})
13471348
)
13481349
def read_vector(args: Dict, env: EvalEnv) -> DelayedVector:
1349-
# TODO EP-3981: deprecated in favor of load_uploaded_files/load_external? https://github.com/Open-EO/openeo-processes/issues/322
1350+
# TODO #114 EP-3981: deprecated in favor of load_uploaded_files/load_external? https://github.com/Open-EO/openeo-processes/issues/322
13501351
path = extract_arg(args, 'filename')
13511352
return DelayedVector(path)
13521353

13531354

13541355
@process_registry_100.add_function(spec=read_spec("openeo-processes/1.x/proposals/load_uploaded_files.json"))
13551356
def load_uploaded_files(args: dict, env: EvalEnv) -> DriverVectorCube:
1356-
# TODO EP-3981 process name is still under discussion https://github.com/Open-EO/openeo-processes/issues/322
1357-
# TODO EP-3981 also other return types: raster data cube, array, ...
1357+
# TODO #114 EP-3981 process name is still under discussion https://github.com/Open-EO/openeo-processes/issues/322
1358+
# TODO also other return types: raster data cube, array, ...
13581359
paths = extract_arg(args, 'paths', process_id="load_uploaded_files")
13591360
format = extract_arg(args, 'format', process_id="load_uploaded_files")
13601361
options = args.get("options", {})
@@ -1376,7 +1377,7 @@ def load_uploaded_files(args: dict, env: EvalEnv) -> DriverVectorCube:
13761377
.returns("TODO", schema={"type": "object", "subtype": "vector-cube"})
13771378
)
13781379
def get_geometries(args: Dict, env: EvalEnv) -> Union[DelayedVector, dict]:
1379-
# TODO: standardize or deprecate this? EP-3981 https://github.com/Open-EO/openeo-processes/issues/322
1380+
# TODO: standardize or deprecate this? #114 EP-3981 https://github.com/Open-EO/openeo-processes/issues/322
13801381
feature_collection = args.get('feature_collection', None)
13811382
path = args.get('filename', None)
13821383
if path is not None:

openeo_driver/datacube.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class DriverVectorCube:
156156
DIM_GEOMETRIES = "geometries"
157157

158158
def __init__(self, geometries: gpd.GeoDataFrame, cube: Optional[xarray.DataArray] = None):
159-
# TODO EP-3981: consider other data containers (xarray) and lazy loading?
159+
# TODO #114 EP-3981: lazy loading (like DelayedVector)?
160160
if cube is not None:
161161
if cube.dims[0] != self.DIM_GEOMETRIES:
162162
log.error(f"First cube dim should be {self.DIM_GEOMETRIES!r} but got dims {cube.dims!r}")
@@ -176,9 +176,9 @@ def with_cube(self, cube: xarray.DataArray) -> "DriverVectorCube":
176176
def from_fiona(cls, paths: List[str], driver: str, options: dict):
177177
"""Factory to load vector cube data using fiona/GeoPandas."""
178178
if len(paths) != 1:
179-
# TODO EP-3981: support multiple paths
179+
# TODO #114 EP-3981: support multiple paths
180180
raise FeatureUnsupportedException(message="Loading a vector cube from multiple files is not supported")
181-
# TODO EP-3981: lazy loading like/with DelayedVector
181+
# TODO #114 EP-3981: lazy loading like/with DelayedVector
182182
return cls(geometries=gpd.read_file(paths[0], driver=driver))
183183

184184
def _as_geopandas_df(self) -> gpd.GeoDataFrame:

openeo_driver/delayed_vector.py

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def _read_shapefile_crs(shp_path: str) -> pyproj.CRS:
199199

200200
@staticmethod
201201
def _as_geometry_collection(feature_collection: Dict) -> Dict:
202+
# TODO #71 #114 Deprecate/avoid usage of GeometryCollection
202203
geometries = (feature['geometry'] for feature in feature_collection['features'])
203204

204205
return {

openeo_driver/dry_run.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def aggregate_spatial(
443443
reducer: dict,
444444
target_dimension: str = "result",
445445
) -> Union[AggregatePolygonResult, AggregatePolygonSpatialResult]:
446-
# TODO EP-3981 normalize to vector cube instead of GeometryCollection
446+
# TODO #71 #114 EP-3981 normalize to vector cube instead of GeometryCollection
447447
geometries, bbox = self._normalize_geometry(geometries)
448448
cube = self.filter_bbox(**bbox, operation="_weak_spatial_extent")
449449
cube._process(operation="aggregate_spatial", arguments={"geometries": geometries})
@@ -456,7 +456,7 @@ def _normalize_geometry(self, geometries) -> Tuple[Union[DriverVectorCube, Delay
456456
Helper to preprocess geometries (as used in aggregate_spatial and mask_polygon)
457457
and extract bbox (e.g. for filter_bbox)
458458
"""
459-
# TODO EP-3981 normalize to vector cube instead of GeometryCollection
459+
# TODO #71 #114 EP-3981 normalize to vector cube instead of GeometryCollection
460460
if isinstance(geometries, DriverVectorCube):
461461
bbox = geometries.get_bounding_box()
462462
elif isinstance(geometries, dict):
@@ -478,7 +478,7 @@ def _normalize_geometry(self, geometries) -> Tuple[Union[DriverVectorCube, Delay
478478
bbox = dict(west=bbox[0], south=bbox[1], east=bbox[2], north=bbox[3], crs="EPSG:4326")
479479
return geometries, bbox
480480

481-
# TODO: this is a workaround until vectorcube is fully upgraded
481+
# TODO: #114 this is a workaround until vectorcube is fully upgraded
482482
def raster_to_vector(self):
483483
return AggregatePolygonResult(timeseries={}, regions=None)
484484

@@ -504,6 +504,7 @@ def reduce_dimension(self, reducer, dimension: str, context: Any, env: EvalEnv)
504504

505505
def chunk_polygon(self, reducer, chunks: MultiPolygon, mask_value: float, env: EvalEnv, context={}) -> 'DryRunDataCube':
506506
polygons: List[Polygon] = chunks.geoms
507+
# TODO #71 #114 Deprecate/avoid usage of GeometryCollection
507508
geometries, bbox = self._normalize_geometry(GeometryCollection(polygons))
508509
cube = self.filter_bbox(**bbox, operation="_weak_spatial_extent")
509510
return cube._process("chunk_polygon", arguments={"geometries": geometries})

openeo_driver/dummy/dummy_backend.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def assert_polygon_sequence(geometries: Union[Sequence, BaseMultipartGeometry]):
219219
for g in geometries:
220220
assert isinstance(g, Polygon) or isinstance(g, MultiPolygon)
221221

222-
# TODO EP-3981 normalize to vector cube and preserve original properties
222+
# TODO #114 EP-3981 normalize to vector cube and preserve original properties
223223
if isinstance(geometries, DriverVectorCube):
224224
# Build dummy aggregation data cube
225225
dims = (DriverVectorCube.DIM_GEOMETRIES,)
@@ -239,7 +239,7 @@ def assert_polygon_sequence(geometries: Union[Sequence, BaseMultipartGeometry]):
239239
geometries = [geometry for geometry in DelayedVector(geometries).geometries]
240240
assert_polygon_sequence(geometries)
241241
elif isinstance(geometries, GeometryCollection):
242-
# TODO EP-3981: GeometryCollection is deprecated
242+
# TODO #71 #114 EP-3981: GeometryCollection is deprecated
243243
assert_polygon_sequence(geometries)
244244
elif isinstance(geometries, BaseGeometry):
245245
assert_polygon_sequence([geometries])
@@ -256,7 +256,7 @@ def assert_polygon_sequence(geometries: Union[Sequence, BaseMultipartGeometry]):
256256

257257

258258
class DummyAggregatePolygonSpatialResult(AggregatePolygonSpatialResult):
259-
# TODO EP-3981 replace with proper VectorCube implementation
259+
# TODO #114 EP-3981 replace with proper VectorCube implementation
260260

261261
def __init__(self, cube: DummyDataCube, geometries: Iterable[BaseGeometry]):
262262
super().__init__(csv_dir="/dev/null", regions=geometries)

openeo_driver/save_result.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class AggregatePolygonResult(JSONResult): # TODO: if it supports NetCDF and CSV
199199
200200
"""
201201

202-
# TODO EP-3981 port this to proper vector cube support
202+
# TODO #71 #114 EP-3981 port this to proper vector cube support
203203

204204
def __init__(self, timeseries: dict, regions: GeometryCollection, metadata:CollectionMetadata=None):
205205
super().__init__(data=timeseries)
@@ -429,11 +429,10 @@ def to_covjson(self) -> dict:
429429
}
430430

431431

432-
433432
class AggregatePolygonResultCSV(AggregatePolygonResult):
433+
# TODO #71 #114 EP-3981 port this to proper vector cube support
434434

435-
436-
def __init__(self, csv_dir, regions: GeometryCollection, metadata:CollectionMetadata=None):
435+
def __init__(self, csv_dir, regions: GeometryCollection, metadata: CollectionMetadata = None):
437436

438437
def _flatten_df(df):
439438
df.index = df.feature_index
@@ -464,7 +463,7 @@ class AggregatePolygonSpatialResult(SaveResult):
464463
"""
465464
Container for result of `aggregate_polygon` process (aka "zonal stats") for a spatial layer.
466465
"""
467-
# TODO EP-3981 replace with proper VectorCube implementation
466+
# TODO #71 #114 EP-3981 replace with proper VectorCube implementation
468467

469468
DEFAULT_FORMAT = "JSON"
470469

@@ -597,7 +596,7 @@ def to_save_result(data: Any, format: Optional[str] = None, options: Optional[di
597596
elif isinstance(data, DriverVectorCube):
598597
return VectorCubeResult(cube=data, format=format, options=options)
599598
elif isinstance(data, DelayedVector):
600-
# TODO EP-3981 add vector cube support: keep features from feature collection
599+
# TODO #114 EP-3981 add vector cube support: keep features from feature collection
601600
geojsons = [mapping(geometry) for geometry in data.geometries]
602601
return JSONResult(geojsons, format=format, options=options)
603602
elif isinstance(data, np.ndarray):

openeo_driver/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def smart_bool(value):
128128

129129
def geojson_to_geometry(geojson: dict) -> shapely.geometry.base.BaseGeometry:
130130
"""Convert GeoJSON object to shapely geometry object"""
131-
# TODO EP-3981 standardize on using (FeatureCollection like) vector cubes instead of GeometryCollection?
131+
# TODO #71 #114 EP-3981 standardize on using (FeatureCollection like) vector cubes instead of GeometryCollection?
132132
if geojson["type"] == "FeatureCollection":
133133
geojson = {
134134
'type': 'GeometryCollection',
@@ -147,6 +147,7 @@ def geojson_to_multipolygon(
147147
means dissolving overlapping polygons into one).
148148
"""
149149
# TODO: option to also force conversion of Polygon to MultiPolygon?
150+
# TODO: #71 #114 migrate/centralize all this kind of logic to vector cubes
150151
if geojson["type"] == "Feature":
151152
geojson = geojson["geometry"]
152153

0 commit comments

Comments
 (0)