
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

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@astro.berkeley.eduwrote:
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@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

Hi Charles,
I like Britton's suggestions, but you can also try out the field_parameters stuff:
http://yt.enzotools.org/doc/howto/creating_derived_fields.html?highlight=set...
-Matt
On Wed, May 12, 2010 at 6:17 AM, Britton Smith brittonsmith@gmail.com wrote:
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@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@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
participants (3)
-
Britton Smith
-
Charles Hansen
-
Matthew Turk