[yt-users] multiply a function of a field with another field

Britton Smith brittonsmith at gmail.com
Wed Oct 16 22:15:32 PDT 2013


Reju,

When you have data[any_field] in your field function, it will just be a
Numpy array containing value for that field, so you can do anything you
want it, including calling another function, as long as the shape of the
data returned from the function is the same as the shape of the field
array.  What you have should work just fine.  I encourage you to go ahead
and try it.

Britton


On Thu, Oct 17, 2013 at 2:06 PM, Reju Sam John <rejusamjohn at gmail.com>wrote:

> Actually I needed some thing like this ([image: \eta(\mathcal{M}) \times
> \frac{1}{2}\rho(\mathcal{M} c_{s})^3] )  *where [image: \eta(\mathcal{M})]is a function of
> "Mach**Number"*, [image: \rho] is  "Density" and [image: c_s]  is "
> SoundSpeed".
>
> can I write some thing like this?
>
>  newfield(field,data)
>  return new-function(data["MachNumber"])*data["any-other-field"]
>
> Please tell me this is possible or not. If not let me know what is the
> correct syntax?
>
>
>
>
> On Wed, Oct 16, 2013 at 4:25 PM, Matthew Turk <matthewturk at gmail.com>wrote:
>
>> Hi Reju,
>>
>> Your best bet would be to do this with a derived field; there are some
>> examples in the docs.  But, as a simple example, this would accomplish
>> it:
>>
>> --
>> from yt.mods import *
>>
>> @derived_field(name = "MyField")
>> def my_new_field(field, data):
>>     return data["Density"] * data["Temperature"]
>> --
>>
>> In the docs it mostly uses the function "add_field" rather than
>> @derived_field, but the result is the same.  This returns Temperature
>> * Density.  You can then plot "MyField" or ask for it or whatever, and
>> it will be the result.
>>
>> Hope that helps!
>>
>> -Matt
>>
>>
>> On Wed, Oct 16, 2013 at 7:53 PM, Reju Sam John <rejusamjohn at gmail.com>
>> wrote:
>> > Dear All,
>> >
>> > I want to multiply a function of a field in YT (function of  MachNumber
>> )
>> > with another field in YT. How can I proceed?
>> >
>> >
>> >
>> > --
>> > Reju Sam John
>> >
>> > _______________________________________________
>> > yt-users mailing list
>> > yt-users at lists.spacepope.org
>> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> >
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>
>
>
> --
> Reju Sam John
>
> _______________________________________________
> 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/20131017/c761d8a6/attachment.html>


More information about the yt-users mailing list