[yt-svn] commit/yt: MatthewTurk: Adding velocity vectors to Reason plotwindow widget. Closes #361.
Bitbucket
commits-noreply at bitbucket.org
Fri Mar 16 08:50:18 PDT 2012
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/changeset/05d141f8da2d/
changeset: 05d141f8da2d
branch: yt
user: MatthewTurk
date: 2012-03-16 16:49:40
summary: Adding velocity vectors to Reason plotwindow widget. Closes #361.
affected #: 2 files
diff -r 6970ff9642908ef6512a3828b90ca978534e185a -r 05d141f8da2dcf6ed624717d880d83c5881e2660 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
@@ -564,8 +564,7 @@
width: 70,
xtype: 'label',
text: 'Field',
- },
- {
+ }, {
x: 80,
y: 20,
width : 160,
@@ -627,6 +626,47 @@
}
}
]
+ }, {
+ xtype: 'panel',
+ title: 'Velocity Vectors',
+ id: 'vector_edit',
+ style: {fontFamily: '"Inconsolata", monospace'},
+ layout: 'absolute',
+ flex: 1,
+ items : [
+ {
+ x: 10,
+ y: 60,
+ width: 70,
+ xtype: 'label',
+ text: 'Skip Factor',
+ }, {
+ x: 80,
+ y: 60,
+ width : 160,
+ xtype: 'slider',
+ id: 'skip',
+ minValue: 1,
+ maxValue: 64,
+ value: 32,
+ increment: 1,
+ plugins: new Ext.slider.Tip(),
+ }, {
+ x: 10,
+ y: 180,
+ width: 80,
+ xtype: 'button',
+ text: 'Apply',
+ handler: function(b, e) {
+ skip = vector_window.get('skip').getValue();
+ yt_rpc.ExtDirectREPL.execute(
+ {code:python_varname
+ + '.set_vector_info('+skip+')',
+ hide:false},
+ cell_finished);
+ }
+ }
+ ]
}
] } /* tabpanel items and entry */
]
@@ -650,6 +690,9 @@
var contour_window = this.panel.get("rhs_panel_" + python_varname);
contour_window = contour_window.get("editor_panel");
contour_window = contour_window.get("contour_edit");
+ var vector_window = this.panel.get("rhs_panel_" + python_varname);
+ vector_window = vector_window.get("editor_panel");
+ vector_window = vector_window.get("vector_edit");
var image_dom = this.image_panel.el.dom;
var control_panel = this.panel;
var metadata_string;
diff -r 6970ff9642908ef6512a3828b90ca978534e185a -r 05d141f8da2dcf6ed624717d880d83c5881e2660 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -90,6 +90,7 @@
_plot_valid = False
_colorbar_valid = False
_contour_info = None
+ _vector_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)
@@ -273,6 +274,10 @@
return
self._contour_info = (field_name, n_cont, colors, logit)
+ @invalidate_plot
+ def set_vector_info(self, skip, scale = 1):
+ self._vector_info = (skip, scale)
+
class PWViewer(PlotWindow):
"""A viewer for PlotWindows.
@@ -405,19 +410,39 @@
ph.add_payload(payload)
def _apply_modifications(self, img):
- if self._contour_info is None:
+ if self._contour_info is None and self._vector_info is None:
return write_png_to_string(img)
from matplotlib.figure import Figure
from yt.visualization._mpl_imports import \
FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
from yt.utilities.delaunay.triangulate import Triangulation as triang
+
+ vi, vj, vn = img.shape
+
+ # Now we need to get our field values
+ 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 apply our modifications
+ self._apply_contours(ax, vi, vj)
+ self._apply_vectors(ax, vi, vj)
+
+ canvas = FigureCanvasAgg(fig)
+ f = cStringIO.StringIO()
+ canvas.print_figure(f)
+ f.seek(0)
+ img = f.read()
+ return img
+
+ def _apply_contours(self, ax, vi, vj):
+ if self._contour_info is None: return
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, yi = na.mgrid[b[0]:b[1]:(vi / 8) * 1j,
@@ -428,20 +453,30 @@
if logit: z = na.log10(z)
fvals = triang(x,y).nn_interpolator(z)(xi,yi).transpose()[::-1,:]
- 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)
+ ax.contour(fvals, number, colors='w')
+
+ def _apply_vectors(self, ax, vi, vj):
+ if self._vector_info is None: return
+ skip, scale = self._vector_info
- # Now contour it
- ax.contour(fvals, number, colors='w')
- canvas = FigureCanvasAgg(fig)
- f = cStringIO.StringIO()
- canvas.print_figure(f)
- f.seek(0)
- img = f.read()
- return img
+ nx = self._frb.buff_size[0]/skip
+ ny = self._frb.buff_size[1]/skip
+ new_frb = FixedResolutionBuffer(self._frb.data_source,
+ self._frb.bounds, (nx,ny))
+
+ axis = self._frb.data_source.axis
+ fx = "%s-velocity" % (axis_names[x_dict[axis]])
+ fy = "%s-velocity" % (axis_names[y_dict[axis]])
+ px = new_frb[fx][::-1,:]
+ py = new_frb[fy][::-1,:]
+ x = na.mgrid[0:vi-1:ny*1j]
+ y = na.mgrid[0:vj-1:nx*1j]
+ # Always normalize, then we scale
+ nn = ((px**2.0 + py**2.0)**0.5).max()
+ px /= nn
+ py /= nn
+ print scale, px.min(), px.max(), py.min(), py.max()
+ ax.quiver(x, y, px, py, scale=float(vi)/skip)
def get_ticks(self, field, height = 400):
# This will eventually change to work with non-logged 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.
More information about the yt-svn
mailing list