<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 8, 2017 at 10:21 AM, Matthew Turk <span dir="ltr"><<a href="mailto:matthewturk@gmail.com" target="_blank">matthewturk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Wolfram,<br>
<span class="gmail-"><br>
On Tue, Aug 8, 2017 at 10:11 AM, Wolfram Schmidt<br>
<<a href="mailto:wolfram.schmidt@uni-hamburg.de">wolfram.schmidt@uni-hamburg.<wbr>de</a>> wrote:<br>
> 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<br>
> units conversion factors for certain quantities in Enzo, but I don't now if<br>
> this somehow enters the data dumps)?<br>
<br>
</span>If you add them, it at leased *used* to be the case that yt would<br>
parse them.  I think this is no longer the case, however.<br>
<span class="gmail-"><br>
><br>
> 2. Could I "teach" yt to assume certain units for a field which it<br>
> interprets as dimensionless on the fly, i.e. in a python session? If so,<br>
> how?<br>
<br>
</span>You can do this in a couple ways; if it's in the output file on disk,<br>
you can do it by appending to the object EnzoFieldInfo (which is<br>
accessible through the yt.frontends.enzo.api module)'s attribute<br>
_known_fluid_fields.  This takes a tuple.  Do this before you<br>
instantiate the dataset, and it should work.<br>
<br>
(This is clumsy, and something that's being worked on sometime in the<br>
medium term.)<br></blockquote><div><br></div><div>You can also define an alias field:</div><div><br></div><div>    def my_ave_momentum_x(field, data):</div><div>        return data.ds.arr(data['enzo', 'AveMomtX'], 'code_mass/code_length**2*code_time')</div><div><br></div><div>    ds.add_field('average_momentum_x', function=my_ave_momentum_x, </div><div>                         units= 'code_mass/code_length**2*code_time')</div><div> </div><div>-Nathan</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
><br>
> Cheers,<br>
><br>
> wolfram<br>
><br>
><br>
> On 05.08.2017 20:14, <a href="mailto:yt-users-request@lists.spacepope.org">yt-users-request@lists.<wbr>spacepope.org</a> wrote:<br>
>><br>
>> Send yt-users mailing list submissions to<br>
>>         <a href="mailto:yt-users@lists.spacepope.org">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/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.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">yt-users-request@lists.<wbr>spacepope.org</a><br>
>><br>
>> You can reach the person managing the list at<br>
>>         <a href="mailto:yt-users-owner@lists.spacepope.org">yt-users-owner@lists.<wbr>spacepope.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">prateekgidolia@gmail.com</a>><br>
>> To: Discussion of the yt analysis package<br>
>>         <<a href="mailto:yt-users@lists.spacepope.org">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>
>><br>
>> <<a href="mailto:CAJcogBoDbsRseqcbuEVdKP0Z9p9LvhO_TkjHYeOgykTbQt0Phg@mail.gmail.com">CAJcogBoDbsRseqcbuEVdKP0Z9p9L<wbr>vhO_TkjHYeOgykTbQt0Phg@mail.<wbr>gmail.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">nathan12343@gmail.com</a>><br>
>> wrote:<br>
>><br>
>>> What are the units of AveMomtX right now? It seems it's getting read in<br>
>>> 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<br>
>>> field<br>
>>> definition. If you've modified the Enzo code to add this new field to<br>
>>> your<br>
>>> Enzo outputs, you could also modify yt's Enzo frontend to "teach" yt<br>
>>> 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">wolfram.schmidt@uni-hamburg.de</a><wbr>> wrote:<br>
>>><br>
>>>> 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/<br>
>>>> 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<br>
>>>> 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>
>>>><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>
>>>> ,<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">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>
>>> ______________________________<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>
>>><br>
>> -------------- next part --------------<br>
>> An HTML attachment was scrubbed...<br>
>> URL:<br>
>> <<a href="http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20170805/939f1676/attachment.html" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>pipermail/yt-users-spacepope.<wbr>org/attachments/20170805/<wbr>939f1676/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">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>
>><br>
>> ------------------------------<br>
>><br>
>> End of yt-users Digest, Vol 114, Issue 2<br>
>> ******************************<wbr>**********<br>
><br>
><br>
> --<br>
> Dr. Wolfram Schmidt<br>
> Head of IT, Hamburg Observatory<br>
> Phone <a href="tel:%2B49%20%280%2940%2042838%208584" value="+4940428388584">+49 (0)40 42838 8584</a><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">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>
______________________________<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>
</div></div></blockquote></div><br></div></div>