question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Errors when nesting Overlays and DynamicMaps

See original GitHub issue

The stacktraces below were from master (as of last night), but I first ran into all these problems on the latest stable.

Following up on some questions I asked on gitter. I start with a analysis function that dynamically generates holoviews objects, possibly Overlays/Layouts, that include large Images and/or Curves. My goal is to regrid all Images (and datashade all Curves). For the following minimal test case, I precompute these holoviews plots and store them in dicts (dat1 and dat2); in my production code, these may be cached in a dict or dynamically generated (so z needs to be a kdim of a DynamicMap, not a HoloMap).

Set up the plots:

import numpy as np
import holoviews as hv
from holoviews.operation.datashader import datashade, regrid
hv.notebook_extension('bokeh')
dat1 = {}
dat2 = {}
for z in range(10):
    dat1[z] = hv.Image(np.random.random((1000,1000)), bounds=(0,0,10,10)) * hv.HLine(z)
    dat2[z] = hv.Curve((np.random.random(1000) - 0.5).cumsum()) * hv.VLine(z*100)

With no datashader, this works as expected:

def cb(z):
    return dat1[z]
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
dmap

It shows a slider for z, and I can easily browse around.

It would be great to be able to write dmap.map(regrid, hv.Image) and have that work. Maybe one day? 😃 I assumed I needed to call .map() before I combine all the z-slices into a DynamicMap, like this:

def cb(z):
    return dat1[z].map(regrid, hv.Image)
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
dmap

This fails. Stacktrace: https://gist.github.com/shenker/16b66fda15093544e9d86d69a60a12af

Heeding the warning message about .collate(), I try:

def cb(z):
    return dat1[z].map(regrid, hv.Image).collate()
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))
dmap

This also fails, with the same error. With either of these, if instead of displaying dmap, I display, e.g., dmap[4], I get an individual image and the dynamic regridding works just fine (obviously, no scroll bar for z).

I was wondering if this issue was specific to hv.Image, so I also tried the above substituting dat1 with dat2 and regrid with datashade, but this failed in similar ways.

Returning to the original working example without datashader,

def cb(z):
    return dat1[z]
dmap = hv.DynamicMap(cb, kdims=['z']).redim.values(z=range(10))

If I try simply dmap.collate(), I get this stacktrace when I use dat1 (with Images) and this stacktrace when I use dat2 (with Curves).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
philippjfrcommented, Feb 4, 2018

If you’re working with a small set of elements and declaring them ahead of time I’d recommend just using a HoloMap btw. Here’s how I’d write your example:

dat1, hlines = {}, {}
for z in range(10):
    dat1[z] = hv.Image(np.random.random((1000,1000)), bounds=(0,0,10,10))
    hlines[z] = hv.HLine(z)
    
regrid(hv.HoloMap(dat1, 'z')) * hv.HoloMap(hlines, 'z')
0reactions
jbednarcommented, Feb 5, 2018

The main issue here is that the regrid operation is dynamic by default which allows it to respond to zoom events on the axes, but you cannot nest DynamicMaps.

Would it be possible to detect nested DynamicMaps and raise an error with your suggestions above? It sounds like the current behavior is very confusing, i.e. that it gives a blank plot rather than some more direct indication that something that seems reasonable is not supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors when nesting Overlays and DynamicMaps · Issue #2298
My goal is to regrid all Images (and datashade all Curves). For the following minimal test case, I precompute these holoviews plots and...
Read more >
holoviews - How do I determine what the nesting issue is ...
I am using HoloViews version 1.12.0 . I am attempting to create a layout that contains two DynamicMaps, but I am getting the...
Read more >
Dynamic Map over a datashade - HoloViews
Exception: Nesting a DynamicMap inside a DynamicMap is not supported. Ensure that the DynamicMap callback returns an Element or (Nd)Overlay.
Read more >
Nesting a DynamicMap inside a DynamicMap is not supported
Ensure that the DynamicMap callback returns an Element or (Nd)Overlay. If you have applied an operation ensure it is not dynamic by setting...
Read more >
pyviz/pyviz - Gitter
Hello every one , I really need help to plot my data , The issue i am facing is regarding nested dynamic map...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found