File: sum_mass_in_sphere.py

package info (click to toggle)
yt 4.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 76,192 kB
  • sloc: python: 125,909; ansic: 6,303; cpp: 3,590; sh: 556; javascript: 352; makefile: 131; csh: 36
file content (23 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import yt

# Load the dataset.
ds = yt.load("Enzo_64/DD0029/data0029")

# Create a 1 Mpc radius sphere, centered on the max density.
sp = ds.sphere("max", (1.0, "Mpc"))

# Use the total_quantity derived quantity to sum up the
# values of the mass and particle_mass fields
# within the sphere.
baryon_mass, particle_mass = sp.quantities.total_quantity(
    [("gas", "mass"), ("all", "particle_mass")]
)

print(
    "Total mass in sphere is %0.3e Msun (gas = %0.3e Msun, particles = %0.3e Msun)"
    % (
        (baryon_mass + particle_mass).in_units("Msun"),
        baryon_mass.in_units("Msun"),
        particle_mass.in_units("Msun"),
    )
)