Examples

Interactive Volume Rendering

This is a simple script for loading the IsolatedGalaxy example dataset and creating an interactive rendering window for it, including a GUI.

1
2
3
4
5
6
7
8
9
import yt

import yt_idv

ds = yt.load_sample("IsolatedGalaxy")

rc = yt_idv.render_context(height=800, width=800, gui=True)
sg = rc.add_scene(ds, "density", no_ghost=True)
rc.run()

Off-screen Volume Rendering

This is a simple script for loading the IsolatedGalaxy example dataset, creating an off-screen rendering context, and then taking two snapshots.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import yt

import yt_idv

ds = yt.load_sample("IsolatedGalaxy")
dd = ds.all_data()

rc = yt_idv.render_context("egl", width=1024, height=1024)
rc.add_scene(dd, "density", no_ghost=True)

image = rc.run()
yt.write_bitmap(image, "step1.png")

rc.scene.camera.move_forward(1.5)

image = rc.run()
yt.write_bitmap(image, "step2.png")

Making a Zoom Movie

This script loads the HiresIsolatedGalaxy sample dataset, creates a 1024x1024 offscreen rendering context, sets the camera position and then zooms toward the center, making 400 snapshots. It also sets the cmap_min and cmap_max attributes, so the colormap is allowed to be dynamically set at every step.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import yt

import yt_idv

N = 400

ds = yt.load_sample("HiresIsolatedGalaxy")
c = [0.53, 0.53, 0.53]

rc = yt_idv.render_context("egl", width=1024, height=1024)
sc = rc.add_scene(ds, "density", no_ghost=False)
sc.components[0].render_method = "projection"
sc.camera.focus = c
sc.camera.position = [0.45, 0.44, 0.43]

ds = (sc.camera.focus - sc.camera.position) / N

for i in range(N):
    sc.components[0].cmap_min = sc.components[0].cmap_max = None
    sc.camera.position = sc.camera.position + ds
    sc.camera._update_matrices()
    rc.snap()

Interactive Widget in Jupyter

This script, when executed as a series of Jupyter notebook cells, will create an off-screen context and render into that. The call to add_image() will create an Image widget that is auto-updated when the scene runs.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import yt
import yt_idv

ds = yt.load_sample("IsolatedGalaxy")
dd = ds.all_data()

rc = yt_idv.render_context("egl", width = 400, height = 400)
rc.add_scene(dd, "density", no_ghost=True)
rc.run()
rc.add_image()

Note that if you have access to OSMesa but not EGL, you can use the OSMesa rendering context instead.