Dear Nathan,

The particle filter worked well and I could read the star density from the data. Thanks!
Now I want to subtract stellar mass density from Dark_Matter_Density. I was trying to define a new field "only_DM", but it did not work. Could you tell me what is wrong with this?

(jupiter notebook session)
import yt
from yt.data_objects.particle_filters import add_particle_filter

def stars(pfilter, data):
    filter = data[(pfilter.filtered_type, "particle_type")] == 2
    return filter

add_particle_filter("stars", function=stars, filtered_type='io',


def only_DM(field, data):
    return data['Dark_Matter_Density'] - data['deposit','stars_density']


ds.add_field(("Dark_Matter_Density", "only_DM_Density"), units="kg/m**3", function=only_DM)

and the error message appears:
YTFieldNotFound: Could not find field '('deposit', 'stars_density')' in redshift00??.


2017-10-11 16:24 GMT-04:00 Nathan Goldbaum <>:
OK, in that case I wouldn't try to infer the stellar mass from the Dark_Matter_Density field (which does include stellar mass despite the name), instead I would define a particle filter for stars ( and then use the new particle type defined by the filter to create a deposited particle field (

There's an example in the docs for how to do this with Tipsy data here:

For Enzo, you should use the particle_type field to create the filter - star particles in Enzo have particle_type equal to 2. Here's a short worked example:

Hope that helps! And I hope to hear more from you - your name is particularly well suited to the yt project ;)


On Wed, Oct 11, 2017 at 12:58 PM, tyuta <> wrote:
Yes, it's Enzo data.

2017-10-11 10:17 GMT-04:00 Nathan Goldbaum <>:
What simulation code are you working with? From the field names it sounds like Enzo data.

On Wed, Oct 11, 2017 at 9:13 AM tyuta <> wrote:
Dear yt-users,

Hi, I'm a new user of yt. I have a question about the default 'Density' field and 'Dark_Matter_Density' field. Do they contain stellar mass? If so, how can I read and subtract stellar mass from the data?

yt-users mailing list

yt-users mailing list

yt-users mailing list

yt-users mailing list