Skip to content

Commit

Permalink
Issue #114/#211/#197 from_geodataframe: add dummy cube when no proper…
Browse files Browse the repository at this point in the history
…ties are specified
  • Loading branch information
soxofaan committed Aug 4, 2023
1 parent 93aebdd commit 9fb130a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
10 changes: 8 additions & 2 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,14 @@ def from_geodataframe(
return cls(geometries=geometries_df, cube=cube)

else:
# TODO: add a dummy 1D no-data cube?
return cls(geometries=data)
# Use 1D dummy cube of NaN values
cube: xarray.DataArray = xarray.DataArray(
data=numpy.full(shape=[data.shape[0]], fill_value=numpy.nan),
dims=[cls.DIM_GEOMETRIES],
coords={cls.DIM_GEOMETRIES: data.geometry.index.to_list()},
attrs={"vector_cube_dummy": True},
)
return cls(geometries=data, cube=cube)

@classmethod
def from_fiona(
Expand Down
26 changes: 24 additions & 2 deletions tests/test_vectorcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ def test_to_internal_json_defaults(self, gdf):
"attrs": {},
},
),
([], None),
(
[],
{
"name": None,
"dims": ("geometries",),
"coords": {
"geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)},
},
"data": [IsNan(), IsNan()],
"attrs": {},
},
),
(
["pop", "id"],
{
Expand Down Expand Up @@ -359,7 +370,18 @@ def test_from_geodataframe_default(self, gdf):
"attrs": {},
},
),
([], None),
(
[],
{
"name": None,
"dims": ("geometries",),
"coords": {
"geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)},
},
"data": [IsNan(), IsNan()],
"attrs": {"vector_cube_dummy": True},
},
),
(
["id"],
{
Expand Down

0 comments on commit 9fb130a

Please sign in to comment.