[Yt-svn] yt: 2 new changesets
hg at spacepope.org
hg at spacepope.org
Sun Mar 28 16:27:13 PDT 2010
hg Repository: yt
details: yt/rev/2c237b98a889
changeset: 1490:2c237b98a889
user: Stephen Skory <stephenskory at yahoo.com>
date:
Sun Mar 28 12:52:49 2010 -0700
description:
Making the disk-wait time a parameter.
hg Repository: yt
details: yt/rev/dd9a2ca7467e
changeset: 1491:dd9a2ca7467e
user: Stephen Skory <stephenskory at yahoo.com>
date:
Sun Mar 28 16:27:01 2010 -0700
description:
Merging.
diffstat:
yt/extensions/MergerTree.py | 10 +-
yt/extensions/image_panner/pan_and_scan_widget.py | 101 ++++++++++++++----------
yt/extensions/image_panner/vm_panner.py | 76 +++++++++++++++++++
3 files changed, 141 insertions(+), 46 deletions(-)
diffs (truncated from 379 to 300 lines):
diff -r 66e4cf437616 -r dd9a2ca7467e yt/extensions/MergerTree.py
--- a/yt/extensions/MergerTree.py Sat Mar 27 19:38:22 2010 -0700
+++ b/yt/extensions/MergerTree.py Sun Mar 28 16:27:01 2010 -0700
@@ -86,11 +86,12 @@
def _close_database(self):
# close the database cleanly.
self.cursor.close()
+ self.conn.close()
class MergerTree(DatabaseFunctions, lagos.ParallelAnalysisInterface):
def __init__(self, restart_files=[], database='halos.db',
halo_finder_function=HaloFinder, halo_finder_threshold=80.0,
- FOF_link_length=0.2, dm_only=False, refresh=False):
+ FOF_link_length=0.2, dm_only=False, refresh=False, sleep=5):
self.restart_files = restart_files # list of enzo restart files
self.database = database # the sqlite database of haloes.
self.halo_finder_function = halo_finder_function # which halo finder to use
@@ -98,6 +99,9 @@
self.FOF_link_length= FOF_link_length # For FOF
self.dm_only = dm_only
self.refresh = refresh
+ self.sleep = sleep # How long to wait between db sync checks.
+ if self.sleep <= 0.:
+ self.sleep = 5
# MPI stuff
self.mine = self._mpi_get_rank()
if self.mine is None:
@@ -211,7 +215,7 @@
except IOError:
# This is to give a little bit of time for the database creation
# to replicate across the file system.
- time.sleep(5)
+ time.sleep(self.sleep)
file = open(self.database)
hash = md5.md5(file.read()).hexdigest()
file.close()
@@ -221,7 +225,7 @@
break
else:
# Wait a little bit for the file system to (hopefully) sync up.
- time.sleep(5)
+ time.sleep(self.sleep)
if len(hashes) == 1:
return
else:
diff -r 66e4cf437616 -r dd9a2ca7467e yt/extensions/image_panner/pan_and_scan_widget.py
--- a/yt/extensions/image_panner/pan_and_scan_widget.py Sat Mar 27 19:38:22 2010 -0700
+++ b/yt/extensions/image_panner/pan_and_scan_widget.py Sun Mar 28 16:27:01 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 66e4cf437616 -r dd9a2ca7467e yt/extensions/image_panner/vm_panner.py
--- a/yt/extensions/image_panner/vm_panner.py Sat Mar 27 19:38:22 2010 -0700
+++ b/yt/extensions/image_panner/vm_panner.py Sun Mar 28 16:27:01 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):
+ """
More information about the yt-svn
mailing list