File: average_value.py

package info (click to toggle)
yt 4.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,084 kB
  • sloc: python: 132,484; ansic: 5,628; cpp: 1,588; javascript: 352; makefile: 138; sh: 43; csh: 36
file content (17 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import yt

ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")  # load data

field = ("gas", "temperature")  # The field to average
weight = ("gas", "mass")  # The weight for the average

ad = ds.all_data()  # This is a region describing the entire box,
# but note it doesn't read anything in yet!

# We now use our 'quantities' call to get the average quantity
average_value = ad.quantities.weighted_average_quantity(field, weight)

print(
    "Average %s (weighted by %s) is %0.3e %s"
    % (field[1], weight[1], average_value, average_value.units)
)