[Yt-svn] yt-commit r943 - in branches/yt-non-3d/yt: lagos raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Mon Nov 17 23:17:34 PST 2008


Author: mturk
Date: Mon Nov 17 23:17:33 2008
New Revision: 943
URL: http://yt.spacepope.org/changeset/943

Log:
* 1D now seems to *actually* work.
* I've generalized the few places I could find that depended on a hardcoded
refinement factor.  This is by no means exhaustive.
* Added a new plot type, the un-untuitively named "Line Query" plot, which
takes an orthogonal ray and plots it.  It's likely got some bugs in it still!
 
I think with this, 1D and 2D support is ready to be moved back into /trunk/
where we'll finish up any bug fixes.



Modified:
   branches/yt-non-3d/yt/lagos/BaseDataTypes.py
   branches/yt-non-3d/yt/lagos/BaseGridType.py
   branches/yt-non-3d/yt/lagos/HierarchyType.py
   branches/yt-non-3d/yt/raven/PlotCollection.py
   branches/yt-non-3d/yt/raven/PlotTypes.py

Modified: branches/yt-non-3d/yt/lagos/BaseDataTypes.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/BaseDataTypes.py	(original)
+++ branches/yt-non-3d/yt/lagos/BaseDataTypes.py	Mon Nov 17 23:17:33 2008
@@ -1014,7 +1014,7 @@
                     args = []
                     args += self.__retval_coords[grid2.id] + [self.__retval_fields[grid2.id]]
                     args += self.__retval_coords[grid1.id] + [self.__retval_fields[grid1.id]]
-                    args.append(int(grid2.dx / grid1.dx))
+                    args.append(int(grid2.dx / grid1.dx)) # Refinement factor
                     args.append(na.ones(args[0].shape, dtype='int64'))
                     kk = PointCombine.CombineGrids(*args)
                     goodI = args[-1].astype('bool')
@@ -1769,7 +1769,7 @@
     def _get_level_array(self, level, fields):
         fields = ensure_list(fields)
         # We assume refinement by a factor of two
-        rf = float(2**(self.level - level))
+        rf = float(self.pf["RefineBy"]**(self.level - level))
         dims = na.maximum(1,self.ActiveDimensions/rf) + 2
         dx = (self.right_edge-self.left_edge)/(dims-2)
         x,y,z = (na.mgrid[0:dims[0],0:dims[1],0:dims[2]].astype('float64')+0.5)\

Modified: branches/yt-non-3d/yt/lagos/BaseGridType.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/BaseGridType.py	(original)
+++ branches/yt-non-3d/yt/lagos/BaseGridType.py	Mon Nov 17 23:17:33 2008
@@ -397,13 +397,14 @@
         space-filling tiling of grids, possibly due to the finite accuracy in a
         standard Enzo hierarchy file.
         """
+        rf = self.pf["RefineBy"]
         my_ind = self.id - self._id_offset
         le = self.LeftEdge
-        self.dx = self.Parent.dx/2.0
-        self.dy = self.Parent.dy/2.0
-        self.dz = self.Parent.dz/2.0
+        self.dx = self.Parent.dx/rf
+        self.dy = self.Parent.dy/rf
+        self.dz = self.Parent.dz/rf
         ParentLeftIndex = na.rint((self.LeftEdge-self.Parent.LeftEdge)/self.Parent.dx)
-        self.start_index = 2*(ParentLeftIndex + self.Parent.get_global_startindex()).astype('int64')
+        self.start_index = rf*(ParentLeftIndex + self.Parent.get_global_startindex()).astype('int64')
         self.LeftEdge = self.Parent.LeftEdge + self.Parent.dx * ParentLeftIndex
         self.RightEdge = self.LeftEdge + \
                          self.ActiveDimensions*na.array([self.dx,self.dy,self.dz])
@@ -440,7 +441,7 @@
         pdx = na.array([self.Parent.dx, self.Parent.dy, self.Parent.dz]).ravel()
         start_index = (self.Parent.get_global_startindex()) + \
                        na.rint((self.LeftEdge - self.Parent.LeftEdge)/pdx)
-        self.start_index = (start_index*2).astype('int64').ravel()
+        self.start_index = (start_index*self.pf["RefineBy"]).astype('int64').ravel()
         return self.start_index
 
     def set_filename(self, filename):

Modified: branches/yt-non-3d/yt/lagos/HierarchyType.py
==============================================================================
--- branches/yt-non-3d/yt/lagos/HierarchyType.py	(original)
+++ branches/yt-non-3d/yt/lagos/HierarchyType.py	Mon Nov 17 23:17:33 2008
@@ -949,8 +949,8 @@
 class EnzoHierarchy1D(EnzoHierarchy):
     def __init__(self, *args, **kwargs):
         EnzoHierarchy.__init__(self, *args, **kwargs)
-        self.gridRightEdge[:,1:2] = 1.0
-        self.gridDimensions[:,1:2] = 1.0
+        self.gridRightEdge[:,1:3] = 1.0
+        self.gridDimensions[:,1:3] = 1.0
         self.gridDys[:,0] = 1.0
         self.gridDzs[:,0] = 1.0
         for g in self.grids:
@@ -967,9 +967,6 @@
             g._prepare_grid()
             g._setup_dx()
 
-class EnzoHierarchy1D(EnzoHierarchy):
-    pass
-
 scanf_regex = {}
 scanf_regex['e'] = r"[-+]?\d+\.?\d*?|\.\d+[eE][-+]?\d+?"
 scanf_regex['g'] = scanf_regex['e']
@@ -995,7 +992,7 @@
 # http://www.reddit.com/r/Python/comments/6hj75/reverse_file_iterator/c03vms4
 # Credit goes to "Brian" on Reddit
 
-def rblocks(f, blocksize=4096*256):
+def rblocks(f, blocksize=4096):
     """Read file as series of blocks from end of file to start.
 
     The data itself is in normal order, only the order of the blocks is reversed.

Modified: branches/yt-non-3d/yt/raven/PlotCollection.py
==============================================================================
--- branches/yt-non-3d/yt/raven/PlotCollection.py	(original)
+++ branches/yt-non-3d/yt/raven/PlotCollection.py	Mon Nov 17 23:17:33 2008
@@ -391,6 +391,14 @@
         p["Axis"] = "na"
         return p
 
+    def add_ortho_ray(self, axis, coords, field, axes = None,
+                      figure = None, **kwargs):
+        data_source = self.pf.h.ortho_ray(axis, coords, field)
+        p = self._add_plot(PlotTypes.LineQueryPlot(data_source,
+                [axis_names[axis], field], self._get_new_id(),
+                figure, axes, plot_options=kwargs))
+        return p
+
     def _get_new_id(self):
         self.__id_counter += 1
         return self.__id_counter-1

Modified: branches/yt-non-3d/yt/raven/PlotTypes.py
==============================================================================
--- branches/yt-non-3d/yt/raven/PlotTypes.py	(original)
+++ branches/yt-non-3d/yt/raven/PlotTypes.py	Mon Nov 17 23:17:33 2008
@@ -766,6 +766,78 @@
     def set_width(self, width, unit):
         mylog.warning("Choosing not to change the width of a phase plot instance")
 
+class LineQueryPlot(RavenPlot):
+    _type_name = "LineQueryPlot"
+
+    def __init__(self, data, fields, id, ticker=None,
+                 figure=None, axes=None, plot_options=None):
+        self._semi_unique_id = id
+        RavenPlot.__init__(self, data, fields, figure, axes)
+
+        self.axis_names["X"] = fields[0]
+        self.axis_names["Y"] = fields[1]
+
+        self._log_x = False
+        if fields[1] in self.pf.field_info and \
+            self.pf.field_info[fields[1]].take_log:
+            self._log_y = True
+        else:
+            self._log_y = False
+
+        if plot_options is None: plot_options = {}
+        self.plot_options = plot_options
+
+    def _generate_prefix(self, prefix):
+        self.prefix = "_".join([prefix, self._type_name,
+                       str(self._semi_unique_id),
+                       self.axis_names['X'], self.axis_names['Y']])
+        self["Field1"] = self.axis_names["X"]
+        self["Field2"] = self.axis_names["Y"]
+
+    def _redraw_image(self):
+        self._axes.clear()
+        if not self._log_x and not self._log_y:
+            func = self._axes.plot
+        elif self._log_x and not self._log_y:
+            func = self._axes.semilogx
+        elif not self._log_x and self._log_y:
+            func = self._axes.semilogy
+        elif self._log_x and self._log_y:
+            func = self._axes.loglog
+        indices = na.argsort(self.data[self.fields[0]])
+        func(self.data[self.fields[0]][indices],
+             self.data[self.fields[1]][indices],
+             **self.plot_options)
+        self.autoset_label(self.fields[0], self._axes.set_xlabel)
+        self.autoset_label(self.fields[1], self._axes.set_ylabel)
+        self._run_callbacks()
+
+    def set_log_field(self, val):
+        if val:
+            self._log_y = True
+        else:
+            self._log_y = False
+
+    def switch_x(self, field, weight="CellMassMsun", accumulation=False):
+        self.fields[0] = field
+        self.axis_names["X"] = field
+    
+    def switch_z(self, field, weight="CellMassMsun", accumulation=False):
+        self.fields[1] = field
+        self.axis_names["Y"] = field
+
+    def autoset_label(self, field_name, func):
+        if self.datalabel != None:
+            func(str(self.datalabel))
+            return
+        data_label = r"$\rm{%s}" % field_name.replace("_"," ")
+        if field_name in self.pf.field_info:
+            data_label += r"\/\/ (%s)" % (self.pf.field_info[field_name].get_units())
+        data_label += r"$"
+        func(str(data_label))
+
+
+    switch_y = switch_z # Compatibility...
 
 # Now we provide some convenience functions to get information about plots.
 # With Matplotlib 0.98.x, the 'transforms' branch broke backwards



More information about the yt-svn mailing list