Skip to content

Commit f57b976

Browse files
refactor timeseries in to_legacy_save_result Open-EO/openeo-geopyspark-driver#663
1 parent 6142d47 commit f57b976

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

openeo_driver/datacube.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,15 @@ def to_legacy_save_result(self) -> Union["AggregatePolygonResult", "JSONResult"]
574574

575575
cube = self._cube
576576
# TODO: more flexible temporal/band dimension detection?
577-
if cube.dims == (self.DIM_GEOMETRY, "t"):
577+
if cube.dims == (self.DIM_GEOMETRY, self.DIM_TIME):
578578
# Add single band dimension
579579
cube = cube.expand_dims({"bands": ["band"]}, axis=-1)
580-
if cube.dims == (self.DIM_GEOMETRY, "t", "bands"):
581-
cube = cube.transpose("t", self.DIM_GEOMETRY, "bands")
582-
timeseries = {
583-
t.item(): t_slice.values.tolist()
584-
for t, t_slice in zip(cube.coords["t"], cube)
585-
}
580+
if cube.dims == (self.DIM_GEOMETRY, self.DIM_TIME, "bands"):
581+
timeseries = {} # {timestamp: List[List[]]} (geometries, bands)
582+
for t, t_slice in cube.groupby(self.DIM_TIME):
583+
t: numpy.generic = t
584+
t_slice: xarray.DataArray = t_slice # (geometries, bands)
585+
timeseries[t.item()] = t_slice.values.tolist()
586586
return AggregatePolygonResult(timeseries=timeseries, regions=self)
587587
elif cube.dims == (self.DIM_GEOMETRY, "bands"):
588588
# This covers the legacy `AggregatePolygonSpatialResult` code path,

0 commit comments

Comments
 (0)