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

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Mon Jun 2 10:28:15 PDT 2008


Author: mturk
Date: Mon Jun  2 10:28:13 2008
New Revision: 514
URL: http://yt.spacepope.org/changeset/514

Log:
One dimensional profiles in raven and reason



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	Mon Jun  2 10:28:13 2008
@@ -146,6 +146,42 @@
         p["Axis"] = lagos.axis_names[axis]
         return p
 
+    def add_profile_object(self, object, fields, cmap=None,
+                           weight="CellMassMsun", accumulation=False,
+                           x_bins=64, x_log=True, x_bounds=None,
+                           lazy_reader=False, id=None):
+        if x_bounds is None:
+            x_min, x_max = object[fields[0]].min(), object[fields[0]].max()
+        else:
+            x_min, x_max = x_bounds
+        profile = lagos.BinnedProfile1D(object,
+                                     x_bins, fields[0], x_min, x_max, x_log,
+                                     lazy_reader)
+        if len(fields) > 1:
+            profile.add_fields(fields[1], weight=weight, accumulation=accumulation)
+        # These next two lines are painful.
+        profile.pf = self.pf
+        profile.hierarchy = self.pf.hierarchy
+        if id is None: id = self._get_new_id()
+        p = self._add_plot(PlotTypes.Profile1DPlot(profile, fields, 
+                                                   id, cmap=cmap))
+        return p
+
+    def add_profile_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_profile_object(sphere, fields, **kwargs)
+        p["Width"] = radius
+        p["Unit"] = unit
+        p["Axis"] = None
+        return p
+
     def add_phase_object(self, object, fields, cmap=None,
                                weight="CellMassMsun", accumulation=False,
                                x_bins=64, x_log=True, x_bounds=None,
@@ -173,10 +209,6 @@
                                                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]
@@ -192,6 +224,11 @@
         p["Axis"] = None
         return p
 
+    def _get_new_id(self):
+        self.__id_counter += 1
+        return self.__id_counter-1
+
+
     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	Mon Jun  2 10:28:13 2008
@@ -433,7 +433,88 @@
         self.set_ylim(l_edge_y, r_edge_y) # At some point, perhaps calculate them?
         self._redraw_image()
 
-class PhasePlot(RavenPlot):
+class ProfilePlot(RavenPlot):
+    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))
+
+
+class Profile1DPlot(ProfilePlot):
+    def __init__(self, data, fields, id, ticker=None, cmap=None,
+                 figure=None, axes=None, plot_options=None):
+        self._type_name = "Profile"
+        self._semi_unique_id = id
+        RavenPlot.__init__(self, data, fields, figure, axes)
+
+        self.axis_names["X"] = fields[0]
+        self.axis_names["Y"] = fields[1]
+
+        if plot_options is None: plot_options = {}
+        self.plot_options = plot_options
+
+        self._log_x = self.data._x_log
+        self._log_y = self.setup_bins(self.fields[1])
+
+    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
+        if field not in self.data.keys():
+            self.data.add_fields(field, weight, accumulation)
+        self._log_x = self.setup_bins(self.fields[0])
+    
+    def switch_z(self, field, weight="CellMassMsun", accumulation=False):
+        self.fields[1] = field
+        self.axis_names["Y"] = field
+        if field not in self.data.keys():
+            self.data.add_fields(field, weight, accumulation)
+        self._log_y = self.setup_bins(self.fields[1])
+    switch_y = switch_z # Compatibility...
+
+class PhasePlot(ProfilePlot):
     def __init__(self, data, fields, id, ticker=None, cmap=None,
                  figure=None, axes=None):
         self._type_name = "Phase"
@@ -464,23 +545,6 @@
                                     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:



More information about the yt-svn mailing list