[Yt-svn] yt-commit r723 - branches/yt-1.0/yt/raven trunk/yt/raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Aug 7 17:07:26 PDT 2008


Author: mturk
Date: Thu Aug  7 17:07:25 2008
New Revision: 723
URL: http://yt.spacepope.org/changeset/723

Log:
Added ClumpContourCallback.  You can add this to a plot and it'll overplot
contour lines wherever the clumps you instantiate it with are located.


An example script:

{{{
#!python
from yt.mods import *

pf = EnzoStaticOutput("galaxy1200")
sp = pf.h.sphere([0.5]*3, 1.0)

bounds, cids = sp.extract_connected_sets("Density", 1, 1e-26, 1e-23)

pc = PlotCollectionInteractive(pf)

for i in range(3):
  pc.add_projection("Density", i)
  pc.plots[-1].add_callback(raven.ClumpContourCallback(cids[0].values(),i,{'colors':'k'}))

pc.set_width(0.005, '1')
}}}

Looks a bit overly-complicated, but I'll work on that later.  I haven't tested
it with Clump.py, but that shouldn't be hard to integrate it with.



Modified:
   branches/yt-1.0/yt/raven/Callbacks.py
   trunk/yt/raven/Callbacks.py

Modified: branches/yt-1.0/yt/raven/Callbacks.py
==============================================================================
--- branches/yt-1.0/yt/raven/Callbacks.py	(original)
+++ branches/yt-1.0/yt/raven/Callbacks.py	Thu Aug  7 17:07:25 2008
@@ -323,4 +323,36 @@
         plot._axes.set_ylim(yy0,yy1)
         plot._axes.hold(False)
 
+class ClumpContourCallback(PlotCallback):
+    def __init__(self, clumps, axis, plot_args = None):
+        """
+        Take a list of *clumps* and plot them as a set of contours.
+        """
+        self.clumps = clumps
+        self.xf = lagos.axis_names[lagos.x_dict[axis]]
+        self.yf = lagos.axis_names[lagos.y_dict[axis]]
+        if plot_args is None: plot_args = {}
+        self.plot_args = plot_args
 
+    def __call__(self, plot):
+        x0, x1 = plot.xlim
+        y0, y1 = plot.ylim
+        xx0, xx1 = plot._axes.get_xlim()
+        yy0, yy1 = plot._axes.get_ylim()
+        plot._axes.hold(True)
+        
+        nx, ny = plot.image._A.shape
+        buff = na.zeros((nx,ny),dtype='float64')
+        for i,clump in enumerate(reversed(self.clumps)):
+            mylog.debug("Pixelizing contour %s", i)
+            temp = _MPL.Pixelize(clump[self.xf],
+                                 clump[self.yf],
+                                 clump['dx'],
+                                 clump['dx'],
+                                 clump['dx']*0.0+i+1, # inits inside Pixelize
+                                 int(nx), int(ny),
+                             (x0, x1, y0, y1), 0).transpose()
+            buff = na.maximum(temp, buff)
+        self.rv = plot._axes.contour(buff, len(self.clumps)+1,
+                                     **self.plot_args)
+        plot._axes.hold(False)

Modified: trunk/yt/raven/Callbacks.py
==============================================================================
--- trunk/yt/raven/Callbacks.py	(original)
+++ trunk/yt/raven/Callbacks.py	Thu Aug  7 17:07:25 2008
@@ -323,4 +323,36 @@
         plot._axes.set_ylim(yy0,yy1)
         plot._axes.hold(False)
 
+class ClumpContourCallback(PlotCallback):
+    def __init__(self, clumps, axis, plot_args = None):
+        """
+        Take a list of *clumps* and plot them as a set of contours.
+        """
+        self.clumps = clumps
+        self.xf = lagos.axis_names[lagos.x_dict[axis]]
+        self.yf = lagos.axis_names[lagos.y_dict[axis]]
+        if plot_args is None: plot_args = {}
+        self.plot_args = plot_args
 
+    def __call__(self, plot):
+        x0, x1 = plot.xlim
+        y0, y1 = plot.ylim
+        xx0, xx1 = plot._axes.get_xlim()
+        yy0, yy1 = plot._axes.get_ylim()
+        plot._axes.hold(True)
+        
+        nx, ny = plot.image._A.shape
+        buff = na.zeros((nx,ny),dtype='float64')
+        for i,clump in enumerate(reversed(self.clumps)):
+            mylog.debug("Pixelizing contour %s", i)
+            temp = _MPL.Pixelize(clump[self.xf],
+                                 clump[self.yf],
+                                 clump['dx'],
+                                 clump['dx'],
+                                 clump['dx']*0.0+i+1, # inits inside Pixelize
+                                 int(nx), int(ny),
+                             (x0, x1, y0, y1), 0).transpose()
+            buff = na.maximum(temp, buff)
+        self.rv = plot._axes.contour(buff, len(self.clumps)+1,
+                                     **self.plot_args)
+        plot._axes.hold(False)



More information about the yt-svn mailing list