[yt-users] Question on derived field
tyuta
y0u1t1a5.t at gmail.com
Tue Oct 17 12:41:36 PDT 2017
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20171017/ad284e3f/attachment.html>
More information about the yt-users
mailing list