[yt-users] dynamic derived fields

Britton Smith brittonsmith at gmail.com
Wed May 12 06:17:20 PDT 2010


Hi Charles,

I think you could do this in a couple ways.  The data argument in field
functions gives you access to the parameter file of the dataset (data.pf).
One thing you can do is set your own parameters in the pf that can later be
used by your function.  So you could do:
pf = load(dataset)
pf.parameters['temperature_threshold'] = 1.e7
Then, inside your field function, you'll have access to that value as
data.pf.parameters['temperature_threshold'].

The other way would be to embed the definition of the field function and the
call to add_field within another function that takes temperature_threshold
as an argument.  You can call that function over and over and it should
overwrite the previous definition of the field.

Britton

On Wed, May 12, 2010 at 1:24 AM, Charles Hansen
<chansen at astro.berkeley.edu>wrote:

> Hi all,
>
> Is it possible to make something like a derived field in yt that takes
> passed variables?  A simple example would be extracting gas density above a
> certain temperature, but changing that temperature threshold on the fly
>
> def _hotgas(field, data, temperature_threshold):
>   reutrn data["density"]*(data["Temperature"] > temperature_threshold)
> add_field("hotgas", function=_hotgas, Something else goes here?)
>
> In this particular case I only need a few temperatures and can make a new
> derived quantity each time, but it seems like a generally useful ability.
>
> Thanks,
> Charles
> _______________________________________________
> 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/20100512/f75878f2/attachment.htm>


More information about the yt-users mailing list