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

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Sun May 18 21:05:02 PDT 2008


Author: mturk
Date: Sun May 18 21:05:01 2008
New Revision: 491
URL: http://yt.spacepope.org/changeset/491

Log:
Committing the inital version of the new 2D profile interface.  This will
become the *only* version soon enough; for now both are included in the source.



Modified:
   trunk/yt/raven/PlotCollection.py
   trunk/yt/reason/App.py
   trunk/yt/reason/Notebook.py
   trunk/yt/reason/Windows.py

Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py	(original)
+++ trunk/yt/raven/PlotCollection.py	Sun May 18 21:05:01 2008
@@ -191,7 +191,8 @@
                                      x_bins, fields[0], x_min, x_max, x_log,
                                      y_bins, fields[1], y_min, y_max, y_log,
                                      lazy_reader)
-        profile.add_fields(fields[2], weight=weight, accumulation=accumulation)
+        if len(fields) > 2:
+            profile.add_fields(fields[2], weight=weight, accumulation=accumulation)
         # These next two lines are painful.
         profile.pf = self.pf
         profile.hierarchy = self.pf.hierarchy

Modified: trunk/yt/reason/App.py
==============================================================================
--- trunk/yt/reason/App.py	(original)
+++ trunk/yt/reason/App.py	Sun May 18 21:05:01 2008
@@ -267,16 +267,37 @@
     def _add_phase(self, event=None):
         MyID = wx.NewId()
         data_object = self.get_output()
+        p2ds = Profile2DSetup(data_object, self)
+        if not p2ds.ShowModal() == wx.ID_OK:
+            p2ds.Destroy()
+            return
+        argdict = p2ds.return_argdict()
+        if argdict is None:
+            p2ds.Destroy()
+            return
+        for ax in 'xy':
+            if argdict['%s_lower_bound'%ax] is None:
+                argdict['%s_lower_bound'%ax] = \
+                    self.__find_min(data_object, argdict['%s_bin_field'%ax])
+            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( \
-            PhasePlotPage(parent=self.plot_panel.nb,
+            NewPhasePlotPage(parent=self.plot_panel.nb,
                           status_bar=self.status_bar,
                           data_object = data_object,
-                          CreationID = MyID,
+                          argdict = argdict, CreationID = MyID,
                           mw = self))
         self.plot_panel.AddPlot(self.windows[-1], t, MyID)
         mylog.debug("Adding with ID: %s", MyID)
 
+    def __find_min(self, data_object, field):
+        return data_object[field].min()
+
+    def __find_max(self, data_object, field):
+        return data_object[field].max()
+
     def _add_proj(self, event=None):
         MyID = wx.NewId()
         data_object = self.get_output()

Modified: trunk/yt/reason/Notebook.py
==============================================================================
--- trunk/yt/reason/Notebook.py	(original)
+++ trunk/yt/reason/Notebook.py	Sun May 18 21:05:01 2008
@@ -654,13 +654,106 @@
         return [self.field]
 
 class NewPhasePlotPage(PlotPage):
-    def __init__(self, parent, status_bar, data_object, mw=None, CreationID = -1):
+    def __init__(self, parent, status_bar, data_object, argdict, mw=None, CreationID = -1):
         self.data_object = data_object
+        self.argdict = argdict
 
         PlotPage.__init__(self, parent, status_bar, mw, CreationID)
+        self.UpdateAvailableFields()
 
     def SetupControls(self):
         self.ButtonPanel = wx.Panel(self, -1)
+        self.sbox = wx.StaticBox(self.ButtonPanel, -1, "Field Selection")
+        self.z_field = wx.Choice(self.ButtonPanel, -1, choices=[])
+        self.add_field = wx.Button(self.ButtonPanel, -1, "Add Field")
+        self.Bind(wx.EVT_BUTTON, self.AddField, self.add_field)
+        self.Bind(wx.EVT_CHOICE, self.switch_z, self.z_field)
+
+    def DoLayout(self):
+        self.MainSizer = wx.BoxSizer(wx.VERTICAL)
+        self.MainSizer.Add(self.figure_canvas, 1, wx.EXPAND)
+        self.MainSizer.Add(self.ButtonPanel, 0, wx.EXPAND)
+
+        sizer = wx.BoxSizer(wx.HORIZONTAL)
+        sizer.Add(self.z_field, 1, wx.EXPAND)
+        sizer.Add(self.add_field, 0, wx.EXPAND)
+        self.ButtonPanel.SetSizer(sizer)
+        self.ButtonPanel.Layout()
+
+        self.SetSizer(self.MainSizer)
+        self.Layout()
+
+    def AddField(self, event=None):
+        pf2daf = Profile2DAddField(self.data_object, self)
+        if pf2daf.ShowModal() == wx.ID_OK:
+            argdict = pf2daf.return_argdict()
+            if argdict is None:
+                pf2daf.Destroy()
+                return
+            self.data.add_fields(**argdict)
+            self.UpdateAvailableFields()
+            self.z_field.SetSelection(
+                    self.z_field.GetItems().index(argdict['fields']))
+            self.switch_z()
+        pf2daf.Destroy()
+
+    def makePlot(self, event=None):
+        self.data = lagos.BinnedProfile2D(self.data_object, **self.argdict)
+        self.data.pf = self.data_object.pf
+        self.data.hierarchy = self.data_object.pf.h
+        # Now, unfortunately, we prompt for the field
+        self.AddField(None)
+        self.plot = be.NewPhasePlot(self.data, 
+                                    [self.argdict['x_bin_field'],
+                                     self.argdict['y_bin_field'],
+                                     self.z_field.GetStringSelection()],
+                                    figure=self.figure, axes=self.axes)
+
+    def UpdateStatusBar(self, event):
+        #print event.x, event.y
+        if event.inaxes:
+            if not hasattr(self.plot, 'pix'): return
+            xp, yp = event.xdata, event.ydata
+            xn = self.data.x_bin_field
+            yn = self.data.y_bin_field
+            vn = self.FieldZ.StringSelection
+            self.status_bar.SetStatusText("%s = %0.5e" % (xn, xp), 0)
+            self.status_bar.SetStatusText("%s = %0.5e" % (yn, yp), 1)
+            self.status_bar.SetStatusText("%s = %0.5e" % \
+                                        (vn, self.GetDataValue(xp,yp)), 2)
+
+    def GetDataValue(self, x, y):
+        xi = na.digitize(na.array([x]), self.plot.x_bins)-1
+        yi = na.digitize(na.array([y]), self.plot.y_bins)-1
+        return self.plot.vals[yi, xi]
+
+    def UpdateAvailableFields(self):
+        self.z_field.SetItems(sorted(self.QueryAvailableFields()))
+
+    def QueryAvailableFields(self):
+        fields = []
+        for field in self.data.keys():
+            if field != self.data.x_bin_field and \
+               field != self.data.y_bin_field:
+                fields.append(field)
+        return fields
+
+    def switch_z(self, event=None):
+        if self.plot is None: return
+        self.plot.switch_z(self.z_field.GetStringSelection())
+        self.UpdateCanvas()
+
+    def UpdateCanvas(self, *args):
+        if self.IsShown():
+            self.plot._redraw_image()
+            self.figure_canvas.draw()
+        #else: print "Opting not to update canvas"
+
+    def ChangeLimits(self, zmin, zmax):
+        print "Change Limits"
+        self.plot.set_zlim(zmin,zmax)
+        self.figure_canvas.draw()
+        # We don't call update canvas
 
 class PhasePlotPage(PlotPage):
     def __init__(self, parent, status_bar, data_object, mw=None, CreationID = -1):

Modified: trunk/yt/reason/Windows.py
==============================================================================
--- trunk/yt/reason/Windows.py	(original)
+++ trunk/yt/reason/Windows.py	Sun May 18 21:05:01 2008
@@ -26,6 +26,60 @@
 
 from yt.reason import *
 
+class Profile2DAddField(wx.Dialog):
+    def __init__(self, data_object, parent):
+        wx.Dialog.__init__(self, parent, -1, title="Add Field to 2D Profile")
+
+        fields = QueryFields(data_object)
+        
+        border = wx.BoxSizer(wx.VERTICAL)
+        inner_border = wx.BoxSizer(wx.VERTICAL)
+
+        sbox = wx.StaticBox(self, -1, "Z Field Specifications")
+        box = wx.StaticBoxSizer(sbox, wx.VERTICAL)
+        gbs = wx.GridBagSizer(5, 5)
+        self.z_field = wx.Choice(self, -1, choices=fields, name="Y")
+        text = wx.StaticText(self, -1, "Weighting Field")
+        self.z_weight = wx.Choice(self, -1, choices=[''] + fields, name="Weight")
+        if "CellMassMsun" in fields: self.z_weight.Select(fields.index("CellMassMsun")+1)
+        self.z_accx = wx.CheckBox(self, -1, "X Accumulation")
+        self.z_accx.SetValue(False)
+        self.z_accy = wx.CheckBox(self, -1, "Y Accumulation")
+        self.z_accy.SetValue(False)
+
+        gbs.Add(self.z_field, (0,0), (1,2))
+        gbs.Add(text, (1,0))
+        gbs.Add(self.z_weight, (2,0), (1,2))
+        gbs.Add(self.z_accx, (3,0), (1,2))
+        gbs.Add(self.z_accy, (4,0), (1,2))
+        box.Add(gbs, 1, wx.EXPAND | wx.ALL)
+        inner_border.Add(box, 1, wx.EXPAND)
+        inner_border.AddSpacer(15)
+
+        gbs = wx.GridBagSizer(5,5)
+        ok_button = wx.Button(self, wx.ID_OK, "OK")
+        ok_button.SetDefault()
+        cancel_button = wx.Button(self, wx.ID_CANCEL, "Cancel")
+        gbs.Add(ok_button, (1,0), flag=wx.EXPAND)
+        gbs.Add(cancel_button, (1,1), flag=wx.EXPAND)
+        inner_border.Add(gbs, 0, wx.EXPAND)
+        
+        border.Add(inner_border, 1, wx.EXPAND|wx.ALL, 25)
+        self.SetSizer(border)
+        self.Fit()
+
+    def return_argdict(self):
+        argdict = {}
+        try:
+            argdict['fields'] = str(self.z_field.GetStringSelection())
+            argdict['weight'] = str(self.z_weight.GetStringSelection())
+            argdict['accumulation'] = (self.z_accx.GetValue(),
+                                       self.z_accy.GetValue())
+            if argdict['weight'] == '': argdict['weight'] = None
+        except ValueError:  
+            return None
+        return argdict
+
 class Profile2DSetup(wx.Dialog):
     def __init__(self, data_object, parent):
         wx.Dialog.__init__(self, parent, -1, title="Setup 2D Profile")
@@ -87,27 +141,6 @@
         inner_border.Add(box, 1, wx.EXPAND)
         inner_border.AddSpacer(15)
 
-        sbox = wx.StaticBox(self, -1, "Z Field Specifications")
-        box = wx.StaticBoxSizer(sbox, wx.VERTICAL)
-        gbs = wx.GridBagSizer(5, 5)
-        self.z_field = wx.Choice(self, -1, choices=fields, name="Y")
-        text = wx.StaticText(self, -1, "Weighting Field")
-        self.z_weight = wx.Choice(self, -1, choices=[''] + fields, name="Weight")
-        if "CellMassMsun" in fields: self.z_weight.Select(fields.index("CellMassMsun")+1)
-        self.z_accx = wx.CheckBox(self, -1, "X Accumulation")
-        self.z_accx.SetValue(False)
-        self.z_accy = wx.CheckBox(self, -1, "Y Accumulation")
-        self.z_accy.SetValue(False)
-
-        gbs.Add(self.z_field, (0,0), (1,2))
-        gbs.Add(text, (1,0))
-        gbs.Add(self.z_weight, (2,0), (1,2))
-        gbs.Add(self.z_accx, (3,0), (1,2))
-        gbs.Add(self.z_accy, (4,0), (1,2))
-        box.Add(gbs, 1, wx.EXPAND | wx.ALL)
-        inner_border.Add(box, 1, wx.EXPAND)
-        inner_border.AddSpacer(15)
-
         gbs = wx.GridBagSizer(5,5)
         self.lazy_reader = wx.CheckBox(self, -1, "Memory Conservative")
         self.Bind(wx.EVT_CHECKBOX, self.OnToggleLaziness, self.lazy_reader)
@@ -157,22 +190,22 @@
         try:
             if self.lazy_reader.GetValue():
                 argdict['lazy_reader'] = True
-                argdict['x_bounds'] = (float(self.x_min.GetValue()),
-                                       float(self.x_max.GetValue()))
-                argdict['y_bounds'] = (float(self.y_min.GetValue()),
-                                       float(self.y_max.GetValue()))
+                argdict['x_lower_bound'] = float(self.x_min.GetValue())
+                argdict['x_upper_bound'] = float(self.x_max.GetValue())
+                argdict['y_lower_bound'] = float(self.y_min.GetValue())
+                argdict['y_upper_bound'] = float(self.y_max.GetValue())
             else:
                 argdict['lazy_reader'] = False
-                argdict['x_bounds'] = None
-                argdict['y_bounds'] = None
+                argdict['x_lower_bound'] = None
+                argdict['x_upper_bound'] = None
+                argdict['y_lower_bound'] = None
+                argdict['y_upper_bound'] = None
             argdict['x_log'] = self.x_log.GetValue()
             argdict['y_log'] = self.y_log.GetValue()
-            argdict['x_bins'] = int(self.x_bins.GetValue())
-            argdict['y_bins'] = int(self.y_bins.GetValue())
-            argdict['fields'] = [str(x.GetStringSelection()) for x in 
-                                  [self.x_field, self.y_field, self.z_field]]
-            argdict['weight'] = str(self.z_weight.GetStringSelection())
-            if argdict['weight'] == '': argdict['weight'] = None
+            argdict['x_n_bins'] = int(self.x_bins.GetValue())
+            argdict['y_n_bins'] = int(self.y_bins.GetValue())
+            argdict['x_bin_field'] = str(self.x_field.GetStringSelection())
+            argdict['y_bin_field'] = str(self.y_field.GetStringSelection())
         except ValueError:  
             return None
         return argdict



More information about the yt-svn mailing list