[Yt-svn] commit/yt: MatthewTurk: Adding a ProfilePlotter object for a minimally-enclosing representation of a 1D

Bitbucket commits-noreply at bitbucket.org
Mon May 23 11:27:10 PDT 2011


1 new changeset in yt:

http://bitbucket.org/yt_analysis/yt/changeset/6bf71aa1b91b/
changeset:   r4275:6bf71aa1b91b
branch:      yt
user:        MatthewTurk
date:        2011-05-23 20:25:58
summary:     Adding a ProfilePlotter object for a minimally-enclosing representation of a 1D
profile.
affected #:  1 file (2.1 KB)

--- a/yt/visualization/profile_plotter.py	Mon May 23 09:51:25 2011 -0700
+++ b/yt/visualization/profile_plotter.py	Mon May 23 14:25:58 2011 -0400
@@ -64,6 +64,10 @@
     cmap = None
     display = True
 
+class PlotContainer(object):
+    x_spec = None
+    y_spec = None
+
 class ImagePlotContainer(object):
     x_spec = None
     y_spec = None
@@ -335,3 +339,54 @@
         img_data = base64.b64encode(pngs)
         return img_data
 
+class ProfilePlotter(object):
+    scale = None
+    _current_field = None
+
+    def __init__(self, data_source, field_x, field_y, 
+                 weight="CellMassMsun", accumulation=False,
+                 x_bins=128, x_log=True, x_bounds=None,
+                 lazy_reader=True, fractional=False):
+        if x_bounds is None:
+            x_min, x_max = data_source.quantities["Extrema"](
+                                    field_x, non_zero = x_log,
+                                    lazy_reader=lazy_reader)[0]
+        else:
+            x_min, x_max = x_bounds
+        profile = BinnedProfile1D(data_source,
+                                  x_bins, field_x, x_min, x_max, x_log,
+                                  lazy_reader)
+        # This is a fallback, in case we forget.
+        if field_y == "CellMassMsun": weight = None
+        profile.add_fields(field_y, weight=weight, accumulation=accumulation, fractional=fractional)
+        self._current_field = field_y
+        self.profile = profile
+        self.scale = {True:'log', False:'linear'}.get(
+                data_source.pf.field_info[field_y], "log")
+        self._setup_plot()
+
+    def _setup_plot(self):
+        xax = AxisSpec()
+        xax.title = self.profile.bin_field
+        xax.bounds = (self.profile._bins[0],
+                      self.profile._bins[-1])
+        xax.scale = {True: 'log', False: 'linear'}[self.profile._x_log]
+        xax.calculate_ticks()
+
+        yax = AxisSpec()
+        yax.title = self._current_field
+        if self.scale == 'log':
+            ny = (self.profile[self._current_field] > 0)
+            mi = self.profile[self._current_field][ny].min()
+        else:
+            mi = self.profile[self._current_field][ny].min()
+        ma = self.profile[self._current_field].max()
+        yax.bounds = (mi, ma)
+        yax.scale = self.scale
+        yax.calculate_ticks()
+
+        self.plot = PlotContainer()
+        self.plot.x_values = self.profile._bins
+        self.plot.y_values = self.profile[self._current_field]
+        self.plot.x_spec = xax
+        self.plot.y_spec = yax

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list