<html><body>
<p>4 new commits in yt:</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/8f7a4aadb3a8/">https://bitbucket.org/yt_analysis/yt/commits/8f7a4aadb3a8/</a> Changeset: 8f7a4aadb3a8 Branch: yt User: MatthewTurk Date: 2016-03-27 15:35:27+00:00 Summary: Adding annotate_cell_edges. Affected #: 4 files</p>
<p>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 @@</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 e1341764121a45280be5b5c15e0e652901b9340d -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 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 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 @@</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 e1341764121a45280be5b5c15e0e652901b9340d -r 8f7a4aadb3a84d0dac1bd7e64b67584243fa5068 yt/visualization/plot_modifications.py --- a/yt/visualization/plot_modifications.py +++ b/yt/visualization/plot_modifications.py @@ -34,7 +34,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>@@ -2280,3 +2281,49 @@</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 the edges of cells, where the <strong>line_width</strong> in pixels is specified. + The <strong>alpha</strong> of the overlaid image and the <strong>color</strong> 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) +</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/395215db880c/">https://bitbucket.org/yt_analysis/yt/commits/395215db880c/</a> 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</p>
<p>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 @@</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><a href="https://bitbucket.org/yt_analysis/yt/commits/846545025cc8/">https://bitbucket.org/yt_analysis/yt/commits/846545025cc8/</a> Changeset: 846545025cc8 Branch: yt User: MatthewTurk Date: 2016-03-27 15:47:52+00:00 Summary: Make docstring numpy-style Affected #: 1 file</p>
<p>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 @@</p>
<pre> """
annotate_cell_edges(line_width=1.0, alpha = 1.0, color = (0.0, 0.0, 0.0))
</pre>
<ul><li><p>Annotate the edges of cells, where the <strong>line_width</strong> in pixels is specified.</p></li>
<li><p>The <strong>alpha</strong> of the overlaid image and the <strong>color</strong> of the lines are also</p></li>
<li><p>specifiable. Note that because the lines are drawn from both sides of a</p></li>
<li><p>cell, the image sometimes has the effect of doubling the line width.</p></li>
<li><p>Color here is in RGB float values (0 to 1).</p></li></ul>
<p>+ 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()</p>
<pre>"""
_type_name = "cell_edges"
def __init__(self, line_width=1.0, alpha = 1.0, color=(0.0, 0.0, 0.0)):</pre>
<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-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27DxPzXAU9Dw-2B74-2F-2FxS0K891OytGken7mo-2Bpr-2B9GFpgoWfMxYFZ7zFzkqvgysSbbUTrQSvq7ulpH4AljdqEq6dDtqg6-2BOAvAv-2BkxJHgF9Bps3XxFdrt6YLhhgGqkqzGdEmgvlTXDzCglhjxGvi2WtzqILHBsR2Eg6-2BR6jDVkse4j772p7NsPzGXgNBhMD4Fqo2A-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>