hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

ValueError when trying to display a netCDF file with the explorer

Open maximlt opened this issue 2 years ago • 0 comments

The file is the first made available on this website https://www.unidata.ucar.edu/software/netcdf/examples/files.html. I attached it to the issue: sresa1b_ncar_ccsm3-example.nc.zip

import hvplot.xarray
import xarray as xr

ds = xr.open_dataset("sresa1b_ncar_ccsm3-example.nc")
ds.hvplot.explorer()
ValueError: cannot select an axis to squeeze out which has size not equal to one
Full traceback

WARNING:param.Image02227: Image dimension lat is  not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.
WARNING:param.Image02227: Image dimension lat is  not evenly sampled to relative tolerance of 0.001. Please use the QuadMesh element for irregularly sampled data or set a higher tolerance on hv.config.image_rtol or the rtol parameter in the Image constructor.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/IPython/core/formatters.py:974, in MimeBundleFormatter.__call__(self, obj, include, exclude)
    971     method = get_real_method(obj, self.print_method)
    973     if method is not None:
--> 974         return method(include=include, exclude=exclude)
    975     return None
    976 else:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/viewable.py:1096, in Viewer._repr_mimebundle_(self, include, exclude)
   1095 def _repr_mimebundle_(self, include=None, exclude=None):
-> 1096     return self._create_view()._repr_mimebundle_(include, exclude)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/viewable.py:820, in Viewable._repr_mimebundle_(self, include, exclude)
    818 doc = Document()
    819 comm = state._comm_manager.get_server_comm()
--> 820 model = self._render_model(doc, comm)
    821 if config.embed:
    822     return render_model(model)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/viewable.py:738, in Viewable._render_model(self, doc, comm)
    736 if comm is None:
    737     comm = state._comm_manager.get_server_comm()
--> 738 model = self.get_root(doc, comm)
    740 if self._design and self._design.theme.bokeh_theme:
    741     doc.theme = self._design.theme.bokeh_theme

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:306, in Panel.get_root(self, doc, comm, preprocess)
    302 def get_root(
    303     self, doc: Optional[Document] = None, comm: Optional[Comm] = None,
    304     preprocess: bool = True
    305 ) -> Model:
--> 306     root = super().get_root(doc, comm, preprocess)
    307     # ALERT: Find a better way to handle this
    308     if hasattr(root, 'styles') and 'overflow-x' in root.styles:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/viewable.py:660, in Renderable.get_root(self, doc, comm, preprocess)
    658 wrapper = self._design._wrapper(self)
    659 if wrapper is self:
--> 660     root = self._get_model(doc, comm=comm)
    661     if preprocess:
    662         self._preprocess(root)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:174, in Panel._get_model(self, doc, root, parent, comm)
    172 root = root or model
    173 self._models[root.ref['id']] = (model, parent)
--> 174 objects, _ = self._get_objects(model, [], doc, root, comm)
    175 props = self._get_properties(doc)
    176 props[self._property_mapping['objects']] = objects

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:156, in Panel._get_objects(self, model, old_objects, doc, root, comm)
    154 else:
    155     try:
--> 156         child = pane._get_model(doc, root, model, comm)
    157     except RerenderError as e:
    158         if e.layout is not None and e.layout is not self:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:174, in Panel._get_model(self, doc, root, parent, comm)
    172 root = root or model
    173 self._models[root.ref['id']] = (model, parent)
--> 174 objects, _ = self._get_objects(model, [], doc, root, comm)
    175 props = self._get_properties(doc)
    176 props[self._property_mapping['objects']] = objects

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:156, in Panel._get_objects(self, model, old_objects, doc, root, comm)
    154 else:
    155     try:
--> 156         child = pane._get_model(doc, root, model, comm)
    157     except RerenderError as e:
    158         if e.layout is not None and e.layout is not self:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:174, in Panel._get_model(self, doc, root, parent, comm)
    172 root = root or model
    173 self._models[root.ref['id']] = (model, parent)
--> 174 objects, _ = self._get_objects(model, [], doc, root, comm)
    175 props = self._get_properties(doc)
    176 props[self._property_mapping['objects']] = objects

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/tabs.py:211, in Tabs._get_objects(self, model, old_objects, doc, root, comm)
    209 else:
    210     try:
--> 211         rendered[pref] = child = pane._get_model(doc, root, model, comm)
    212     except RerenderError as e:
    213         if e.layout is not None and e.layout is not self:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:174, in Panel._get_model(self, doc, root, parent, comm)
    172 root = root or model
    173 self._models[root.ref['id']] = (model, parent)
--> 174 objects, _ = self._get_objects(model, [], doc, root, comm)
    175 props = self._get_properties(doc)
    176 props[self._property_mapping['objects']] = objects

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:156, in Panel._get_objects(self, model, old_objects, doc, root, comm)
    154 else:
    155     try:
--> 156         child = pane._get_model(doc, root, model, comm)
    157     except RerenderError as e:
    158         if e.layout is not None and e.layout is not self:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:174, in Panel._get_model(self, doc, root, parent, comm)
    172 root = root or model
    173 self._models[root.ref['id']] = (model, parent)
--> 174 objects, _ = self._get_objects(model, [], doc, root, comm)
    175 props = self._get_properties(doc)
    176 props[self._property_mapping['objects']] = objects

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/layout/base.py:156, in Panel._get_objects(self, model, old_objects, doc, root, comm)
    154 else:
    155     try:
--> 156         child = pane._get_model(doc, root, model, comm)
    157     except RerenderError as e:
    158         if e.layout is not None and e.layout is not self:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/pane/holoviews.py:413, in HoloViews._get_model(self, doc, root, parent, comm)
    411     plot = self.object
    412 else:
--> 413     plot = self._render(doc, comm, root)
    415 plot.pane = self
    416 backend = plot.renderer.backend

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/panel/pane/holoviews.py:508, in HoloViews._render(self, doc, comm, root)
    505     if comm:
    506         kwargs['comm'] = comm
--> 508 return renderer.get_plot(self.object, **kwargs)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/plotting/bokeh/renderer.py:68, in BokehRenderer.get_plot(self_or_cls, obj, doc, renderer, **kwargs)
     61 @bothmethod
     62 def get_plot(self_or_cls, obj, doc=None, renderer=None, **kwargs):
     63     """
     64     Given a HoloViews Viewable return a corresponding plot instance.
     65     Allows supplying a document attach the plot to, useful when
     66     combining the bokeh model with another plot.
     67     """
---> 68     plot = super().get_plot(obj, doc, renderer, **kwargs)
     69     if plot.document is None:
     70         plot.document = Document() if self_or_cls.notebook_context else curdoc()

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/plotting/renderer.py:240, in Renderer.get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
    237     defaults = [kd.default for kd in plot.dimensions]
    238     init_key = tuple(v if d is None else d for v, d in
    239                      zip(plot.keys[0], defaults))
--> 240     plot.update(init_key)
    241 else:
    242     plot = obj

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/plotting/plot.py:955, in DimensionedPlot.update(self, key)
    953 def update(self, key):
    954     if len(self) == 1 and key in (0, self.keys[0]) and not self.drawn:
--> 955         return self.initialize_plot()
    956     item = self.__getitem__(key)
    957     self.traverse(lambda x: setattr(x, '_updated', True))

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/plotting/bokeh/element.py:1887, in ElementPlot.initialize_plot(self, ranges, plot, plots, source)
   1885 if self.autorange:
   1886     self._setup_autorange()
-> 1887 self._init_glyphs(plot, element, ranges, source)
   1888 if not self.overlaid:
   1889     self._update_plot(key, plot, style_element)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/plotting/bokeh/element.py:1806, in ElementPlot._init_glyphs(self, plot, element, ranges, source)
   1804 else:
   1805     style = self.style[self.cyclic_index]
-> 1806     data, mapping, style = self.get_data(element, ranges, style)
   1807     current_id = element._plot_id
   1809 with abbreviated_exception():

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/plotting/bokeh/raster.py:109, in RasterPlot.get_data(self, element, ranges, style)
    107 if i > 2 and 'hover' not in self.handles:
    108     break
--> 109 img = element.dimension_values(i, flat=False)
    110 if img.dtype.kind == 'b':
    111     img = img.astype(np.int8)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/core/data/__init__.py:196, in PipelineMeta.pipelined.<locals>.pipelined_fn(*args, **kwargs)
    193     inst._in_method = True
    195 try:
--> 196     result = method_fn(*args, **kwargs)
    197     if PipelineMeta.disable:
    198         return result

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/core/data/__init__.py:1099, in Dataset.dimension_values(self, dimension, expanded, flat)
   1083 """Return the values along the requested dimension.
   1084 
   1085 Args:
   (...)
   1096     NumPy array of values along the requested dimension
   1097 """
   1098 dim = self.get_dimension(dimension, strict=True)
-> 1099 values = self.interface.values(self, dim, expanded, flat)
   1100 if dim.nodata is not None:
   1101     # Ensure nodata applies to boolean data in py2
   1102     values = np.where(values==dim.nodata, np.nan, values)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/core/data/xarray.py:423, in XArrayInterface.values(cls, dataset, dim, expanded, flat, compute, keep_index)
    421         data = cupy.asnumpy(data)
    422     if not keep_index:
--> 423         data = cls.canonicalize(dataset, data, data_coords=data_coords,
    424                                 virtual_coords=virtual_coords)
    425     return data.T.flatten() if flat and not keep_index else data
    426 elif expanded:

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/holoviews/core/data/grid.py:329, in GridInterface.canonicalize(cls, dataset, data, data_coords, virtual_coords)
    327         data = data.flatten()
    328     else:
--> 329         data = np.squeeze(data, axis=tuple(dropped))
    331 if not any(cls.irregular(dataset, d) for d in dataset.kdims):
    332     inds = [dims.index(kd.name) for kd in dataset.kdims]

File <__array_function__ internals>:200, in squeeze(*args, **kwargs)

File ~/miniconda3/envs/hvplot310/lib/python3.10/site-packages/numpy/core/fromnumeric.py:1571, in squeeze(a, axis)
   1569     return squeeze()
   1570 else:
-> 1571     return squeeze(axis=axis)

ValueError: cannot select an axis to squeeze out which has size not equal to one

Issue observed when trying https://github.com/holoviz/hvplot/pull/1256

maximlt avatar Feb 02 '24 09:02 maximlt