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.

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.

Extracting Data Values From a Rendering

With version 0.5.5, you can now extract data values from a rendering block collection renders for AMR data. To enable image data extraction, set component.store_first_pass_fb = True before rendering:

 1import numpy as np
 2import yt
 3
 4import yt_idv
 5
 6ds = yt.load_sample("IsolatedGalaxy")
 7
 8rc = yt_idv.render_context(height=800, width=800, gui=False)
 9sg = rc.add_scene(ds, "density", no_ghost=True)
10
11component = rc.scene.components[0]
12component.store_first_pass_fb = True
13component.render_method = "max_intensity"
14
15rc.scene.render()
16
17rendered_plane = component.rendered_image_plane()

The resulting rendered_plane object represents the rendered image plane and includes attributes describing the image extent in physical units as well as the data being rendered. The image plane extraction is currently supported for render_method of max_intensity, slice and projection. For the case of projection, the data values are the path-integrated data values along ray paths and will be sensitive to the camera type (which determines ray path).

See rendered_image_plane() for more details.