Question about deposited fields: follow up
I also have a follow-up question. My previous question was about the build-in deposited fields. But when I try to do that myself, units seem to be screwed up. ----------------------- import yt import numpy as np def StellarMass2(field,data): ms = data[('STAR','particle_mass')] if('FieldDetector' in str(type(data))): return ms else: return ms.in_units("Msun") 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"),"nearest",weight_field='particle_ones') xcen = d.arr([5,5,5],"Mpccm/h") s = d.sphere(xcen,(100,"kpc")) sf = ('STAR','mass2') df = ('deposit','STAR_nn_mass2') print(np.amax(s[sf]),np.amax(s[df])) ----------------------------
1625.2196373326824 Msun 1625.2196373326824 Msun I.e, the units of the deposited field are that of mass, rather than density. Even worse, if I treat the deposited field as the mass per cell rather than density, it does not add up: print("sum=%9.3e int=%9.3e"%(np.sum(s[sf].in_units("Msun")),np.sum(s[df].in_units("Msun"))))
sum=3.252e+04 int=1.521e+05
So, I am totally lost about what add_deposited_particle_field() function actually does. n
I wonder if this message could have been overlooked somehow. On 05/27/2018 03:23 PM, Nick Gnedin wrote:
I also have a follow-up question. My previous question was about the build-in deposited fields. But when I try to do that myself, units seem to be screwed up.
----------------------- import yt import numpy as np
def StellarMass2(field,data): ms = data[('STAR','particle_mass')] if('FieldDetector' in str(type(data))): return ms else: return ms.in_units("Msun")
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"),"nearest",weight_field='particle_ones')
xcen = d.arr([5,5,5],"Mpccm/h") s = d.sphere(xcen,(100,"kpc")) sf = ('STAR','mass2') df = ('deposit','STAR_nn_mass2') print(np.amax(s[sf]),np.amax(s[df])) ----------------------------
1625.2196373326824 Msun 1625.2196373326824 Msun
I.e, the units of the deposited field are that of mass, rather than density.
Even worse, if I treat the deposited field as the mass per cell rather than density, it does not add up:
print("sum=%9.3e int=%9.3e"%(np.sum(s[sf].in_units("Msun")),np.sum(s[df].in_units("Msun"))))
sum=3.252e+04 int=1.521e+05
So, I am totally lost about what add_deposited_particle_field() function actually does.
n
Sorry Nick, I accidentally skipped over this question.
The nearest neighbor deposit operation deposits a the field value of the
particle closest to that cell's position - I don't think it's doing what
you thought it was doing. Take a look at this modified version of your
script:
https://gist.github.com/ngoldbaum/a1ea4dc0c8cde6ca1630f251a350b110
It should output:
1625.2196373326824 Msun 2367.0651822468562 Msun
32518.862230804152 Msun 32518.862230804152 Msun
32518.862230804152 Msun
Note that I'm running the development version of yt, where PR 1802 is
merged (https://github.com/yt-project/yt/pull/1802), so I didn't need to
FieldDetector stuff in the field definition.
You can see that this is more or less how the ('deposit', 'foo_density')
fields that automatically created by yt work:
https://github.com/yt-project/yt/blob/be560338a0a144055706b8a4a3295606a3f25e...
If you're interested in seeing more about how to use the low-level particle
deposition API (i.e. bypassing ds.add_particle_field), that file is pretty
rich with examples.
On Fri, Jun 1, 2018 at 2:36 PM, Nick Gnedin
I wonder if this message could have been overlooked somehow.
On 05/27/2018 03:23 PM, Nick Gnedin wrote:
I also have a follow-up question. My previous question was about the build-in deposited fields. But when I try to do that myself, units seem to be screwed up.
----------------------- import yt import numpy as np
def StellarMass2(field,data): ms = data[('STAR','particle_mass')] if('FieldDetector' in str(type(data))): return ms else: return ms.in_units("Msun")
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"),"nearest",weight_field='particle_ones')
xcen = d.arr([5,5,5],"Mpccm/h") s = d.sphere(xcen,(100,"kpc")) sf = ('STAR','mass2') df = ('deposit','STAR_nn_mass2') print(np.amax(s[sf]),np.amax(s[df])) ----------------------------
1625.2196373326824 Msun 1625.2196373326824 Msun
I.e, the units of the deposited field are that of mass, rather than density.
Even worse, if I treat the deposited field as the mass per cell rather than density, it does not add up:
print("sum=%9.3e int=%9.3e"%(np.sum(s[sf].in_un its("Msun")),np.sum(s[df].in_units("Msun"))))
sum=3.252e+04 int=1.521e+05
So, I am totally lost about what add_deposited_particle_field() function actually does.
n
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org
participants (3)
-
Nathan Goldbaum
-
Nick Gnedin
-
Nick Gnedin