Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/doc/source/cookbook/average_value.py
928 views
1
import yt
2
3
ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # load data
4
5
field = ("gas", "temperature") # The field to average
6
weight = ("gas", "mass") # The weight for the average
7
8
ad = ds.all_data() # This is a region describing the entire box,
9
# but note it doesn't read anything in yet!
10
11
# We now use our 'quantities' call to get the average quantity
12
average_value = ad.quantities.weighted_average_quantity(field, weight)
13
14
print(
15
"Average %s (weighted by %s) is %0.3e %s"
16
% (field[1], weight[1], average_value, average_value.units)
17
)
18
19