From 4f503299814c4b033890b537dcdfa7adb1e90eef Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Thu, 14 Dec 2023 15:59:05 +0100 Subject: [PATCH] dimension_labels should return a list, datetimes should be ISO formatted --- .../process_implementations/cubes/general.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openeo_processes_dask/process_implementations/cubes/general.py b/openeo_processes_dask/process_implementations/cubes/general.py index 14639250..5013b1ef 100644 --- a/openeo_processes_dask/process_implementations/cubes/general.py +++ b/openeo_processes_dask/process_implementations/cubes/general.py @@ -3,6 +3,8 @@ import xarray as xr from openeo_pg_parser_networkx.pg_schema import * +import numpy as np +from numpy.typing import ArrayLike from openeo_processes_dask.process_implementations.data_model import RasterCube from openeo_processes_dask.process_implementations.exceptions import ( DimensionLabelCountMismatch, @@ -28,12 +30,17 @@ def create_raster_cube() -> RasterCube: return xr.DataArray() -def dimension_labels(data: RasterCube, dimension: str) -> RasterCube: +def dimension_labels(data: RasterCube, dimension: str) -> ArrayLike: if dimension not in data.dims: raise DimensionNotAvailable( f"Provided dimension ({dimension}) not found in data.dims: {data.dims}" ) - return data.coords[dimension] + + coords = data.coords[dimension] + if np.issubdtype(coords.dtype, np.datetime64): + return np.datetime_as_string(coords, timezone="UTC") + else: + return np.array(data.coords[dimension]) def add_dimension(