Notebook

# A Brief Demo of Volume Rendering¶

This shows a small amount of volume rendering. Really, just enough to get your feet wet!

In [1]:
import yt


To create a volume rendering, we need a camera and a transfer function. We'll use the ColorTransferFunction, which accepts (in log space) the minimum and maximum bounds of our transfer function. This means behavior for data outside these values is undefined.

We then add on "layers" like an onion. This function can accept a width (here specified) in data units, and also a color map. Here we add on four layers.

Finally, we create a camera. The focal point is [0.5, 0.5, 0.5], the width is 20 kpc (including front-to-back integration) and we specify a transfer function. Once we've done that, we call show to actually cast our rays and display them inline.

In [2]:
sc = yt.create_scene(ds)

sc.camera.set_width(ds.quan(20, 'kpc'))

source = sc.sources['source_00']

tf = yt.ColorTransferFunction((-28, -24))

source.set_transfer_function(tf)

sc.show()

/var/jenkins_home/workspace/yt_docs/sandbox/temp/lib64/python3.4/site-packages/yt-3.3.5-py3.4-linux-x86_64.egg/yt/utilities/amr_kdtree/amr_kdtree.py:311: RuntimeWarning: invalid value encountered in log10
dds.append(np.log10(vcd[field].astype('float64')))


If we want to apply a clipping, we can specify the sigma_clip. This will clip the upper bounds to this value times the standard deviation of the values in the image array.

In [3]:
sc.show(sigma_clip=4)


There are several other options we can specify. Note that here we have turned on the use of ghost zones, shortened the data interval for the transfer function, and widened our gaussian layers.

In [4]:
sc = yt.create_scene(ds)

sc.camera.set_width(ds.quan(20, 'kpc'))

source = sc.sources['source_00']

source.set_fields('density', no_ghost=False)

tf = yt.ColorTransferFunction((-28, -25))

source.set_transfer_function(tf)

sc.show(sigma_clip=4.0)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-83cb3839c84f> in <module>()
5 source = sc.sources['source_00']
6
----> 7 source.set_fields('density', no_ghost=False)
8
9 tf = yt.ColorTransferFunction((-28, -25))

AttributeError: 'VolumeSource' object has no attribute 'set_fields'