[Yt-svn] yt-commit r415 - trunk/yt/raven
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Tue Apr 29 07:14:28 PDT 2008
Author: mturk
Date: Tue Apr 29 07:14:24 2008
New Revision: 415
URL: http://yt.spacepope.org/changeset/415
Log:
Adding the profile objects to the PlotCollections object. Right now the API
may be unstable, but I am making progress toward closing #58.
Modified:
trunk/yt/raven/PlotCollection.py
trunk/yt/raven/PlotTypes.py
Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py (original)
+++ trunk/yt/raven/PlotCollection.py Tue Apr 29 07:14:24 2008
@@ -169,6 +169,38 @@
p["Axis"] = None
return p
+ def add_new_threephase_sphere(self, radius, unit, fields, center=None, cmap=None,
+ weight="CellMassMsun", accumulation=False,
+ x_bins=64, x_log=True, x_bounds=None,
+ y_bins=64, y_log=True, y_bounds=None,
+ lazy_reader=False):
+ if center == None:
+ center = self.c
+ r = radius/self.pf[unit]
+ sphere = self.pf.hierarchy.sphere(center, r, fields)
+ if x_bounds is None:
+ x_min, x_max = sphere[fields[0]].min(), sphere[fields[0]].max()
+ else:
+ x_min, x_max = x_bounds
+ if y_bounds is None:
+ y_min, y_max = sphere[fields[1]].min(), sphere[fields[1]].max()
+ else:
+ y_min, y_max = y_bounds
+ profile = lagos.BinnedProfile2D(sphere,
+ x_bins, fields[0], x_min, x_max, x_log,
+ y_bins, fields[1], y_min, y_max, y_log,
+ lazy_reader)
+ profile.add_fields(fields[2], weight=weight, accumulation=accumulation)
+ # These next two lines are painful.
+ profile.pf = self.pf
+ profile.hierarchy = self.pf.hierarchy
+ p = self._add_plot(PlotTypes.NewPhasePlot(profile, fields, width=radius,
+ unit=unit, cmap=cmap))
+ p["Width"] = radius
+ p["Unit"] = unit
+ p["Axis"] = None
+ return p
+
def clear_plots(self):
for i in range(len(self.plots)):
del self.plots[i].data
Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py (original)
+++ trunk/yt/raven/PlotTypes.py Tue Apr 29 07:14:24 2008
@@ -597,6 +597,109 @@
self["Field2"] = self.axis_names["Y"]
self["Field3"] = self.axis_names["Z"]
+class NewPhasePlot(RavenPlot):
+ def __init__(self, data, fields, width=None, unit=None,
+ ticker=None, cmap=None, figure=None, axes=None):
+ self._type_name = "Phase"
+ RavenPlot.__init__(self, data, fields, figure, axes)
+ self.ticker = ticker
+ self.image = None
+ self.set_cmap(cmap)
+
+ self.axis_names["X"] = fields[0]
+ self.axis_names["Y"] = fields[1]
+ self.axis_names["Z"] = fields[2]
+
+ self.x_bins = self.data[self.fields[0]]
+ self.y_bins = self.data[self.fields[1]]
+ self._log_x = self.data._x_log
+ self._log_y = self.data._y_log
+ self._log_z = self.setup_bins(self.fields[2])
+ self.__init_colorbar()
+
+ def __init_colorbar(self):
+ temparray = na.ones((self.x_bins.size, self.y_bins.size))
+ self.norm = matplotlib.colors.Normalize()
+ self.image = self._axes.pcolormesh(self.x_bins, self.y_bins,
+ temparray, shading='flat',
+ norm=self.norm)
+ self.colorbar = self._figure.colorbar(self.image,
+ extend='neither', shrink=0.95,
+ format="%0.2e" )
+
+ def setup_bins(self, field, func=None):
+ if field in lagos.fieldInfo and lagos.fieldInfo[field].take_log:
+ log_field = True
+ if func: func('log')
+ else:
+ log_field = False
+ if func: func('linear')
+ mylog.debug("Field: %s, log_field: %s", field, log_field)
+ return log_field
+
+ def autoset_label(self, field, func):
+ dataLabel = r"$\rm{%s}" % (field)
+ if field in lagos.fieldInfo:
+ dataLabel += r" (%s)" % (lagos.fieldInfo[field].get_units())
+ dataLabel += r"$"
+ func(str(dataLabel))
+
+ def set_cmap(self, cmap):
+ RavenPlot.set_cmap(self, cmap)
+ if self.image != None and self.cmap != None:
+ self.image.set_cmap(self.cmap)
+
+ def switch_z(self, field, weight="CellMassMsun", accumulation=False):
+ self.fields[2] = field
+ self.axis_names["Z"] = field
+ if field not in self.data.keys(): self.data.add_fields(field, weight, accumulation)
+ self._log_z = self.setup_bins(self.fields[2])
+
+ def _redraw_image(self):
+ vals = self.data[self.fields[2]].transpose()
+ used_bin = self.data["UsedBins"].transpose()
+ vals[~used_bin] = na.nan
+ vmin = na.nanmin(vals[used_bin])
+ vmax = na.nanmax(vals[used_bin])
+ if self._log_z:
+ # We want smallest non-zero vmin
+ self.norm=matplotlib.colors.LogNorm(vmin=vmin, vmax=vmax,
+ clip=False)
+ self.ticker = matplotlib.ticker.LogLocator()
+ else:
+ self.norm=matplotlib.colors.Normalize(vmin=vmin, vmax=vmax,
+ clip=False)
+ self.ticker = matplotlib.ticker.MaxNLocator()
+ self.colorbar.set_norm(self.norm)
+ if self.cmap == None:
+ self.cmap = matplotlib.cm.get_cmap()
+ self.cmap.set_bad("w")
+ self.cmap.set_under("w")
+ self.cmap.set_over("w")
+ self._axes.clear()
+ self._axes.set_xscale("linear")
+ self._axes.set_yscale("linear")
+ self.image = self._axes.pcolormesh(self.x_bins, self.y_bins, \
+ vals, shading='flat', \
+ norm=self.norm, cmap=self.cmap)
+ self._axes.set_xscale("log" if self._log_x else "linear")
+ self._axes.set_yscale("log" if self._log_y else "linear")
+ self.vals = vals
+
+ self.colorbar.notify(self.image)
+
+ self.autoset_label(self.fields[0], self._axes.set_xlabel)
+ self.autoset_label(self.fields[1], self._axes.set_ylabel)
+ self.autoset_label(self.fields[2], self.colorbar.set_label)
+
+ def _generate_prefix(self, prefix):
+ self.prefix = "_".join([prefix, self._type_name, \
+ self.axis_names['X'], self.axis_names['Y'], \
+ self.axis_names['Z']])
+ self["Field1"] = self.axis_names["X"]
+ self["Field2"] = self.axis_names["Y"]
+ self["Field3"] = self.axis_names["Z"]
+
def quiverCallback(field_x, field_y, axis, factor):
def runCallback(plot):
x0, x1 = plot.xlim
More information about the yt-svn
mailing list