[Yt-svn] yt-commit r499 - in trunk/yt: raven reason

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Wed May 28 16:02:06 PDT 2008


Author: mturk
Date: Wed May 28 16:02:05 2008
New Revision: 499
URL: http://yt.spacepope.org/changeset/499

Log:
 * Added phase plot wrapper, to make a plot page from an arbitrary object.  It
   shows up in the shell as add_phase.
 * Refactored adding of notebook pages
 * Added cutting planes, which can be added from spheres in the data objects
   menu.
 * Fixed bug in PlotTypes where we were not mandating that the CPixelize output
   was at fixed aspect ratio.  Now it matches the methods in the slice plot.



Modified:
   trunk/yt/raven/PlotTypes.py
   trunk/yt/reason/App.py
   trunk/yt/reason/Notebook.py
   trunk/yt/reason/Toolbars.py

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Wed May 28 16:02:05 2008
@@ -405,17 +405,19 @@
         px_min, px_max = self.xlim
         py_min, py_max = self.ylim
         l, b, width, height = self._axes.bbox.get_bounds()
+        self.pix = (width,height)
         indices = na.argsort(self.data['dx'])[::-1]
         buff = _MPL.CPixelize( self.data['x'], self.data['y'], self.data['z'],
                                self.data['px'], self.data['py'],
                                self.data['pdx'], self.data['pdy'], self.data['pdz'],
                                self.data.center, self.data._inv_mat, indices,
                                self.data[self.axis_names['Z']],
-                               int(width), int(height),
+                               int(width), int(width),
                                (px_min, px_max, py_min, py_max))
         return buff
 
     def _refresh_display_width(self, width=None):
+        
         if width:
             self.width = width
         else:

Modified: trunk/yt/reason/App.py
==============================================================================
--- trunk/yt/reason/App.py	(original)
+++ trunk/yt/reason/App.py	Wed May 28 16:02:05 2008
@@ -27,9 +27,10 @@
 from yt.reason import *
 
 _StaticOutputMenuItems = ["proj","slice"]
-_SphereObjectMenuItems = ["phase"]
+_SphereObjectMenuItems = ["phase","cutting"]
 _ProjObjectMenuItems = []
 _SliceObjectMenuItems = []
+_CuttingPlaneObjectMenuItems = []
 
 class ReasonMainWindow(wx.Frame):
     def __init__(self, *args, **kwds):
@@ -81,7 +82,8 @@
                        'windows':self.windows,
                        'mainwindow':self,
                        'data_objects':self.data_objects,
-                       'pylab':pylab}
+                       'pylab':pylab,
+                       'add_phase':self.__add_phase_wrapper}
         wx.py.buffer.Buffer.updateNamespace = \
                 get_new_updateNamespace(self.locals)
         self.int_panel = wx.Panel(self.main_splitter, -1)
@@ -118,11 +120,13 @@
         self.PopupMenuIds["slice"] = self.PopupMenu.Append(-1, "Slice")
         self.PopupMenuIds["proj"] = self.PopupMenu.Append(-1, "Project")
         self.PopupMenuIds["phase"] = self.PopupMenu.Append(-1, "Phase Plot")
-        self.PopupMenuIds["vr"] = self.PopupMenu.Append(-1, "Volume Render")
+        self.PopupMenuIds["cutting"] = self.PopupMenu.Append(-1, "Cutting Plane")
+        self.PopupMenuIds["extract"] = self.PopupMenu.Append(-1, "Extract Set")
 
         self.Bind(wx.EVT_MENU, self._add_slice, self.PopupMenuIds["slice"])
         self.Bind(wx.EVT_MENU, self._add_proj, self.PopupMenuIds["proj"])
         self.Bind(wx.EVT_MENU, self._add_phase, self.PopupMenuIds["phase"])
+        self.Bind(wx.EVT_MENU, self._add_cutting, self.PopupMenuIds["cutting"])
 
     def __setup_data_tree(self):
 
@@ -264,9 +268,21 @@
         # These all get passed in
         self._add_data_object(title, sphere, _SphereObjectMenuItems)
 
-    def _add_phase(self, event=None):
+    def __add_phase_wrapper(self, obj):
+        """
+        Add a phase plot from an arbitrary object.
+        """
+        self._add_phase(data_object=obj)
+
+    def _add_page_to_notebook(self, page, name, id):
+        self.windows.append(page)
+        self.plot_panel.AddPlot(self.windows[-1], name, id)
+        mylog.debug("Adding page with ID: %s", id)
+        wx.SafeYield(onlyIfNeeded = True)
+
+    def _add_phase(self, event=None, data_object = None):
         MyID = wx.NewId()
-        data_object = self.get_output()
+        if data_object is None: parent_id, data_object = self.get_output()
         p2ds = Profile2DSetup(data_object, self)
         if not p2ds.ShowModal() == wx.ID_OK:
             p2ds.Destroy()
@@ -282,15 +298,13 @@
             if argdict['%s_upper_bound'%ax] is None:
                 argdict['%s_upper_bound'%ax] = \
                     self.__find_max(data_object, argdict['%s_bin_field'%ax])
-        t = "Phase Plot"
-        self.windows.append( \
+        self._add_page_to_notebook(
             PhasePlotPage(parent=self.plot_panel.nb,
                           status_bar=self.status_bar,
                           data_object = data_object,
                           argdict = argdict, CreationID = MyID,
-                          mw = self))
-        self.plot_panel.AddPlot(self.windows[-1], t, MyID)
-        mylog.debug("Adding with ID: %s", MyID)
+                          mw = self),
+            "Phase Plot %s" % MyID, MyID)
 
     def __find_min(self, data_object, field):
         return data_object[field].min()
@@ -300,7 +314,7 @@
 
     def _add_proj(self, event=None):
         MyID = wx.NewId()
-        data_object = self.get_output()
+        parent_id, data_object = self.get_output()
         width = 1.0
         unit = "1"
         proj_setup = ProjectionSetup(data_object, self)
@@ -313,18 +327,17 @@
         axes = []
         for i, ax in enumerate('xyz'):
             if not getattr(proj_setup,'%s_ax' % ax).GetValue(): continue
-            t = "%s - Projection - %s" % (data_object.basename, ax)
-            mylog.info("Adding %s projection of %s\n" % (ax, data_object))
-            self.windows.append( \
+            mylog.info("Adding %s projection of %s" % (ax, data_object))
+            self._add_page_to_notebook(
                 ProjPlotPage(parent=self.plot_panel.nb,
                               status_bar=self.status_bar,
                               outputfile = data_object,
                               axis=i,
                               field = field,
                               weight_field = weight_field,
-                              mw = self, CreationID=MyID))
-            self.plot_panel.AddPlot(self.windows[-1], t, MyID)
-            wx.SafeYield(onlyIfNeeded = True)
+                              mw = self, CreationID=MyID),
+                "%s - Projection - %s" % (data_object.basename, ax),
+                MyID)
             self._add_data_object("Proj: %s %s" % (data_object, ax),
                                self.windows[-1].plot.data,
                                _ProjObjectMenuItems)
@@ -334,28 +347,52 @@
 
     def _add_slice(self, event=None):
         MyID = wx.NewId()
-        data_object = self.get_output()
-        field = "Density"
-        width = 1.0
-        unit = "1"
+        parent_id, data_object = self.get_output()
+        field, width, unit = "Density", 1.0, '1'
         for i, ax in enumerate('xyz'):
-            t = "%s - Slice - %s" % (data_object.basename, ax)
-            mylog.info("Adding %s projection of %s\n" % (ax, data_object))
-            self.windows.append( \
+            mylog.info("Adding %s slice of %s" % (ax, data_object))
+            self._add_page_to_notebook(
                 SlicePlotPage(parent=self.plot_panel.nb,
                               status_bar=self.status_bar,
                               outputfile = data_object,
                               axis=i,
                               field = field,
-                              mw = self, CreationID=MyID))
-            self.plot_panel.AddPlot(self.windows[-1], t, MyID)
-            wx.SafeYield(onlyIfNeeded = True)
+                              mw = self, CreationID=MyID),
+                "%s - Slice - %s" % (data_object.basename, ax),
+                MyID)
             self._add_data_object("Slice: %s %s" % (data_object, ax),
                                self.windows[-1].plot.data,
                                _SliceObjectMenuItems)
-            print "Adding with ID:", MyID
         for w in self.windows[-3:]: w.ChangeWidth(1,'1')
 
+    def __add_cutting_wrapper(self, parameter_file, normal):
+        self._add_cutting(parameter_file=parameter_file, normal=normal)
+
+    def _add_cutting(self, event=None, parameter_file = None, normal=None,
+                     center = None):
+        if parameter_file is None or normal is None or center is None:
+            parent_id, data_object = self.get_output()
+            data_object.set_field_parameter("bulk_velocity",
+                data_object.quantities["BulkVelocity"](lazy_reader=True))
+            normal = data_object.quantities["AngularMomentumVector"](lazy_reader=True)
+            center = data_object.get_field_parameter("center")
+            parameter_file = data_object.pf
+        MyID = wx.NewId()
+        field, width, unit = "Density", 1.0, '1'
+        mylog.info("Adding cutting plane of %s with normal %s",
+                   data_object, normal)
+        self._add_page_to_notebook(
+            CuttingPlanePlotPage(parent=self.plot_panel.nb,
+                            status_bar=self.status_bar,
+                            outputfile=parameter_file, field=field, mw=self,
+                            CreationID=MyID, axis=4, normal=normal,
+                            center = center),
+            "%s - Cutting Plane" % (parameter_file.basename), MyID)
+        self._add_data_object("Cutting Plane" % (parameter_file),
+                              self.windows[-1].plot.data,
+                              _CuttingPlaneObjectMenuItems)
+        self.windows[-1].ChangeWidth(1,'1')
+
     def get_output(self, event=None):
         # Figure out which outputs are selected
         #tid = self.data_tree.GetFirstSelected()
@@ -368,7 +405,7 @@
             newData = wx.TreeItemData((ii, z, t, mids))
             self.data_tree.SetItemData(tid, newData)
         print "Got output:", ii
-        return ii
+        return tid, ii
 
     # Functions bound to messages in pubsub
 

Modified: trunk/yt/reason/Notebook.py
==============================================================================
--- trunk/yt/reason/Notebook.py	(original)
+++ trunk/yt/reason/Notebook.py	Wed May 28 16:02:05 2008
@@ -266,6 +266,12 @@
     def ChangeCenterFromMessage(self, message):
         pass
 
+    def ChangeFieldParamFromMessage(self, message):
+        pass
+
+    def WipePlotDataFromMessage(self, message):
+        pass
+
     def ChangeWidthFromMessage(self, message):
         pass
 
@@ -326,12 +332,15 @@
 
 class VMPlotPage(PlotPage):
     def __init__(self, parent, status_bar, outputfile, axis, field="Density",
-                 weight_field = None, mw=None, CreationID = -1):
+                 weight_field = None, mw=None, CreationID = -1,
+                 center = None):
         self.outputfile = outputfile
         self.field = field
         self.weight_field = weight_field
         self.axis = axis
-        self.center = [0.5, 0.5, 0.5]
+        if center is None:
+            center = [0.5, 0.5, 0.5]
+        self.center = center
         self.AmDrawingCircle = False
         self.circles = []
 
@@ -345,11 +354,11 @@
     def SetupMenu(self):
         PlotPage.SetupMenu(self)
         self.popupmenu.AppendSeparator()
-        centerOnMax = self.popupmenu.Append(-1, "Center on max")
-        centerHere = self.popupmenu.Append(-1, "Center here")
+        self.center_on_max = self.popupmenu.Append(-1, "Center on max")
+        self.center_here = self.popupmenu.Append(-1, "Center here")
         self.popupmenu.AppendSeparator()
-        gridBoundaries = self.popupmenu.AppendCheckItem(-1, "Show Grid Boundaries")
-        gridBoundaries.Check(False)
+        self.grid_boundaries = self.popupmenu.AppendCheckItem(-1, "Show Grid Boundaries")
+        self.grid_boundaries.Check(False)
         velocities = self.popupmenu.AppendCheckItem(-1, "Show Velocities")
         velocities.Check(False)
         self.popupmenu.AppendSeparator()
@@ -358,9 +367,9 @@
         fullDomain = self.popupmenu.Append(-1, "Zoom Top")
         bulk_velocity = self.popupmenu.Append(-1, "Set Bulk Velocity")
 
-        self.Bind(wx.EVT_MENU, self.OnCenterOnMax, centerOnMax)
-        self.Bind(wx.EVT_MENU, self.OnCenterHere, centerHere)
-        self.Bind(wx.EVT_MENU, self.show_grid_boundaries, gridBoundaries)
+        self.Bind(wx.EVT_MENU, self.OnCenterOnMax, self.center_on_max)
+        self.Bind(wx.EVT_MENU, self.OnCenterHere, self.center_here)
+        self.Bind(wx.EVT_MENU, self.show_grid_boundaries, self.grid_boundaries)
         self.Bind(wx.EVT_MENU, self.show_velocities, velocities)
         self.Bind(wx.EVT_MENU, self.take_log, self.take_log_menu)
         self.Bind(wx.EVT_MENU, self.fulldomain, fullDomain)
@@ -683,6 +692,26 @@
     def QueryFields(self):
         return [self.field]
 
+class CuttingPlanePlotPage(VMPlotPage):
+    def __init__(self, *args, **kwargs):
+        self.normal = kwargs.pop("normal")
+        VMPlotPage.__init__(self, *args, **kwargs)
+        self.__fix_menu()
+
+    def makePlot(self):
+        self.data = self.outputfile.hierarchy.cutting(self.normal,
+                                    self.center, self.field)
+        self.plot = be.CuttingPlanePlot(self.data, self.field,
+                                    figure=self.figure, axes=self.axes)
+
+    def UpdateStatusBar(self, event):
+        pass
+
+    def __fix_menu(self):
+        self.center_on_max.Enable(False)
+        self.center_here.Enable(False)
+        self.grid_boundaries.Enable(False)
+
 class PhasePlotPage(PlotPage):
     def __init__(self, parent, status_bar, data_object, argdict, mw=None, CreationID = -1):
         self.data_object = data_object

Modified: trunk/yt/reason/Toolbars.py
==============================================================================
--- trunk/yt/reason/Toolbars.py	(original)
+++ trunk/yt/reason/Toolbars.py	Wed May 28 16:02:05 2008
@@ -131,6 +131,27 @@
     dlg.Destroy()
     return w, u
 
+def GetAngularMomentumVector(outputfile, center):
+    dlg = ReasonWidthSelectionWindow(outputfile,
+                "Radius Selector",
+            "With the current display-center, over \n" + \
+            "what radius should bulk velocity be calculated?")
+    resp = dlg.ShowModal()
+    bv = None
+    if resp == wx.ID_OK:
+        w, u = dlg.GetData()
+        sp = outputfile.h.sphere(center=center, radius=w/outputfile[u])
+        bv = sp.quantities["BulkVelocity"](lazy_reader=True)
+        if na.any(na.isnan(bv)):
+            err = wx.MessageDialog(None, "Error",
+                            "The values were bad.  Try a bigger sphere?",
+                            wx.OK)
+            err.ShowModal()
+            err.Destroy()
+            bv = None
+    dlg.Destroy()
+    return bv
+
 def GetBulkVelocity(outputfile, center):
     dlg = ReasonWidthSelectionWindow(outputfile,
                 "Radius Selector",



More information about the yt-svn mailing list