<div dir="ltr"><div><div><div><div>I think it is possible to define units to new field (AveMomtX) and for simply achieving it, you have to derive an another new field in yt in which you can give units to your field (AveMomtX) by simply multiply AveMomtX field with momentum units, but for correctness in doing so, you should know first about the value of AveMomtX field that whether it's value taken in yt in code_units or in some other momentum units (c.g.s or m.k.s), although it seems in dimensionless (units). I think Enzo fields are possibly in code_units.<br><br></div>According to my opinion, it is possible to give units at least for an urgent requirement.<br><br></div>Wait for Nathan's comment on this.<br><br><br></div>Best Regards<br></div>-Prateek Gupta<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 8, 2017 at 8:41 PM, Wolfram Schmidt <span dir="ltr"><<a href="mailto:wolfram.schmidt@uni-hamburg.de" target="_blank">wolfram.schmidt@uni-hamburg.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Nathan, hi Prateek,<br>
<br>
before I look into the frontend and try to modify it, I wonder:<br>
<br>
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)?<br>
<br>
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?<br>
<br>
Cheers,<br>
<br>
wolfram<br>
<br>
<br>
On 05.08.2017 20:14, <a href="mailto:yt-users-request@lists.spacepope.org" target="_blank">yt-users-request@lists.spacepo<wbr>pe.org</a> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Send yt-users mailing list submissions to<br>
        <a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/lis<wbr>tinfo.cgi/yt-users-spacepope.<wbr>org</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:yt-users-request@lists.spacepope.org" target="_blank">yt-users-request@lists.spacepo<wbr>pe.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:yt-users-owner@lists.spacepope.org" target="_blank">yt-users-owner@lists.spacepope<wbr>.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of yt-users digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
    1. Re: problem with units when defining difference of<br>
       velocity-like fields (Prateek Gupta)<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Sat, 5 Aug 2017 04:48:11 +0530<br>
From: Prateek Gupta <<a href="mailto:prateekgidolia@gmail.com" target="_blank">prateekgidolia@gmail.com</a>><br>
To: Discussion of the yt analysis package<br>
        <<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a>><br>
Subject: Re: [yt-users] problem with units when defining difference of<br>
        velocity-like fields<br>
Message-ID:<br>
        <<a href="mailto:CAJcogBoDbsRseqcbuEVdKP0Z9p9LvhO_TkjHYeOgykTbQt0Phg@mail.gmail.com" target="_blank">CAJcogBoDbsRseqcbuEVdKP0Z9p9L<wbr>vhO_TkjHYeOgykTbQt0Phg@mail.gm<wbr>ail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
I think just applying units to AveMomtX field while defining will work if<br>
you derived it in yt. May be while defining a new field (AveMomtX), it<br>
doesn't get units of momentum, it seems as "dimensionless" quantity.<br>
But if you are taking AveMomtX as a new field from Enzo itself, after<br>
modification of Enzo code, then yt required to know about this that<br>
this(AveMomtX) is also the field in Enzo.<br>
<br>
<br>
Best Regards<br>
-Prateek Gupta<br>
<br>
On Thu, Aug 3, 2017 at 6:07 PM, Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>><br>
wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
What are the units of AveMomtX right now? It seems it's getting read in as<br>
dimensionless, probably because it's not a field yt knows about. To fix<br>
this error you will need to apply units to the AveMomtX field in your field<br>
definition. If you've modified the Enzo code to add this new field to your<br>
Enzo outputs, you could also modify yt's Enzo frontend to "teach" yt about<br>
the new field you've added. See yt/frontends/enzo/fields.py, specifically<br>
the known_other_fields tuple.<br>
<br>
On Thu, Aug 3, 2017 at 3:28 AM Wolfram Schmidt <<br>
<a href="mailto:wolfram.schmidt@uni-hamburg.de" target="_blank">wolfram.schmidt@uni-hamburg.de</a><wbr>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all,<br>
<br>
I encountered a problem when defining a the fluctuation of the velocity<br>
with respect to a smoothed velocity as derived field in yt:<br>
<br>
def _fluc_velocity_x(field, data):<br>
      return data["x-velocity"] - data["AveMomtX"]/data["density<wbr>"]<br>
<br>
ds.add_field("fluc_velocity_x"<wbr>, function=_fluc_velocity_x,<br>
force_override=True)<br>
<br>
Here x-velocity and density are standard baryon fields defined in Enzo<br>
and AveMomtX is an additional baryon field for smoothed momentum.<br>
<br>
When I load a data dump and execute the above definition, I get the<br>
following error:<br>
<br>
/lrz/sys/tools/python/2.7_anac<wbr>onda_nompi/lib/python2.7/<br>
site-packages/yt/units/yt_arra<wbr>y.py<br>
in sanitize_units_add(this_object<wbr>, other_object, op_string)<br>
      126     if isinstance(ret, YTArray):<br>
      127         if not inp.units.same_dimensions_as(r<wbr>et.units):<br>
--> 128             raise YTUnitOperationError(op_string<wbr>, inp.units,<br>
ret.units)<br>
      129         ret = ret.in_units(inp.units)<br>
      130     # If the other object is not a YTArray, the only valid case<br>
is adding<br>
<br>
YTUnitOperationError: The subtraction operator for YTArrays with units<br>
(code_velocity) and (code_length**3/code_mass) is not well defined.<br>
<br>
After looking into<br>
<a href="http://yt-project.org/doc/analyzing/units/fields_and_unit_conversion.html" rel="noreferrer" target="_blank">http://yt-project.org/doc/anal<wbr>yzing/units/fields_and_unit_<wbr>conversion.html</a><br>
,<br>
I tried<br>
<br>
ds.add_field("fluc_velocity_x"<wbr>, units="cm/s", function=_fluc_velocity_x,<br>
force_override=True)<br>
<br>
but this results in the same error as before. Apparently, the problem is<br>
that yt does not recognize that momentum divided by density is a<br>
velocity and therefore cannot match the units to the first term<br>
(x-velocity).<br>
<br>
There are unit conversion functions such as .in_cgs(), but they are not<br>
applicable to the data objects in the above definition.<br>
<br>
So can anyone tell me how to fix this?<br>
<br>
Cheers,<br>
<br>
Wolfram<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/lis<wbr>tinfo.cgi/yt-users-spacepope.<wbr>org</a><br>
<br>
</blockquote>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/lis<wbr>tinfo.cgi/yt-users-spacepope.<wbr>org</a><br>
<br>
<br>
</blockquote>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170805/939f1676/attachment.html" rel="noreferrer" target="_blank">http://lists.spacepope.org/pi<wbr>permail/yt-users-spacepope.org<wbr>/attachments/20170805/939f1676<wbr>/attachment.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/lis<wbr>tinfo.cgi/yt-users-spacepope.<wbr>org</a><br>
<br>
<br>
------------------------------<br>
<br>
End of yt-users Digest, Vol 114, Issue 2<br>
******************************<wbr>**********<span class="HOEnZb"><font color="#888888"><br>
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Dr. Wolfram Schmidt<br>
Head of IT, Hamburg Observatory<br>
Phone +49 (0)40 42838 8584<br>
<a href="http://www.hs.uni-hamburg.de" rel="noreferrer" target="_blank">http://www.hs.uni-hamburg.de</a><br>
<br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/lis<wbr>tinfo.cgi/yt-users-spacepope.<wbr>org</a><br>
</font></span></blockquote></div><br></div>