Skip to content

Instantly share code, notes, and snippets.

@ngoldbaum
Created June 1, 2018 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngoldbaum/a1ea4dc0c8cde6ca1630f251a350b110 to your computer and use it in GitHub Desktop.
Save ngoldbaum/a1ea4dc0c8cde6ca1630f251a350b110 to your computer and use it in GitHub Desktop.
import yt
import numpy as np
def StellarMass2(field, data):
return data['STAR', 'particle_mass'].in_units("Msun")
def deposit_density2(field, data):
mass = data['deposit', 'STAR_sum_mass2']
return mass / data['index', 'cell_volume']
d = yt.load("rei10_a0.1001/rei10_a0.1001.art")
d.add_field(("STAR", "mass2"), function=StellarMass2,
sampling_type="particle", units="Msun")
d.add_deposited_particle_field(
("STAR", "mass2"), "sum", weight_field='particle_ones')
d.add_field(("deposit", "STAR_density2"), function=deposit_density2,
sampling_type='cell', units='Msun/pc**3')
xcen = d.arr([5, 5, 5], "Mpccm/h")
s = d.sphere(xcen, (100, "kpc"))
sf = ('STAR', 'mass2')
df = ('deposit', 'STAR_sum_mass2')
print(np.amax(s[sf]), np.amax(s[df]))
print(s[sf].sum(), s[df].sum())
print((s['deposit', 'STAR_density2']*s['index', 'cell_volume']).sum().to('Msun'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment