[Yt-svn] yt-commit r540 - in trunk/yt: lagos raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Jun 5 12:52:59 PDT 2008


Author: mturk
Date: Thu Jun  5 12:52:57 2008
New Revision: 540
URL: http://yt.spacepope.org/changeset/540

Log:
Added manual serialization of 3D profiles in the .yt file.  Closes #116.

Added point plotting in the 3D phase profiles, toggled by spacebar.

Added attribute setting for the datastore.



Modified:
   trunk/yt/lagos/HierarchyType.py
   trunk/yt/lagos/Profiles.py
   trunk/yt/raven/Plot3DInterface.py

Modified: trunk/yt/lagos/HierarchyType.py
==============================================================================
--- trunk/yt/lagos/HierarchyType.py	(original)
+++ trunk/yt/lagos/HierarchyType.py	Thu Jun  5 12:52:57 2008
@@ -201,15 +201,17 @@
             self.__data_file = None
             pass
 
-    def save_data(self, array, node, name):
+    def save_data(self, array, node, name, set_attr=None):
         """
         Arbitrary numpy data will be saved to the region in the datafile
         described by *node* and *name*.  If data file does not exist, it throws
         no error and simply does not save.
         """
-        if self.__data_file != None:
-            self.__data_file.createArray(node, name, array, createparents=True)
-            self.__data_file.flush()
+        if self.__data_file is None: return
+        arr = self.__data_file.createArray(node, name, array, createparents=True)
+        if set_attr is not None:
+            for i, j in set_attr.items(): arr.setAttr(i,j)
+        self.__data_file.flush()
 
     def get_data(self, node, name):
         """

Modified: trunk/yt/lagos/Profiles.py
==============================================================================
--- trunk/yt/lagos/Profiles.py	(original)
+++ trunk/yt/lagos/Profiles.py	Thu Jun  5 12:52:57 2008
@@ -397,3 +397,51 @@
 
     def write_out(self, filename, format="%0.16e"):
         pass # Will eventually dump HDF5
+
+    def store_profile(self, name):
+        """
+        By identifying the profile with a fixed, user-input *name* we can
+        store it in the serialized data section of the hierarchy file.
+        """
+        # First we get our data in order
+        order = []
+        set_attr = {'x_bin_field':self.x_bin_field,
+                    'y_bin_field':self.y_bin_field,
+                    'z_bin_field':self.z_bin_field,
+                    'x_bin_values':self[self.x_bin_field],
+                    'y_bin_values':self[self.y_bin_field],
+                    'z_bin_values':self[self.z_bin_field],
+                    '_x_log':self._x_log,
+                    '_y_log':self._y_log,
+                    '_z_log':self._z_log,
+                    'shape': (self[self.x_bin_field].size,
+                              self[self.y_bin_field].size,
+                              self[self.z_bin_field].size),
+                    'field_order':order }
+        values = []
+        for field in self._data:
+            if field in set_attr.values(): continue
+            order.append(field)
+            values.append(self[field].ravel())
+        values = na.array(values).transpose()
+        self._data_source.hierarchy.save_data(values, "/Profiles", name,
+                                              set_attr)
+
+class StoredBinnedProfile3D(BinnedProfile3D):
+    def __init__(self, pf, name):
+        self._data = {}
+        prof_arr = pf.h.get_data("/Profiles", name)
+        if prof_arr is None: raise KeyError("No such array")
+        for ax in 'xyz':
+            for base in ['%s_bin_field', '_%s_log']:
+                setattr(self, base % ax, prof_arr.getAttr(base % ax))
+        for ax in 'xyz':
+            fn = getattr(self, '%s_bin_field' % ax)
+            self._data[fn] = prof_arr.getAttr('%s_bin_values' % ax)
+        shape = prof_arr.getAttr('shape')
+        for fn, fd in zip(prof_arr.getAttr('field_order'),
+                          prof_arr.read().transpose()):
+            self._data[fn] = fd.reshape(shape)
+
+    def add_fields(self, *args, **kwargs):
+        raise RuntimeError("Sorry, you can't add to a stored profile.")

Modified: trunk/yt/raven/Plot3DInterface.py
==============================================================================
--- trunk/yt/raven/Plot3DInterface.py	(original)
+++ trunk/yt/raven/Plot3DInterface.py	Thu Jun  5 12:52:57 2008
@@ -39,6 +39,7 @@
     return check_started
 
 class VolumeRendering(object):
+    xyz = None
     def __init__(self, data, take_log=True,
                  window_opts="/S2MONO", cmap="rainbow",
                  amin=0.0, amax=0.1, bounds = None):
@@ -143,6 +144,9 @@
 
     def __my_callback(self, t, kc):
         s2plot.ds2dvr(self.vrid, 0)
+        if self.xyz is not None and kc % 2 == 0 and kc > 0:
+            s2plot.s2sci(s2plot.S2_PG_LTGREY)
+            s2plot.s2pt(*self.xyz)
 
 class VolumeRenderingDataCube(VolumeRendering):
     def __init__(self, pf, center=None, width=1, unit='1',
@@ -156,6 +160,7 @@
         dx = self.width / dims
         self.max_level = na.unique(pf.h.gridDxs[pf.h.gridDxs>=dx]).argmax()+1
         self.data_grid = self.__get_data()
+        self.xyz = None
         VolumeRendering.__init__(self, self.data_grid[field], **kwargs)
         
     def __get_data(self):
@@ -188,3 +193,7 @@
     def _setup_labels(self):
         s2plot.s2env(self.x0,self.x1, self.y0,self.y1, self.z0,self.z1, 0, 1)
         s2plot.s2lab(self.bf[0][1],self.bf[1][1],self.bf[2][1],self.field)
+
+    def setup_plot_points(self):
+        xyz = [f[0](self.profile._data_source[f[1]]) for f in self.bf]
+        self.xyz = [xyz[0].size] + xyz +  [1]



More information about the yt-svn mailing list