<div dir="ltr"><div>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.<br>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.<br><br><br></div><div>Best Regards<br></div>-Prateek Gupta<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 3, 2017 at 6:07 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="auto">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.</div><div><div class="h5"><br><div class="gmail_quote"><div>On Thu, Aug 3, 2017 at 3:28 AM Wolfram Schmidt <<a href="mailto:wolfram.schmidt@uni-hamburg.de" target="_blank">wolfram.schmidt@uni-hamburg.<wbr>de</a>> wrote:<br></div><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["<wbr>density"]<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_<wbr>anaconda_nompi/lib/python2.7/<wbr>site-packages/yt/units/yt_<wbr>array.py<br>
in sanitize_units_add(this_<wbr>object, other_object, op_string)<br>
     126     if isinstance(ret, YTArray):<br>
     127         if not inp.units.same_dimensions_as(<wbr>ret.units):<br>
--> 128             raise YTUnitOperationError(op_<wbr>string, 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/<wbr>analyzing/units/fields_and_<wbr>unit_conversion.html</a>,<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/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
</blockquote></div></div></div></div>
<br>______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">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/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
<br></blockquote></div><br></div>