Hello, I was trying to get the position and mass information for the dark matter (and stellar) particles in an Enzo simulation. I have tried a couple of different ways and I was curious about the units on the following method. In this case I am presumably accessing the dark matter particles (particle_type = 1) *from yt.mods import ** *pf = load("DD0252/DD0252")* *array = pf.h.find_particles_by_type(ptype=1, max_num=3)* *print "(%.5f, %.5f, %.5f) = %f\n" %(array['particle_position_x'][0], array['particle_position_y'][0], array['particle_position_z'][0], array['particle_mass'][0])* 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 *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. 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])* Which returns *(0.010554 0.018727 0.002239) = 82255596.670652 Msun, ptype= 1* This seems to give reasonable values. Both methods should be equivalent ways of to access the particle (both stellar and dark matter) data, correct? So how do I get my units in solar masses when using * pf.h.find_particles_by_type()*? Thanks for your time! ~ali
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/fiel...) 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@skory.us http://stephenskory.com/ 510.621.3687 (google voice)
participants (2)
-
Ali Snedden
-
Stephen Skory