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

unevenly spaced coordinates for volume rendering #11

Open
rabernat opened this issue Mar 4, 2017 · 9 comments
Open

unevenly spaced coordinates for volume rendering #11

rabernat opened this issue Mar 4, 2017 · 9 comments

Comments

@rabernat
Copy link

rabernat commented Mar 4, 2017

I just discovered ipyvolume and think it is fantastic! Thanks for this contribution to the python visualization world.

I work in ocean modeling, and I often want to visualize the output of my simulations using volume rendering. I have been using paraview (example), but it is pretty heavy duty and doesn't integrate well with the rest of my analysis pipeline. I would be thrilled to be able to stay in a notebook environment.

Ipyvolume could really fill a missing need for me if it supported unevenly spaced coordinates (as in a VTK rectilinear grid). I would like to be able to do something like this:

ipyvolume.volshow(data, x=x, y=y, z=z)

where x, y, and z, are one-dimensional coordinate variables. (Even better would be to be able to pass and xarray DataArray, which has the coordinates built in.)

Would this be a difficult feature to add?

@maartenbreddels
Copy link
Collaborator

Hi, thanks for your kind words, nice to hear it's being used (or planned to be)in different sciences.

Would binning the data to a regular grid work? How are the samples distributed? If you have many per gridcell you could take a look at vaex.

import vaex
ds = vaex.from_arrays(x=x, y=y, z=z)
vol = ds.count(binby=['x', 'y', 'z'], shape=128)

And volshow that. Vaex can process about 1 billion samples a second, it the mother project of ipyvolume.
Btw, your links are not working.

@rabernat
Copy link
Author

rabernat commented Mar 5, 2017

Sorry, here is the fixed link to xarray: http://xarray.pydata.org/en/stable

@rabernat
Copy link
Author

rabernat commented Mar 5, 2017

Would binning the data to a regular grid work? How are the samples distributed? If you have many per gridcell you could take a look at vaex.

The samples are distributed regularly, on a grid, but unevenly (i.e closer grid spacing near the surface.) The thing I don't understand from your example is, where do I input the actual data? In my example data is a scalar (e.g. temperature) located at the x, y, and z points.

@maartenbreddels
Copy link
Collaborator

The video link is now also working, so i understand it better now.
Using vaex you'd have to use ds.mean, but what i think you need is: https://docs.scipy.org/doc/scipy-0.18.1/reference/generated/scipy.interpolate.griddata.html#scipy.interpolate.griddata
Interpolate on a regular grid and volshow that. Let me know it that works out, would be nice if you could share the data/notebook for maybe one of the examples for how ipyvolume can be used.

@rabernat
Copy link
Author

rabernat commented Mar 5, 2017

Thanks @maartenbreddels for these tips! I am an experienced numpy/scipy user and am familiar with various approaches for interpolating and regridding data.

What I am asking with my issue is whether you think ipyvolume should do these things for the user automatically, using the api I suggested above. Your response suggests that the answer is "no"; such features are outside the scope of what you aim to provide.

@maartenbreddels
Copy link
Collaborator

Ah ok, I misunderstood you then. Well, i'm not against supporting this, although I wouldn't directly add it in volshow now. I did think of having say 'incubator.py' module, where a function that does this could go without problem (with the regridding), and where when things are more mature/sorted out/merged etc could then move to the pylab.py file. Another thing might be to have a per science module, 'astro.py', 'earth.py', 'bio.py' etc where more science specific things could do.

But I think this example is quite general. I also think it must be possible to do this without regridding/interpolating, so in the long term I do see this as something that volshow could support. Until (or if) that happens, I'm happy to accept a PR with an incubator.py file that does sth like you propose, volshow_rectilinear(data, x=x, y=y, z=z) using scipy to regrid the data.

@victortxa
Copy link

@maartenbreddels thanks for your explanation above. However I would like to confirm some information. Now, it is only necessary to have a 3d numpy array to plot using ipyvolume. So, if I have any input I would like to plot using ipyvolume I need to "convert" it to a 3d numpy array, right?
I am asking it also because I have a python package which 3d output I would like to plot with ipyvolume. The output are the bounds of the geometric element (polyhedron) with a correspondent property value for it. For example, I have the coordinates of the bounds of a cube and inside this cube I consider I have a property with value 2.0. I was wondering if it would be possible to only give these bounds and a property value in order to have a plot of my figure.

@maartenbreddels
Copy link
Collaborator

Hi @victortxa, please open a new issue the next time.

I am not sure I understand your question, but ipyvolume does both volume rendering (volshow, displayed 3d cubes/arrays) and glyphs (a shape/symbol at a specific location). Currently it does not do arbitrary objects, like meshes, but pythreejs would solve think I'd think.
Let me know if that answers your question.

@mfouesneau
Copy link

mfouesneau commented Dec 22, 2022

With python 3.10, ipyvolume=='0.6.0-alpha.10'

I cannot show a volume from xarray dataarray

import ipyvolume as ipv
ipv.volshow(ds)

I obtain the following error message

Open Browser Console for more detailed log - Double click to close this message]
Failed to create view for 'VolumeView' from module 'ipyvolume' with model 'VolumeModel' from module 'ipyvolume'
TypeError: Cannot read properties of undefined (reading 'getRenderSize')
    at d.render (http://localhost:8888/lab/extensions/ipyvolume/static/568.9cf325ecd07f6f56b10f.js?v=9cf325ecd07f6f56b10f:1:255709)
    at http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.b0e841b75317744a7595.js?v=b0e841b75317744a7595:1:2959
    at async w.renderModel (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.40eaa5b8e976096d50b2.js?v=40eaa5b8e976096d50b2:1:72264)

ds is a regular grid 64x64x64
description: xarray.DataArray gmag: 64 g_min_rp: 64 dmod: 64

quickvolshow seems to work but does not read the coordinates.

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