[Yt-svn] yt: Updating vm panner and adding the Chaco pan-n-scan widget
hg at spacepope.org
hg at spacepope.org
Fri Mar 19 15:26:26 PDT 2010
hg Repository: yt
details: yt/rev/f25078d03f66
changeset: 1461:f25078d03f66
user: Matthew Turk <matthewturk at gmail.com>
date:
Fri Mar 19 15:26:19 2010 -0700
description:
Updating vm panner and adding the Chaco pan-n-scan widget
diffstat:
yt/extensions/image_panner/pan_and_scan_widget.py | 87 +++++++++++++++++++++++++++++
yt/extensions/image_panner/vm_panner.py | 26 +++++++-
2 files changed, 108 insertions(+), 5 deletions(-)
diffs (140 lines):
diff -r 391510e5789c -r f25078d03f66 yt/extensions/image_panner/pan_and_scan_widget.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/extensions/image_panner/pan_and_scan_widget.py Fri Mar 19 15:26:19 2010 -0700
@@ -0,0 +1,87 @@
+"""
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: KIPAC/SLAC/Stanford
+Homepage: http://yt.enzotools.org/
+License:
+ Copyright (C) 2010 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+
+# Major library imports
+from vm_panner import VariableMeshPanner
+from numpy import linspace, meshgrid, pi, sin, mgrid
+
+# Enthought library imports
+from enthought.enable.api import Component, ComponentEditor, Window
+from enthought.traits.api import HasTraits, Instance, Button
+from enthought.traits.ui.api import Item, Group, View
+
+# Chaco imports
+from enthought.chaco.api import ArrayPlotData, jet, Plot
+from enthought.chaco.image_data import FunctionImageData
+from enthought.chaco.tools.api import PanTool, ZoomTool
+from enthought.chaco.tools.image_inspector_tool import ImageInspectorTool, \
+ ImageInspectorOverlay
+from enthought.chaco.function_data_source import FunctionDataSource
+
+class VariableMeshPannerView(HasTraits):
+
+ plot = Instance(Plot)
+ panner = Instance(VariableMeshPanner)
+ fid = Instance(FunctionImageData)
+ limits = Button
+
+ traits_view = View(
+ Group(
+ Item('plot', editor=ComponentEditor(size=(512,512)),
+ show_label=False),
+ Item('limits', show_label=False),
+ orientation = "vertical"),
+ width = 800, height=800,
+ resizable=True, title="Pan and Scan",
+ )
+
+ def __init__(self, **kwargs):
+ super(VariableMeshPannerView, self).__init__(**kwargs)
+ # Create the plot
+ pd = ArrayPlotData()
+ fid = FunctionImageData(func = self.panner.set_low_high)
+ self.fid = fid
+ bounds = self.panner.bounds
+ pd.set_data("imagedata", fid)
+
+ plot = Plot(pd)
+ img_plot = plot.img_plot("imagedata", colormap=jet)[0]
+
+ xlim, ylim = self.panner.bounds
+ plot.range2d.set_bounds( (xlim[0], ylim[0]), (xlim[1], ylim[1]) )
+
+ fid.data_range = plot.range2d
+
+ plot.tools.append(PanTool(img_plot))
+ zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
+ plot.overlays.append(zoom)
+ imgtool = ImageInspectorTool(img_plot)
+ img_plot.tools.append(imgtool)
+ overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool,
+ bgcolor="white", border_visible=True)
+
+ img_plot.overlays.append(overlay)
+ self.plot = plot
+
+ def _limits_fired(self):
+ print self.fid.data.min(), self.fid.data.max()
diff -r 391510e5789c -r f25078d03f66 yt/extensions/image_panner/vm_panner.py
--- a/yt/extensions/image_panner/vm_panner.py Wed Mar 17 21:27:55 2010 -0700
+++ b/yt/extensions/image_panner/vm_panner.py Fri Mar 19 15:26:19 2010 -0700
@@ -21,6 +21,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
+import numpy as na
from yt.raven import FixedResolutionBuffer, ObliqueFixedResolutionBuffer
from yt.lagos import data_object_registry, AMRProjBase, AMRSliceBase, \
x_dict, y_dict
@@ -37,12 +38,16 @@
self.size = size
self.source = source
self.field = field
- if pf is None: pf = self.pf
- DLE, DRE = pf["DomainLeftEdge"], pf["DomainRightEdge"]
- ax = source.axis
+ self.xlim, self.ylim = self.bounds
+
+ @property
+ def bounds(self):
+ DLE, DRE = self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]
+ ax = self.source.axis
xax, yax = x_dict[ax], y_dict[ax]
- self.xlim = DLE[xax], DRE[xax]
- self.ylim = DLE[yax], DRE[yax]
+ xbounds = DLE[xax], DRE[xax]
+ ybounds = DLE[yax], DRE[yax]
+ return (xbounds, ybounds)
@property
def width(self):
@@ -98,4 +103,15 @@
self.size)
self._buffer = new_buffer
+ def set_low_high(self, low, high):
+ print "Setting low, high", low, high
+ self.xlim = (low[0], high[0])
+ self.ylim = (low[1], high[1])
+ b = na.log10(self.buffer)
+ mi, ma = b.min(), b.max()
+ print "Returning buffer with extrema",
+ print mi, ma
+ b = (b - mi)/(ma - mi)
+ return b
+
data_object_registry["image_panner"] = VariableMeshPanner
More information about the yt-svn
mailing list