Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/downsampling_amr.py
928 views
1
import yt
2
3
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
4
5
# The maximum refinement level of this dataset is 8
6
print(ds.max_level)
7
8
# If we ask for *all* of the AMR data, we get back field
9
# values sampled at about 3.6 million AMR zones
10
ad = ds.all_data()
11
print(ad["gas", "density"].shape)
12
13
# Let's only sample data up to AMR level 2
14
ad.max_level = 2
15
16
# Now we only sample from about 200,000 zones
17
print(ad["gas", "density"].shape)
18
19
# Note that this includes data at level 2 that would
20
# normally be masked out. There aren't any "holes" in
21
# the downsampled AMR mesh, the volume still sums to
22
# the volume of the domain:
23
print(ad["gas", "volume"].sum())
24
print(ds.domain_width.prod())
25
26
# Now let's make a downsampled plot
27
plot = yt.SlicePlot(ds, "z", ("gas", "density"), data_source=ad)
28
plot.save("downsampled.png")
29
30