[yt-svn] commit/yt: ngoldbaum: Merged in MatthewTurk/yt (pull request #1959)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Jan 27 09:13:44 PST 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/29b4b633e951/
Changeset:   29b4b633e951
Branch:      yt
User:        ngoldbaum
Date:        2016-01-27 17:13:36+00:00
Summary:     Merged in MatthewTurk/yt (pull request #1959)

Rewrite off-axis pixelization in Cython
Affected #:  4 files

diff -r 7b3234d68c60aa8d575160408559fbc03089b058 -r 29b4b633e95188794e985934b7d3cfe2d158ad78 yt/geometry/coordinates/cartesian_coordinates.py
--- a/yt/geometry/coordinates/cartesian_coordinates.py
+++ b/yt/geometry/coordinates/cartesian_coordinates.py
@@ -23,7 +23,7 @@
     cylindrical_to_cartesian
 from yt.funcs import mylog
 from yt.utilities.lib.pixelization_routines import \
-    pixelize_element_mesh
+    pixelize_element_mesh, pixelize_off_axis_cartesian
 from yt.data_objects.unstructured_mesh import SemiStructuredMesh
 import yt.visualization._MPL as _MPL
 
@@ -134,7 +134,8 @@
 
     def _oblique_pixelize(self, data_source, field, bounds, size, antialias):
         indices = np.argsort(data_source['dx'])[::-1]
-        buff = _MPL.CPixelize(data_source['x'], data_source['y'],
+        buff = pixelize_off_axis_cartesian(
+                              data_source['x'], data_source['y'],
                               data_source['z'], data_source['px'],
                               data_source['py'], data_source['pdx'],
                               data_source['pdy'], data_source['pdz'],

diff -r 7b3234d68c60aa8d575160408559fbc03089b058 -r 29b4b633e95188794e985934b7d3cfe2d158ad78 yt/utilities/lib/pixelization_routines.pyx
--- a/yt/utilities/lib/pixelization_routines.pyx
+++ b/yt/utilities/lib/pixelization_routines.pyx
@@ -178,6 +178,93 @@
                                 my_array[j,i] = dsp
     return my_array
 
+ at cython.cdivision(True)
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+def pixelize_off_axis_cartesian(
+                       np.float64_t[:] x,
+                       np.float64_t[:] y,
+                       np.float64_t[:] z,
+                       np.float64_t[:] px,
+                       np.float64_t[:] py,
+                       np.float64_t[:] pdx,
+                       np.float64_t[:] pdy,
+                       np.float64_t[:] pdz,
+                       np.float64_t[:] center,
+                       np.float64_t[:,:] inv_mat,
+                       np.int64_t[:] indices,
+                       np.float64_t[:] data,
+                       int cols, int rows, bounds):
+    cdef np.float64_t x_min, x_max, y_min, y_max
+    cdef np.float64_t width, height, px_dx, px_dy, ipx_dx, ipx_dy, md
+    cdef int i, j, p, ip
+    cdef int lc, lr, rc, rr
+    # These are the temp vars we get from the arrays
+    cdef np.float64_t xsp, ysp, zsp, dxsp, dysp, dzsp, dsp
+    cdef np.float64_t pxsp, pysp, cxpx, cypx, cx, cy, cz
+    # Some periodicity helpers
+    cdef np.ndarray[np.float64_t, ndim=2] my_array
+    cdef np.ndarray[np.int64_t, ndim=2] mask
+    x_min = bounds[0]
+    x_max = bounds[1]
+    y_min = bounds[2]
+    y_max = bounds[3]
+    width = x_max - x_min
+    height = y_max - y_min
+    px_dx = width / (<np.float64_t> rows)
+    px_dy = height / (<np.float64_t> cols)
+    ipx_dx = 1.0 / px_dx
+    ipx_dy = 1.0 / px_dy
+    if rows == 0 or cols == 0:
+        raise YTPixelizeError("Cannot scale to zero size")
+    if px.shape[0] != py.shape[0] or \
+       px.shape[0] != pdx.shape[0] or \
+       px.shape[0] != pdy.shape[0] or \
+       px.shape[0] != pdz.shape[0] or \
+       px.shape[0] != indices.shape[0] or \
+       px.shape[0] != data.shape[0]:
+        raise YTPixelizeError("Arrays are not of correct shape.")
+    my_array = np.zeros((rows, cols), "float64")
+    mask = np.zeros((rows, cols), "int64")
+    with nogil:
+        for ip in range(indices.shape[0]):
+            p = indices[ip]
+            xsp = x[p]
+            ysp = y[p]
+            zsp = z[p]
+            pxsp = px[p]
+            pysp = py[p]
+            dxsp = pdx[p]
+            dysp = pdy[p]
+            dzsp = pdz[p]
+            dsp = data[p]
+            # Any point we want to plot is at most this far from the center
+            md = 2.0 * math.sqrt(dxsp*dxsp + dysp*dysp + dzsp*dzsp)
+            if pxsp + md < x_min or \
+               pxsp - md > x_max or \
+               pysp + md < y_min or \
+               pysp - md > y_max:
+                continue
+            lc = <int> fmax(((pxsp - md - x_min)*ipx_dx),0)
+            lr = <int> fmax(((pysp - md - y_min)*ipx_dy),0)
+            rc = <int> fmin(((pxsp + md - x_min)*ipx_dx + 1), rows)
+            rr = <int> fmin(((pysp + md - y_min)*ipx_dy + 1), cols)
+            for i in range(lr, rr):
+                cypx = px_dy * (i + 0.5) + y_min
+                for j in range(lc, rc):
+                    cxpx = px_dx * (j + 0.5) + x_min
+                    cx = inv_mat[0,0]*cxpx + inv_mat[0,1]*cypx + center[0]
+                    cy = inv_mat[1,0]*cxpx + inv_mat[1,1]*cypx + center[1]
+                    cz = inv_mat[2,0]*cxpx + inv_mat[2,1]*cypx + center[2]
+                    if fabs(xsp - cx) * 0.95 > dxsp or \
+                       fabs(ysp - cy) * 0.95 > dysp or \
+                       fabs(zsp - cz) * 0.95 > dzsp:
+                        continue
+                    mask[i, j] = 1
+                    my_array[i, j] += dsp
+    my_array /= mask
+    return my_array
+
 
 @cython.cdivision(True)
 @cython.boundscheck(False)

diff -r 7b3234d68c60aa8d575160408559fbc03089b058 -r 29b4b633e95188794e985934b7d3cfe2d158ad78 yt/visualization/fixed_resolution.py
--- a/yt/visualization/fixed_resolution.py
+++ b/yt/visualization/fixed_resolution.py
@@ -23,11 +23,10 @@
 from .fixed_resolution_filters import apply_filter, filter_registry
 from yt.data_objects.image_array import ImageArray
 from yt.utilities.lib.pixelization_routines import \
-    pixelize_cylinder
+    pixelize_cylinder, pixelize_off_axis_cartesian
 from yt.utilities.lib.api import add_points_to_greyscale_image
 from yt.frontends.stream.api import load_uniform_grid
 
-from . import _MPL
 import numpy as np
 import weakref
 import re
@@ -537,7 +536,8 @@
             if hasattr(b, "in_units"):
                 b = float(b.in_units("code_length"))
             bounds.append(b)
-        buff = _MPL.CPixelize( self.data_source['x'],   self.data_source['y'],   self.data_source['z'],
+        buff = pixelize_off_axis_cartesian(
+                               self.data_source['x'],   self.data_source['y'],   self.data_source['z'],
                                self.data_source['px'],  self.data_source['py'],
                                self.data_source['pdx'], self.data_source['pdy'], self.data_source['pdz'],
                                self.data_source.center, self.data_source._inv_mat, indices,

diff -r 7b3234d68c60aa8d575160408559fbc03089b058 -r 29b4b633e95188794e985934b7d3cfe2d158ad78 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -33,7 +33,8 @@
 from yt.units.yt_array import YTQuantity, YTArray
 from yt.visualization.image_writer import apply_colormap
 from yt.utilities.lib.geometry_utils import triangle_plane_intersect
-from yt.utilities.lib.pixelization_routines import pixelize_element_mesh
+from yt.utilities.lib.pixelization_routines import \
+    pixelize_element_mesh, pixelize_off_axis_cartesian
 from yt.analysis_modules.cosmological_observation.light_ray.light_ray import \
     periodic_ray
 from yt.utilities.lib.line_integral_convolution import \
@@ -829,14 +830,16 @@
         nx = plot.image._A.shape[0] / self.factor
         ny = plot.image._A.shape[1] / self.factor
         indices = np.argsort(plot.data['dx'])[::-1]
-        pixX = _MPL.CPixelize( plot.data['x'], plot.data['y'], plot.data['z'],
+        pixX = pixelize_off_axis_cartesian(
+                               plot.data['x'], plot.data['y'], plot.data['z'],
                                plot.data['px'], plot.data['py'],
                                plot.data['pdx'], plot.data['pdy'], plot.data['pdz'],
                                plot.data.center, plot.data._inv_mat, indices,
                                plot.data[self.field_x],
                                int(nx), int(ny),
                                (x0, x1, y0, y1),).transpose()
-        pixY = _MPL.CPixelize( plot.data['x'], plot.data['y'], plot.data['z'],
+        pixY = pixelize_off_axis_cartesian(
+                               plot.data['x'], plot.data['y'], plot.data['z'],
                                plot.data['px'], plot.data['py'],
                                plot.data['pdx'], plot.data['pdy'], plot.data['pdz'],
                                plot.data.center, plot.data._inv_mat, indices,

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