Dear Nathan,

It worked fine after restarting kernel on jupyter notebook.
I'm terribly sorry for taking your time...
Thank you very much for your swift response.

Sincerely,
Y.T.

2017-10-17 15:50 GMT-04:00 Nathan Goldbaum <nathan12343@gmail.com>:
I'm not able to reproduce the behavior you're seeing. If you can trigger it using one of the example datasets on yt-project.org/data that would help to narrow down the issue. Here's a modified version of your script using one of those datasets:

http://paste.yt-project.org/show/7262/

(this script runs without error on my laptop)

It would also help to know what yt version you're using.

If I had to guess what the issue was, it might be that you aren't using the full field names in your field definition. Rather than defining as you have it in your script, why not try:

    def my_cell_mass(field, data):
        return (data['gas', 'density']*data['index', 'cell_volume'])


That's just a guess though.


On Tue, Oct 17, 2017 at 2:41 PM, tyuta <y0u1t1a5.t@gmail.com> wrote:
Dear yt users,

Hi, I have a question on derived field. I want to define "Dark Matter cell mass", which can be defined by (Dark matter density) * (cell_volume). To check that "Dark Matter cell mass" defined well, I also tried to define "my_cell_mass", which should give the same value as the default  'cell_mass', but it gave me an error, and I don't have any idea what the problem is. Could you help me with the problem?

I'm working on Enzo data.

Here is my python code (I'm sorry that it's lengthy):

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
def DMparticles(pfilter, data):
    filter = data[(pfilter.filtered_type, "particle_type")] == 1
    return filter

add_particle_filter("stars", function=stars, filtered_type='io',
                  requires=["particle_type"])
add_particle_filter("DMparticles", function=DMparticles, filtered_type='io', requires=["particle_type"])

def only_DM(field, data):
    return data['deposit','DMparticles_density']
def DM_in_cell_mass(field, data):
    return (data['only_DM_Density']*data['cell_volume'])
def my_cell_mass(field, data):
    return (data['density']*data['cell_volume'])

ds_all=yt.load("/.../redshift00??")

ds_all.add_particle_filter('stars')
ds_all.add_particle_filter('DMparticles')

ds_all.add_field(("gas", "only_DM_Density"), units="g/cm**3", function=only_DM)
ds_all.add_field(("gas", "DM_in_cell_mass"), units="g", function=DM_in_cell_mass)
ds_all.add_field(("gas", "my_cell_mass"), units="g", function=my_cell_mass)

sp = ds_all.sphere([centerx, centery, centerz], ((somevalue), "kpc"))

sp['cell_volume']
YTArray([  4.44089210e-16,   4.44089210e-16,   4.44089210e-16, ...,
           6.93889390e-18,   6.93889390e-18,   6.93889390e-18]) code_length**3

sp[('gas', 'my_cell_mass')]
YTFieldNotFound: Could not find field '('gas', 'my_cell_mass')' in redshift00??.

Best,
Y.T.

_______________________________________________
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org



_______________________________________________
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org