Is there a way to convert a DynamicMap to HoloMap?

import holoviews as hv
import hvplot.xarray
hv.save(ds_list[0].hvplot("lon", "lat", dynamic=False), "test.gif")

If I leave out dynamic=False, it generates test.gif.html.

So I was wondering if there’s a way I can cast the DynamicMap to HoloMap after the fact?

This is described in Live Data — HoloViews v1.15.3, unless I misunderstand your question. I can’t make an example to show you from your code snippet, because ds_list is undefined.

3 Likes

Thanks for the pointer and I apologize for the unfinished example.

import xarray as xr
import holoviews as hv
import hvplot.xarray
ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 3))
hv.save(hv.HoloMap(ds.hvplot("lon", "lat")), "test.gif")

I tried this and it results in:


/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/holoviews/core/options.py in lookup_options(cls, backend, obj, group, defaults)
   1275     def lookup_options(cls, backend, obj, group, defaults=True):
   1276         # Current custom_options dict may not have entry for obj.id
-> 1277         if obj.id in cls._custom_options[backend]:
   1278             return cls._custom_options[backend][obj.id].closest(
   1279                 obj, group, defaults, backend=backend)

AttributeError: 'NoneType' object has no attribute 'id'

I think the issue is not exactly with the conversion to HoloMap, but rather that you are trying to save an object that contains no data.

import xarray as xr
import holoviews as hv
import hvplot.xarray

ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 3))
dmap = ds.hvplot("lon", "lat")
print(dmap.info)
# DynamicMap containing no items
# ------------------------------
# 
# Key Dimensions: 
# 	 Time: nan...nan 

print(dmap.data)
# OrderedDict()

hmap = hv.HoloMap(dmap)
# the HoloMap has the same .info and .data

Of course, the entire point of DynamicMaps is that they are lazy and don’t load the data until it’s needed. If you render dmap before converting it then it will contain the data corresponding to the coordinates at which it was rendered, and then saving it works for me. Alternatively, in the conversion step you can specify which elements to sample by providing either a list of coordinates or a Cartesian product, as explained in the user guide I linked above.

Perhaps someone who is more expert than me can suggest a method to convert a DynamicMap to a HoloMap containing all the elements that would have been sampled if you scrubbed through all the slider values in the DynamicMap, but I hope this helps explain what is going on in your examples at least.

1 Like

Thanks again for pointing me in the right direction.

Reading the docs more carefully, I found that I can subset it by doing:

import xarray as xr
import holoviews as hv
import hvplot.xarray

ds = xr.tutorial.open_dataset("air_temperature").isel(time=slice(0, 3))
dmap = ds.hvplot("lon", "lat")
hv.HoloMap(dmap[[t for t in ds["time"].values]])

based off of

hv.HoloMap(dmap[{(2,0.3), (2,0.6), (3,0.3), (3,0.6)}])
2 Likes