Hi Sam,

A construction like this:


Is a way of getting runtime parameters from the dataset, not accessing a field. The reason your script is failing is that “velocity_x_gradient_x” is a field, not a runtime parameter, so the key error you get is appropriate.

If you want to access field values, you need to create a data object first:

ad = ds.all_data()

There are a number of data objects in yt, see:


Finally, yt 3.3.1 is somewhat out of date, the latest version is yt 3.4.0. You likely want to upgrade if you are able to since 3.4.0 includes a number of fixes for issues in the 3.3.x series.



On Thu, Jan 25, 2018 at 8:25 AM Sam Patrick <sam.patrick@port.ac.uk> wrote:
Hello all,

I am rather new to yt and have recently tried using the gradient fields
functionality. I'm attempting to write a script which involves basic
calculations with the gradient of the velocity field, however I keep
coming across the same error when assigning the gradient field to a

My current version of yt is 3.3.1 and my version of Python is 2.7.12.
The data dumps I'm reading from were produced by an Enzo cosmology
simulation (version 2.5).

The following code is a simplified version of the script which runs
successfully and outputs a slice plot of the velocity gradient:

import yt
from yt import derived_field


ds = yt.load("DD0045/output_0045")
val, loc = ds.find_max('density')

ds.periodicity = (True, True, True)

ds.add_gradient_fields(('gas', 'velocity_x'))

#grad_x = ds['velocity_x_gradient_x']

plt = yt.SlicePlot(ds, 'z', 'velocity_x_gradient_x', center= loc, width=
(6.0, 'pc')


However, when I try to assign this gradient field to a variable by
removing the comment and adding the line "grad_x =
ds['velocity_x_gradient_x']" and plotting this instead I come across the
following error:

line 352, in __getitem__
return self.parameters[key]
P015 yt : [ERROR    ] 2018-01-25 10:49:00,443 KeyError:

I am unsure what I am doing wrong here. Any help will be very much

Sam Patrick

yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org