[yt-users] particle_mass
Stephen Skory
s at skory.us
Fri Mar 23 16:08:00 PDT 2012
Hi Ali,
> This returns (0.01055, 0.01873, 0.00224) = 0.835448. What are the mass units
> on the 0.835448? I don't think that they are cgs, and there doesn't appear
> to be a conversion factor available via pf[' * ']. If I continue and enter
Yup, they are not CGS. They are in Enzo's internal units for cosmology
simulations for particles. That number is the amount of
CosmologyOmegaMatterNow that is due to dark matter, which is found
with (CosmologyOmegaMatterNow - CosmologyOmegaBaryonNow) /
CosmologyOmegaMatterNow from the initial conditions of the simulation
(if you're using inits.exe).
> print pf.field_info['Density'].get_units()
> print pf.field_info['particle_mass'].get_units()
>
> The 'Density' line returns \rm{g}/\rm{cm}^3, but the 'particle_mass'
> line returns nothing. So I can't get the units from here.
Yeah, this is exposing another hidden 'feature' of Enzo. Particle
masses in Enzo are actually densities, which makes the gravity
calculation step easier because then the "particle mass" can just be
added directly with the gas density. If you look at the guts of yt
staring at line 520 of yt/frontends/enzo/fields.py
(https://bitbucket.org/yt_analysis/yt/src/b9613e068053/yt/frontends/enzo/fields.py#cl-520)
you'll see that to get to the ParticleMassMsun there's a bunch of
conversion factors that have to go into it. Basically, since it's a
density, you need to first multiply by the size of the cell the
particle is in, which gets you a mass, and then you can apply your CGS
conversion factors. The complication is with AMR, the cell sizes
change, and therefore the "mass" of a particle changes depending on
the size of the cell it "lives" in. So you can't convert
"particle_mass" to a physical mass without knowing the cell size it
lives in.
> I can, however,
> access the same particle (or at least a particle at the same location) by
> using
>
> from yt.mods import *
> pf = load("DD0252/DD0252")
> dd = pf.h.all_data()
> print "(%f %f %f) = %f Msun, ptype= %i\n"%(dd["particle_position_x"][0],
> dd["particle_pos ition_y"][0], dd["particle_position_z"][0],
> dd["ParticleMassMsun"][0],dd["particle_type"][0])
All of the above is a long-winded way of saying that doing something
that you've been trying to do is unnecessarily difficult. But you are
on the right track with your second set of examples. I'd do your
original code of selecting only DM like this (using some numpy
trickery!):
from yt.mods import *
pf = load("DD0252/DD0252")
dd = pf.h.all_data()
type = dd['particle_type']
select = (type == 1)
px = dd['particle_position_x'][select]
py = dd['particle_position_y'][select]
pz = dd['particle_position_z'][select]
pm = dd['ParticleMassMsun'][select]
print "(%.5f, %.5f, %.5f) = %f\n" %(px[0], py[0], pz[0], pm[0])
The keys are that the 'select' which uses numpy 'fancy indexing' with
a boolean array, which you can read more than you want to know about
it here: http://www.scipy.org/Cookbook/Indexing only picks out the
dark matter particles,
and also the fact that the data container (pf.h.all_data() here) takes
care of the cell size issue for you automatically.
Good luck, and welcome to yt!
--
Stephen Skory
s at skory.us
http://stephenskory.com/
510.621.3687 (google voice)
More information about the yt-users
mailing list