boutproject / xBOUT

Collects BOUT++ data from parallelized simulations into xarray.
https://xbout.readthedocs.io/en/latest/
Apache License 2.0
22 stars 10 forks source link

3D plotting #103

Open TomNicholas opened 4 years ago

TomNicholas commented 4 years ago

It would be sweet to be able to make 3D plots of BOUT data. Unfortunately matplotlib3D is not great, and mayavi is a bit outdated (not sure if it's still actively developed?).

But I recently found this library, which runs in a jupyter notebook and uses WebGL as the plotting backend so it's really fast. The examples are insanely cool and the one of a chest cavity in particular is worth a look.

Here's me using K3D-jupyter to plot some filaments from a 3D slab turbulence simulation in like 3 lines of code (after preloading the values DataArray using xbout):

3D_plotting

@johnomotani

bendudson commented 4 years ago

Very neat! That looks really useful. There is also some interface to VisIT, though it's a bit clunky. The pain with 3D plotting really comes in tokamak field-aligned geometry, because the data has to be interpolated so that the plotting follows the curved field-lines. This is especially noticeable in STs near the centre-column. There is some code lying around somewhere to do this for Mayavi inputs, but I'm not sure where it is now.

rdoyle45 commented 4 years ago

Looks class Tom. Regarding tokamak geometries I think @friva000 has done a fair few 3D realistic plots of MAST, albeit in MATLAB if I remember correctly. Though he may have some techniques that could be replicated in xBOUT?

TomNicholas commented 4 years ago

Fabio did a 3D plot in python using mayavi which I've stored here, including his code.

Ideally someone would write a 3D plotting accessor for xbout which first does the field-aligned interpolation, then plots using whichever of mayavi and K3D-jupyter turns out to be better.

(It's unlikely I will have time to do that though)

johnomotani commented 4 years ago

I've started working on some plotting using K3D-jupyter... Watch this space! (also get #107 and #108 merged :wink: )

johnomotani commented 4 years ago

A couple of previews with TORPEX simulation data... K3D-1585615328415 K3D-1585615262792

Unfortunately, github won't let me put the interactive html version in these comments!

TomNicholas commented 4 years ago

oh cooooooool!

Have you tried doing isosurface plots? Should be able to see full 3D filaments then.

Unfortunately, github won't let me put the interactive html version in these comments!

(I used this excellent tool to quickly screengrab the gifs of me messing with the 3D plots.)

johnomotani commented 4 years ago

Haven't had a chance to dig into any more features yet! I found one example that let me replicate Fabio's mayavi implementation for the top fig, and then the second one was just a different choice of surfaces... Isosurfaces and animations are definitely on the wishlist. My main motivation for wanting to fix #115 is that it'd be nice to be able to slice in x or y, (not just in z) to put surfaces in interesting bits of the turbulence.

johnomotani commented 4 years ago

Tom found another potentially interesting 3d visualisation library: https://blog.jupyter.org/ipygany-jupyter-into-the-third-dimension-29a97597fc33?gi=65070678f5e5

johnomotani commented 3 years ago

In case anyone ever gets a chance to pick this up, the branch that I was working on is here https://github.com/boutproject/xBOUT/tree/plot3d. The 3d plotting stuff is in new functions, so I hope would be relatively straightforward to merge, although likely needs a few updates for compatibility with the changes to master since I was working on it...

TomNicholas commented 1 year ago

Another recent option for 3D plotting is pyvista, which like Mayavi wraps VTK tools, but unlike Mayavi someone made a neat xarray accessor for pyvista so you can get 3D plots in just one line!

johnomotani commented 11 months ago

An alternative approach has been developed here: https://github.com/DomLonghorn/SciViPy/blob/main/SciViPy/bout_cartesian_convert.py