[yt-users] volume rendering handedness

Michael Zingale michael.zingale at stonybrook.edu
Wed Jul 23 08:26:00 PDT 2014


I will do a PR.  I just wanted a quick sanity check.


On Wed, Jul 23, 2014 at 11:03 AM, Chris Malone <chris.m.malone at gmail.com>
wrote:

> My intuition agrees with yours, but I don't know if that change will break
> anything else.  If the VR is touched in the test suite (is it?) then maybe
> it would be best to issue a pull request.
>
>
> On Wed, Jul 23, 2014 at 8:07 AM, Michael Zingale <
> michael.zingale at stonybrook.edu> wrote:
>
>> ok, the following change makes things good for me, but I'd like others to
>> comment.
>>
>> in camera.py: show_mpl, I change the
>>
>> origin='upper'
>>
>> to
>>
>> origin='lower'
>>
>> then I set the north vector as my intuition suggests, (0,0,1) to be +z,
>> and the plot has the right orientation and handedness.
>>
>> (There is a separate issues still the sometimes using
>> draw_coordinate_vector() erases the image, but when I can get it to show,
>> it has the right handedness too).  Here's another plot from actual data
>> (uploaded to the yt data page) showing things that look right to me:
>>
>> http://bender.astro.sunysb.edu/random/xrb_vol_radvel.png
>>
>>
>>
>> On Tue, Jul 22, 2014 at 3:50 PM, Michael Zingale <
>> michael.zingale at stonybrook.edu> wrote:
>>
>>> so that swapaxes(0,1) in save_annotated is needed -- otherwise the plot
>>> is sideways.  Looks like we need a flip as well though.
>>>
>>>
>>> On Tue, Jul 22, 2014 at 12:37 PM, Nathan Goldbaum <nathan12343 at gmail.com
>>> > wrote:
>>>
>>>> Hi Mike,
>>>>
>>>> At this point, if yt isn't using a right-handed coordinate system
>>>> somewhere, it's a bug.
>>>>
>>>> If I remember correctly, save_annotated does a transpose on the image
>>>> before saving it to disk - that might be the source of one of your
>>>> workarounds?
>>>>
>>>> The orientation of volume rendering cameras is controlled via the
>>>> Orientation class.  You might want to poke around in there to see what it
>>>> does - it might be the source of the left-handedness.
>>>>
>>>> I don't think anyone has gone through in detail to make sure the volume
>>>> rendering orientation is consistent in all cases.  It would be a major help
>>>> to do that.
>>>>
>>>> -Nathan
>>>>
>>>>
>>>> On Tue, Jul 22, 2014 at 9:00 AM, Michael Zingale <
>>>> michael.zingale at stonybrook.edu> wrote:
>>>>
>>>>> I've been having trouble understanding the parameters that specify the
>>>>> orientation of the camera for volume rendering.  To help, I made a test
>>>>> dataset.  On [-1,1]^3, there is a sphere at the origin, a single cube on
>>>>> the +x axis, two cubes on the +y axis, and three cubes on the +z axis.
>>>>>  When I do a simple volume-render, I see this:
>>>>>
>>>>> http://bender.astro.sunysb.edu/random/yt-test.png
>>>>>
>>>>> Note that it looks left-handed.
>>>>>
>>>>> I've attached my script.  There are a few hacks that I needed to do
>>>>> that I don't completely understand.  In particular, if I turn on the
>>>>> coordinate_vectors, the image is blank.  I've seen this a lot.  Also, I had
>>>>> to make the north vector negative of what I would think.
>>>>>
>>>>> Mike
>>>>>
>>>>> --
>>>>>
>>>>> #!/usr/bin/env python
>>>>>
>>>>> import matplotlib
>>>>> matplotlib.use('agg')
>>>>>
>>>>> # this example comes from
>>>>> # http://yt-project.org/doc/visualizing/volume_rendering.html
>>>>>
>>>>> import math
>>>>> import sys
>>>>> import pylab
>>>>>
>>>>> from yt.mods import *
>>>>> import yt.visualization.volume_rendering.api as vr
>>>>>
>>>>> def doit(plotfile):
>>>>>
>>>>>     ds = load(plotfile)
>>>>>
>>>>>     cm = "gist_rainbow"
>>>>>
>>>>>
>>>>>     field = ('gas', 'density')
>>>>>     use_log = False
>>>>>     vals = [0.1, 1]
>>>>>     sigma = 0.1
>>>>>
>>>>>     dd = ds.h.all_data()
>>>>>
>>>>>     ds.field_info[field].take_log = use_log
>>>>>
>>>>>
>>>>>     mi = min(vals)
>>>>>     ma = max(vals)
>>>>>
>>>>>     if use_log:
>>>>>         mi, ma = np.log10(mi), np.log10(ma)
>>>>>
>>>>>
>>>>>     # Instantiate the ColorTransferfunction.
>>>>>     tf =  vr.ColorTransferFunction((mi, ma))
>>>>>
>>>>>     # Set up the camera parameters: center, looking direction, width,
>>>>> resolution
>>>>>     c = np.array([0.0, 0.0, 0.0])
>>>>>     L = np.array([1.0, 1.0, 1.0])
>>>>>     L = np.array([1.0, 1.0, 1.2])
>>>>>     W = 1.5*ds.domain_width
>>>>>     N = 720
>>>>>
>>>>>     north=[0.0,0.0,-1.0]
>>>>>
>>>>>     for v in vals:
>>>>>         if (use_log):
>>>>>             tf.sample_colormap(math.log10(v), sigma**2, colormap=cm)
>>>>> #, alpha=0.2)
>>>>>         else:
>>>>>             tf.sample_colormap(v, sigma**2, colormap=cm) #, alpha=0.2)
>>>>>
>>>>>
>>>>>     # alternate attempt
>>>>>     ds.periodicity = (True, True, True)
>>>>>
>>>>>     # Create a camera object
>>>>>     cam = vr.Camera(c, L, W, N, transfer_function=tf, ds=ds,
>>>>>                     no_ghost=False, #data_source=reg,
>>>>>                     north_vector=north,
>>>>>                     fields = [field], log_fields = [use_log])
>>>>>
>>>>>     #cam.rotate(3.0*np.pi/2., rot_vector=rot_vector)
>>>>>
>>>>>
>>>>>     # make an image
>>>>>     im = cam.snapshot()
>>>>>
>>>>>
>>>>>     # add an axes triad -- note if we do this, we HAVE to do draw
>>>>>     # domain, otherwise the image is blank (likely a bug)
>>>>>     #cam.draw_coordinate_vectors(im)
>>>>>
>>>>>     # add the domain box to the image:
>>>>>     nim = cam.draw_domain(im)
>>>>>
>>>>>     # increase the contrast -- for some reason, the enhance default
>>>>>     # to save_annotated doesn't do the trick (likely a bug)
>>>>>     max_val = im[:,:,:3].std() * 4.0
>>>>>     nim[:,:,:3] /= max_val
>>>>>
>>>>>     f = pylab.figure()
>>>>>
>>>>>     pylab.text(0.2, 0.85, "{:.3g} s".format(float(ds.current_time.d)),
>>>>>                transform=f.transFigure, color="white")
>>>>>
>>>>>     cam._render_figure = f
>>>>>
>>>>>     # save annotated -- this added the transfer function values,
>>>>>     # but this messes up our image size defined above
>>>>>     cam.save_annotated("yt-test.png", nim,
>>>>>                        dpi=145, clear_fig=False)
>>>>>
>>>>>
>>>>>
>>>>> if __name__ == "__main__":
>>>>>
>>>>>     # Choose a field
>>>>>     plotfile = ""
>>>>>
>>>>>
>>>>>     try: plotfile = sys.argv[1]
>>>>>     except: sys.exit("ERROR: no plotfile specified")
>>>>>
>>>>>     doit(plotfile)
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Michael Zingale
>>>>> Associate Professor
>>>>>
>>>>> Dept. of Physics & Astronomy • Stony Brook University • Stony Brook,
>>>>> NY 11794-3800
>>>>> *phone*:  631-632-8225
>>>>> *e-mail*: Michael.Zingale at stonybrook.edu
>>>>> *web*: http://www.astro.sunysb.edu/mzingale
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>>
>>>>
>>>
>>>
>>> --
>>> Michael Zingale
>>> Associate Professor
>>>
>>> Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
>>> 11794-3800
>>> *phone*:  631-632-8225
>>> *e-mail*: Michael.Zingale at stonybrook.edu
>>> *web*: http://www.astro.sunysb.edu/mzingale
>>>
>>
>>
>>
>> --
>> Michael Zingale
>> Associate Professor
>>
>> Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
>> 11794-3800
>> *phone*:  631-632-8225
>> *e-mail*: Michael.Zingale at stonybrook.edu
>> *web*: http://www.astro.sunysb.edu/mzingale
>>
>> _______________________________________________
>> 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
>
>


-- 
Michael Zingale
Associate Professor

Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
11794-3800
*phone*:  631-632-8225
*e-mail*: Michael.Zingale at stonybrook.edu
*web*: http://www.astro.sunysb.edu/mzingale
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140723/53468c75/attachment.htm>


More information about the yt-users mailing list