Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/amrkdtree_downsampling.py
928 views
1
# Using AMRKDTree Homogenized Volumes to examine large datasets
2
# at lower resolution.
3
4
# In this example we will show how to use the AMRKDTree to take a simulation
5
# with 8 levels of refinement and only use levels 0-3 to render the dataset.
6
7
# Currently this cookbook is flawed in that the data that is covered by the
8
# higher resolution data gets masked during the rendering. This should be
9
# fixed by changing either the data source or the code in
10
# yt/utilities/amr_kdtree.py where data is being masked for the partitioned
11
# grid. Right now the quick fix is to create a data_collection, but this
12
# will only work for patch based simulations that have ds.index.grids.
13
14
# We begin by loading up yt, and importing the AMRKDTree
15
import numpy as np
16
17
import yt
18
from yt.utilities.amr_kdtree.api import AMRKDTree
19
20
# Load up a dataset and define the kdtree
21
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
22
im, sc = yt.volume_render(ds, ("gas", "density"), fname="v0.png")
23
sc.camera.set_width(ds.arr(100, "kpc"))
24
render_source = sc.get_source()
25
kd = render_source.volume
26
27
# Print out specifics of KD Tree
28
print("Total volume of all bricks = %i" % kd.count_volume())
29
print("Total number of cells = %i" % kd.count_cells())
30
31
new_source = ds.all_data()
32
new_source.max_level = 3
33
kd_low_res = AMRKDTree(ds, data_source=new_source)
34
print(kd_low_res.count_volume())
35
print(kd_low_res.count_cells())
36
37
# Now we pass this in as the volume to our camera, and render the snapshot
38
# again.
39
40
render_source.set_volume(kd_low_res)
41
render_source.set_field(("gas", "density"))
42
sc.save("v1.png", sigma_clip=6.0)
43
44
# This operation was substantially faster. Now lets modify the low resolution
45
# rendering until we find something we like.
46
47
tf = render_source.transfer_function
48
tf.clear()
49
tf.add_layers(
50
4,
51
0.01,
52
col_bounds=[-27.5, -25.5],
53
alpha=np.ones(4, dtype="float64"),
54
colormap="RdBu_r",
55
)
56
sc.save("v2.png", sigma_clip=6.0)
57
58
# This looks better. Now let's try turning on opacity.
59
60
tf.grey_opacity = True
61
sc.save("v3.png", sigma_clip=6.0)
62
#
63
## That seemed to pick out some interesting structures. Now let's bump up the
64
## opacity.
65
#
66
tf.clear()
67
tf.add_layers(
68
4,
69
0.01,
70
col_bounds=[-27.5, -25.5],
71
alpha=10.0 * np.ones(4, dtype="float64"),
72
colormap="RdBu_r",
73
)
74
tf.add_layers(
75
4,
76
0.01,
77
col_bounds=[-27.5, -25.5],
78
alpha=10.0 * np.ones(4, dtype="float64"),
79
colormap="RdBu_r",
80
)
81
sc.save("v4.png", sigma_clip=6.0)
82
#
83
## This looks pretty good, now lets go back to the full resolution AMRKDTree
84
#
85
render_source.set_volume(kd)
86
sc.save("v5.png", sigma_clip=6.0)
87
88
# This looks great!
89
90