<html><body>
<p>1 new commit in yt:</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/e376760e7ac4/">https://bitbucket.org/yt_analysis/yt/commits/e376760e7ac4/</a> Changeset:   e376760e7ac4 Branch:      yt User:        atmyers Date:        2016-03-30 22:14:14+00:00 Summary:     Merged in MatthewTurk/yt (pull request #2088)</p>
<p>Adding annotate_cell_edges.  Closes #1198 Affected #:  5 files</p>
<p>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 @@</p>
<pre>~yt.visualization.plot_window.PWViewerMPL.annotate_clear
~yt.visualization.plot_modifications.ArrowCallback</pre>
<p>+   ~yt.visualization.plot_modifications.CellEdgesCallback</p>
<pre>~yt.visualization.plot_modifications.ClumpContourCallback
~yt.visualization.plot_modifications.ContourCallback
~yt.visualization.plot_modifications.CuttingQuiverCallback</pre>
<p>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 @@</p>
<pre>   slc.annotate_grids()
   slc.save()
</pre>
<p>+.. _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() +</p>
<pre>.. _annotate-halos:

Overplot Halo Annotations</pre>
<p>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 @@</p>
<pre>int cols, int rows, bounds,
int antialias = 1,
period = None,</pre>
<ul><li><p>int check_period = 1):</p></li></ul>
<p>+                       int check_period = 1, +                       np.float64_t line_width = 0.0):</p>
<pre>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</pre>
<p>+    cdef np.float64_t ld_x, ld_y, cx, cy</p>
<pre>cdef int i, j, p, xi, yi
cdef int lc, lr, rc, rr
cdef np.float64_t lypx, rypx, lxpx, rxpx, overlap1, overlap2</pre>
<p>@@ -170,13 +172,29 @@</p>
<pre>for j in range(lc, rc):
    lxpx = px_dx * j + x_min
    rxpx = px_dx * (j+1) + x_min</pre>
<ul><li><p>if antialias == 1:</p></li></ul>
<p>+                            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:</p>
<pre>    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</pre>
<p>+</p>
<pre>    return my_array

@cython.cdivision(True)</pre>
<p>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 @@</p>
<pre>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 \</pre>
<ul><li><p>pixelize_element_mesh, pixelize_off_axis_cartesian</p></li></ul>
<p>+    pixelize_element_mesh, pixelize_off_axis_cartesian, \ +    pixelize_cartesian</p>
<pre>from yt.analysis_modules.cosmological_observation.light_ray.light_ray import \
    periodic_ray
from yt.utilities.lib.line_integral_convolution import \</pre>
<p>@@ -2361,3 +2362,68 @@</p>
<pre>        plot._axes.hold(False)

        return plot</pre>
<p>+ +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) +</p>
<p>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 @@</p>
<pre>            max_level=3, cmap="gist_stern")
        p.save(prefix)
</pre>
<p>+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) +</p>
<pre>def test_line_integral_convolution_callback():
    with _cleanup_fname() as prefix:
        ds = fake_amr_ds(fields =</pre>
<p>Repository URL: <a href="https://bitbucket.org/yt_analysis/yt/">https://bitbucket.org/yt_analysis/yt/</a></p>
<p>—</p>
<p>This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.</p>

<img src="http://link.bitbucket.org/wf/open?upn=ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27D-2FFbknS0TFlCStLn-2Bbm5PX2TDG9HgtExjBVIylWGCRMRpJ5ISpMbhCiDXonw0VIuasa4Cgn5SC5wng7HvkhkET515Sb8gh0BWUPE1gROJIg58rv98hvZbGZNCtle79k6JxGCYQZcLAEC7teQ0T5LMQrCw1-2BeRDsMpc8jhOmPOBpGQRTzvhUF0RV8yGWYIPYJM-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>