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:

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 (, 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:

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 <> wrote:

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
         return ms.in_units("Msun")

d = yt.load("rei10_a0.1001/")


xcen = d.arr([5,5,5],"Mpccm/h")
s = d.sphere(xcen,(100,"kpc"))
sf = ('STAR','mass2')
df = ('deposit','STAR_nn_mass2')

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.

yt-users mailing list --
To unsubscribe send an email to