Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/custom_transfer_function_volume_rendering.py
928 views
1
import numpy as np
2
3
import yt
4
5
# Load the dataset
6
ds = yt.load("Enzo_64/DD0043/data0043")
7
8
# Create a volume rendering
9
sc = yt.create_scene(ds, field=("gas", "density"))
10
11
# Modify the transfer function
12
13
# First get the render source, in this case the entire domain,
14
# with field ('gas','density')
15
render_source = sc.get_source()
16
17
# Clear the transfer function
18
render_source.transfer_function.clear()
19
20
# Map a range of density values (in log space) to the Reds_r colormap
21
render_source.transfer_function.map_to_colormap(
22
np.log10(ds.quan(5.0e-31, "g/cm**3")),
23
np.log10(ds.quan(1.0e-29, "g/cm**3")),
24
scale=30.0,
25
colormap="RdBu_r",
26
)
27
28
sc.save("new_tf.png")
29
30