[Yt-svn] yt-commit r772 - trunk/yt/raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Fri Sep 12 13:47:59 PDT 2008


Author: mturk
Date: Fri Sep 12 13:47:59 2008
New Revision: 772
URL: http://yt.spacepope.org/changeset/772

Log:
Added periodic boundary support for projection plots and slice plots.  Use the
keyword periodic=True.

Note that if you do comparisons, you will clearly see the problem of non-unity
aspect ratios -- this is a problem that has been going on ever since I tried to
make the boundaries != (0,1) in all dimensions.  I'll be looking at that later;
I think the solution is going to be simply allowing the plots to go off the
edge of the axis, and then having them be blank there.  If you want to crop, do
so, or else set periodicity.



Modified:
   trunk/yt/raven/PlotCollection.py
   trunk/yt/raven/PlotTypes.py
   trunk/yt/raven/_MPL.c

Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py	(original)
+++ trunk/yt/raven/PlotCollection.py	Fri Sep 12 13:47:59 2008
@@ -147,7 +147,8 @@
         return plot
 
     def add_slice(self, field, axis, coord=None, center=None,
-                 use_colorbar=True, figure = None, axes = None, fig_size=None):
+                 use_colorbar=True, figure = None, axes = None, fig_size=None,
+                 periodic = False):
         """
         Generate a slice through *field* along *axis*, optionally at
         [axis]=*coord*, with the *center* attribute given (some 
@@ -163,7 +164,7 @@
         slice = self.pf.hierarchy.slice(axis, coord, field, center)
         p = self._add_plot(PlotTypes.SlicePlot(slice, field, use_colorbar=use_colorbar,
                          axes=axes, figure=figure,
-                         size=fig_size))
+                         size=fig_size, periodic=periodic))
         mylog.info("Added slice of %s at %s = %s with 'center' = %s", field,
                     axis_names[axis], coord, list(center))
         p["Axis"] = lagos.axis_names[axis]
@@ -196,7 +197,8 @@
 
     def add_projection(self, field, axis, weight_field=None,
                       center=None, use_colorbar=True,
-                      figure = None, axes = None, fig_size=None):
+                      figure = None, axes = None, fig_size=None,
+                      periodic = False):
         """
         Generate a projection of *field* along *axis*, optionally giving
         a *weight_field*-weighted average with *use_colorbar*
@@ -209,7 +211,7 @@
         proj = self.pf.hierarchy.proj(axis, field, weight_field, center=center)
         p = self._add_plot(PlotTypes.ProjectionPlot(proj, field,
                          use_colorbar=use_colorbar, axes=axes, figure=figure,
-                         size=fig_size))
+                         size=fig_size, periodic=periodic))
         p["Axis"] = lagos.axis_names[axis]
         return p
 

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Fri Sep 12 13:47:59 2008
@@ -108,7 +108,6 @@
         self.im = defaultdict(lambda: "")
         self["ParameterFile"] = "%s" % self.data.pf
         self.axis_names = {}
-        self._ax_max = self.data.pf["DomainRightEdge"]
         if not figure:
             self._figure = matplotlib.figure.Figure(size)
         else:
@@ -217,8 +216,9 @@
 
 class VMPlot(RavenPlot):
     _antialias = True
+    _period = (0.0, 0.0)
     def __init__(self, data, field, figure = None, axes = None,
-                 use_colorbar = True, size=None):
+                 use_colorbar = True, size=None, periodic = False):
         fields = ['X', 'Y', field, 'X width', 'Y width']
         if not size:
             size = (10,8)
@@ -226,14 +226,23 @@
         RavenPlot.__init__(self, data, fields, figure, axes, size=size)
         self._figure.subplots_adjust(hspace=0, wspace=0, bottom=0.0,
                                     top=1.0, left=0.0, right=1.0)
-        self.xmin = 0.0
-        self.ymin = 0.0
-        self.xmax = 1.0
-        self.ymax = 1.0
-        self.cmap = None
+        DLE = self.data.pf["DomainLeftEdge"]
+        DRE = self.data.pf["DomainRightEdge"]
+        DD = float(periodic)*(DRE - DLE)
         if self.data.axis < 3:
-            self._x_max = self._ax_max[lagos.x_dict[self.data.axis]]
-            self._y_max = self._ax_max[lagos.y_dict[self.data.axis]]
+            xax = lagos.x_dict[self.data.axis]
+            yax = lagos.y_dict[self.data.axis]
+            self.xmin = DLE[xax] - DD[xax]
+            self.xmax = DRE[xax] + DD[xax]
+            self.ymin = DLE[yax] - DD[yax]
+            self.ymax = DRE[yax] + DD[yax]
+            self._period = (DD[xax], DD[yax])
+        else:
+            # Not quite sure how to deal with this, particularly
+            # in the Orion case.  Cutting planes are tricky.
+            self.xmin = self.ymin = 0.0
+            self.xmax = self.ymax = 1.0
+        self.cmap = None
         self.__setup_from_field(field)
         self.__init_temp_image(use_colorbar)
 
@@ -290,7 +299,7 @@
                             self.data['pdy'],
                             self[self.axis_names["Z"]],
                             int(width), int(width),
-                            (x0, x1, y0, y1),aa).transpose()
+                            (x0, x1, y0, y1),aa,self._period).transpose()
         return buff
 
     def _redraw_image(self, *args):
@@ -364,8 +373,8 @@
         r_edge_x = self.data.center[lagos.x_dict[self.data.axis]] + width_x/2.0
         l_edge_y = self.data.center[lagos.y_dict[self.data.axis]] - width_y/2.0
         r_edge_y = self.data.center[lagos.y_dict[self.data.axis]] + width_y/2.0
-        self.set_xlim(max(l_edge_x,0.0), min(r_edge_x,self._x_max))
-        self.set_ylim(max(l_edge_y,0.0), min(r_edge_y,self._y_max))
+        self.set_xlim(max(l_edge_x,self.xmin), min(r_edge_x,self.xmax))
+        self.set_ylim(max(l_edge_y,self.ymin), min(r_edge_y,self.ymax))
         self._redraw_image()
 
     def autoscale(self):

Modified: trunk/yt/raven/_MPL.c
==============================================================================
--- trunk/yt/raven/_MPL.c	(original)
+++ trunk/yt/raven/_MPL.c	Fri Sep 12 13:47:59 2008
@@ -55,11 +55,14 @@
   unsigned int rows, cols;
   int antialias = 1;
   double x_min, x_max, y_min, y_max;
+  double period_x, period_y;
+  period_x = period_y = 0;
 
-    if (!PyArg_ParseTuple(args, "OOOOOII(dddd)|i",
-        &xp, &yp, &dxp, &dyp, &dp, &cols, &rows,
-        &x_min, &x_max, &y_min, &y_max, &antialias))
-        return PyErr_Format(_pixelizeError, "Pixelize: Invalid Parameters.");
+  if (!PyArg_ParseTuple(args, "OOOOOII(dddd)|i(dd)",
+      &xp, &yp, &dxp, &dyp, &dp, &cols, &rows,
+      &x_min, &x_max, &y_min, &y_max,
+      &antialias, &period_x, &period_y))
+      return PyErr_Format(_pixelizeError, "Pixelize: Invalid Parameters.");
 
   double width = x_max - x_min;
   double height = y_max - y_min;
@@ -132,6 +135,10 @@
     dxsp = *((npy_float64 *)PyArray_GETPTR1(dx, p));
     dysp = *((npy_float64 *)PyArray_GETPTR1(dy, p));
     dsp = *((npy_float64 *)PyArray_GETPTR1(d, p));
+    if(xsp + dxsp < x_min) (xsp+=period_x);
+    else if (xsp+dxsp > x_max) (xsp-=period_x);
+    if(ysp + dysp < y_min) (ysp+=period_y);
+    else if (ysp+dysp > y_max) (ysp-=period_y);
     if(((xsp+dxsp<x_min) ||
         (xsp-dxsp>x_max)) ||
        ((ysp+dysp<y_min) ||



More information about the yt-svn mailing list