[yt-users] creating gradient of a field as a derived field
tazkera haque
h.tazkera at gmail.com
Fri Jun 24 18:54:22 PDT 2016
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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160624/cc371d5b/attachment.html>
-------------- next part --------------
File "slice_gravity.py", line 104, in <module>
slc =yt.SlicePlot(ds,axislist[i],varlist[i],origin="center-domain")
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/visualization/plot_window.py", line 2137, in SlicePlot
return AxisAlignedSlicePlot(ds, normal, fields, *args, **kwargs)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/visualization/plot_window.py", line 1275, in __init__
slc.get_data(fields)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 643, in get_data
self.index._identify_base_chunk(self)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py", line 143, in index
self._index = self.ds.index
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/data_objects/static_output.py", line 326, in index
self.create_field_info()
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/data_objects/static_output.py", line 380, in create_field_info
self.field_info.load_all_plugins()
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/field_info_container.py", line 241, in load_all_plugins
self.find_dependencies(loaded)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/field_info_container.py", line 254, in find_dependencies
deps, unavailable = self.check_derived_fields(loaded)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/field_info_container.py", line 323, in check_derived_fields
fd = fi.get_dependencies(ds = self.ds)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/derived_field.py", line 163, in get_dependencies
e[self.name]
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/field_detector.py", line 113, in __missing__
vv = finfo(self)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/derived_field.py", line 189, in __call__
dd = self._function(self, data)
File "slice_gravity.py", line 37, in _GradientY
Gy = -1.0*data["gravitational_potential_gradient_y"]
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/fields/field_detector.py", line 93, in __missing__
finfo = self.ds._get_field_info(*field)
File "/work/03858/thaque56/sw/yt-3.1/yt-x86_64/src/yt-hg/yt/data_objects/static_output.py", line 543, in _get_field_info
raise YTFieldNotFound((ftype, fname), self)
yt.utilities.exceptions.YTFieldNotFound: Could not find field '('all', 'gravitational_potential_gradient_y')' in super3d_hdf5_plt_cnt_0000.
[c557-303.stampede.tacc.utexas.edu:mpispawn_0][child_handler] MPI process (rank: 0, pid: 67268) exited with status 1
TACC: MPI job exited with code: 1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: slices.py
Type: text/x-python
Size: 3833 bytes
Desc: not available
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160624/cc371d5b/attachment-0002.py>
More information about the yt-users
mailing list