From 5314a343328a73f06a839d9aa06f9207c82a47da Mon Sep 17 00:00:00 2001 From: b8raoult <53792887+b8raoult@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:02:38 +0100 Subject: [PATCH] Bugfix/unknow coordinates (#72) * allow for unknown coordinates --- CHANGELOG.md | 4 ++++ .../datasets/create/functions/sources/xarray/__init__.py | 2 +- .../datasets/create/functions/sources/xarray/coordinates.py | 6 ++++++ .../datasets/create/functions/sources/xarray/flavour.py | 5 ++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cf0f1df..14fbe571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Keep it human-readable, your future self will thank you! ## [0.5.5](https://github.com/ecmwf/anemoi-datasets/compare/0.5.4...0.5.5) - 2024-10-04 +### Changed + +- Allow for unknown coordinates when parsing CF input + ## [Add support for (semi-)constant fields](https://github.com/ecmwf/anemoi-datasets/compare/0.5.1...0.5.2) - 2024-10-03 ### Changed diff --git a/src/anemoi/datasets/create/functions/sources/xarray/__init__.py b/src/anemoi/datasets/create/functions/sources/xarray/__init__.py index 3afc899b..451c149e 100644 --- a/src/anemoi/datasets/create/functions/sources/xarray/__init__.py +++ b/src/anemoi/datasets/create/functions/sources/xarray/__init__.py @@ -42,7 +42,7 @@ def load_one(emoji, context, dates, dataset, options={}, flavour=None, **kwargs) We have seen this bug triggered when we run many clients in parallel, for example, when we create a new dataset using `xarray-zarr`. """ - context.trace(emoji, dataset, options) + context.trace(emoji, dataset, options, kwargs) if isinstance(dataset, str) and ".zarr" in dataset: data = xr.open_zarr(name_to_zarr_store(dataset), **options) diff --git a/src/anemoi/datasets/create/functions/sources/xarray/coordinates.py b/src/anemoi/datasets/create/functions/sources/xarray/coordinates.py index 2da4861c..c5543d51 100644 --- a/src/anemoi/datasets/create/functions/sources/xarray/coordinates.py +++ b/src/anemoi/datasets/create/functions/sources/xarray/coordinates.py @@ -244,3 +244,9 @@ class ScalarCoordinate(Coordinate): @property def mars_names(self): return (self.variable.name,) + + +class UnsupportedCoordinate(Coordinate): + @property + def mars_names(self): + return (self.variable.name,) diff --git a/src/anemoi/datasets/create/functions/sources/xarray/flavour.py b/src/anemoi/datasets/create/functions/sources/xarray/flavour.py index df89aeba..1bdd5d15 100644 --- a/src/anemoi/datasets/create/functions/sources/xarray/flavour.py +++ b/src/anemoi/datasets/create/functions/sources/xarray/flavour.py @@ -18,6 +18,7 @@ from .coordinates import ScalarCoordinate from .coordinates import StepCoordinate from .coordinates import TimeCoordinate +from .coordinates import UnsupportedCoordinate from .coordinates import XCoordinate from .coordinates import YCoordinate from .coordinates import is_scalar @@ -157,11 +158,13 @@ def _guess(self, c, coord): if c.shape in ((1,), tuple()): return ScalarCoordinate(c) - raise NotImplementedError( + LOG.warning( f"Coordinate {coord} not supported\n{axis=}, {name=}," f" {long_name=}, {standard_name=}, units\n\n{c}\n\n{type(c.values)} {c.shape}" ) + return UnsupportedCoordinate(c) + def grid(self, coordinates, variable): lat = [c for c in coordinates if c.is_lat] lon = [c for c in coordinates if c.is_lon]