On Sun, May 27, 2018 at 2:48 PM, Nick Gnedin wrote:

Guys,

What are the implicit units of the deposited field? In the following script using implicit units returns an incorrect result, while setting them explicitly gives the correct one.

import yt
import numpy as np

xcen = d.arr([5,5,5],"Mpccm/h")
s = d.sphere(xcen,(100,"kpc"))

sf = ('STAR','particle_mass')
df = ('deposit','STAR_density')
print("sum=%9.3e int=%9.3e"%(np.sum(s[sf]),np.sum(s[df]*s[('gas','cell_volume')])))

The left-hand expression has units of code_mass, the right-hand expression has units of code_length^3 * g/cm^3.

It helps to see what's going on if you print out the result without using float formatting:

In [17]: print(np.sum(s[sf]),np.sum(s[df]*s[('gas','cell_volume')]))
6.893747161029751e-05 code_mass 1.8183255409899212e-31 code_length**3*g/cm**3

In [18]: print(np.sum(s[sf]).to("Msun"),np.sum(s[df]*s[('gas','cell_volume')]).to("Msun"))
32518.862230804152 Msun 32518.862230804145 Msun

print("sum=%9.3e int=%9.3e"%(np.sum(s[sf].in_units("Msun")),np.sum(s[df].in_units("Msun/kpc**3")*s[('gas','cell_volume')].in_units("kpc**3"))))

>
sum=6.894e-05 int=1.818e-31
sum=3.252e+04 int=3.252e+04

n
_______________________________________________
yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org