[yt-users] gradient field in yt3

Yuan Li bear0980 at gmail.com
Thu Aug 13 12:52:24 PDT 2015


Hi Nathan,

I think you are probably right!

The script is super short:

import yt
import numpy as numpy
from yt import derived_field
@derived_field(name="logP",units="")
def _logP(field,data):
    return numpy.log(numpy.array(data["gas","pressure"]))
pf=yt.load("DD0060/data0060") #load your data
pf.add_gradient_fields(("gas","logP"))
print pf.derived_field_list
dd=pf.all_data()
a=dd["gas","logP_gradient_y"]

I forgot how to make a PR...It has been a while. I should relearn it, but
it might be easier for you to do this one :). Thank you!!


Yuan

On Thu, Aug 13, 2015 at 3:40 PM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:

> So I *think* the parenthesis in the units are coming from this line:
>
>
> https://bitbucket.org/yt_analysis/yt/src/603eab147248f1a165778c76208906201eb7baae/yt/fields/fluid_fields.py?at=yt#fluid_fields.py-218
>
> And I think this is happening because no one has tried to create a
> gradient field for a unitless field. This is something we should be able to
> do, but it's definitely a corner case.
>
> I don't have a script to run to test out any possible fixes, is there any
> chance you could make a script that uses one of the public test datasets on
> yt-project.org/data so I can reproduce your issue locally?
>
> Please also feel free to try fixing this yourself in your local copy of yt
> so you can make a PR.  I think all we need to do is modify the line I
> linked to so if "field_units" is an empty string, we drop the parenthesis
> and just make the gradient field units "1/cm".
>
> On Thu, Aug 13, 2015 at 2:30 PM, Yuan Li <bear0980 at gmail.com> wrote:
>
>> Traceback (most recent call last):
>>   File "logP.py", line 11, in <module>
>>     a=dd["gas","logP_gradient_y"]
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
>> line 253, in __getitem__
>>     self.get_data(f)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
>> line 751, in get_data
>>     self._generate_fields(fields_to_generate)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
>> line 771, in _generate_fields
>>     fd = self._generate_field(field)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
>> line 290, in _generate_field
>>     tr = self._generate_fluid_field(field)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
>> line 308, in _generate_fluid_field
>>     rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/data_objects/data_containers.py",
>> line 318, in _generate_spatial_fluid
>>     rv = self.ds.arr(np.empty(self.ires.size, dtype="float64"), units)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/units/yt_array.py", line
>> 332, in __new__
>>     units = Unit(input_units, registry=registry)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/units/unit_object.py",
>> line 204, in __new__
>>     unit_data = _get_unit_data_from_expr(unit_expr, registry.lut)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/units/unit_object.py",
>> line 496, in _get_unit_data_from_expr
>>     unit_data = _get_unit_data_from_expr(expr, unit_symbol_lut)
>>   File
>> "/Users/yuanli/source/yt3/yt-x86_64/src/yt-hg/yt/units/unit_object.py",
>> line 504, in _get_unit_data_from_expr
>>     "objects." % str(unit_expr))
>> yt.units.unit_object.UnitParseError: Cannot parse for unit data from
>> '()'. Please supply an expression of only Unit, Symbol, Pow, and Mulobjects.
>>
>> On Thu, Aug 13, 2015 at 3:28 PM, Nathan Goldbaum <nathan12343 at gmail.com>
>> wrote:
>>
>>>
>>>
>>> On Thu, Aug 13, 2015 at 2:22 PM, Yuan Li <yuan at astro.columbia.edu>
>>> wrote:
>>>
>>>> Hi all:
>>>>
>>>> I am having trouble creating a gradient field in yt3. What I want is
>>>> the gradient of logP, where logP is defined as:
>>>>
>>>> @derived_field(name="logP",units="")
>>>> def _logP(field,data):
>>>>     return numpy.log(numpy.array(data["gas","pressure"]))
>>>>
>>>> Then I add the gradient field:
>>>>
>>>> pf.add_gradient_fields(("gas","logP"))
>>>>
>>>
>>>> which seems to work and I can find it in pf.derived_field_list.
>>>>
>>>> But if I try to use it, I get this error message:
>>>> yt.units.unit_object.UnitParseError: Cannot parse for unit data from
>>>> '()'. Please supply an expression of only Unit, Symbol, Pow, and Mulobjects.
>>>>
>>>
>>> Can you pastebin the full traceback?
>>>
>>>
>>>>
>>>> Is this because logP does not have a unit?
>>>>
>>>> Also, I had another unrelated question about the gradient fields:
>>>> Can I add the gradient fields globally instead of to a specific
>>>> dataset?
>>>>
>>>>
>>> Not right now, no.
>>>
>>>
>>>>
>>>> Thanks!
>>>> Yuan
>>>>
>>>> _______________________________________________
>>>> 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
>>
>>
>
> _______________________________________________
> 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/20150813/7315fe1c/attachment.html>


More information about the yt-users mailing list