Skip to content

Commit

Permalink
dimension_labels should return a list, datetimes should be ISO formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mohr committed Dec 14, 2023
1 parent 8d9e3fb commit 4f50329
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions openeo_processes_dask/process_implementations/cubes/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 4f50329

Please sign in to comment.