[yt-users] Units for camera.draw_line

Sean Couch smc at tapir.caltech.edu
Mon Dec 29 15:27:22 PST 2014


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)

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 <mailto: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 <tel:%28626%29%20395-4282>
> www.tapir.caltech.edu/~smc <http://www.tapir.caltech.edu/~smc>
> 
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org <mailto:yt-users at lists.spacepope.org>
> http://lists.spacepope.org/listinfo.cgi/yt-users-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/c60b2fec/attachment.htm>
-------------- 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