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.
1import yt
2
3import yt_idv
4
5ds = yt.load_sample("IsolatedGalaxy")
6
7rc = yt_idv.render_context(height=800, width=800, gui=True)
8sg = rc.add_scene(ds, "density", no_ghost=True)
9rc.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.
1import yt
2
3import yt_idv
4
5ds = yt.load_sample("IsolatedGalaxy")
6dd = ds.all_data()
7
8rc = yt_idv.render_context("egl", width=1024, height=1024)
9rc.add_scene(dd, "density", no_ghost=True)
10
11image = rc.run()
12yt.write_bitmap(image, "step1.png")
13
14rc.scene.camera.move_forward(1.5)
15
16image = rc.run()
17yt.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.
1import yt
2
3import yt_idv
4
5N = 400
6
7ds = yt.load_sample("HiresIsolatedGalaxy")
8c = [0.53, 0.53, 0.53]
9
10rc = yt_idv.render_context("egl", width=1024, height=1024)
11sc = rc.add_scene(ds, "density", no_ghost=False)
12sc.components[0].render_method = "projection"
13sc.camera.focus = c
14sc.camera.position = [0.45, 0.44, 0.43]
15
16ds = (sc.camera.focus - sc.camera.position) / N
17
18for _ in range(N):
19 sc.components[0].cmap_min = sc.components[0].cmap_max = None
20 sc.camera.position = sc.camera.position + ds
21 sc.camera._update_matrices()
22 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.
1import yt
2import yt_idv
3
4ds = yt.load_sample("IsolatedGalaxy")
5dd = ds.all_data()
6
7rc = yt_idv.render_context("egl", width=400, height=400)
8rc.add_scene(dd, "density", no_ghost=True)
9rc.run()
10rc.add_image()
Note that if you have access to OSMesa but not EGL, you can use the OSMesa rendering context instead.