[yt-users] creating gradient of a field as a derived field
Prateek Gupta
prateekgidolia at gmail.com
Mon Jun 27 04:37:55 PDT 2016
Hello Turhan
Try this whether it works or helps you or not.
*def _Varlist(field, data): varlist = [data["Gx"], data["Gy"],
data["Gz"]] return varlistyt.add_field("varlist", function=_Varlist,
take_log=False, units="code length/ code time**2") slc =
yt.SlicePlot(ds, 'z', 'varlist', origin="native")*
I hope it will work.
Regrads
Prateek
On Mon, Jun 27, 2016 at 4:19 PM, Prateek Gupta <prateekgidolia at gmail.com>
wrote:
> Hello Tazkera
>
> As much I understood, you want to store values of Gx, Gy, Gz in array
> named varlist. But your syntax
> varlist = ['Gx', 'Gy', 'Gz']
> will not store values of Gx, Gy, Gz. It stores Gx, Gy, Gz as strings in
> varlist.
> if you want to store values you have to write syntax as
> varlist = [Gx, Gy, Gz]
>
> But this will also not work for you. Because if you want to take the slice
> plot then you have to define varlist as field I think.
> I will try to solve it. And we will wait for Nathan reply also.
>
>
> Regards
> Prateek
>
> On Sat, Jun 25, 2016 at 7:24 AM, tazkera haque <h.tazkera at gmail.com>
> wrote:
>
>> Hi Prateek and Nathan,
>>
>> thanks for your suggestion, I did accordingly, and seems the field is not
>> add up properly. I have attached the error.
>>
>> At this point I would ask you to kindly take a look at my code too, i am
>> new in python and I want to make sure I am not doing other things wrong
>> along with it.
>>
>> I am trying to make slice plots of gravitational acceleration through
>> z-axis from the FLASH plotfiles and make a folder with it.
>> thanks in advance.
>>
>> Turhan
>>
>> On Fri, Jun 24, 2016 at 9:20 AM, Nathan Goldbaum <nathan12343 at gmail.com>
>> wrote:
>>
>>>
>>>
>>> On Fri, Jun 24, 2016 at 6:40 AM, Prateek Gupta <prateekgidolia at gmail.com
>>> > wrote:
>>>
>>>> Hello Turhan,
>>>>
>>>> I am not sure but I think this will work, you can try this...
>>>>
>>>>
>>>> *ds = yt.load("data_file_Name")*
>>>>
>>>> *grad = ds.add_gradient_fields(("gas","gravitational_potential"))*
>>>>
>>>> *grad *list will have a list of new field names which representing the
>>>> 3 different components of the field and the magnitude of the gradient ,
>>>> e.g., "*gravitational_potential_gradient_x*" , "
>>>> *gravitational_potential_gradient_y*" , "
>>>> *gravitational_potential_gradient_z*" and "
>>>> *gravitational_potential_gradient_magnitude*"
>>>>
>>>> Now for getting the negative gradient of gravitational potential we can
>>>> derive field as follows:
>>>>
>>>>
>>>> *####...x-component of negative of gradient of gravitational
>>>> potential...*
>>>> *def _GradientX(field, data)*
>>>> * Gx = -1.0*data["gravitational_potential_gradient_x"]*
>>>> * return Gx*
>>>>
>>>> *yt.add_field("Gx", function=_GradientX, take_log=False, units="code
>>>> length/ code time**2")*
>>>>
>>>> *####...y-component of negative of gradient of gravitational
>>>> potential...*
>>>> *def _GradientY(field, data)*
>>>> * Gy = -1.0*data["gravitational_potential_gradient_y"]*
>>>> * return Gx*
>>>> *yt.add_field("Gy", function=_GradientY, take_log=False, units="**code
>>>> length/ code time**2**")*
>>>>
>>>> *####...z-component of negative of gradient of gravitational
>>>> potential...*
>>>> *def _GradientZ(field, data)*
>>>> * Gz = -1.0*data["gravitational_potential_gradient_z"]*
>>>> * return Gz*
>>>> *yt.add_field("Gz", function=_GradientZ, take_log=False, units="**code
>>>> length/ code time**2**")*
>>>>
>>>>
>>>>
>>>> Otherwise you can do this also,
>>>>
>>>> *grad = -1.0*ds.add_gradient_fields(("gas","gravitational_potential"))*
>>>>
>>>
>>> This isn't quite right. The ds.add_gradient_fields function returns a
>>> set of field names, not a field object itself. If you want to add the
>>> negative signs to the field definition, you'll need to define some derived
>>> fields as Prateek suggested above.
>>>
>>>
>>>>
>>>> I think this will work but this will also make the magnitude negative.
>>>> But if you want to use only 3-components then this works and you can access
>>>> it , e.g., *data["gravitational_potential_gradient_x"]* and similar
>>>> for y and z component.
>>>>
>>>>
>>>>
>>>> Please let me know if this work.
>>>>
>>>>
>>>>
>>>> Regards
>>>> Prateek Gupta
>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>>
>>
>> _______________________________________________
>> 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/20160627/1075b979/attachment.html>
More information about the yt-users
mailing list