[Yt-svn] yt: 5 new changesets

hg at spacepope.org hg at spacepope.org
Sun Mar 28 15:18:09 PDT 2010


hg Repository: yt
details:   yt/rev/03b796e1ce91
changeset: 1485:03b796e1ce91
user:      Matthew Turk <matthewturk at gmail.com>
date:
Sun Mar 28 09:16:29 2010 -0700
description:
Refactored out the plot from the window in the variable mesh plot widget for
Chaco

hg Repository: yt
details:   yt/rev/b7cc98e575fa
changeset: 1486:b7cc98e575fa
user:      mturk
date:
Sun Mar 28 09:20:52 2010 -0700
description:
[svn r1674] Backport from hg:

 * Optimizations to the pixelization step, which should increase performance by about 40% at most for some pixelizations.
 * Adding an image panner, to be better documented, but which provides us with
the ability to control tile display walls, use Chaco for a "google maps" style
interface to plots, and simplify our overall interaction with variable mesh
plots as a whole.

I'm pretty excited about this image panner, because it's a very cool and fun
way to interact with 2D AMR data.  And it's able to operate remotely, so the
client can run on a local machine (where Chaco may be easier to install, for
intance) getting remote images passed back.  It can also handle "windowing", so
that the pixelization jobs can be distributed across machines -- for instance,
for tile displays!

hg Repository: yt
details:   yt/rev/81f4cc2c2a67
changeset: 1487:81f4cc2c2a67
user:      mturk
date:
Sun Mar 28 13:49:34 2010 -0700
description:
[svn r1675] Adding a bunch of docstrings to the image panner module.

hg Repository: yt
details:   yt/rev/438f10638a5b
changeset: 1488:438f10638a5b
user:      Matthew Turk <matthewturk at gmail.com>
date:
Sun Mar 28 13:52:49 2010 -0700
description:
Merging back from trunk

hg Repository: yt
details:   yt/rev/8472d0d8acc3
changeset: 1489:8472d0d8acc3
user:      Matthew Turk <matthewturk at gmail.com>
date:
Sun Mar 28 15:18:05 2010 -0700
description:
Merging from yt branch

diffstat:

 yt/extensions/StarAnalysis.py                     |    9 ++-
 yt/extensions/image_panner/pan_and_scan_widget.py |  101 ++++++++++++++----------
 yt/extensions/image_panner/vm_panner.py           |   76 +++++++++++++++++++
 yt/lagos/StructureFunctionGenerator.py            |   31 +++++--
 4 files changed, 164 insertions(+), 53 deletions(-)

diffs (truncated from 444 to 300 lines):

diff -r 0ea10be4b283 -r 8472d0d8acc3 yt/extensions/StarAnalysis.py
--- a/yt/extensions/StarAnalysis.py	Thu Mar 25 23:29:56 2010 -0700
+++ b/yt/extensions/StarAnalysis.py	Sun Mar 28 15:18:05 2010 -0700
@@ -114,11 +114,18 @@
         """
         fp = open(name, "w")
         if self.mode == 'data_source':
-            vol = self._data_source.volume('mpc')
+            try:
+                vol = self._data_source.volume('mpc')
+            except AttributeError:
+                # If we're here, this is probably a HOPHalo object, and we
+                # can get the volume this way.
+                ds = self._data_source.get_sphere()
+                vol = ds.volume('mpc')
         elif self.mode == 'provided':
             vol = self.volume
         tc = self._pf["Time"]
         # Use the center of the time_bin, not the left edge.
+        fp.write("#time\tlookback\tredshift\tMsol/yr\tMsol/yr/Mpc3\tMsol\tcumMsol\t\n")
         for i, time in enumerate((self.time_bins[1:] + self.time_bins[:-1])/2.):
             line = "%1.5e\t%1.5e\t%1.5e\t%1.5e\t%1.5e\t%1.5e\t%1.5e\n" % \
             (time * tc / YEAR, # Time
diff -r 0ea10be4b283 -r 8472d0d8acc3 yt/extensions/image_panner/pan_and_scan_widget.py
--- a/yt/extensions/image_panner/pan_and_scan_widget.py	Thu Mar 25 23:29:56 2010 -0700
+++ b/yt/extensions/image_panner/pan_and_scan_widget.py	Sun Mar 28 15:18:05 2010 -0700
@@ -28,14 +28,16 @@
 # Enthought library imports
 from enthought.enable.api import Component, ComponentEditor, Window
 from enthought.traits.api import HasTraits, Instance, Button, Any, Callable, \
-        on_trait_change
+        on_trait_change, Bool
 from enthought.traits.ui.api import Item, Group, View
 
 # Chaco imports
 from enthought.chaco.api import ArrayPlotData, jet, Plot, HPlotContainer, \
-        ColorBar, DataRange1D, DataRange2D, LinearMapper, ImageData
+        ColorBar, DataRange1D, DataRange2D, LinearMapper, ImageData, \
+        CMapImagePlot
 from enthought.chaco.tools.api import PanTool, ZoomTool, RangeSelection, \
-        RangeSelectionOverlay
+        RangeSelectionOverlay, RangeSelection
+from zoom_overlay import ZoomOverlay
 from enthought.chaco.tools.image_inspector_tool import ImageInspectorTool, \
      ImageInspectorOverlay
 
@@ -75,14 +77,11 @@
         raise RuntimeError("Cannot set numerical data on a FunctionDataSource")
 
     def set_mask(self, mask):
-        # This would be REALLY FREAKING SLICK, but it's current unimplemented
         raise NotImplementedError
 
     def remove_mask(self):
         raise NotImplementedError
 
-
-
 class ImagePixelizerHelper(object):
     index = None
     def __init__(self, panner):
@@ -98,59 +97,74 @@
             self.index.set_data( xs, ys )
         return b
 
+class VMImagePlot(HasTraits):
+    plot = Instance(Plot)
+    fid = Instance(FunctionImageData)
+    img_plot = Instance(CMapImagePlot)
+    panner = Instance(VariableMeshPanner)
+    helper = Instance(ImagePixelizerHelper)
+
+    def _plot_default(self):
+        pd = ArrayPlotData()
+        plot = Plot(pd)
+        self.fid._data = self.panner.buffer
+
+        pd.set_data("imagedata", self.fid)
+
+        img_plot = plot.img_plot("imagedata", colormap=jet,
+                                 interpolation='nearest',
+                                 xbounds=(0.0, 1.0),
+                                 ybounds=(0.0, 1.0))[0]
+        self.fid.data_range = plot.range2d
+        self.helper.index = img_plot.index
+        self.img_plot = img_plot
+        return plot
+
+    def _fid_default(self):
+        return FunctionImageData(func = self.helper)
+
+    def _helper_default(self):
+        return ImagePixelizerHelper(self.panner)
+
 class VariableMeshPannerView(HasTraits):
 
     plot = Instance(Plot)
-    pd = Instance(ArrayPlotData)
-    panner = Instance(VariableMeshPanner)
-    fid = Instance(FunctionImageData)
-    limits = Button
-    helper = Any
+    spawn_zoom = Button
+    vm_plot = Instance(VMImagePlot)
+    use_tools = Bool(True)
     
     traits_view = View(
                     Group(
                         Item('container', editor=ComponentEditor(size=(512,512)), 
                              show_label=False),
-                        Item('limits', show_label=False),
+                        Item('spawn_zoom', show_label=False),
                         orientation = "vertical"),
                     width = 800, height=800,
                     resizable=True, title="Pan and Scan",
                     )
+
+    def _vm_plot_default(self):
+        return VMImagePlot(panner=self.panner)
     
     def __init__(self, **kwargs):
         super(VariableMeshPannerView, self).__init__(**kwargs)
         # Create the plot
-        pd = ArrayPlotData()
-        plot = Plot(pd)
-        self.pd = pd
-        helper = ImagePixelizerHelper(self.panner)
-        fid = FunctionImageData(func = helper)
-        fid._data = self.panner.buffer
-        self.fid = fid
-        bounds = self.panner.bounds
-        pd.set_data("imagedata", fid)
 
-        img_plot = plot.img_plot("imagedata", colormap=jet,
-                                 interpolation='nearest',
-                                 xbounds=(0.0, 1.0),
-                                 ybounds=(0.0, 1.0))[0]
-        helper.index = img_plot.index
-        self.helper = helper
+        plot = self.vm_plot.plot
+        img_plot = self.vm_plot.img_plot
 
-        fid.data_range = plot.range2d
+        if self.use_tools:
+            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)
 
-        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
-
-        image_value_range = DataRange1D(fid)
+        image_value_range = DataRange1D(self.vm_plot.fid)
         cbar_index_mapper = LinearMapper(range=image_value_range)
         self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                  plot=img_plot,
@@ -178,8 +192,9 @@
 
         self.container = HPlotContainer(padding=30)
         self.container.add(self.colorbar)
-        self.container.add(self.plot)
+        self.container.add(self.vm_plot.plot)
 
-    def _limits_fired(self):
-        print self.pd["imagedata"].min(), self.pd["imagedata"].max(),
-        print self.fid.data.min(), self.fid.data.max()
+    def _spawn_zoom_fired(self):
+        np = self.panner.source.pf.h.image_panner(
+                self.panner.source, self.panner.size, self.panner.field)
+        new_window = VariableMeshPannerView(panner = np)
diff -r 0ea10be4b283 -r 8472d0d8acc3 yt/extensions/image_panner/vm_panner.py
--- a/yt/extensions/image_panner/vm_panner.py	Thu Mar 25 23:29:56 2010 -0700
+++ b/yt/extensions/image_panner/vm_panner.py	Sun Mar 28 15:18:05 2010 -0700
@@ -32,6 +32,16 @@
 
     def __init__(self, source, size, field, callback = None,
                  viewport_callback = None):
+        """
+        This class describes a meta-view onto a 2D data interface.  You provide
+        it with a slice or a projection (*source*), a tuple of the x and y
+        resolution of the final image you want (*size) and a *field* to
+        display, and then it will generate a new buffer each time you call its
+        methods for moving the window around and changing its size.  *callback*
+        is a routine called with the new buffer each time the buffer changes
+        and *viewport_callback* is called with the new *xlim* and *ylim* values
+        each time the viewport changes.
+        """
         if not isinstance(source, (AMRProjBase, AMRSliceBase)):
             raise RuntimeError
         if callback is None:
@@ -65,6 +75,9 @@
         return (Wx, Wy)
 
     def zoom(self, factor):
+        """
+        This zooms the window by *factor*.
+        """
         Wx, Wy = self.width
         centerx = self.xlim[0] + Wx*0.5
         centery = self.ylim[0] + Wy*0.5
@@ -74,26 +87,49 @@
         self._run_callbacks()
 
     def pan(self, deltas):
+        """
+        This accepts a tuple of *deltas*, composed of (delta_x, delta_y) that
+        will pan the window by those values in absolute coordinates.
+        """
         self.xlim = (self.xlim[0] + deltas[0], self.xlim[1] + deltas[0])
         self.ylim = (self.ylim[0] + deltas[1], self.ylim[1] + deltas[1])
         self._run_callbacks()
 
     def pan_x(self, delta):
+        """
+        This pans the window by *delta* in the x direction.
+        """
         self.pan( (delta, 0.0) )
 
     def pan_y(self, delta):
+        """
+        This pans the window by *delta* in the y direction.
+        """
         self.pan( (0.0, delta) )
 
     def pan_rel(self, deltas):
+        """
+        This accepts a tuple of *deltas*, composed of (delta_x, delta_y) that
+        will pan the window by those values in relative values, relative to the
+        current window view.
+        """
         Wx, Wy = self.width
         px = deltas[0] * Wx
         py = deltas[1] * Wy
         self.pan( (px, py) )
 
     def pan_rel_x(self, delta):
+        """
+        This pans the window by *delta* in the x direction, where *delta* is
+        relative to the current window view.
+        """
         self.pan_rel( (delta, 0.0) )
 
     def pan_rel_y(self, delta):
+        """
+        This pans the window by *delta* in the y direction, where *delta* is
+        relative to the current window view.
+        """
         self.pan_rel( (0.0, delta) )
 
     @property
@@ -113,11 +149,19 @@
         self._buffer = new_buffer
 
     def set_low_high(self, low, high):
+        """
+        This accepts *low* in the format (x_min, y_min) and *high* in the
+        format (x_max, y_max) and changes the viewport appropriately.  In
+        breaking from tradition, it also returns the buffer.
+        """
         self.xlim = (low[0], high[0])
         self.ylim = (low[1], high[1])
         return na.log10(self.buffer)
 
     def set_limits(self, xlim, ylim):
+        """
+        This accepts a new *xlim* and *ylim*.
+        """
         self.xlim = xlim
         self.ylim = ylim
         self._run_callbacks()
@@ -128,6 +172,13 @@
 
     def __init__(self, source, full_size, my_size, start_indices,
                  field, callback = None):
+        """
+        This image panner accepts a *full_size*, which describes the full size
+        of the image which it will be displaying a portion of.  *my_size* is
+        the size that this window will be responsible for, and *start_indices*
+        is a tuple of indices that this window begins at.  *field* and
+        *callback* function as in the vanilla image panner.
+        """
         self.my_size = my_size
         self.start_indices = start_indices
         VariableMeshPanner.__init__(self, source, full_size, field, callback)
@@ -146,6 +197,11 @@
 
 class MultipleWindowVariableMeshPanner(object):



More information about the yt-svn mailing list