hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

WARNING: Calling the .opts method with options broken down by options group ... is deprecated

Open MarcSkovMadsen opened this issue 1 year ago • 2 comments

hvplot=0.8.0, holoviews=1.15.0

I'm trying to help a user here https://discourse.holoviz.org/t/interactive-and-dynamically-created-dict-of-widgets-to-xarray-sel/4000/5

When running the below code example I see the WARNING

WARNING:param.main: Calling the .opts method with options broken down by options group (i.e. separate plot, style and norm groups) is deprecated. Use the .options method converting to the simplified format instead or use hv.opts.apply_groups for backward compatibility.
2022-08-07 15:06:51,458 Calling the .opts method with options broken down by options group (i.e. separate plot, style and norm groups) is deprecated. Use the .options method converting to the simplified format instead or use hv.opts.apply_groups for backward compatibility.
import collections
from pathlib import Path

import cartopy.crs as ccrs
import gdown
import hvplot
import hvplot.xarray
import numpy as np
import panel as pn
import panel.widgets as pnw
import xarray as xr
import pathlib

collections.Callable = collections.abc.Callable

CONFIG = {
    "2022070700_231_example.nc": "1vI5xH-kmA4OkoqJJz9keze-vN3cYCIf4",
    "2022070700_237_example.nc": "1RnWmfiW3U7VYS4Qoqo7_uFdeAIXAajye",
}

for file, file_id in CONFIG.items():
    if not pathlib.Path(file).exists():
        gdown.download(id=file_id, output=file, quiet=False)

file_list = [pathlib.Path(file) for file in CONFIG]

def open_dataset(file):
    key = f"file {file}"
    if not key in pn.state.cache:
        pn.state.cache[key]=xr.open_dataset(file)
    return pn.state.cache[key]

def get_sub_dataset(file, field):
    xds = open_dataset(file)
    return xds[field]

def get_options(file, field):
    options = {}
    xds_sub = get_sub_dataset(file, field)
    for (_, d) in enumerate(xds_sub.dims):
        for (_, c) in enumerate(xds_sub.coords):
            if d == c and (d != "lon" and d != "lat"):
                if xds_sub.coords[c].dtype == np.dtype("<M8[ns]"):
                    time_list = []
                    for _, el in np.ndenumerate(
                        xds_sub.coords["time"].values
                    ):
                        time_list.append(np.datetime_as_string(el, timezone="UTC"))
                    options[d] = time_list
                else:
                    options[d] = xds_sub.coords[c].values.tolist()
    return options

def get_widgets(file, field):
    options=get_options(file, field)
    print("options", file,field,options)
    return {key: pnw.DiscreteSlider(options=value) for key, value in options.items()}

xds = open_dataset(file_list[0])
select_file = pnw.Select(name="File", options=file_list)
select_field = pnw.Select(name="Field", value="HU", options=list(xds.data_vars))

# I just want to see the options
def warm():
    for file in file_list:
        xds = open_dataset(file)
        for field in xds.data_vars:
            options = get_options(file, field)
            print(file, field, options)
warm()

@pn.depends(select_file, select_field)
def load_file(file, field):
    xds_sub = get_sub_dataset(file,field)
    widgets = get_widgets(file, field)
    
    return (
        xds_sub
        .interactive.sel(**widgets)
        .hvplot(
            kind="quadmesh",
            rasterize=True,
            data_aspect=1,
            frame_height=800,
            cmap="jet",
            crs=ccrs.PlateCarree(),
            projection=ccrs.PlateCarree(),
            project=True,
            geo=True,
            coastline=True,
            global_extent=True,
        )
    )


pn.Row(pn.Card(select_file, select_field), load_file).servable()
WARNING:param.main: Calling the .opts method with options broken down by options group (i.e. separate plot, style and norm groups) is deprecated. Use the .options method converting to the simplified format instead or use hv.opts.apply_groups for backward compatibility.
2022-08-07 15:06:51,458 Calling the .opts method with options broken down by options group (i.e. separate plot, style and norm groups) is deprecated. Use the .options method converting to the simplified format instead or use hv.opts.apply_groups for backward compatibility.

So I believe something in hvPlot needs an update. But I don't know where.

Please note the log seems to output every message twice with a different format. That is a bit of friction that would be nice to remove.

MarcSkovMadsen avatar Aug 07 '22 15:08 MarcSkovMadsen

This is properly https://github.com/holoviz/geoviews/issues/576 which is causing the issue.

Can you try to remove all the geo features from the plot to verify it?

hoxbro avatar Aug 07 '22 15:08 hoxbro

I removed the geo stuff (see code below) and I no longer see the warning.

I'm running geoviews=1.9.5

import collections

import gdown
import hvplot
import hvplot.xarray
import numpy as np
import panel as pn
import panel.widgets as pnw
import xarray as xr
import pathlib

collections.Callable = collections.abc.Callable

CONFIG = {
    "2022070700_231_example.nc": "1vI5xH-kmA4OkoqJJz9keze-vN3cYCIf4",
    "2022070700_237_example.nc": "1RnWmfiW3U7VYS4Qoqo7_uFdeAIXAajye",
}

for file, file_id in CONFIG.items():
    if not pathlib.Path(file).exists():
        gdown.download(id=file_id, output=file, quiet=False)

file_list = [pathlib.Path(file) for file in CONFIG]

def open_dataset(file):
    key = f"file {file}"
    if not key in pn.state.cache:
        pn.state.cache[key]=xr.open_dataset(file)
    return pn.state.cache[key]

def get_sub_dataset(file, field):
    xds = open_dataset(file)
    return xds[field]

def get_options(file, field):
    options = {}
    xds_sub = get_sub_dataset(file, field)
    for (_, d) in enumerate(xds_sub.dims):
        for (_, c) in enumerate(xds_sub.coords):
            if d == c and (d != "lon" and d != "lat"):
                if xds_sub.coords[c].dtype == np.dtype("<M8[ns]"):
                    time_list = []
                    for _, el in np.ndenumerate(
                        xds_sub.coords["time"].values
                    ):
                        time_list.append(np.datetime_as_string(el, timezone="UTC"))
                    options[d] = time_list
                else:
                    options[d] = xds_sub.coords[c].values.tolist()
    return options

def get_widgets(file, field):
    options=get_options(file, field)
    print("options", file,field,options)
    return {key: pnw.DiscreteSlider(options=value) for key, value in options.items()}

xds = open_dataset(file_list[0])
select_file = pnw.Select(name="File", options=file_list)
select_field = pnw.Select(name="Field", value="HU", options=list(xds.data_vars))

# I just want to see the options
def warm():
    for file in file_list:
        xds = open_dataset(file)
        for field in xds.data_vars:
            options = get_options(file, field)
            print(file, field, options)
warm()

@pn.depends(select_file, select_field)
def load_file(file, field):
    xds_sub = get_sub_dataset(file,field)
    widgets = get_widgets(file, field)
    
    return (
        xds_sub
        .interactive.sel(**widgets)
        .hvplot(
            kind="quadmesh",
            rasterize=True,
            data_aspect=1,
            frame_height=800,
            cmap="jet",
        )
    )


pn.Row(pn.Card(select_file, select_field), load_file).servable()

MarcSkovMadsen avatar Aug 07 '22 16:08 MarcSkovMadsen