<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Everyone,<div class=""><br class=""></div><div class="">Nathan — thank you very much for that detailed explanation. </div><div class=""><br class=""></div><div class="">I like Cameron’s idea of having a force override — much of the code I write isn’t “good” so much as debugging and checking. For that, user checks impede more than help since speed-writing is what I’m after.</div><div class=""><br class=""></div><div class="">Elizabeth</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 25 Nov 2015, at 10:23, Cameron Hummels <<a href="mailto:chummels@gmail.com" class="">chummels@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I guess what I meant to ask was if the code I put was a solution to the problem, not an example of the problem?</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Nov 24, 2015 at 11:56 AM, Kacper Kowalik <span dir="ltr" class=""><<a href="mailto:xarthisius.kk@gmail.com" target="_blank" class="">xarthisius.kk@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 11/24/2015 12:33 PM, Cameron Hummels wrote:<br class="">
> On Tue, Nov 24, 2015 at 9:10 AM, Kacper Kowalik <<a href="mailto:xarthisius.kk@gmail.com" class="">xarthisius.kk@gmail.com</a>><br class="">
> wrote:<br class="">
>><br class="">
>><br class="">
>> I'd be strongly -1 on "force_units". In that scenario you invoke several<br class="">
>> costly calls to sympy just to disregard the result. IMO you should drop<br class="">
>> units at the very beginning and create YTArray during return in the<br class="">
>> derived field's definition.<br class="">
>><br class="">
><br class="">
> By this you mean something like:<br class="">
><br class="">
> def _temperature(field, data):<br class="">
>     tr = array_of_wrong_units<br class="">
>     data.apply_units(tr, 'K')<br class="">
>     return tr<br class="">
><br class="">
> ds.add_field('temperature', function=_temperature, units='K')<br class="">
<br class="">
</span>Nope, if you change units of the array that's cheap (I think), but when<br class="">
you do:<br class="">
<br class="">
def _temp(field, data):<br class="">
    temp = data["foo"] * constant1 * constant2<br class="">
    return temp<br class="">
<br class="">
only to disregard units, that's a huge waste of cycles.<br class="">
Cheers,<br class="">
Kacper<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
> ?<br class="">
><br class="">
> Or is the syntax wrong here?  I'm not really sure how to use this.<br class="">
><br class="">
><br class="">
><br class="">
><br class="">
>> Cheers,<br class="">
>> Kacper<br class="">
>><br class="">
>>> On Tue, Nov 24, 2015 at 7:32 AM, Matthew Turk <<a href="mailto:matthewturk@gmail.com" class="">matthewturk@gmail.com</a>><br class="">
>> wrote:<br class="">
>>><br class="">
>>>> If absolutely necessary, you can "force" units with:<br class="">
>>>><br class="">
>>>> data.apply_units(array_to_override, unit_string)<br class="">
>>>><br class="">
>>>> On Tue, Nov 24, 2015 at 9:31 AM, Cameron Hummels <<a href="mailto:chummels@gmail.com" class="">chummels@gmail.com</a>><br class="">
>>>> wrote:<br class="">
>>>>> I would be a fan of making a "force_units" kwarg to enable one to<br class="">
>> create<br class="">
>>>> a<br class="">
>>>>> new field with different units than those specified.  This could<br class="">
>> resolve<br class="">
>>>>> some of the problems with native frontend fields being stuck in the<br class="">
>> wrong<br class="">
>>>>> unit, like I was running into last week.  As long as force_unit is off<br class="">
>> by<br class="">
>>>>> default, it would just enable us to give full control to the user.<br class="">
>>>>><br class="">
>>>>> On Tue, Nov 24, 2015 at 4:25 AM, Nathan Goldbaum <<br class="">
>> <a href="mailto:nathan12343@gmail.com" class="">nathan12343@gmail.com</a>><br class="">
>>>>> wrote:<br class="">
>>>>>><br class="">
>>>>>> Hi Elizabeth,<br class="">
>>>>>><br class="">
>>>>>> This is discussed in the docs here:<br class="">
>>>>>><br class="">
>>>>>><br class="">
>>>>>><br class="">
>>>><br class="">
>> <a href="http://yt-project.org/doc/developing/creating_derived_fields.html#defining-a-new-field" rel="noreferrer" target="_blank" class="">http://yt-project.org/doc/developing/creating_derived_fields.html#defining-a-new-field</a><br class="">
>>>>>><br class="">
>>>>>> You can do one of two things. First, the way I'd handle this is to<br class="">
>>>> ensure<br class="">
>>>>>> that your field definition is returning data that have units of<br class="">
>> Kelvin.<br class="">
>>>>>><br class="">
>>>>>> For example, something like:<br class="">
>>>>>><br class="">
>>>>>>     from yt.utilities.physical_constants import kb, mh<br class="">
>>>>>><br class="">
>>>>>>     mu = 0.6<br class="">
>>>>>><br class="">
>>>>>>     @derived_field(name=‘Temp’, units=“K”)<br class="">
>>>>>>     def _Temp(field, data):<br class="">
>>>>>>         return data['thermal_energy'] / kb * mu * mh<br class="">
>>>>>><br class="">
>>>>>> You could also make mu a field parameter rather than a constant, or if<br class="">
>>>> you<br class="">
>>>>>> have a simulation where mu varies with position, make a mean molecular<br class="">
>>>>>> weight derived field.<br class="">
>>>>>><br class="">
>>>>>> You can also ensure that your field definition returning a<br class="">
>> dimensionless<br class="">
>>>>>> value by stripping the units:<br class="">
>>>>>><br class="">
>>>>>>     @derived_field(name=‘Temp’, units=“K”)<br class="">
>>>>>>     def _Temp(field, data):<br class="">
>>>>>>         ret = data['thermal_energy'])<br class="">
>>>>>>         return ret.ndarray_view()<br class="">
>>>>>><br class="">
>>>>>> We don't currently have a way to *force* the units to be whatever you<br class="">
>>>>>> specify in add_field. That said, I don't think it would be terribly<br class="">
>>>> hard to<br class="">
>>>>>> implement.<br class="">
>>>>>><br class="">
>>>>>> We already have units='auto', which forces the units to be the same as<br class="">
>>>> the<br class="">
>>>>>> return value of your field function. We might add a keyword<br class="">
>>>>>> 'force_units=True' to add_field which does what you're looking for.<br class="">
>> I'd<br class="">
>>>> be<br class="">
>>>>>> happy to review a pull request adding this, or feel free to open an<br class="">
>>>> issue<br class="">
>>>>>> about it to add to our project backlog.<br class="">
>>>>>><br class="">
>>>>>> Also, worth pointing out that this was designed this way not to anger<br class="">
>>>>>> users, but to protect them from making mistakes in their field units,<br class="">
>>>> which<br class="">
>>>>>> we found to be a common cause of bugs in yt-2. It does mean you need<br class="">
>> to<br class="">
>>>> "buy<br class="">
>>>>>> into" the unit system in your field definition, but the bonus is that<br class="">
>>>> you<br class="">
>>>>>> can be much more sure that you're not making a mistake.<br class="">
>>>>>><br class="">
>>>>>> Hope that helps,<br class="">
>>>>>><br class="">
>>>>>> Nathan<br class="">
>>>>>><br class="">
>>>>>> On Tue, Nov 24, 2015 at 12:41 AM, Elizabeth Tasker<br class="">
>>>>>> <<a href="mailto:tasker@astro1.sci.hokudai.ac.jp" class="">tasker@astro1.sci.hokudai.ac.jp</a>> wrote:<br class="">
>>>>>>><br class="">
>>>>>>> Hi everyone,<br class="">
>>>>>>><br class="">
>>>>>>> While using yt-3, I created a derived field:<br class="">
>>>>>>><br class="">
>>>>>>> @derived_field(name=‘Temp’, units=“K”)<br class="">
>>>>>>> def _Temp …..<br class="">
>>>>>>><br class="">
>>>>>>> It crashes with a YTFieldUnitError because it believes the units<br class="">
>> should<br class="">
>>>>>>> be cm**2/s**2. I understand why yt thinks this — I’m using<br class="">
>>>> thermal_energy in<br class="">
>>>>>>> the definition for Temp. However, the units are truly Kelvin and I<br class="">
>>>> think I<br class="">
>>>>>>> should be able to specify whatever I like in “units”!<br class="">
>>>>>>><br class="">
>>>>>>> Is there a way to stop yt crashing when it disagrees with your life<br class="">
>>>>>>> choices?<br class="">
>>>>>>><br class="">
>>>>>>> Elizabeth<br class="">
>>>>>>> _______________________________________________<br class="">
>>>>>>> yt-users mailing list<br class="">
>>>>>>> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
>>>>>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
>>>>>><br class="">
>>>>>><br class="">
>>>>>><br class="">
>>>>>> _______________________________________________<br class="">
>>>>>> yt-users mailing list<br class="">
>>>>>> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
>>>>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
>>>>>><br class="">
>>>>><br class="">
>>>>><br class="">
>>>>><br class="">
>>>>> --<br class="">
>>>>> Cameron Hummels<br class="">
>>>>> NSF Postdoctoral Fellow<br class="">
>>>>> Department of Astronomy<br class="">
>>>>> California Institute of Technology<br class="">
>>>>> <a href="http://chummels.org/" rel="noreferrer" target="_blank" class="">http://chummels.org</a><br class="">
>>>>><br class="">
>>>>> _______________________________________________<br class="">
>>>>> yt-users mailing list<br class="">
>>>>> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
>>>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
>>>>><br class="">
>>>> _______________________________________________<br class="">
>>>> yt-users mailing list<br class="">
>>>> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
>>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
>>>><br class="">
>>><br class="">
>>><br class="">
>>><br class="">
>>><br class="">
>>><br class="">
>>> _______________________________________________<br class="">
>>> yt-users mailing list<br class="">
>>> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
>>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
>>><br class="">
>><br class="">
>><br class="">
>><br class="">
>> _______________________________________________<br class="">
>> yt-users mailing list<br class="">
>> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
>> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
>><br class="">
>><br class="">
><br class="">
><br class="">
><br class="">
><br class="">
> _______________________________________________<br class="">
> yt-users mailing list<br class="">
> <a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
><br class="">
<br class="">
<br class="">
</div></div><br class="">_______________________________________________<br class="">
yt-users mailing list<br class="">
<a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">Cameron Hummels<div class=""><span style="font-size:12.8000001907349px" class="">NSF Postdoctoral Fellow</span></div><div class=""><span style="font-size:12.8000001907349px" class="">Department of Astronomy</span></div><div class=""><span style="font-size:12.8000001907349px" class="">California Institute of Technology</span><br class=""></div><div class=""><a href="http://chummels.org/" style="font-size:12.8000001907349px" target="_blank" class="">http://chummels.org</a><br class=""></div></div></div></div>
</div>
_______________________________________________<br class="">yt-users mailing list<br class=""><a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org<br class=""></div></blockquote></div><br class=""></div></body></html>