Skip to content

"No dimension found with axis 'x'" ValueError on earthkit-data v 0.13.5 #663

@alicemont1

Description

@alicemont1

What happened?

Expected a point cloud image but encountered a ValueError: "No dimension found with axis 'x'." This seems to be caused by an error during the conversion of CovJSON to xarray, which then leads to the issue when plotting. Happens on all polytope-example notebooks where there is feature extraction and where plotting done with point_cloud. No error when plotting grib data with point_cloud.
Downgrading to earthkit version 0.13.4 solves the issue so problem is in latest release.

What are the steps to reproduce the bug?

When running the notebook [https://github.com/destination-earth-digital-twins/polytope-examples/blob/main/climate-dt/climate-dt-earthkit-fe-boundingbox.ipynb]
I encounter an error after executing chart.point_cloud(da['2t'], x="y", y="x")

Version

0.13.5

Platform (OS and architecture)

RHEL 8 (HPC) Python 3.11.10

Relevant log output

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/sources/xarray.py:168](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/sources/xarray.py#line=167), in XarraySource.crs(self)
    167 try:
--> 168     self._crs = earthkit_data.projection().to_cartopy_crs()
    169 except ValueError:

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/core/fieldlist.py:1599](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/core/fieldlist.py#line=1598), in FieldList.projection(self)
   1566 r"""Return the projection information shared by all the fields.
   1567 
   1568 Returns
   (...)   1597 '+proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to_meter=111319.4907932736 +no_defs +type=crs'
   1598 """
-> 1599 if self._is_shared_grid():
   1600     return self[0].projection()

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/decorators.py:322](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/decorators.py#line=321), in cached_method.<locals>.wrapped(self)
    321 if getattr(self, name, None) is None:
--> 322     setattr(self, name, method(self))
    323 return getattr(self, name)

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/core/fieldlist.py:1620](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/core/fieldlist.py#line=1619), in FieldList._is_shared_grid(self)
   1619 if len(self) > 0:
-> 1620     grid = self[0]._metadata.geography._unique_grid_id()
   1621     if grid is not None:

File [/usr/local/apps/python3/3.11.10-01/lib/python3.11/functools.py:1001](https://jupyterhub.ecmwf.int/usr/local/apps/python3/3.11.10-01/lib/python3.11/functools.py#line=1000), in cached_property.__get__(self, instance, owner)
   1000 if val is _NOT_FOUND:
-> 1001     val = self.func(instance)
   1002     try:

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py:158](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py#line=157), in XArrayMetadata.geography(self)
    156 @cached_property
    157 def geography(self):
--> 158     return XArrayFieldGeography(self, self._field._ds, self._field.variable)

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py:35](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py#line=34), in XArrayFieldGeography.__init__(self, metadata, ds, variable)
     34 self.ds = ds
---> 35 self.north, self.west, self.south, self.east = self.ds.bbox(variable)

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py:44](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py#line=43), in DataSet.bbox(self, variable)
     42 data_array = self[variable]
---> 44 keys, dims = self._get_xy_dims(data_array)
     45 key = ("bbox", tuple(keys), tuple(dims))

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py:117](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py#line=116), in DataSet._get_xy_dims(self, data_array)
    116     if ax not in keys:
--> 117         raise ValueError(f"No dimension found with axis '{ax}'")
    119 return keys, dims

ValueError: No dimension found with axis 'x'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Cell In[3], line 4
      2 import earthkit.plots
      3 chart = earthkit.plots.Map(domain="Europe")
----> 4 chart.point_cloud(da['2t'], x="y", y="x")
      6 chart.coastlines()
      7 chart.borders()

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/schemas.py:136](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/schemas.py#line=135), in Schema.apply.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    135 def wrapper(*args, **kwargs):
--> 136     return function(*args, **self._update_kwargs(kwargs, keys))

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/maps.py:164](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/maps.py#line=163), in Map.point_cloud(self, *args, **kwargs)
    148 @schema.point_cloud.apply()
    149 def point_cloud(self, *args, **kwargs):
    150     """
    151     Plot a point cloud on the map.
    152 
   (...)    162         Additional keyword arguments to pass to `matplotlib.pyplot.scatter`.
    163     """
--> 164     return self.scatter(*args, **kwargs)

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/schemas.py:136](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/schemas.py#line=135), in Schema.apply.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    135 def wrapper(*args, **kwargs):
--> 136     return function(*args, **self._update_kwargs(kwargs, keys))

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/subplots.py:166](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/subplots.py#line=165), in Subplot.plot_2D.<locals>.decorator.<locals>.wrapper(self, data, x, y, z, style, **kwargs)
    157 def wrapper(
    158     self,
    159     data=None,
   (...)    164     **kwargs,
    165 ):
--> 166     return self._extract_plottables(
    167         method_name or method.__name__,
    168         args=tuple(),
    169         data=data,
    170         x=x,
    171         y=y,
    172         z=z,
    173         style=style,
    174         **kwargs,
    175     )

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/subplots.py:321](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/subplots.py#line=320), in Subplot._extract_plottables(self, method_name, args, data, x, y, z, style, units, every, source_units, extract_domain, **kwargs)
    319 else:
    320     source = get_source(*args, data=data, x=x, y=y, z=z)
--> 321 kwargs = {**self._plot_kwargs(source), **kwargs}
    322 if method_name == "contourf":
    323     source.regrid = True

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/maps.py:121](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/components/maps.py#line=120), in Map._plot_kwargs(self, source)
    119 if self._crs is None:
    120     self._crs = source.crs or ccrs.PlateCarree()
--> 121 return {"transform": source.crs or ccrs.PlateCarree()}

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/sources/xarray.py:171](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/plots/sources/xarray.py#line=170), in XarraySource.crs(self)
    169 except ValueError:
    170     try:
--> 171         self._crs = earthkit_data[0].projection().to_cartopy_crs()
    172     except (AttributeError, NotImplementedError):
    173         self._crs = None

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/core/fieldlist.py:441](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/core/fieldlist.py#line=440), in Field.projection(self)
    412 def projection(self):
    413     r"""Return information about the projection.
    414 
    415     Returns
   (...)    439     '+proj=eqc +ellps=WGS84 +a=6378137.0 +lon_0=0.0 +to_meter=111319.4907932736 +no_defs +type=crs'
    440     """
--> 441     return self._metadata.geography.projection()

File [/usr/local/apps/python3/3.11.10-01/lib/python3.11/functools.py:1001](https://jupyterhub.ecmwf.int/usr/local/apps/python3/3.11.10-01/lib/python3.11/functools.py#line=1000), in cached_property.__get__(self, instance, owner)
    999 val = cache.get(self.attrname, _NOT_FOUND)
   1000 if val is _NOT_FOUND:
-> 1001     val = self.func(instance)
   1002     try:
   1003         cache[self.attrname] = val

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py:158](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py#line=157), in XArrayMetadata.geography(self)
    156 @cached_property
    157 def geography(self):
--> 158     return XArrayFieldGeography(self, self._field._ds, self._field.variable)

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py:35](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/field.py#line=34), in XArrayFieldGeography.__init__(self, metadata, ds, variable)
     33 self.variable = variable
     34 self.ds = ds
---> 35 self.north, self.west, self.south, self.east = self.ds.bbox(variable)

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py:44](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py#line=43), in DataSet.bbox(self, variable)
     41 def bbox(self, variable):
     42     data_array = self[variable]
---> 44     keys, dims = self._get_xy_dims(data_array)
     45     key = ("bbox", tuple(keys), tuple(dims))
     46     if key in self._cache:

File [/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py:117](https://jupyterhub.ecmwf.int/etc/ecmwf/nfs/dh1_perm_a/maes/venvs/earthkit/lib/python3.11/site-packages/earthkit/data/readers/netcdf/dataset.py#line=116), in DataSet._get_xy_dims(self, data_array)
    115 for ax in axes:
    116     if ax not in keys:
--> 117         raise ValueError(f"No dimension found with axis '{ax}'")
    119 return keys, dims

ValueError: No dimension found with axis 'x'
Click to add a cell.

Accompanying data

No response

Organisation

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions