Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about setting vdims on NdMapping types #811

Closed
rpep opened this issue Aug 10, 2016 · 12 comments
Closed

Warn about setting vdims on NdMapping types #811

rpep opened this issue Aug 10, 2016 · 12 comments
Milestone

Comments

@rpep
Copy link

rpep commented Aug 10, 2016

I'm having trouble with visualising some data files, and I was just wondering if anyone can help.

I've got a large number of data files, and the data is on a regular grid that can be displayed using hv.Image. For simplicity, we can say that the for each data is represented by some function f(x, y, p). In advance we know that the bounds of f(x, y, p) for all values of p are [-1, 1], but for any given data file the bounds might be some narrower region of that range, because p changes the function. However, I still want to set the colourbar range between the bounds [-1, 1] even if, for some given set of data, the bounds are only something like [-0.5, 0.5].

I'm not sure where to look in Holoviews to try and do this - it seems to me that this is linked in with the data side rather than the visualisation side, because it's intrinsically linked to the function f mathematically. However, I can't see an option in the help to specify the data bounds. Ideally, I'd have thought there'd be some kind of parameter, similar to extent, which allows an overwrite the data range - something like how bounds works:

hv.image(data, bounds=[-100, -100, 100, 100], data_extent=[-1, 1])

@jlstevens
Copy link
Contributor

It sounds like you are looking for what we call 'value dimensions'. Something like:

hv.Image(data, kdims=['X','Y'], vdims=[hv.Dimension('Data', range=(-1,1))])

I believe that specifying the range on the value dimension will function the way you are looking for using what you've called data_extents.

@rpep
Copy link
Author

rpep commented Aug 10, 2016

Hi @jlstevens. Thanks for the suggestion. It doesn't seem to do what I want, unfortunately - you can see this in this example:

%%opts Image style(interpolation='nearest')[colorbar=True]
import numpy as np
import holoviews as hv
hv.notebook_extension()
x,y = np.mgrid[-50:51, -50:51] * 0.1
def sine_image(freq):
    return hv.Image(np.sin(freq*x**2+freq*y**2)**2)

dmap = hv.DynamicMap(sine_image, kdims=[hv.Dimension('frequency', range=(0, np.pi))],
                                            vdims=[hv.Dimension('data', range=(0, 1))])

dmap

If you adjust the value of the frequency parameter, you can see that the colourbar changes:
Frequency = 0:
image
Frequency = 0.02:
image

@rpep
Copy link
Author

rpep commented Aug 10, 2016

I think it therefore may be the case that the description of the data isn't taken into account in the colourbar plotting?

@jbednar
Copy link
Member

jbednar commented Aug 17, 2016

Does it change only for freq=0? If so it could just be that the colorbar has a default for plots with no color range (as freq=0 means that it's a constant plot, with no changes over x and y).

@philippjfr
Copy link
Member

philippjfr commented Aug 17, 2016

The DynamicMap itself does not have any vdims, so declaring it like you did here has no effect:

dmap = hv.DynamicMap(sine_image, kdims=[hv.Dimension('frequency', range=(0, np.pi))],
                                            vdims=[hv.Dimension('data', range=(0, 1))])

What you presumably want is this:

def sine_image(freq):
    return hv.Image(np.sin(freq*x**2+freq*y**2)**2,
                    vdims=[hv.Dimension('data', range=(0, 1))])

@jlstevens
Copy link
Contributor

The DynamicMap itself does not have any vdims...

You are right, I wasn't thinking. As Philipp indicates, the vdim range needs to be on the element returned by the DynamicMap callback. Now it should work!

@jlstevens
Copy link
Contributor

Actually, this looks like another place we could issue a warning to prevent confusion. I don't think a DynamicMap ever has meaningful vdims so I believe we could issue a warning.

@jlstevens
Copy link
Contributor

jlstevens commented Aug 17, 2016

I just noticed that in my original comment, I did suggest setting the vdims on hv.Image. :-)

I think my point about issuing a warning if vdims are set on DynamicMap still holds though (I can see why it might be confusing).

@philippjfr philippjfr changed the title Bounding of data in Image and having correct bounds on colorbar Warn about setting vdims on NdMapping types Oct 21, 2016
@philippjfr
Copy link
Member

I've repurposed this issue to remind us to raise the appropriate warning.

@jlstevens jlstevens added this to the v1.7.0 milestone Oct 21, 2016
@jlstevens
Copy link
Contributor

Agreed. Issuing a warning shouldn't be much work so I've assigned this to the 1.7 milestone.

@philippjfr
Copy link
Member

NdMapping types will now raise an exception when setting vdims, closing.

@rpep
Copy link
Author

rpep commented Oct 25, 2016

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants