[Yt-svn] yt-commit r828 - trunk/yt/raven
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Wed Oct 22 09:08:48 PDT 2008
Author: mturk
Date: Wed Oct 22 09:08:47 2008
New Revision: 828
URL: http://yt.spacepope.org/changeset/828
Log:
Added (natural neighbor) interpolated projection plots, refactored interpolated slice plots, added what I think is a fix for grid boundary callbacks.
Modified:
trunk/yt/raven/Callbacks.py
trunk/yt/raven/PlotCollection.py
trunk/yt/raven/PlotTypes.py
Modified: trunk/yt/raven/Callbacks.py
==============================================================================
--- trunk/yt/raven/Callbacks.py (original)
+++ trunk/yt/raven/Callbacks.py Wed Oct 22 09:08:47 2008
@@ -129,12 +129,16 @@
y0, y1 = plot.ylim
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()
+ print "Particle bounding box:", x0, x1, y0, y1, z0, z1
# Now we rescale because our axes limits != data limits
goodI = na.where( (self.particles_x < x1) & (self.particles_x > x0)
& (self.particles_y < y1) & (self.particles_y > y0)
& (self.particles_z < z1) & (self.particles_z > z0))
particles_x = (self.particles_x[goodI] - x0) * (xx1-xx0)/(x1-x0) + xx0
particles_y = (self.particles_y[goodI] - y0) * (yy1-yy0)/(y1-y0) + yy0
+ print "Particle px extrema", particles_x.min(), particles_x.max(), \
+ particles_y.min(), particles_y.max()
+ print "Axial limits", xx0, xx1, yy0, yy1
if not self.color_field: particles_c = self.color
else: particles_c = self.particles_c[goodI]
plot._axes.hold(True)
@@ -209,16 +213,21 @@
def __call__(self, plot):
x0, x1 = plot.xlim
y0, y1 = plot.ylim
+ xx0, xx1 = plot._axes.get_xlim()
+ yy0, yy1 = plot._axes.get_ylim()
dx = plot.image._A.shape[0] / (x1-x0)
dy = plot.image._A.shape[1] / (y1-y0)
GLE = plot.data.gridLeftEdge
GRE = plot.data.gridRightEdge
px_index = lagos.x_dict[plot.data.axis]
py_index = lagos.y_dict[plot.data.axis]
- left_edge_px = (GLE[:,px_index]-x0)*dx
- left_edge_py = (GLE[:,py_index]-y0)*dy
- right_edge_px = (GRE[:,px_index]-x0)*dx
- right_edge_py = (GRE[:,py_index]-y0)*dy
+ left_edge_px = na.maximum((GLE[:,px_index]-x0)*dx, xx0)
+ left_edge_py = na.maximum((GLE[:,py_index]-y0)*dy, yy0)
+ right_edge_px = na.minimum((GRE[:,px_index]-x0)*dx, xx1)
+ right_edge_py = na.minimum((GRE[:,py_index]-y0)*dy, yy1)
+ print left_edge_px.min(), left_edge_px.max(), \
+ right_edge_px.min(), right_edge_px.max(), \
+ x0, x1, y0, y1
verts = na.array(
[(left_edge_px, left_edge_px, right_edge_px, right_edge_px),
(left_edge_py, right_edge_py, right_edge_py, left_edge_py)])
@@ -459,3 +468,12 @@
if self.annotate:
plot._axes.text(center_x, center_y, "%s" % halo.id)
+
+class FloorToValueInPlot(PlotCallback):
+ def __init__(self):
+ pass
+
+ def __call__(self, plot):
+ aa = plot.image._A
+ min_val = aa[aa>0].min()
+ aa[aa==0] = min_val
Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py (original)
+++ trunk/yt/raven/PlotCollection.py Wed Oct 22 09:08:47 2008
@@ -151,14 +151,17 @@
return plot
def add_slice(self, *args, **kwargs):
+ """
+ Generate a slice through *field* along *axis*, optionally at
+ [axis]=*coord*, with the *center* attribute given (some
+ degeneracy with *coord*, but not complete), with *use_colorbar*
+ specifying whether the plot is naked or not and optionally
+ providing pre-existing Matplotlib *figure* and *axes* objects.
+ *fig_size* in (height_inches, width_inches)
+ """
return self.__add_slice(PlotTypes.SlicePlot, *args, **kwargs)
def add_slice_interpolated(self, *args, **kwargs):
- return self.__add_slice(PlotTypes.SlicePlotNaturalNeighbor, *args, **kwargs)
-
- def __add_slice(self, ptype, field, axis, coord=None, center=None,
- use_colorbar=True, figure = None, axes = None, fig_size=None,
- periodic = False, **kwargs):
"""
Generate a slice through *field* along *axis*, optionally at
[axis]=*coord*, with the *center* attribute given (some
@@ -166,13 +169,22 @@
specifying whether the plot is naked or not and optionally
providing pre-existing Matplotlib *figure* and *axes* objects.
*fig_size* in (height_inches, width_inches)
+
+ The slice will be interpolated using the delaunay module, with natural
+ neighbor interpolation.
"""
+ return self.__add_slice(PlotTypes.SlicePlotNaturalNeighbor, *args, **kwargs)
+
+ def __add_slice(self, ptype, field, axis, coord=None, center=None,
+ use_colorbar=True, figure = None, axes = None, fig_size=None,
+ periodic = False, data_source = None, **kwargs):
if center == None:
center = self.c
if coord == None:
coord = center[axis]
- slice = self.pf.hierarchy.slice(axis, coord, field, center, **kwargs)
- p = self._add_plot(ptype(slice, field, use_colorbar=use_colorbar,
+ if data_source is None:
+ data_source = self.pf.hierarchy.slice(axis, coord, field, center, **kwargs)
+ p = self._add_plot(ptype(data_source, field, use_colorbar=use_colorbar,
axes=axes, figure=figure,
size=fig_size, periodic=periodic))
mylog.info("Added slice of %s at %s = %s with 'center' = %s", field,
@@ -218,22 +230,38 @@
p["Axis"] = "CuttingPlane"
return p
- def add_projection(self, field, axis, weight_field=None,
- center=None, use_colorbar=True,
- figure = None, axes = None, fig_size=None,
- periodic = False, **kwargs):
+ def add_projection(self, *args, **kwargs):
+ """
+ Generate a projection of *field* along *axis*, optionally giving
+ a *weight_field*-weighted average with *use_colorbar*
+ specifying whether the plot is naked or not and optionally
+ providing pre-existing Matplotlib *figure* and *axes* objects.
+ *fig_size* in (height_inches, width_inches)
+ """
+ return self._add_projection(PlotTypes.ProjectionPlot, *args, **kwargs)
+
+ def add_projection_interpolated(self, *args, **kwargs):
"""
Generate a projection of *field* along *axis*, optionally giving
a *weight_field*-weighted average with *use_colorbar*
specifying whether the plot is naked or not and optionally
providing pre-existing Matplotlib *figure* and *axes* objects.
*fig_size* in (height_inches, width_inches)
+
+ The projection will be interpolated using the delaunay module, with
+ natural neighbor interpolation.
"""
+ return self._add_projection(PlotTypes.ProjectionPlotNaturalNeighbor, *args, **kwargs)
+
+ def _add_projection(self, ptype, field, axis, weight_field=None,
+ center=None, use_colorbar=True,
+ figure = None, axes = None, fig_size=None,
+ periodic = False, **kwargs):
if center == None:
center = self.c
proj = self.pf.hierarchy.proj(axis, field, weight_field, center=center,
**kwargs)
- p = self._add_plot(PlotTypes.ProjectionPlot(proj, field,
+ p = self._add_plot(ptype(proj, field,
use_colorbar=use_colorbar, axes=axes, figure=figure,
size=fig_size, periodic=periodic))
p["Axis"] = lagos.axis_names[axis]
Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py (original)
+++ trunk/yt/raven/PlotTypes.py Wed Oct 22 09:08:47 2008
@@ -307,7 +307,7 @@
def _redraw_image(self, *args):
self._axes.clear() # To help out the colorbar
buff = self._get_buff()
- mylog.debug("Received buffer of min %s and max %s (%s %s)",
+ mylog.debug("Received buffer of min %s and max %s (data: %s %s)",
na.nanmin(buff), na.nanmax(buff),
self[self.axis_names["Z"]].min(),
self[self.axis_names["Z"]].max())
@@ -448,9 +448,7 @@
data_label += r"$"
if self.colorbar != None: self.colorbar.set_label(str(data_label))
-class SlicePlotNaturalNeighbor(SlicePlot):
- _type_name = "NNSlice"
-
+class NNVMPlot:
def _get_buff(self, width=None):
import delaunay as de
x0, x1 = self.xlim
@@ -479,6 +477,10 @@
if self.log_field: buff = 10**buff
return buff.transpose()
+
+class SlicePlotNaturalNeighbor(NNVMPlot, SlicePlot):
+ _type_name = "NNSlice"
+
class ProjectionPlot(VMPlot):
_type_name = "Projection"
@@ -496,6 +498,8 @@
def switch_z(self, field):
mylog.warning("Choosing not to change the field of a projection instance")
+class ProjectionPlotNaturalNeighbor(NNVMPlot, ProjectionPlot):
+ _type_name = "NNProj"
class CuttingPlanePlot(SlicePlot):
More information about the yt-svn
mailing list