[yt-svn] commit/yt: 4 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Mar 30 15:14:23 PDT 2016


4 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/8f7a4aadb3a8/
Changeset:   8f7a4aadb3a8
Branch:      yt
User:        MatthewTurk
Date:        2016-03-27 15:35:27+00:00
Summary:     Adding annotate_cell_edges.
Affected #:  4 files

diff -r e1341764121a45280be5b5c15e0e652901b9340d -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -743,6 +743,7 @@
 
    ~yt.visualization.plot_window.PWViewerMPL.annotate_clear
    ~yt.visualization.plot_modifications.ArrowCallback
+   ~yt.visualization.plot_modifications.CellEdgesCallback
    ~yt.visualization.plot_modifications.ClumpContourCallback
    ~yt.visualization.plot_modifications.ContourCallback
    ~yt.visualization.plot_modifications.CuttingQuiverCallback

diff -r e1341764121a45280be5b5c15e0e652901b9340d -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 doc/source/visualizing/callbacks.rst
--- a/doc/source/visualizing/callbacks.rst
+++ b/doc/source/visualizing/callbacks.rst
@@ -273,6 +273,31 @@
    slc.annotate_grids()
    slc.save()
 
+.. _annotate-cell-edges:
+
+Overplot Cell Edges
+~~~~~~~~~~~~~~~~~~~
+
+.. function:: annotate_cell_edges(line_width=1.0, alpha = 1.0,
+                                  color = (0.0, 0.0, 0.0))
+
+   (This is a proxy for
+   :class:`~yt.visualization.plot_modifications.CellEdgesCallback`.)
+
+    Annotate the edges of cells, where the ``line_width`` in pixels is specified.
+    The ``alpha`` of the overlaid image and the ``color`` of the lines are also
+    specifiable.  Note that because the lines are drawn from both sides of a
+    cell, the image sometimes has the effect of doubling the line width.
+    Color here is in RGB float values (0 to 1).
+
+.. python-script::
+
+   import yt
+   ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+   slc = yt.SlicePlot(ds, 'z', 'density', width=(10,'kpc'), center='max')
+   slc.annotate_cell_edges()
+   slc.save()
+
 .. _annotate-halos:
 
 Overplot Halo Annotations

diff -r e1341764121a45280be5b5c15e0e652901b9340d -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 yt/utilities/lib/pixelization_routines.pyx
--- a/yt/utilities/lib/pixelization_routines.pyx
+++ b/yt/utilities/lib/pixelization_routines.pyx
@@ -61,10 +61,12 @@
                        int cols, int rows, bounds,
                        int antialias = 1,
                        period = None,
-                       int check_period = 1):
+                       int check_period = 1,
+                       np.float64_t line_width = 0.0):
     cdef np.float64_t x_min, x_max, y_min, y_max
     cdef np.float64_t period_x = 0.0, period_y = 0.0
     cdef np.float64_t width, height, px_dx, px_dy, ipx_dx, ipx_dy
+    cdef np.float64_t ld_x, ld_y, cx, cy
     cdef int i, j, p, xi, yi
     cdef int lc, lr, rc, rr
     cdef np.float64_t lypx, rypx, lxpx, rxpx, overlap1, overlap2
@@ -170,13 +172,29 @@
                         for j in range(lc, rc):
                             lxpx = px_dx * j + x_min
                             rxpx = px_dx * (j+1) + x_min
-                            if antialias == 1:
+                            if line_width > 0:
+                                # Here, we figure out if we're within
+                                # line_width*px_dx of the cell edge
+                                # Midpoint of x:
+                                cx = (rxpx+lxpx)*0.5
+                                ld_x = fmin(fabs(cx - (xsp+dxsp)),
+                                            fabs(cx - (xsp-dxsp)))
+                                ld_x *= ipx_dx
+                                # Midpoint of y:
+                                cy = (rypx+lypx)*0.5
+                                ld_y = fmin(fabs(cy - (ysp+dysp)),
+                                            fabs(cy - (ysp-dysp)))
+                                ld_y *= ipx_dy
+                                if ld_x <= line_width or ld_y <= line_width:
+                                    my_array[j,i] = 1.0
+                            elif antialias == 1:
                                 overlap1 = ((fmin(rxpx, xsp+dxsp)
                                            - fmax(lxpx, (xsp-dxsp)))*ipx_dx)
                                 if overlap1 < 0.0: continue
                                 my_array[j,i] += (dsp * overlap1) * overlap2
                             else:
                                 my_array[j,i] = dsp
+                            
     return my_array
 
 @cython.cdivision(True)

diff -r e1341764121a45280be5b5c15e0e652901b9340d -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -34,7 +34,8 @@
 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, pixelize_off_axis_cartesian
+    pixelize_element_mesh, pixelize_off_axis_cartesian, \
+    pixelize_cartesian
 from yt.analysis_modules.cosmological_observation.light_ray.light_ray import \
     periodic_ray
 from yt.utilities.lib.line_integral_convolution import \
@@ -2280,3 +2281,49 @@
         plot._axes.hold(False)
 
         return plot
+
+class CellEdgesCallback(PlotCallback):
+    """
+    annotate_cell_edges(line_width=1.0, alpha = 1.0, color = (0.0, 0.0, 0.0))
+
+    Annotate the edges of cells, where the *line_width* in pixels is specified.
+    The *alpha* of the overlaid image and the *color* of the lines are also
+    specifiable.  Note that because the lines are drawn from both sides of a
+    cell, the image sometimes has the effect of doubling the line width.
+    Color here is in RGB float values (0 to 1).
+    """
+    _type_name = "cell_edges"
+    def __init__(self, line_width=1.0, alpha = 1.0, color=(0.0, 0.0, 0.0)):
+        PlotCallback.__init__(self)
+        self.line_width = line_width
+        self.alpha = alpha
+        self.color = (np.array(color) * 255).astype("uint8")
+
+    def __call__(self, plot):
+        x0, x1 = plot.xlim
+        y0, y1 = plot.ylim
+        xx0, xx1 = plot._axes.get_xlim()
+        yy0, yy1 = plot._axes.get_ylim()
+        plot._axes.hold(True)
+        nx = plot.image._A.shape[0]
+        ny = plot.image._A.shape[1]
+        im = pixelize_cartesian(plot.data['px'],
+                                plot.data['py'],
+                                plot.data['pdx'],
+                                plot.data['pdy'],
+                                plot.data['px'], # dummy field
+                                int(nx), int(ny),
+                                (x0, x1, y0, y1),
+                                line_width=self.line_width).transpose()
+        # New image:
+        im_buffer = np.zeros((nx, ny, 4), dtype="uint8")
+        im_buffer[im>0,3] = 255
+        im_buffer[im>0,:3] = self.color
+        plot._axes.imshow(im_buffer, origin='lower',
+                          interpolation='nearest',
+                          extent = [xx0, xx1, yy0, yy1],
+                          alpha = self.alpha)
+        plot._axes.set_xlim(xx0,xx1)
+        plot._axes.set_ylim(yy0,yy1)
+        plot._axes.hold(False)
+


https://bitbucket.org/yt_analysis/yt/commits/395215db880c/
Changeset:   395215db880c
Branch:      yt
User:        MatthewTurk
Date:        2016-03-27 15:43:50+00:00
Summary:     Adding test for cell_edges callback
Affected #:  1 file

diff -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 -r 395215db880c12901930306683388835d69c64ec yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -339,6 +339,25 @@
             max_level=3, cmap="gist_stern")
         p.save(prefix)
 
+def test_cell_edges_callback():
+    with _cleanup_fname() as prefix:
+        ds = fake_amr_ds(fields = ("density",))
+        for ax in 'xyz':
+            p = ProjectionPlot(ds, ax, "density")
+            p.annotate_cell_edges()
+            yield assert_fname, p.save(prefix)[0]
+            p = ProjectionPlot(ds, ax, "density", weight_field="density")
+            p.annotate_cell_edges()
+            yield assert_fname, p.save(prefix)[0]
+            p = SlicePlot(ds, ax, "density")
+            p.annotate_cell_edges()
+            yield assert_fname, p.save(prefix)[0]
+        # Now we'll check a few additional minor things
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_cell_edges(alpha=0.7, line_width=0.9,
+                              color=(0.0, 1.0, 1.0))
+        p.save(prefix)
+
 def test_line_integral_convolution_callback():
     with _cleanup_fname() as prefix:
         ds = fake_amr_ds(fields =


https://bitbucket.org/yt_analysis/yt/commits/846545025cc8/
Changeset:   846545025cc8
Branch:      yt
User:        MatthewTurk
Date:        2016-03-27 15:47:52+00:00
Summary:     Make docstring numpy-style
Affected #:  1 file

diff -r 395215db880c12901930306683388835d69c64ec -r 846545025cc886fd14db13bd0ddbdeae78814e88 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -2286,11 +2286,30 @@
     """
     annotate_cell_edges(line_width=1.0, alpha = 1.0, color = (0.0, 0.0, 0.0))
 
-    Annotate the edges of cells, where the *line_width* in pixels is specified.
-    The *alpha* of the overlaid image and the *color* of the lines are also
-    specifiable.  Note that because the lines are drawn from both sides of a
-    cell, the image sometimes has the effect of doubling the line width.
-    Color here is in RGB float values (0 to 1).
+    Annotate cell edges.  This is done through a second call to pixelize, where
+    the distance from a pixel to a cell boundary in pixels is compared against
+    the `line_width` argument.  The secondary image is colored as `color` and
+    overlaid with the `alpha` value.
+
+    Parameters
+    ----------
+    line_width : float
+        Distance, in pixels, from a cell edge that will mark a pixel as being
+        annotated as a cell edge.  Default is 1.0.
+    alpha : float
+        When the second image is overlaid, it will have this level of alpha
+        transparency.  Default is 1.0 (fully-opaque).
+    color : tuple of three floats
+        This is the color of the cell edge values.  It defaults to black.
+
+    Examples
+    --------
+
+    >>> import yt
+    >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+    >>> s = yt.SlicePlot(ds, 'z', 'density')
+    >>> s.annotate_cell_edges()
+    >>> s.save()
     """
     _type_name = "cell_edges"
     def __init__(self, line_width=1.0, alpha = 1.0, color=(0.0, 0.0, 0.0)):


https://bitbucket.org/yt_analysis/yt/commits/e376760e7ac4/
Changeset:   e376760e7ac4
Branch:      yt
User:        atmyers
Date:        2016-03-30 22:14:14+00:00
Summary:     Merged in MatthewTurk/yt (pull request #2088)

Adding annotate_cell_edges.  Closes #1198
Affected #:  5 files

diff -r f027ae00224c357e0cf4b49c3ff1afdd9d69bbaa -r e376760e7ac426c9e47ff916655e60bc7ec78a2d doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -743,6 +743,7 @@
 
    ~yt.visualization.plot_window.PWViewerMPL.annotate_clear
    ~yt.visualization.plot_modifications.ArrowCallback
+   ~yt.visualization.plot_modifications.CellEdgesCallback
    ~yt.visualization.plot_modifications.ClumpContourCallback
    ~yt.visualization.plot_modifications.ContourCallback
    ~yt.visualization.plot_modifications.CuttingQuiverCallback

diff -r f027ae00224c357e0cf4b49c3ff1afdd9d69bbaa -r e376760e7ac426c9e47ff916655e60bc7ec78a2d doc/source/visualizing/callbacks.rst
--- a/doc/source/visualizing/callbacks.rst
+++ b/doc/source/visualizing/callbacks.rst
@@ -273,6 +273,31 @@
    slc.annotate_grids()
    slc.save()
 
+.. _annotate-cell-edges:
+
+Overplot Cell Edges
+~~~~~~~~~~~~~~~~~~~
+
+.. function:: annotate_cell_edges(line_width=1.0, alpha = 1.0,
+                                  color = (0.0, 0.0, 0.0))
+
+   (This is a proxy for
+   :class:`~yt.visualization.plot_modifications.CellEdgesCallback`.)
+
+    Annotate the edges of cells, where the ``line_width`` in pixels is specified.
+    The ``alpha`` of the overlaid image and the ``color`` of the lines are also
+    specifiable.  Note that because the lines are drawn from both sides of a
+    cell, the image sometimes has the effect of doubling the line width.
+    Color here is in RGB float values (0 to 1).
+
+.. python-script::
+
+   import yt
+   ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+   slc = yt.SlicePlot(ds, 'z', 'density', width=(10,'kpc'), center='max')
+   slc.annotate_cell_edges()
+   slc.save()
+
 .. _annotate-halos:
 
 Overplot Halo Annotations

diff -r f027ae00224c357e0cf4b49c3ff1afdd9d69bbaa -r e376760e7ac426c9e47ff916655e60bc7ec78a2d yt/utilities/lib/pixelization_routines.pyx
--- a/yt/utilities/lib/pixelization_routines.pyx
+++ b/yt/utilities/lib/pixelization_routines.pyx
@@ -61,10 +61,12 @@
                        int cols, int rows, bounds,
                        int antialias = 1,
                        period = None,
-                       int check_period = 1):
+                       int check_period = 1,
+                       np.float64_t line_width = 0.0):
     cdef np.float64_t x_min, x_max, y_min, y_max
     cdef np.float64_t period_x = 0.0, period_y = 0.0
     cdef np.float64_t width, height, px_dx, px_dy, ipx_dx, ipx_dy
+    cdef np.float64_t ld_x, ld_y, cx, cy
     cdef int i, j, p, xi, yi
     cdef int lc, lr, rc, rr
     cdef np.float64_t lypx, rypx, lxpx, rxpx, overlap1, overlap2
@@ -170,13 +172,29 @@
                         for j in range(lc, rc):
                             lxpx = px_dx * j + x_min
                             rxpx = px_dx * (j+1) + x_min
-                            if antialias == 1:
+                            if line_width > 0:
+                                # Here, we figure out if we're within
+                                # line_width*px_dx of the cell edge
+                                # Midpoint of x:
+                                cx = (rxpx+lxpx)*0.5
+                                ld_x = fmin(fabs(cx - (xsp+dxsp)),
+                                            fabs(cx - (xsp-dxsp)))
+                                ld_x *= ipx_dx
+                                # Midpoint of y:
+                                cy = (rypx+lypx)*0.5
+                                ld_y = fmin(fabs(cy - (ysp+dysp)),
+                                            fabs(cy - (ysp-dysp)))
+                                ld_y *= ipx_dy
+                                if ld_x <= line_width or ld_y <= line_width:
+                                    my_array[j,i] = 1.0
+                            elif antialias == 1:
                                 overlap1 = ((fmin(rxpx, xsp+dxsp)
                                            - fmax(lxpx, (xsp-dxsp)))*ipx_dx)
                                 if overlap1 < 0.0: continue
                                 my_array[j,i] += (dsp * overlap1) * overlap2
                             else:
                                 my_array[j,i] = dsp
+                            
     return my_array
 
 @cython.cdivision(True)

diff -r f027ae00224c357e0cf4b49c3ff1afdd9d69bbaa -r e376760e7ac426c9e47ff916655e60bc7ec78a2d yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -36,7 +36,8 @@
 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, pixelize_off_axis_cartesian
+    pixelize_element_mesh, pixelize_off_axis_cartesian, \
+    pixelize_cartesian
 from yt.analysis_modules.cosmological_observation.light_ray.light_ray import \
     periodic_ray
 from yt.utilities.lib.line_integral_convolution import \
@@ -2361,3 +2362,68 @@
         plot._axes.hold(False)
 
         return plot
+
+class CellEdgesCallback(PlotCallback):
+    """
+    annotate_cell_edges(line_width=1.0, alpha = 1.0, color = (0.0, 0.0, 0.0))
+
+    Annotate cell edges.  This is done through a second call to pixelize, where
+    the distance from a pixel to a cell boundary in pixels is compared against
+    the `line_width` argument.  The secondary image is colored as `color` and
+    overlaid with the `alpha` value.
+
+    Parameters
+    ----------
+    line_width : float
+        Distance, in pixels, from a cell edge that will mark a pixel as being
+        annotated as a cell edge.  Default is 1.0.
+    alpha : float
+        When the second image is overlaid, it will have this level of alpha
+        transparency.  Default is 1.0 (fully-opaque).
+    color : tuple of three floats
+        This is the color of the cell edge values.  It defaults to black.
+
+    Examples
+    --------
+
+    >>> import yt
+    >>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+    >>> s = yt.SlicePlot(ds, 'z', 'density')
+    >>> s.annotate_cell_edges()
+    >>> s.save()
+    """
+    _type_name = "cell_edges"
+    def __init__(self, line_width=1.0, alpha = 1.0, color=(0.0, 0.0, 0.0)):
+        PlotCallback.__init__(self)
+        self.line_width = line_width
+        self.alpha = alpha
+        self.color = (np.array(color) * 255).astype("uint8")
+
+    def __call__(self, plot):
+        x0, x1 = plot.xlim
+        y0, y1 = plot.ylim
+        xx0, xx1 = plot._axes.get_xlim()
+        yy0, yy1 = plot._axes.get_ylim()
+        plot._axes.hold(True)
+        nx = plot.image._A.shape[0]
+        ny = plot.image._A.shape[1]
+        im = pixelize_cartesian(plot.data['px'],
+                                plot.data['py'],
+                                plot.data['pdx'],
+                                plot.data['pdy'],
+                                plot.data['px'], # dummy field
+                                int(nx), int(ny),
+                                (x0, x1, y0, y1),
+                                line_width=self.line_width).transpose()
+        # New image:
+        im_buffer = np.zeros((nx, ny, 4), dtype="uint8")
+        im_buffer[im>0,3] = 255
+        im_buffer[im>0,:3] = self.color
+        plot._axes.imshow(im_buffer, origin='lower',
+                          interpolation='nearest',
+                          extent = [xx0, xx1, yy0, yy1],
+                          alpha = self.alpha)
+        plot._axes.set_xlim(xx0,xx1)
+        plot._axes.set_ylim(yy0,yy1)
+        plot._axes.hold(False)
+

diff -r f027ae00224c357e0cf4b49c3ff1afdd9d69bbaa -r e376760e7ac426c9e47ff916655e60bc7ec78a2d yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -341,6 +341,25 @@
             max_level=3, cmap="gist_stern")
         p.save(prefix)
 
+def test_cell_edges_callback():
+    with _cleanup_fname() as prefix:
+        ds = fake_amr_ds(fields = ("density",))
+        for ax in 'xyz':
+            p = ProjectionPlot(ds, ax, "density")
+            p.annotate_cell_edges()
+            yield assert_fname, p.save(prefix)[0]
+            p = ProjectionPlot(ds, ax, "density", weight_field="density")
+            p.annotate_cell_edges()
+            yield assert_fname, p.save(prefix)[0]
+            p = SlicePlot(ds, ax, "density")
+            p.annotate_cell_edges()
+            yield assert_fname, p.save(prefix)[0]
+        # Now we'll check a few additional minor things
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_cell_edges(alpha=0.7, line_width=0.9,
+                              color=(0.0, 1.0, 1.0))
+        p.save(prefix)
+
 def test_line_integral_convolution_callback():
     with _cleanup_fname() as prefix:
         ds = fake_amr_ds(fields =

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160330/c02f53eb/attachment.html>


More information about the yt-svn mailing list