Repository: yt-project/yt

Issue:
VR Multiple Fields
**Bug summary**

 I'm trying to plot two fields at once by adding them independently as VolumeSources, but when I render the image they seem flipped relative to one another on the x-axis. Everything seems fine when I plot the fields as slices, so it's something going on in the volume rendering.

**Code for reproduction**

Script: https://pastebin.com/ci3u68C9
Data: http://use.yt/upload/1ca4b2cd

**Actual outcome**

http://imgur.com/a/JeFkN

**Expected outcome**
Same plots, but the volume rendering isn't flipping the H+ relative to the O2+

**Version Information**
yt 3.3.5 installed via pip




Discussion:

Resolving patch:
diff --git a/yt/visualization/volume_rendering/render_source.py b/yt/visualization/volume_rendering/render_source.py
--- a/yt/visualization/volume_rendering/render_source.py
+++ b/yt/visualization/volume_rendering/render_source.py
@@ -444,16 +444,17 @@ def render(self, camera, zbuffer=None):
             self.sampler(brick, num_threads=self.num_threads)
             total_cells += np.prod(brick.my_data[0].shape)
         mylog.debug("Done casting rays")
+        self.current_image = self.finalize_image(
+            camera, self.sampler.aimage)
 
-        self.current_image = self.finalize_image(camera,
-                                                 self.sampler.aimage,
-                                                 call_from_VR=True)
         if zbuffer is None:
-            self.zbuffer = ZBuffer(self.current_image,
-                                   np.full(self.current_image.shape[:2], np.inf))
+            self.zbuffer = ZBuffer(
+                self.current_image,
+                np.full(self.current_image.shape[:2], np.inf))
+
         return self.current_image
 
-    def finalize_image(self, camera, image, call_from_VR=False):
+    def finalize_image(self, camera, image):
         """Parallel reduce the image.
 
         Parameters
@@ -462,17 +463,12 @@ def finalize_image(self, camera, image, call_from_VR=False):
             The camera used to produce the volume rendering image.
         image: :class:`yt.data_objects.image_array.ImageArray` instance
             A reference to an image to fill
-        call_from_vr: boolean, optional
-            Whether or not this is being called from a higher level in the VR
-            interface. Used to set the correct orientation.
         """
         if self._volume is not None:
             image = self.volume.reduce_tree_images(image, camera.lens.viewpoint)
         image.shape = camera.resolution[0], camera.resolution[1], 4
         # If the call is from VR, the image is rotated by 180 to get correct
         # up direction
-        if call_from_VR is True:
-            image = np.rot90(image, k=2)
         if self.transfer_function.grey_opacity is False:
             image[:, :, 3] = 1
         return image
@@ -712,6 +708,7 @@ def render(self, camera, zbuffer=None):
 
         return self.current_image
 
+
     def finalize_image(self, camera):
         sam = self.sampler
 
@@ -720,11 +717,6 @@ def finalize_image(self, camera):
         Ny = camera.resolution[1]
         self.data = sam.aimage[:,:,0].reshape(Nx, Ny)
 
-        # rotate
-        self.data = np.rot90(self.data, k=2)
-        sam.aimage_used = np.rot90(sam.aimage_used, k=2)
-        sam.amesh_lines = np.rot90(sam.amesh_lines, k=2)
-        sam.azbuffer = np.rot90(sam.azbuffer, k=2)
 
     def annotate_mesh_lines(self, color=None, alpha=1.0):
         r"""
diff --git a/yt/visualization/volume_rendering/scene.py b/yt/visualization/volume_rendering/scene.py
--- a/yt/visualization/volume_rendering/scene.py
+++ b/yt/visualization/volume_rendering/scene.py
@@ -501,7 +501,9 @@ def composite(self, camera=None):
             im = source.render(camera, zbuffer=opaque)
             opaque.rgba = im
 
-        return im
+        # rotate image 180 degrees so orientation agrees with e.g.
+        # a PlotWindow plot
+        return np.rot90(im, k=2)
 
     def add_camera(self, data_source=None, lens_type='plane-parallel',
                    auto=False):


Test patch: