Hi Sam, A construction like this: ds[key] 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() ad[“velocity_x_gradient_x”] There are a number of data objects in yt, see: http://yt-project.org/doc/analyzing/objects.html 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. Best, Nathan 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 variable.
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
yt.enable_parallelism()
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')
plt.save("plot.png")
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:
File
"/opt/apps/yt/3.3.1/yt-conda/lib/python2.7/site-packages/yt/data_objects/static_output.py", line 352, in __getitem__ return self.parameters[key] P015 yt : [ERROR ] 2018-01-25 10:49:00,443 KeyError: 'velocity_x_gradient_x'
I am unsure what I am doing wrong here. Any help will be very much appreciated.
Thanks, Sam Patrick
_______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org