On Tue, Aug 8, 2017 at 10:21 AM, Matthew Turk <matthewturk@gmail.com> wrote:
Hi Wolfram,

On Tue, Aug 8, 2017 at 10:11 AM, Wolfram Schmidt
<wolfram.schmidt@uni-hamburg.de> wrote:
> Hi Nathan, hi Prateek,
>
> before I look into the frontend and try to modify it, I wonder:
>
> 1. Is possible to define units for a new field in the Enzo output (there are
> units conversion factors for certain quantities in Enzo, but I don't now if
> this somehow enters the data dumps)?

If you add them, it at leased *used* to be the case that yt would
parse them.  I think this is no longer the case, however.

>
> 2. Could I "teach" yt to assume certain units for a field which it
> interprets as dimensionless on the fly, i.e. in a python session? If so,
> how?

You can do this in a couple ways; if it's in the output file on disk,
you can do it by appending to the object EnzoFieldInfo (which is
accessible through the yt.frontends.enzo.api module)'s attribute
_known_fluid_fields.  This takes a tuple.  Do this before you
instantiate the dataset, and it should work.

(This is clumsy, and something that's being worked on sometime in the
medium term.)

You can also define an alias field:

    def my_ave_momentum_x(field, data):
        return data.ds.arr(data['enzo', 'AveMomtX'], 'code_mass/code_length**2*code_time')

    ds.add_field('average_momentum_x', function=my_ave_momentum_x, 
                         units= 'code_mass/code_length**2*code_time')
 
-Nathan


>
> Cheers,
>
> wolfram
>
>
> On 05.08.2017 20:14, yt-users-request@lists.spacepope.org wrote:
>>
>> Send yt-users mailing list submissions to
>>         yt-users@lists.spacepope.org
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>>         http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>> or, via email, send a message with subject or body 'help' to
>>         yt-users-request@lists.spacepope.org
>>
>> You can reach the person managing the list at
>>         yt-users-owner@lists.spacepope.org
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of yt-users digest..."
>>
>>
>> Today's Topics:
>>
>>     1. Re: problem with units when defining difference of
>>        velocity-like fields (Prateek Gupta)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Sat, 5 Aug 2017 04:48:11 +0530
>> From: Prateek Gupta <prateekgidolia@gmail.com>
>> To: Discussion of the yt analysis package
>>         <yt-users@lists.spacepope.org>
>> Subject: Re: [yt-users] problem with units when defining difference of
>>         velocity-like fields
>> Message-ID:
>>
>> <CAJcogBoDbsRseqcbuEVdKP0Z9p9LvhO_TkjHYeOgykTbQt0Phg@mail.gmail.com>
>> Content-Type: text/plain; charset="utf-8"
>>
>> I think just applying units to AveMomtX field while defining will work if
>> you derived it in yt. May be while defining a new field (AveMomtX), it
>> doesn't get units of momentum, it seems as "dimensionless" quantity.
>> But if you are taking AveMomtX as a new field from Enzo itself, after
>> modification of Enzo code, then yt required to know about this that
>> this(AveMomtX) is also the field in Enzo.
>>
>>
>> Best Regards
>> -Prateek Gupta
>>
>> On Thu, Aug 3, 2017 at 6:07 PM, Nathan Goldbaum <nathan12343@gmail.com>
>> wrote:
>>
>>> What are the units of AveMomtX right now? It seems it's getting read in
>>> as
>>> dimensionless, probably because it's not a field yt knows about. To fix
>>> this error you will need to apply units to the AveMomtX field in your
>>> field
>>> definition. If you've modified the Enzo code to add this new field to
>>> your
>>> Enzo outputs, you could also modify yt's Enzo frontend to "teach" yt
>>> about
>>> the new field you've added. See yt/frontends/enzo/fields.py, specifically
>>> the known_other_fields tuple.
>>>
>>> On Thu, Aug 3, 2017 at 3:28 AM Wolfram Schmidt <
>>> wolfram.schmidt@uni-hamburg.de> wrote:
>>>
>>>> Dear all,
>>>>
>>>> I encountered a problem when defining a the fluctuation of the velocity
>>>> with respect to a smoothed velocity as derived field in yt:
>>>>
>>>> def _fluc_velocity_x(field, data):
>>>>       return data["x-velocity"] - data["AveMomtX"]/data["density"]
>>>>
>>>> ds.add_field("fluc_velocity_x", function=_fluc_velocity_x,
>>>> force_override=True)
>>>>
>>>> Here x-velocity and density are standard baryon fields defined in Enzo
>>>> and AveMomtX is an additional baryon field for smoothed momentum.
>>>>
>>>> When I load a data dump and execute the above definition, I get the
>>>> following error:
>>>>
>>>> /lrz/sys/tools/python/2.7_anaconda_nompi/lib/python2.7/
>>>> site-packages/yt/units/yt_array.py
>>>> in sanitize_units_add(this_object, other_object, op_string)
>>>>       126     if isinstance(ret, YTArray):
>>>>       127         if not inp.units.same_dimensions_as(ret.units):
>>>> --> 128             raise YTUnitOperationError(op_string, inp.units,
>>>> ret.units)
>>>>       129         ret = ret.in_units(inp.units)
>>>>       130     # If the other object is not a YTArray, the only valid
>>>> case
>>>> is adding
>>>>
>>>> YTUnitOperationError: The subtraction operator for YTArrays with units
>>>> (code_velocity) and (code_length**3/code_mass) is not well defined.
>>>>
>>>> After looking into
>>>>
>>>> http://yt-project.org/doc/analyzing/units/fields_and_unit_conversion.html
>>>> ,
>>>> I tried
>>>>
>>>> ds.add_field("fluc_velocity_x", units="cm/s", function=_fluc_velocity_x,
>>>> force_override=True)
>>>>
>>>> but this results in the same error as before. Apparently, the problem is
>>>> that yt does not recognize that momentum divided by density is a
>>>> velocity and therefore cannot match the units to the first term
>>>> (x-velocity).
>>>>
>>>> There are unit conversion functions such as .in_cgs(), but they are not
>>>> applicable to the data objects in the above definition.
>>>>
>>>> So can anyone tell me how to fix this?
>>>>
>>>> Cheers,
>>>>
>>>> Wolfram
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>>
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>> URL:
>> <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170805/939f1676/attachment.html>
>>
>> ------------------------------
>>
>> Subject: Digest Footer
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users@lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
>> ------------------------------
>>
>> End of yt-users Digest, Vol 114, Issue 2
>> ****************************************
>
>
> --
> Dr. Wolfram Schmidt
> Head of IT, Hamburg Observatory
> Phone +49 (0)40 42838 8584
> http://www.hs.uni-hamburg.de
>
> _______________________________________________
> 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