[Yt-svn] yt-commit r495 - in trunk/yt: raven reason
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Wed May 28 09:27:08 PDT 2008
Author: mturk
Date: Wed May 28 09:27:06 2008
New Revision: 495
URL: http://yt.spacepope.org/changeset/495
Log:
Got rid of old phase plot system.
Everything uses the Profile objects now.
Profile objects have unique IDs associated with them.
Modified:
trunk/yt/raven/PlotCollection.py
trunk/yt/raven/PlotTypes.py
trunk/yt/reason/App.py
trunk/yt/reason/Notebook.py
Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py (original)
+++ trunk/yt/raven/PlotCollection.py Wed May 28 09:27:06 2008
@@ -31,6 +31,7 @@
from yt.raven import *
class PlotCollection:
+ __id_counter = 0
def __init__(self, pf, deliverator_id=-1, center=None):
PlotTypes.Initialize()
self.plots = []
@@ -144,50 +145,21 @@
size=fig_size))
p["Axis"] = lagos.axis_names[axis]
return p
- def add_twophase_sphere(self, radius, unit, fields, center=None, cmap=None):
- if center == None:
- center = self.c
- fields = fields[:2] + ["CellsPerBin"] + fields[2:]
- r = radius/self.pf[unit]
- sphere = self.pf.hierarchy.sphere(center, r, fields)
- p = self._add_plot(PlotTypes.PhasePlot(sphere, fields, width=radius,
- unit=unit, cmap=cmap))
- p["Width"] = radius
- p["Unit"] = unit
- p["Axis"] = None
- return p
- def add_threephase_sphere(self, radius, unit, fields, center=None, cmap=None,
- weight="CellMass"):
- if center == None:
- center = self.c
- r = radius/self.pf[unit]
- sphere = self.pf.hierarchy.sphere(center, r, fields)
- p = self._add_plot(PlotTypes.PhasePlot(sphere, fields, width=radius,
- unit=unit, cmap=cmap, weight=weight))
- p["Width"] = radius
- p["Unit"] = unit
- 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, sphere = None):
- if center == None:
- center = self.c
- r = radius/self.pf[unit]
- if sphere is None:
- sphere = self.pf.hierarchy.sphere(center, r, fields)
+ def add_phase_object(self, object, fields, 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 x_bounds is None:
- x_min, x_max = sphere[fields[0]].min(), sphere[fields[0]].max()
+ x_min, x_max = object[fields[0]].min(), object[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()
+ y_min, y_max = object[fields[1]].min(), object[fields[1]].max()
else:
y_min, y_max = y_bounds
- profile = lagos.BinnedProfile2D(sphere,
+ profile = lagos.BinnedProfile2D(object,
x_bins, fields[0], x_min, x_max, x_log,
y_bins, fields[1], y_min, y_max, y_log,
lazy_reader)
@@ -196,8 +168,25 @@
# 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 = self._add_plot(PlotTypes.NewPhasePlot(profile, fields,
+ self._get_new_id(),
+ cmap=cmap))
+ return p
+
+ def _get_new_id(self):
+ self.__id_counter += 1
+ return self.__id_counter-1
+
+ def add_phase_sphere(self, radius, unit, fields, **kwargs):
+ center = kwargs.pop("center",self.c)
+ r = radius/self.pf[unit]
+ if 'sphere' in kwargs:
+ sphere = kwargs.pop('sphere')
+ else:
+ ftg = fields[:]
+ if kwargs.get("lazy_reader",False): ftg = []
+ sphere = self.pf.hierarchy.sphere(center, r, ftg)
+ p = self.add_phase_object(sphere, fields, **kwargs)
p["Width"] = radius
p["Unit"] = unit
p["Axis"] = None
Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py (original)
+++ trunk/yt/raven/PlotTypes.py Wed May 28 09:27:06 2008
@@ -300,7 +300,7 @@
if self.colorbar != None:
self.image.set_norm(self.norm)
self.colorbar.set_norm(self.norm)
- self.colorbar.notify(self.image)
+ if self.do_autoscale: self.colorbar.notify(self.image)
self.autoset_label()
def set_xlim(self, xmin, xmax):
@@ -434,177 +434,10 @@
self._redraw_image()
class PhasePlot(RavenPlot):
- def __init__(self, data, fields, width=None, unit=None, bins=100,
- weight=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.bins = bins
- self.set_cmap(cmap)
- self.weight = weight
-
- self.axis_names["X"] = fields[0]
- self.axis_names["Y"] = fields[1]
- self.axis_names["Z"] = fields[2]
-
- self._log_x, self.x_v, self.x_bins = self.setup_bins(self.fields[0])
- self._log_y, self.y_v, self.y_bins = self.setup_bins(self.fields[1])
- self._log_z, self.z_v, self.z_bins = self.setup_bins(self.fields[2])
-
- self.colorbar = None
-
- def setup_bins(self, field, func = None):
- log_field = False
- v = self.data[field]
- if field in lagos.log_fields or lagos.fieldInfo[field].take_log:
- log_field = True
- bins = na.logspace(na.log10(v.min()*0.99),
- na.log10(v.max()*1.01),
- num=self.bins)
- if func: func('log')
- else:
- bins = na.linspace(v.min()*0.99,v.max()*1.01,num=self.bins)
- if func: func('linear')
- mylog.debug("Field: %s, log_field: %s", field, log_field)
- return log_field, v, bins
-
- def autoset_label(self, field, func):
- dataLabel = r"$\rm{%s}" % (field)
- if lagos.fieldInfo.has_key(field):
- 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_x(self, field):
- self.fields[0] = field
- self.axis_names["X"] = field
- self._log_x, self.x_v, self.x_bins = self.setup_bins(self.fields[0])
-
- def switch_y(self, field):
- self.fields[1] = field
- self.axis_names["Y"] = field
- self._log_y, self.y_v, self.y_bins = self.setup_bins(self.fields[1])
-
- def switch_z(self, field):
- self.fields[2] = field
- self.axis_names["Z"] = field
- self._log_z, self.z_v, self.z_bins = self.setup_bins(self.fields[2])
-
- def switch_weight(self, weight):
- if weight == "": weight=None
- self.weight = weight
-
- def set_zlim(self, zmin, zmax):
- self.norm.autoscale(na.array([zmin,zmax]))
- self.image.changed()
- if self.colorbar != None:
- self.colorbar.notify(self.image)
-
- def _redraw_image(self):
- l, b, width, height = self._axes.bbox.get_bounds()
- self.pix = (width,height)
- x_bins_ids = na.digitize(self.x_v, self.x_bins)
- y_bins_ids = na.digitize(self.y_v, self.y_bins)
-
- vals = na.zeros((self.bins,self.bins), dtype='float64')
- weight_vals = na.zeros((self.bins,self.bins), dtype='float64')
- used_bin = na.zeros((self.bins,self.bins), dtype='bool')
-
- x_ind, y_ind = (x_bins_ids-1,y_bins_ids-1) # To match up with pcolor
- # pcolor expects value to be between i and i+1, digitize gives
- # bin between i-1 and i
- used_bin[y_ind,x_ind] = True
- nx = len(self.x_v)
- if self.weight != None:
- weight = self.data[self.weight]
- else:
- weight = na.ones(nx)
-
- z_v = self.z_v
- code =r"""
- int i,j;
- for(int n = 0; n < nx ; n++) {
- //printf("%d\n",n);
- j = x_bins_ids(n)-1;
- i = y_bins_ids(n)-1;
- weight_vals(i,j) += weight(n);
- vals(i,j) += z_v(n) * weight(n);
- }
- """
- try:
- weave.inline(code, ['nx','x_bins_ids','y_bins_ids',
- 'weight_vals','weight','vals','z_v'],
- compiler='gcc', type_converters=converters.blitz,
- auto_downcast = 0)
- except:
- mylog.debug("SciPy weaving did not work; falling back on loop")
- for k in range(nx):
- j,i = x_bins_ids[k]-1, y_bins_ids[k]-1
- weight_vals[i,j] += weight[k]
- vals[i,j] += self.z_v[k]*weight[k]
-
- vi = na.where(used_bin == False)
- vit = na.where(used_bin == True)
- if self.weight != None: vals = vals / weight_vals
-
- vmin = na.nanmin(vals[vit])
- vmax = na.nanmax(vals[vit])
- vals[vi] = 0.0
- if self._log_z:
- # We want smallest non-zero vmin
- vmin=vals[vals>0.0].min()
- self.norm=matplotlib.colors.LogNorm(vmin=vmin, vmax=vmax,
- clip=False)
- location_of_ticks = na.logspace(vmin*1.1, vmax*0.9, num=6)
- self.ticker = matplotlib.ticker.LogLocator()
- else:
- self.ticker = matplotlib.ticker.MaxNLocator()
- self.norm=matplotlib.colors.Normalize(vmin=vmin, vmax=vmax,
- clip=False)
- 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.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.ticker = matplotlib.ticker.LogLocator(subs=[0.25, 0.5, 0.75, 1])
-
- if self.colorbar == None:
- self.colorbar = self._figure.colorbar(self.image, \
- extend='neither', \
- shrink=0.95, cmap=self.cmap, \
- ticks = self.ticker, format="%0.2e" )
-
- 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"]
-
-class NewPhasePlot(RavenPlot):
- def __init__(self, data, fields, width=None, unit=None,
- ticker=None, cmap=None, figure=None, axes=None):
+ def __init__(self, data, fields, id, ticker=None, cmap=None,
+ figure=None, axes=None):
self._type_name = "Phase"
+ self._semi_unique_id = id
RavenPlot.__init__(self, data, fields, figure, axes)
self.ticker = ticker
self.image = None
@@ -714,9 +547,10 @@
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.prefix = "_".join([prefix, self._type_name,
+ str(self._semi_unique_id),
+ 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"]
Modified: trunk/yt/reason/App.py
==============================================================================
--- trunk/yt/reason/App.py (original)
+++ trunk/yt/reason/App.py Wed May 28 09:27:06 2008
@@ -284,7 +284,7 @@
self.__find_max(data_object, argdict['%s_bin_field'%ax])
t = "Phase Plot"
self.windows.append( \
- NewPhasePlotPage(parent=self.plot_panel.nb,
+ PhasePlotPage(parent=self.plot_panel.nb,
status_bar=self.status_bar,
data_object = data_object,
argdict = argdict, CreationID = MyID,
Modified: trunk/yt/reason/Notebook.py
==============================================================================
--- trunk/yt/reason/Notebook.py (original)
+++ trunk/yt/reason/Notebook.py Wed May 28 09:27:06 2008
@@ -653,7 +653,7 @@
def QueryFields(self):
return [self.field]
-class NewPhasePlotPage(PlotPage):
+class PhasePlotPage(PlotPage):
def __init__(self, parent, status_bar, data_object, argdict, mw=None, CreationID = -1):
self.data_object = data_object
self.argdict = argdict
@@ -711,11 +711,12 @@
self.data.hierarchy = self.data_object.pf.h
# Now, unfortunately, we prompt for the field
self.AddField(None)
- self.plot = be.NewPhasePlot(self.data,
- [self.argdict['x_bin_field'],
- self.argdict['y_bin_field'],
- self.z_field.GetStringSelection()],
- figure=self.figure, axes=self.axes)
+ self.plot = be.PhasePlot(self.data,
+ [self.argdict['x_bin_field'],
+ self.argdict['y_bin_field'],
+ self.z_field.GetStringSelection()],
+ id = wx.NewId(),
+ figure=self.figure, axes=self.axes)
def UpdateStatusBar(self, event):
#print event.x, event.y
@@ -767,155 +768,6 @@
self.figure_canvas.draw()
# We don't call update canvas
-class PhasePlotPage(PlotPage):
- def __init__(self, parent, status_bar, data_object, mw=None, CreationID = -1):
- self.data_object = data_object
-
- PlotPage.__init__(self, parent, status_bar, mw, CreationID)
-
- def SetupControls(self):
- self.ButtonPanel = wx.Panel(self, -1)
- fs = self.QueryFields()
- self.FieldX = wx.Choice(self.ButtonPanel, -1, choices=fs, name="X")
- self.FieldX.SetSelection(0)
- self.FieldY = wx.Choice(self.ButtonPanel, -1, choices=fs, name="Y")
- self.FieldY.SetSelection(0)
- self.FieldZ = wx.Choice(self.ButtonPanel, -1, choices=fs, name="Z")
- self.FieldZ.SetSelection(0)
- self.FieldW = wx.Choice(self.ButtonPanel, -1, choices=fs, name="W")
- self.FieldW.SetSelection(0)
- self.FirePlot = wx.Button(self.ButtonPanel, label = "Make Plot")
-
- #self.Bind(wx.EVT_CHOICE, self.switch_x, self.FieldX)
- #self.Bind(wx.EVT_CHOICE, self.switch_y, self.FieldY)
- #self.Bind(wx.EVT_CHOICE, self.switch_z, self.FieldZ)
- #self.Bind(wx.EVT_CHOICE, self.switch_weight, self.FieldW)
- self.Bind(wx.EVT_BUTTON, self.fire_plot, self.FirePlot)
-
- def DoLayout(self):
- self.MainSizer = wx.BoxSizer(wx.VERTICAL)
- self.MainSizer.Add(self.figure_canvas, 1, wx.EXPAND)
- self.MainSizer.Add(self.ButtonPanel, 0, wx.EXPAND)
-
- self.ButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
- self.XSizer = wx.BoxSizer(wx.VERTICAL)
- self.YSizer = wx.BoxSizer(wx.VERTICAL)
- self.ZSizer = wx.BoxSizer(wx.VERTICAL)
- self.WSizer = wx.BoxSizer(wx.VERTICAL)
-
-
- self.ButtonSizer.AddSpacer(10)
-
- self.ButtonSizer.Add(self.XSizer, 1, wx.EXPAND)
- self.XSizer.Add(wx.StaticText(self.ButtonPanel, -1, "X Field"), 1, wx.EXPAND)
- self.XSizer.Add(self.FieldX, 1, wx.EXPAND)
- self.ButtonSizer.AddSpacer(20)
-
- self.ButtonSizer.Add(self.YSizer, 1, wx.EXPAND)
- self.YSizer.Add(wx.StaticText(self.ButtonPanel, -1, "Y Field"), 1, wx.EXPAND)
- self.YSizer.Add(self.FieldY, 1, wx.EXPAND)
- self.ButtonSizer.AddSpacer(20)
-
- self.ButtonSizer.Add(self.ZSizer, 1, wx.EXPAND)
- self.ZSizer.Add(wx.StaticText(self.ButtonPanel, -1, "Z Field"), 1, wx.EXPAND)
- self.ZSizer.Add(self.FieldZ, 1, wx.EXPAND)
- self.ButtonSizer.AddSpacer(20)
-
- self.ButtonSizer.Add(self.WSizer, 1, wx.EXPAND)
- self.WSizer.Add(wx.StaticText(self.ButtonPanel, -1, "Weight"), 1, wx.EXPAND)
- self.WSizer.Add(self.FieldW, 1, wx.EXPAND)
-
- self.ButtonSizer.AddSpacer(10)
- self.ButtonSizer.Add(self.FirePlot, 1, wx.EXPAND)
- self.ButtonSizer.AddSpacer(10)
- self.ButtonPanel.SetSizer(self.ButtonSizer)
- self.ButtonPanel.Layout()
-
- self.SetSizer(self.MainSizer)
- self.Layout()
-
-
- def QueryFields(self):
- return QueryFields(self.data_object)
-
- def makePlot(self, event=None):
- pass
-
- def fire_plot(self, event):
- if self.plot is not None:
- for ax in self.figure.axes[1:]: self.figure.delaxes(ax)
- self.axes.clear()
- self.figure.subplots_adjust()
- self.axes.set_xscale('linear')
- self.axes.set_xlim([0.0,1.0])
- self.axes.set_yscale('linear')
- self.axes.set_ylim([0.0,1.0])
- del self.plot
- X = self.FieldX.GetStringSelection()
- Y = self.FieldY.GetStringSelection()
- Z = self.FieldZ.GetStringSelection()
- W = self.FieldW.GetStringSelection()
- if len(W) == 0: W=None
- self.plot = be.PhasePlot(self.data_object, [X,Y,Z], weight = W,
- figure = self.figure, axes = self.axes)
- self.UpdateCanvas()
-
- def UpdateStatusBar(self, event):
- #print event.x, event.y
- if event.inaxes:
- if not hasattr(self.plot, 'pix'): return
- xp, yp = event.xdata, event.ydata
- xn = self.FieldX.StringSelection
- yn = self.FieldY.StringSelection
- vn = self.FieldZ.StringSelection
- self.status_bar.SetStatusText("%s = %0.5e" % (xn, xp), 0)
- self.status_bar.SetStatusText("%s = %0.5e" % (yn, yp), 1)
- self.status_bar.SetStatusText("%s = %0.5e" % \
- (vn, self.GetDataValue(xp,yp)), 2)
-
- def GetDataValue(self, x, y):
- xi = na.digitize(na.array([x]), self.plot.x_bins)-1
- yi = na.digitize(na.array([y]), self.plot.y_bins)-1
- return self.plot.vals[yi, xi]
-
- def switch_weight(self, event):
- if self.plot is None: return
- W = event.String
- if len(event.String) == 0: W = None
- self.plot.switch_weight(W)
- self.UpdateCanvas()
-
- def switch_x(self, event):
- if self.plot is None: return
- self.plot.switch_x(event.String)
- self.UpdateCanvas()
-
- def switch_y(self, event):
- if self.plot is None: return
- self.plot.switch_y(event.String)
- self.UpdateCanvas()
-
- def switch_z(self, event):
- if self.plot is None: return
- self.plot.switch_z(event.String)
- self.UpdateCanvas()
-
- def UpdateCanvas(self, *args):
- if self.IsShown():
- self.plot._redraw_image()
- self.figure_canvas.draw()
- #else: print "Opting not to update canvas"
-
- def ChangeLimitsFromMessage(self, message):
- zmin, zmax = message.data
- self.ChangeLimits(zmin,zmax)
-
- def ChangeLimits(self, zmin, zmax):
- print "Change Limits"
- self.plot.set_zlim(zmin,zmax)
- self.figure_canvas.draw()
- # We don't call update canvas
-
if __name__ == "__main__":
app = ReasonApp(0)
app.MainLoop()
More information about the yt-svn
mailing list