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

Bitbucket commits-noreply at bitbucket.org
Sun Feb 19 18:34:01 PST 2012


2 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/3d61c62199f5/
changeset:   3d61c62199f5
branch:      yt
user:        MatthewTurk
date:        2012-02-17 16:00:35
summary:     [reason] Layout and a bit of support structure for contours in a plotwindow
widget.
affected #:  2 files

diff -r b330e66192d0f43e2090d6540b99574d296f4c8b -r 3d61c62199f55f7b7c0d6202b434fcd5a787ca55 yt/gui/reason/html/js/widget_plotwindow.js
--- a/yt/gui/reason/html/js/widget_plotwindow.js
+++ b/yt/gui/reason/html/js/widget_plotwindow.js
@@ -447,6 +447,11 @@
                           html: 'Welcome to the Plot Window.',
                           height: 200,
                         }, {
+                          xtype: 'tabpanel',
+                          flex: 1,
+                          activeTab: 0,
+                          items: [
+                        {
                           xtype: 'panel',
                           title: 'Plot Editor',
                           id: 'plot_edit',
@@ -523,7 +528,57 @@
                                }}
                              }
                           ]
-                        }]
+                        }, {
+                          xtype: 'panel',
+                          title: 'Contours',
+                          id: 'contour_edit',
+                          style: {fontFamily: '"Inconsolata", monospace'},
+                          layout: 'absolute',
+                          flex: 1,
+                          items : [
+                             {
+                               x: 10,
+                               y: 20,
+                               width: 70,
+                               xtype: 'label',
+                               text: 'Field',
+                             },
+                             {
+                               x: 80,
+                               y: 20,
+                               width : 160,
+                               xtype: 'combo',
+                               editable: false,
+                               triggerAction: 'all',
+                               validateOnBlur: false,
+                               store: widget_data['fields'],
+                               listeners: {select: function(combo, record, index){ 
+                               }}
+                             },
+                             {
+                               x: 10,
+                               y: 60,
+                               width: 70,
+                               xtype: 'label',
+                               text: 'Levels',
+                             },
+                             {
+                               x: 80,
+                               y: 60,
+                               width : 160,
+                               xtype: 'slider',
+                               minValue: 0,
+                               maxValue: 10,
+                               value: 0,
+                               increment: 1,
+                               plugins: new Ext.slider.Tip(),
+                               listeners: {select: function(combo, record, index){ 
+                               }}
+                             }
+                          ]
+                        }
+                        ] } /* tabpanel items and entry */
+                        ]
                 }
             ]
         }


diff -r b330e66192d0f43e2090d6540b99574d296f4c8b -r 3d61c62199f55f7b7c0d6202b434fcd5a787ca55 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -24,6 +24,7 @@
 """
 import base64
 import matplotlib.pyplot
+import cStringIO
 from functools import wraps
 
 import numpy as na
@@ -88,6 +89,7 @@
 class PlotWindow(object):
     _plot_valid = False
     _colorbar_valid = False
+    _contour_info = None
     def __init__(self, data_source, bounds, buff_size=(800,800), antialias = True, periodic = True):
         r"""
         PlotWindow(data_source, bounds, buff_size=(800,800), antialias = True)
@@ -263,6 +265,14 @@
     def set_antialias(self,aa):
         self.antialias = aa
 
+    @invalidate_plot
+    def set_contour_info(self, field_name, n_cont = 8, colors = None,
+                         logit = True):
+        if field_name == "None":
+            self._contour_info = None
+            return
+        self._contour_info = (field_name, n_cont, colors, logit)
+
 class PWViewer(PlotWindow):
     """A viewer for PlotWindows.
 
@@ -379,6 +389,7 @@
             to_plot = apply_colormap(self._frb[field],
                 func = self._field_transform[field],
                 cmap_name = self._colormaps[field])
+            self._apply_modifications(to_plot)
             pngs = write_png_to_string(to_plot)
             img_data = base64.b64encode(pngs)
             # We scale the width between 200*min_dx and 1.0
@@ -394,6 +405,45 @@
             payload.update(addl_keys)
             ph.add_payload(payload)
 
+    def _apply_modifications(self, img):
+        from matplotlib.figure import Figure
+        from yt.visualization._mpl_imports import \
+            FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
+        from yt.utilities.delaunay.triangulate import Triangulation as triang
+
+        if self._contour_info is None: return img
+        plot_args = {}
+        field, number, colors, logit = self._contour_info
+        if colors is not None: plot_args['colors'] = colors
+
+        vi, vj, vn = img.shape
+
+        # Now we need to get our field values
+        raw_data = self._frb.data_source
+        b = self._frb.bounds
+        xi = na.mgrid[b[0]:b[1]:(vi / 8) * 1j]
+        yi = na.mgrid[b[2]:b[3]:(vj / 8) * 1j]
+        x = raw_data['px']
+        y = raw_data['py']
+        z = raw_data[field]
+        if logit: z = na.log10(z)
+        fvals = triang(x,y).nn_interpolator(z)(xi,yi)
+
+        fig = Figure((vi/100.0, vj/100.0), dpi = 100)
+        fig.figimage(img)
+        # Add our contour
+        ax = fig.add_axes([0.0, 0.0, 1.0, 1.0], frameon=False)
+        ax.patch.set_alpha(0.0)
+
+        # Now contour it
+        ax.contour(fvals, colors='w')
+        canvas = FigureCanvasAgg(fig)
+        f = cStringIO.StringIO()
+        canvas.print_figure(f)
+        f.seek(0)
+        img = f.read()
+        return img
+        
     def get_ticks(self, field, height = 400):
         # This will eventually change to work with non-logged fields
         ticks = []
@@ -482,7 +532,6 @@
             units = units.replace(r"\rm{", "").replace("}","")
         return units
 
-
 class YtPlot(object):
     """A base class for all yt plots. It should abstract the actual
     plotting engine completely, allowing plotting even without matplotlib. 



https://bitbucket.org/yt_analysis/yt/changeset/ea93318de132/
changeset:   ea93318de132
branch:      yt
user:        MatthewTurk
date:        2012-02-20 03:33:43
summary:     [reason] If we tile the raw data before plotting it, we get a much nicer
looking, pre-scaled plot.
affected #:  1 file

diff -r 3d61c62199f55f7b7c0d6202b434fcd5a787ca55 -r ea93318de1321669a863bd765608f3f15d667ed5 yt/visualization/profile_plotter.py
--- a/yt/visualization/profile_plotter.py
+++ b/yt/visualization/profile_plotter.py
@@ -340,6 +340,8 @@
             func = na.log10
         else:
             func = lambda a: a
+        raw_data = na.repeat(raw_data, 3, axis=0)
+        raw_data = na.repeat(raw_data, 3, axis=1)
         to_plot = apply_colormap(raw_data, self.plot.cbar.bounds,
                                  self.plot.cbar.cmap, func)
         if self.plot.cbar.scale == 'log':

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