[yt-users] yt-3.0 : derived fields in python notebooks

Britton Smith brittonsmith at gmail.com
Fri Nov 14 06:14:58 PST 2014


Hi Elizabeth,

I don't know whether that syntax works anymore, but the following should:
have your field function without the @derived_field decorator, and then,
after ds = yt.load(...), do ds.add_field("thermalenergy", function=...,
units=...)

Britton


On Fri, Nov 14, 2014 at 11:33 AM, Elizabeth Tasker <
tasker at astro1.sci.hokudai.ac.jp> wrote:

> Hi,
>
> I'm hitting a problem with deriving a field within a python notebook with
> yt 3.0. I'm following:
>
>
> http://yt-project.org/docs/3.0/quickstart/derived_fields_and_profiles.html
>
> and have:
>
> @derived_field(name = "thermenergy", units = "g * cm**2/s**2")
> def _thermenergy(field, data):
>     return data[("gas", "cell_mass")]*data[("gas", "thermal_energy")]
>
>
> but I get:
>
> TypeError                                 Traceback (most recent call last)
> <ipython-input-30-55b30d60c209> in <module>()
> ----> 1 @derived_field(name = "thermenergy", units = "g * cm**2/s**2")
>       2 def _thermenergy(field, data):
>       3     return data[("gas", "cell_mass")]*data[("gas",
> "thermal_energy")]
>       4
>       5 yt.add_field("thermenergy", function=_thermenergy,
> units="gcm**2/s**2")
>
> TypeError: 'NoneType' object is not callable
>
>
> I don't get an error if I do:
>
> def _thermenergy(field, data):
>     return data[("gas", "cell_mass")]*data[("gas", "thermal_energy")]
>
> yt.add_field("thermenergy", function=_thermenergy, units="gcm**2/s**2")
>
> but nor can I use the field:
>
> ds = yt.load("DD0002/sbcool_0002")
> dd = ds.all_data()
> dd["thermenergy"]
>
>
> YTFieldNotFound                           Traceback (most recent call last)
> <ipython-input-33-c293394ac99f> in <module>()
>       1 ds = yt.load("DD0002/sbcool_0002")
>       2 dd = ds.all_data()
> ----> 3 dd["thermenergy"]
>
>
> ... what did I do wrong?
>
> Elizabeth
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20141114/f0839c53/attachment.html>


More information about the yt-users mailing list