Ouranosinc / pavics-sdi

Power Analytics and Visualization for Climate Science - Spatial Data Infrastructure
https://pavics-sdi.readthedocs.io
6 stars 2 forks source link

subset-user-input.ipynb: ImportError: cannot import name 'LinkCallback' from 'holoviews.plotting.bokeh.callbacks' #291

Closed tlvu closed 1 year ago

tlvu commented 1 year ago

Found with upcoming Jupyter env.

15:43:32  _ pavics-sdi-fix_climex/docs/source/notebooks/subset-user-input.ipynb::Cell 24 _
15:43:32  Notebook cell execution failed
15:43:32  Cell 24: Cell execution caused an exception
15:43:32  
15:43:32  Input:
15:43:32  # NBVAL_IGNORE_OUTPUT
15:43:32  import hvplot.xarray
15:43:32  
15:43:32  dsremote = xr.open_dataset(output_thredds_url)
15:43:32  dsremote.hvplot.quadmesh(
15:43:32      "lon",
15:43:32      "lat",
15:43:32      "heat_wave_frequency",
15:43:32      geo=True,
15:43:32      alpha=0.8,
15:43:32      frame_height=540,
15:43:32      cmap="viridis",
15:43:32      tiles="CartoLight",
15:43:32  )
15:43:32  
15:43:32  Traceback:
15:43:32  
15:43:32  ---------------------------------------------------------------------------
15:43:32  ImportError                               Traceback (most recent call last)
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/util.py:233, in process_crs(crs)
15:43:32      232 import cartopy.crs as ccrs
15:43:32  --> 233 import geoviews as gv # noqa
15:43:32      234 import pyproj
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/geoviews/__init__.py:13
15:43:32       11     pass
15:43:32  ---> 13 from .annotators import annotate # noqa (API import)
15:43:32       14 from .element import ( # noqa (API import)
15:43:32       15     _Element, Feature, Tiles, WMTS, LineContours, FilledContours,
15:43:32       16     Text, Image, Points, Path, Polygons, Shape, Dataset, RGB,
15:43:32       17     Contours, Graph, TriMesh, Nodes, EdgePaths, QuadMesh, VectorField,
15:43:32       18     HexTiles, Labels, Rectangles, Segments
15:43:32       19 )
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/geoviews/annotators.py:14
15:43:32       13 from .models.custom_tools import CheckpointTool, RestoreTool, ClearTool
15:43:32  ---> 14 from .links import VertexTableLink, PointTableLink, HvRectanglesTableLink, RectanglesTableLink
15:43:32       15 from .operation import project
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/geoviews/links.py:4
15:43:32        3 from holoviews.plotting.links import Link, RectanglesTableLink as HvRectanglesTableLink
15:43:32  ----> 4 from holoviews.plotting.bokeh.callbacks import (
15:43:32        5     LinkCallback, RectanglesTableLinkCallback as HvRectanglesTableLinkCallback
15:43:32        6 )
15:43:32        7 from holoviews.core.util import dimension_sanitizer
15:43:32  
15:43:32  ImportError: cannot import name 'LinkCallback' from 'holoviews.plotting.bokeh.callbacks' (/opt/conda/envs/birdy/lib/python3.10/site-packages/holoviews/plotting/bokeh/callbacks.py)
15:43:32  
15:43:32  During handling of the above exception, another exception occurred:
15:43:32  
15:43:32  ImportError                               Traceback (most recent call last)
15:43:32  Cell In[25], line 5
15:43:32        2 import hvplot.xarray
15:43:32        4 dsremote = xr.open_dataset(output_thredds_url)
15:43:32  ----> 5 dsremote.hvplot.quadmesh(
15:43:32        6     "lon",
15:43:32        7     "lat",
15:43:32        8     "heat_wave_frequency",
15:43:32        9     geo=True,
15:43:32       10     alpha=0.8,
15:43:32       11     frame_height=540,
15:43:32       12     cmap="viridis",
15:43:32       13     tiles="CartoLight",
15:43:32       14 )
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/plotting/core.py:2067, in hvPlot.quadmesh(self, x, y, z, colorbar, **kwds)
15:43:32     2018 def quadmesh(self, x=None, y=None, z=None, colorbar=True, **kwds):
15:43:32     2019     """
15:43:32     2020     QuadMesh plot
15:43:32     2021 
15:43:32     (...)
15:43:32     2065     - HoloViews: [https://holoviews.org/reference/elements/bokeh/QuadMesh.html](https://holoviews.org/reference/elements/bokeh/QuadMesh.html%1B[39;00m)
15:43:32     2066     """
15:43:32  -> 2067     return self(x, y, z=z, kind="quadmesh", colorbar=colorbar, **kwds)
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/plotting/core.py:92, in hvPlotBase.__call__(self, x, y, kind, **kwds)
15:43:32       89         plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
15:43:32       90         return pn.panel(plot, **panel_dict)
15:43:32  ---> 92 return self._get_converter(x, y, kind, **kwds)(kind, x, y)
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/plotting/core.py:99, in hvPlotBase._get_converter(self, x, y, kind, **kwds)
15:43:32       97 y = y or params.pop("y", None)
15:43:32       98 kind = kind or params.pop("kind", None)
15:43:32  ---> 99 return HoloViewsConverter(self._data, x, y, kind=kind, **params)
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/converter.py:397, in HoloViewsConverter.__init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, symmetric, logx, logy, loglog, hover, subplots, label, invert, stacked, colorbar, datashade, rasterize, row, col, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, hover_cols, x_sampling, y_sampling, project, tools, attr_labels, coastline, tiles, sort_date, check_symmetric_max, transforms, stream, cnorm, features, rescale_discrete_levels, **kwds)
15:43:32      395 self.dynamic = dynamic
15:43:32      396 self.geo = any([geo, crs, global_extent, projection, project, coastline, features])
15:43:32  --> 397 self.crs = self._process_crs(data, crs) if self.geo else None
15:43:32      398 self.project = project
15:43:32      399 self.coastline = coastline
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/converter.py:651, in HoloViewsConverter._process_crs(self, data, crs)
15:43:32      648     _crs = getattr(data, 'attrs', {}).get(crs or 'crs', crs)
15:43:32      650 try:
15:43:32  --> 651     return process_crs(_crs)
15:43:32      652 except ValueError:
15:43:32      653     # only raise error if crs was specified in kwargs
15:43:32      654     if crs:
15:43:32  
15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/hvplot/util.py:236, in process_crs(crs)
15:43:32      234     import pyproj
15:43:32      235 except ImportError:
15:43:32  --> 236     raise ImportError('Geographic projection support requires geoviews, pyproj and cartopy.')
15:43:32      238 if crs is None:
15:43:32      239     return ccrs.PlateCarree()
15:43:32  
15:43:32  ImportError: Geographic projection support requires geoviews, pyproj and cartopy.
aulemahal commented 1 year ago

You need to update geoviews I believe.

tlvu commented 1 year ago

You need to update geoviews I believe.

It's a fresh build so I should have the latest geoviews ...

aulemahal commented 1 year ago

Ok weird, because the part here:

15:43:32  File /opt/conda/envs/birdy/lib/python3.10/site-packages/geoviews/links.py:4
15:43:32        3 from holoviews.plotting.links import Link, RectanglesTableLink as HvRectanglesTableLink
15:43:32  ----> 4 from holoviews.plotting.bokeh.callbacks import (
15:43:32        5     LinkCallback, RectanglesTableLinkCallback as HvRectanglesTableLinkCallback
15:43:32        6 )
15:43:32        7 from holoviews.core.util import dimension_sanitizer

is code from geoviews 1.9.1 or earlier. This was modified in 1.9.2 and latter in 1.10.0 .

tlvu commented 1 year ago

Oh geez you are right, mamba gave me geoviews 1.8.2 (1 year old version) !!!

This makes no sense !!!

tlvu commented 1 year ago

Fixed by forcing geoviews to latest 1.9.6.