Decoder KeyError 'ncells'
Running the following code from icon-vis with the environment file environment.yml:
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import psyplot.project as psy
from psy_transect import utils
import iconarray
iconarray.get_example_data()
data_dir = "data/example_data/nc"
icon_ds = psy.open_dataset(Path(data_dir, "icon_19790101T000000Z.nc"))
orography = psy.open_dataset(Path(data_dir, "icon_19790101T000000Zc.nc")).psy.HHL
new_ds = utils.mesh_to_cf_bounds(orography, "height", "height_2", icon_ds)
new_ds["clon"] = new_ds.clon.copy(data=np.rad2deg(new_ds.clon))
new_ds["clat"] = new_ds.clat.copy(data=np.rad2deg(new_ds.clat))
new_ds["clon"].attrs["units"] = "degrees_east"
new_ds["clat"].attrs["units"] = "degrees_north"
new_ds["clat_bnds"] = new_ds.clat_bnds.copy(data=np.rad2deg(new_ds.clat_bnds))
new_ds["clon_bnds"] = new_ds.clon_bnds.copy(data=np.rad2deg(new_ds.clon_bnds))
encodings = {v: var.encoding for v, var in new_ds.variables.items()}
attrs = {v: var.attrs for v, var in new_ds.variables.items()}
new_ds = new_ds.where(new_ds.HHL.notnull().any("height_2"), drop=True)
for v, enc in encodings.items():
new_ds[v].encoding.update(enc)
for v, att in attrs.items():
new_ds[v].attrs.update(att)
new_ds.psy.plot.vertical_maptransect(
name="temp",
background="0.5",
transect_resolution=0.1,
cmap="Reds",
decoder={"z": {"HHL"}},
clabel="Temperature (K)",
ylim=(0,6000),
yticks=np.linspace(0,6000,7),
)
produces the following error:
Traceback (most recent call last):
File "/scratch/snx3000/alauber/icon-vis/transect/plot_icon_transects.py", line 40, in <module>
sp = new_ds.psy.plot.vertical_maptransect(
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/project.py", line 2180, in __call__
return super(DatasetPlotterInterface, self).__call__(*args, **kwargs)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/project.py", line 1983, in __call__
return self._project_plotter._add_data(
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/project.py", line 2222, in _add_data
return super(DatasetPlotter, self)._add_data(plotter_cls, self._ds,
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/project.py", line 1772, in _add_data
return self.project._add_data(*args, **kwargs)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/project.py", line 180, in wrapper
return func(self, *args, **kwargs)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/project.py", line 801, in _add_data
plotter_cls(arr, make_plot=(not bool(share) and make_plot),
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psy_transect/plotters.py", line 319, in __init__
super().__init__(*args, **kwargs)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/plotter.py", line 1260, in __init__
self.initialize_plot(data, ax=ax, draw=draw, clear=clear,
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/plotter.py", line 1418, in initialize_plot
self._plot_by_priority(fmto_priority, grouper,
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/plotter.py", line 1623, in _plot_by_priority
self._make_plot()
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/plotter.py", line 2466, in _make_plot
fmto.make_plot()
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psy_simple/plotters.py", line 3317, in make_plot
self._plot_funcs[self.value]()
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psy_simple/plotters.py", line 3324, in _pcolormesh
return self._polycolor()
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psy_simple/plotters.py", line 3407, in _polycolor
ybounds = self.cell_nodes_y
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psy_simple/plotters.py", line 3740, in cell_nodes_y
return super(SimplePlot2D, self).cell_nodes_y
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psy_simple/plotters.py", line 3398, in cell_nodes_y
ybounds = decoder.get_cell_node_coord(
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/data.py", line 757, in get_cell_node_coord
bounds = self._get_coord_cell_node_coord(coord, coords, nans,
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/psyplot/data.py", line 831, in _get_coord_cell_node_coord
bounds = bounds.sel(**{
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/dataarray.py", line 1549, in sel
ds = self._to_temp_dataset().sel(
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/dataset.py", line 2656, in sel
result = self.isel(indexers=query_results.dim_indexers, drop=drop)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/dataset.py", line 2496, in isel
return self._isel_fancy(indexers, drop=drop, missing_dims=missing_dims)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/dataset.py", line 2542, in _isel_fancy
indexes, index_variables = isel_indexes(self.xindexes, valid_indexers)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/indexes.py", line 1478, in isel_indexes
return _apply_indexes(indexes, indexers, "isel")
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/indexes.py", line 1462, in _apply_indexes
new_index = getattr(index, func)(index_args)
File "/project/g110/alauber/envs/psyplot-transect/lib/python3.9/site-packages/xarray/core/indexes.py", line 429, in isel
indxr = indexers[self.dim]
KeyError: 'ncells'