[yt-svn] commit/yt: MatthewTurk: Enabling upload of Plot Collections to the data hub

Bitbucket commits-noreply at bitbucket.org
Mon May 7 13:34:57 PDT 2012


1 new commit in yt:


https://bitbucket.org/yt_analysis/yt/changeset/ea174c37c88e/
changeset:   ea174c37c88e
branch:      yt
user:        MatthewTurk
date:        2012-05-07 22:34:13
summary:     Enabling upload of Plot Collections to the data hub

This includes adding an image collection object and a _pretty_name attribute to
plot types.  I didn't overload repr because this is for a somewhat different
purpose.
affected #:  2 files

diff -r 9ece5c1017fdb66c6da89c01aa2ce941ce1fc985 -r ea174c37c88e9e198a74b009282a01fb9d9b4aab yt/visualization/plot_collection.py
--- a/yt/visualization/plot_collection.py
+++ b/yt/visualization/plot_collection.py
@@ -24,6 +24,8 @@
 """
 
 from matplotlib import figure
+import shutil
+import tempfile
 import numpy as na
 
 from yt.funcs import *
@@ -47,6 +49,8 @@
     PhasePlot, \
     LineQueryPlot, \
     ScatterPlot
+from yt.utilities.minimal_representation import \
+    MinimalImageCollectionData
 
 # No better place to put this
 def concatenate_pdfs(output_fn, input_fns):
@@ -60,6 +64,18 @@
 def _fix_axis(axis):
     return inv_axis_names.get(axis, axis)
 
+
+class ImageCollection(object):
+    def __init__(self, pf, name):
+        self.pf = pf
+        self.name = name
+        self.images = []
+        self.image_metadata = []
+
+    def add_image(self, fn, descr):
+        self.image_metadata.append(descr)
+        self.images.append((fn, na.fromfile(fn, dtype='c')))
+
 class PlotCollection(object):
     __id_counter = 0
     def __init__(self, pf, center=None):
@@ -117,6 +133,16 @@
         for p in self.plots:
             yield p
 
+    @property
+    def _mrep(self):
+        ic = ImageCollection(self.pf, "Plot Collection with center %s" % self.c)
+        dd = tempfile.mkdtemp()
+        fns = self.save(os.path.join(dd, "temp"))
+        for fn, p in zip(fns, self.plots):
+            ic.add_image(fn, p._pretty_name())
+        shutil.rmtree(dd)
+        return MinimalImageCollectionData(ic)
+
     def save(self, basename=None, format="png", override=False, force_save=False):
         r"""Save out all the plots hanging off this plot collection, using
         generated names.


diff -r 9ece5c1017fdb66c6da89c01aa2ce941ce1fc985 -r ea174c37c88e9e198a74b009282a01fb9d9b4aab yt/visualization/plot_types.py
--- a/yt/visualization/plot_types.py
+++ b/yt/visualization/plot_types.py
@@ -295,6 +295,17 @@
             if not hasattr(c, '_type_name'): continue
             self.modify[c._type_name] = c
 
+    def _pretty_name(self):
+        width = self.im.get("Width", "NA")
+        unit = self.im.get("Unit", "NA")
+        field = self.axis_names.get("Z", self.axis_names.get("Field1"))
+        if hasattr(self.data, "_data_source"):
+            data = self.data._data_source
+        else:
+            data = self.data
+        return "%s: %s (%s %s) %s" % (self._type_name,
+            field, width, unit, data)
+
 class VMPlot(RavenPlot):
     _antialias = True
     _period = (0.0, 0.0)
@@ -493,6 +504,7 @@
         if self.colorbar != None:
             self.colorbar.set_label(str(data_label), **self.label_kws)
 
+
 class FixedResolutionPlot(VMPlot):
 
     # This is a great argument in favor of changing the name

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