[yt-svn] commit/yt: MatthewTurk: Change HEALpix camera to use interpolated projection sampler.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu May 30 12:14:31 PDT 2013


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/b7bdb30af6f0/
Changeset:   b7bdb30af6f0
Branch:      yt
User:        MatthewTurk
Date:        2013-05-29 22:15:08
Summary:     Change HEALpix camera to use interpolated projection sampler.

Because the partitioned grids in the HEALpix camera (in contrast to
allsky_projection) use interpolated, vertex-centered values, there was a
size-of-brick issue causing a nasty-looking bug.  This fixes that by
(as-needed) swapping to using the interpolated projection sampler.

It also adds the inner_radius (default 10dx) to avoid multipole moments when
starting in dense regions, and it removes a bit of code that duplicated logic
from the plot_allsky_projection routine.

Fixes #570 .
Affected #:  1 file

diff -r 31ee3fa3dbd2fff189ad740ba726a91979afa16d -r b7bdb30af6f0fb52125eec834cbf80322ed60ddb yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -1107,11 +1107,13 @@
     def __init__(self, center, radius, nside,
                  transfer_function = None, fields = None,
                  sub_samples = 5, log_fields = None, volume = None,
-                 pf = None, use_kd=True, no_ghost=False, use_light=False):
+                 pf = None, use_kd=True, no_ghost=False, use_light=False,
+                 inner_radius = 10):
         ParallelAnalysisInterface.__init__(self)
         if pf is not None: self.pf = pf
         self.center = np.array(center, dtype='float64')
         self.radius = radius
+        self.inner_radius = inner_radius
         self.nside = nside
         self.use_kd = use_kd
         if transfer_function is None:
@@ -1119,9 +1121,11 @@
         self.transfer_function = transfer_function
 
         if isinstance(self.transfer_function, ProjectionTransferFunction):
-            self._sampler_object = ProjectionSampler
+            self._sampler_object = InterpolatedProjectionSampler
+            self._needs_tf = 0
         else:
             self._sampler_object = VolumeRenderSampler
+            self._needs_tf = 1
 
         if fields is None: fields = ["Density"]
         self.fields = fields
@@ -1145,15 +1149,20 @@
     def get_sampler_args(self, image):
         nv = 12 * self.nside ** 2
         vs = arr_pix2vec_nest(self.nside, np.arange(nv))
-        vs *= self.radius
-        vs.shape = nv, 1, 3
+        vs.shape = (nv, 1, 3)
+        vs += 1e-8
         uv = np.ones(3, dtype='float64')
         positions = np.ones((nv, 1, 3), dtype='float64') * self.center
+        dx = min(g.dds.min() for g in self.pf.h.find_point(self.center)[0])
+        positions += self.inner_radius * dx * vs
+        vs *= self.radius
         args = (positions, vs, self.center,
                 (0.0, 1.0, 0.0, 1.0),
                 image, uv, uv,
-                np.zeros(3, dtype='float64'),
-                self.transfer_function, self.sub_samples)
+                np.zeros(3, dtype='float64'))
+        if self._needs_tf:
+            args += (self.transfer_function,)
+        args += (self.sub_samples,)
         return args
 
     def _render(self, double_check, num_threads, image, sampler):
@@ -1228,28 +1237,14 @@
     def save_image(self, image, fn=None, clim=None, label = None):
         if self.comm.rank == 0 and fn is not None:
             # This assumes Density; this is a relatively safe assumption.
-            import matplotlib.figure
-            import matplotlib.backends.backend_agg
-            phi, theta = np.mgrid[0.0:2*np.pi:800j, 0:np.pi:800j]
-            pixi = arr_ang2pix_nest(self.nside, theta.ravel(), phi.ravel())
-            image *= self.radius * self.pf['cm']
-            img = np.log10(image[:,0,0][pixi]).reshape((800,800))
-
-            fig = matplotlib.figure.Figure((10, 5))
-            ax = fig.add_subplot(1,1,1,projection='hammer')
-            implot = ax.imshow(img, extent=(-np.pi,np.pi,-np.pi/2,np.pi/2), clip_on=False, aspect=0.5)
-            cb = fig.colorbar(implot, orientation='horizontal')
-
-            if label == None:
-                cb.set_label("Projected %s" % self.fields[0])
+            if label is None:
+                label = "Projected %s" % (self.fields[0])
+            if clim is not None:
+                cmin, cmax = clim
             else:
-                cb.set_label(label)
-            if clim is not None: cb.set_clim(*clim)
-            ax.xaxis.set_ticks(())
-            ax.yaxis.set_ticks(())
-            canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
-            canvas.print_figure(fn)
-
+                cmin = cmax = None
+            plot_allsky_healpix(image[:,0,0], self.nside, fn, label, 
+                                cmin = cmin, cmax = cmax)
 
 class AdaptiveHEALpixCamera(Camera):
     def __init__(self, center, radius, nside,
@@ -2019,7 +2014,7 @@
     nv = 12*nside**2
     image = np.zeros((nv,1,4), dtype='float64', order='C')
     vs = arr_pix2vec_nest(nside, np.arange(nv))
-    vs.shape = (nv,1,3)
+    vs.shape = (nv, 1, 3)
     if rotation is not None:
         vs2 = vs.copy()
         for i in range(3):

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list