Skip to content

Commit

Permalink
PR #200 default to using "properties" dim name
Browse files Browse the repository at this point in the history
aligns better with load_geojson spec
  • Loading branch information
soxofaan committed Aug 3, 2023
1 parent 090efca commit cb651ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class DriverVectorCube:
"""
DIM_GEOMETRIES = "geometries"
DIM_BANDS = "bands"
DIM_PROPERTIES = "properties"
FLATTEN_PREFIX = "vc"
COLUMN_SELECTION_ALL = "all"
COLUMN_SELECTION_NUMERICAL = "numerical"
Expand Down Expand Up @@ -254,8 +255,7 @@ def from_geodataframe(
data: gpd.GeoDataFrame,
*,
columns_for_cube: Union[List[str], str] = COLUMN_SELECTION_NUMERICAL,
# TODO: change default band name to "properties" (per `load_geojson` spec introduced by https://github.com/Open-EO/openeo-processes/pull/427)
dimension_name: str = DIM_BANDS,
dimension_name: str = DIM_PROPERTIES,
) -> "DriverVectorCube":
"""
Build a DriverVectorCube from given GeoPandas data frame,
Expand Down Expand Up @@ -600,7 +600,8 @@ def apply_dimension(

if single_run_udf:
# Process with single "run_udf" node
if dimension == self.DIM_BANDS and target_dimension is None:
# TODO: check provided dimension with actual dimension of the cube
if dimension in (self.DIM_BANDS, self.DIM_PROPERTIES) and target_dimension is None:
log.warning(
f"Using experimental feature: DriverVectorCube.apply_dimension along dim {dimension} and empty cube"
)
Expand Down
22 changes: 12 additions & 10 deletions tests/test_vectorcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,20 @@ def test_from_geodataframe_default(self, gdf):
}
)
cube = vc.get_cube()
assert cube.dims == ("geometries", "bands")
assert cube.dims == ("geometries", "properties")
assert cube.shape == (2, 1)
assert {k: list(v.values) for k, v in cube.coords.items()} == {"geometries": [0, 1], "bands": ["pop"]}
assert {k: list(v.values) for k, v in cube.coords.items()} == {"geometries": [0, 1], "properties": ["pop"]}

@pytest.mark.parametrize(
["columns_for_cube", "expected"],
[
("numerical", {"shape": (2, 1), "coords": {"geometries": [0, 1], "bands": ["pop"]}}),
("all", {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["id", "pop"]}}),
("numerical", {"shape": (2, 1), "coords": {"geometries": [0, 1], "properties": ["pop"]}}),
("all", {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["id", "pop"]}}),
([], None),
(["id"], {"shape": (2, 1), "coords": {"geometries": [0, 1], "bands": ["id"]}}),
(["pop", "id"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["pop", "id"]}}),
(["id"], {"shape": (2, 1), "coords": {"geometries": [0, 1], "properties": ["id"]}}),
(["pop", "id"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "id"]}}),
# TODO: test specifying non-existent column (to be filled with no-data):
# (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["pop", "nopenope"]}}),
# (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "nopenope"]}}),
],
)
def test_from_geodataframe_columns_for_cube(self, gdf, columns_for_cube, expected):
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_from_geodataframe_columns_for_cube(self, gdf, columns_for_cube, expecte
if expected is None:
assert cube is None
else:
assert cube.dims == ("geometries", "bands")
assert cube.dims == ("geometries", "properties")
assert cube.shape == expected["shape"]
assert {k: list(v.values) for k, v in cube.coords.items()} == expected["coords"]

Expand Down Expand Up @@ -571,7 +571,9 @@ def test_buffer_points(self):
}
)

def test_apply_dimension_run_udf_change_geometry(self, vc, backend_implementation):
@pytest.mark.parametrize("dimension", ["bands", "properties"])
def test_apply_dimension_run_udf_change_geometry(self, gdf, backend_implementation, dimension):
vc = DriverVectorCube.from_geodataframe(gdf, dimension_name=dimension)
udf = textwrap.dedent(
"""
from openeo.udf import UdfData, FeatureCollection
Expand All @@ -592,7 +594,7 @@ def process_geometries(udf_data: UdfData) -> UdfData:
}
}
env = EvalEnv({"backend_implementation": backend_implementation})
result = vc.apply_dimension(process=callback, dimension="bands", env=env)
result = vc.apply_dimension(process=callback, dimension=dimension, env=env)
assert isinstance(result, DriverVectorCube)
feature_collection = result.to_geojson()
assert feature_collection == DictSubSet(
Expand Down

0 comments on commit cb651ef

Please sign in to comment.