[Yt-svn] yt-commit r543 - trunk/yt/reason

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Jun 5 23:55:19 PDT 2008


Author: mturk
Date: Thu Jun  5 23:55:18 2008
New Revision: 543
URL: http://yt.spacepope.org/changeset/543

Log:
 * Added set extraction (closes #105) from spheres (and other extracted sets)
 * Fixed the hierarchy of objects, so each object is now directly underneath
the one it was spawned from.
 * This changed the way we describe projections and slices, so that has been
changed; they no longer include the data output name.



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

Modified: trunk/yt/reason/App.py
==============================================================================
--- trunk/yt/reason/App.py	(original)
+++ trunk/yt/reason/App.py	Thu Jun  5 23:55:18 2008
@@ -27,7 +27,7 @@
 from yt.reason import *
 
 _StaticOutputMenuItems = ["proj","slice","export",]
-_SphereObjectMenuItems = ["phase","profile","cutting","export",]
+_SphereObjectMenuItems = ["phase","profile","cutting","export","extract"]
 _ProjObjectMenuItems = ["export",]
 _SliceObjectMenuItems = []
 _CuttingPlaneObjectMenuItems = ["export",]
@@ -134,7 +134,7 @@
         self.Bind(wx.EVT_MENU, self._add_phase, self.PopupMenuIds["phase"])
         self.Bind(wx.EVT_MENU, self._add_profile, self.PopupMenuIds["profile"])
         self.Bind(wx.EVT_MENU, self._add_cutting, self.PopupMenuIds["cutting"])
-        #self.Bind(wx.EVT_MENU, self._extract_set, self.PopupMenuIds["extract"])
+        self.Bind(wx.EVT_MENU, self._extract_set, self.PopupMenuIds["extract"])
         #self.Bind(wx.EVT_MENU, self._extract_cube, self.PopupMenuIds["cube"])
         self.Bind(wx.EVT_MENU, self._export_data_object, self.PopupMenuIds["export"])
 
@@ -282,9 +282,9 @@
         ni = self.data_tree.AppendItem(parent_id, "%s" % (title), data=tid)
         self.data_tree.Expand(parent_id)
 
-    def _add_sphere(self, title, sphere):
+    def _add_sphere(self, title, sphere, parent_id=None):
         # These all get passed in
-        self._add_data_object(title, sphere, _SphereObjectMenuItems)
+        self._add_data_object(title, sphere, _SphereObjectMenuItems, parent_id)
 
     def __add_profile_wrapper(self, obj):
         """
@@ -328,7 +328,7 @@
                             status_bar=self.status_bar,
                             data_object = data_object,
                             argdict = argdict, CreationID = MyID,
-                            mw = self),
+                            mw = self, parent_id=parent_id),
             "Profile Plot %s" % MyID, MyID)
         if parent_id is not None:
             self._add_data_object("Profile: %s" % (argdict['bin_field']),
@@ -360,10 +360,9 @@
                           status_bar=self.status_bar,
                           data_object = data_object,
                           argdict = argdict, CreationID = MyID,
-                          mw = self),
+                          mw = self, parent_id=parent_id),
             "Phase Plot %s" % MyID, MyID)
         if parent_id is not None:
-            self.pid = parent_id
             self._add_data_object("Phase: %s, %s" % (argdict['x_bin_field'],
                                                  argdict['y_bin_field']),
                                self.windows[-1].plot.data,
@@ -387,7 +386,7 @@
         field = proj_setup.field.GetStringSelection()
         weight_field = proj_setup.weight_field.GetStringSelection()
         if weight_field == "": weight_field = None
-        axes = []
+        total = 0
         for i, ax in enumerate('xyz'):
             if not getattr(proj_setup,'%s_ax' % ax).GetValue(): continue
             mylog.info("Adding %s projection of %s" % (ax, data_object))
@@ -398,14 +397,16 @@
                               axis=i,
                               field = field,
                               weight_field = weight_field,
-                              mw = self, CreationID=MyID),
+                              mw = self, CreationID=MyID,
+                              parent_id=parent_id),
                 "%s - Projection - %s" % (data_object.basename, ax),
                 MyID)
-            self._add_data_object("Proj: %s %s" % (data_object, ax),
+            self._add_data_object("Proj: %s - %s (%s)" % (ax, field, weight_field),
                                self.windows[-1].plot.data,
                                _ProjObjectMenuItems, parent_id)
             print "Adding with ID:", MyID
-        for w in self.windows[-3:]: w.ChangeWidth(1,'1')
+            total += 1
+        for w in self.windows[-total:]: w.ChangeWidth(1,'1')
         proj_setup.Destroy()
 
     def _add_slice(self, event=None):
@@ -420,10 +421,11 @@
                               outputfile = data_object,
                               axis=i,
                               field = field,
-                              mw = self, CreationID=MyID),
+                              mw = self, CreationID=MyID,
+                              parent_id = parent_id),
                 "%s - Slice - %s" % (data_object.basename, ax),
                 MyID)
-            self._add_data_object("Slice: %s %s" % (data_object, ax),
+            self._add_data_object("Slice: %s" % (ax),
                                self.windows[-1].plot.data,
                                _SliceObjectMenuItems, parent_id)
         for w in self.windows[-3:]: w.ChangeWidth(1,'1')
@@ -447,6 +449,21 @@
                 err.Destroy()
         dlg.Destroy()
 
+    def _extract_set(self, event=None, data_object=None):
+        MyID = wx.NewId()
+        parent_id = None
+        if data_object is None: parent_id, data_object = self.get_output()
+        ess = ExtractSetSetup(data_object, self)
+        if not ess.ShowModal() == wx.ID_OK:
+            ess.Destroy()
+            return
+        ind = ess.return_indices()
+        ess.Destroy()
+        extracted_set = data_object.extract_region(ind)
+        self._add_data_object("Extracted Set",
+                              extracted_set,
+                              _SphereObjectMenuItems, parent_id)
+
     def __add_cutting_wrapper(self, parameter_file, normal):
         self._add_cutting(parameter_file=parameter_file, normal=normal)
 
@@ -469,7 +486,7 @@
                             status_bar=self.status_bar,
                             outputfile=parameter_file, field=field, mw=self,
                             CreationID=MyID, axis=4, normal=normal,
-                            center = center),
+                            center = center, parent_id=parent_id),
             "%s - Cutting Plane" % (parameter_file.basename), MyID)
         self._add_data_object("Cutting Plane" % (parameter_file),
                               self.windows[-1].plot.data,

Modified: trunk/yt/reason/Notebook.py
==============================================================================
--- trunk/yt/reason/Notebook.py	(original)
+++ trunk/yt/reason/Notebook.py	Thu Jun  5 23:55:18 2008
@@ -156,13 +156,15 @@
 
 class PlotPage(wx.Panel):
     plot = None
-    def __init__(self, parent, status_bar, mw=None, CreationID = -1):
+    def __init__(self, parent, status_bar, mw=None, CreationID = -1,
+                 parent_id = None):
         wx.Panel.__init__(self, parent)
         self.Hide()
 
         self.CreationID = CreationID
         self.parent = parent
         self.mw = mw
+        self.parent_id = parent_id
 
         self.figure = be.matplotlib.figure.Figure((1,1))
         self.axes = self.figure.add_subplot(111)
@@ -343,7 +345,7 @@
 class VMPlotPage(PlotPage):
     def __init__(self, parent, status_bar, outputfile, axis, field="Density",
                  weight_field = None, mw=None, CreationID = -1,
-                 center = None):
+                 center = None, parent_id = None):
         self.outputfile = outputfile
         self.field = field
         self.weight_field = weight_field
@@ -357,7 +359,7 @@
         if ytcfg.getboolean("reason","centeronmax"):
             self.center = outputfile.hierarchy.findMax("Density")[1]
 
-        PlotPage.__init__(self, parent, status_bar, mw, CreationID)
+        PlotPage.__init__(self, parent, status_bar, mw, CreationID, parent_id)
         self.SetBackgroundColour(wx.NamedColor("WHITE"))
         self.UpdateWidth()
 
@@ -539,7 +541,8 @@
                 sphere = self.outputfile.hierarchy.sphere( \
                     cc, r)
                 self.mw._add_sphere("Sphere: %0.3e %s" \
-                        % (r*unit, unitname), sphere)
+                        % (r*unit, unitname), sphere,
+                        self.parent_id)
                 self.AmDrawingCircle = False
             else:
                 self.x1 = xp
@@ -634,7 +637,7 @@
                 self.center,
                 radius/self.outputfile[unit])
             self.mw._add_sphere("Sphere: %0.3e %s" \
-                    % (radius, unit), sphere)
+                    % (radius, unit), sphere, self.parent_id)
 
     def WipePlotDataFromMessage(self, message):
         self.data.clear_data()
@@ -736,11 +739,11 @@
 
 class ProfilePlotPage(PlotPage):
     def __init__(self, parent, status_bar, data_object, argdict, mw=None,
-                 CreationID = -1):
+                 CreationID = -1, parent_id = None):
         self.data_object = data_object
         self.argdict = argdict
 
-        PlotPage.__init__(self, parent, status_bar, mw, CreationID)
+        PlotPage.__init__(self, parent, status_bar, mw, CreationID, parent_id)
         self.UpdateAvailableFields()
 
     def SetupControls(self):

Modified: trunk/yt/reason/Windows.py
==============================================================================
--- trunk/yt/reason/Windows.py	(original)
+++ trunk/yt/reason/Windows.py	Thu Jun  5 23:55:18 2008
@@ -355,7 +355,86 @@
         return argdict
 
 class ExtractSetSetup(wx.Dialog):
-    pass
+    def __init__(self, data_object, parent):
+
+        wx.Dialog.__init__(self, parent, -1, title="Set Arbitrary Bounds")
+
+        self.data_object = data_object
+        fields = QueryFields(data_object)
+        
+        border = wx.BoxSizer(wx.VERTICAL)
+        inner_border = wx.BoxSizer(wx.VERTICAL)
+
+        sbox = wx.StaticBox(self, -1, "Bounded Cell Extraction")
+        box = wx.StaticBoxSizer(sbox, wx.VERTICAL)
+        gbs = wx.GridBagSizer(5, 5)
+
+        self.field = wx.Choice(self, -1, choices=fields, name="Field")
+
+        self.bound_above = wx.CheckBox(self, -1, "Bound from above")
+        self.bound_above.SetValue(False)
+        self.upper_bound = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
+        self.upper_bound.SetValue('Upper Bound')
+        self.upper_bound.Enable(False)
+
+        self.bound_below = wx.CheckBox(self, -1, "Bound from below")
+        self.bound_below.SetValue(False)
+        self.lower_bound = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
+        self.lower_bound.SetValue('Lower Bound')
+        self.lower_bound.Enable(False)
+
+        ok_button = wx.Button(self, wx.ID_OK, "OK")
+        ok_button.SetDefault()
+        cancel_button = wx.Button(self, wx.ID_CANCEL, "Cancel")
+
+        gbs.Add(self.field, (0,0), (1,2))
+        gbs.Add(self.bound_above, (1,0))
+        gbs.Add(self.upper_bound, (1,1))
+        gbs.Add(self.bound_below, (2,0))
+        gbs.Add(self.lower_bound, (2,1))
+        gbs.Add(ok_button, (3,0), flag=wx.EXPAND)
+        gbs.Add(cancel_button, (3,1), flag=wx.EXPAND)
+
+        box.Add(gbs, 1, wx.EXPAND | wx.ALL)
+        inner_border.Add(box, 1, wx.EXPAND)
+        inner_border.AddSpacer(15)
+
+        border.Add(inner_border, 1, wx.EXPAND|wx.ALL, 25)
+        self.SetSizer(border)
+        self.Fit()
+        
+        self.Bind(wx.EVT_CHECKBOX, self.OnToggleUpper, self.bound_above)
+        self.Bind(wx.EVT_CHECKBOX, self.OnToggleLower, self.bound_below)
+
+    def OnToggleUpper(self, event):
+        if self.bound_above.GetValue():
+            self.upper_bound.Enable(True)
+            self.upper_bound.SetValue('')
+        else:
+            self.upper_bound.Enable(False)
+            self.upper_bound.SetValue('Upper Bound')
+
+    def OnToggleLower(self, event):
+        if self.bound_below.GetValue():
+            self.lower_bound.Enable(True)
+            self.lower_bound.SetValue('')
+        else:
+            self.lower_bound.Enable(False)
+            self.lower_bound.SetValue('Lower Bound')
+
+    def return_indices(self):
+        field = str(self.field.GetStringSelection())
+        if field == '': return None
+        # Now we do the logical operation
+        if self.bound_below.GetValue():
+           lb = float(self.lower_bound.GetValue())
+        else: lb = -na.inf
+        if self.bound_above.GetValue():
+           ub = float(self.upper_bound.GetValue())
+        else: ub = na.inf
+        ind = ((self.data_object[field] > lb)
+            &  (self.data_object[field] < ub))
+        return na.where(ind)
 
 class ExtractCubeSetup(wx.Dialog):
     pass



More information about the yt-svn mailing list