[yt-users] Units for camera.draw_line

Nathan Goldbaum nathan12343 at gmail.com
Mon Dec 29 16:24:10 PST 2014


On Mon, Dec 29, 2014 at 3:27 PM, Sean Couch <smc at tapir.caltech.edu> wrote:

> Hi Nathan,
>
> Thanks!  That seems to have fixed the units problem, but another has
> cropped up.  I’m guessing this is related to draw_lines not being fully
> updated to yt 3.0:
>
> Traceback (most recent call last):
>   File "render_radv.py", line 53, in <module>
>     cam.draw_line(im, [2e8,0.,0.]*ds.length_unit,
> [0.,2e8,0.]*ds.length_unit)
>   File
> "/work/00863/smc/yt-x86_64/src/yt-hg/yt/visualization/volume_rendering/camera.py",
> line 426, in draw_lin\
> e
>     lines(im, np.array([px0,px1]), np.array([py0,py1]),
> color=np.array([color,color]),flip=1)
>   File "misc_utilities.pyx", line 215, in
> yt.utilities.lib.misc_utilities.lines (yt/utilities/lib/misc_utilitie\
> s.c:4877)
>
>
Yeah, it looks like it's not calling the lines() function correctly. I was
able to reproduce this on my laptop and have issued a pull request to fix
it, along with the issue you originally noticed with the draw_line
function.  The reason why this was never updated is that there aren't any
tests for this function. To head off breakage in the future, I've also
added a quick test for these functions.

https://bitbucket.org/yt_analysis/yt/pull-request/1380/fixing-issues-with-the-draw_line-function/diff

You can test that locally by pulling in the changes to your local copy of
the yt mercurial repository:

$ hg pull -r 2596e9f https://bitbucket.org/ngoldbaum/yt
$ hg update 2596e9f
$ python setup.py develop

You might see an error on the hg update step if you've made local changes.
You can save any local changes you've made with "hg shelve" or just delete
them with "hg update -C  2596e9f".

If you could leave a comment saying whether or not this fixes your issue on
the pull request, that would be great.

-Nathan


> I’m looking into the source code now, but I thought you might have an idea
> straightaway.
>
> Sean
>
>
> On Dec 29, 2014, at 2:22 PM, Nathan Goldbaum <nathan12343 at gmail.com>
> wrote:
>
> Hi Sean,
>
> Can you try again with:
>
> cam.draw_line(im, [2e8,0.,0.]*ds.length_unit, [0.,2e8,0.]*ds.length_unit)
>
> It looks like this function was never properly updated for yt-3.0.  What's
> happening is that the camera's origin vector is a YTArray, but the second
> and third argument of the draw_line function are specified in that
> function's docstrings as ndarrays.  When the draw_line function tries to
> compute the difference between camera.origin and [2e8, 0, 0], it throws a
> unit error (as it should) since camera.origin has units of code_length
> (which is the same as centimeters for your FLASH simulation), but x0 is
> unitless.
>
> We should probably add some code to the draw_line function so that if a
> user passes in a list or ndarray rather than a YTArray, we cast x0 and x1
> to be YTArrays in code_length units.  This would be a super simple initial
> contribution to yt, if you're up for it.
>
> -Nathan
>
> On Mon, Dec 29, 2014 at 2:07 PM, Sean Couch <smc at tapir.caltech.edu> wrote:
>
>> Hi yt-users,
>>
>> Newb question:  I’m trying to draw a line on my volume render of some
>> FLASH data using camera.draw_line but I’m getting an error.  My guess is
>> that it is something to do with units, but I can’t figure out how to fix
>> what I’m doing.  I’m assuming that draw_line using code units, which for
>> FLASH should be cgs.  Here is my code snippet:
>>
>>
>> cam = ds.camera(c, L, W, N, transfer_function=tf, ds=ds, no_ghost=True,
>>                 fields=field, log_fields=[False])
>> im = cam.snapshot()
>>
>> cam.draw_coordinate_vectors(im)
>> cam.draw_domain(im)
>> cam.draw_line(im, [2e8,0.,0.], [0.,2e8,0.])
>>
>> And here is the error I get when I run it:
>>
>> Traceback (most recent call last):
>>   File "render_radv.py", line 53, in <module>
>>     cam.draw_line(im, [2e8,0.,0.], [0.,2e8,0.])
>>   File
>> "/work/00863/smc/yt-x86_64/src/yt-hg/yt/visualization/volume_rendering/camera.py",
>> line 415, in draw_lin\
>> e
>>     dx0 = ((x0-self.origin)*self.orienter.unit_vectors[1]).sum()
>>   File "/work/00863/smc/yt-x86_64/src/yt-hg/yt/units/yt_array.py", line
>> 716, in __rsub__
>>     lo = sanitize_units_add(self, left_object, "subtraction")
>>   File "/work/00863/smc/yt-x86_64/src/yt-hg/yt/units/yt_array.py", line
>> 134, in sanitize_units_add
>>     raise YTUnitOperationError(op_string, inp.units, dimensionless)
>> yt.utilities.exceptions.YTUnitOperationError: The subtraction operator
>> for YTArrays with units (code_length) an\
>> d (1) is not well defined.
>>
>> Any help or guidance would be much appreciated!
>>
>> Thanks,
>> Sean
>>
>>
>>
>> -----------------------------------------------------------
>> Sean M. Couch
>> Theoretical Astrophysics Including Relativity
>> California Institute of Technology
>> Mail Code 350-17
>> Pasadena, CA  91125
>> (626) 395-4282
>> www.tapir.caltech.edu/~smc
>>
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
>
> _______________________________________________
> yt-users mailing list
> yt-users at 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/20141229/baf4ba46/attachment.html>
-------------- next part --------------
_______________________________________________
yt-users mailing list
yt-users at lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org


More information about the yt-users mailing list