[yt-svn] commit/yt: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Sep 18 13:39:54 PDT 2012


2 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/eeb5923f215e/
changeset:   eeb5923f215e
branch:      yt
user:        MatthewTurk
date:        2012-09-18 22:39:29
summary:     Adding IPython Notebooks to the Hub upload types, and "yt upload_notebook"
command.
affected #:  3 files

diff -r af06f14fcd9eab09d59a8f065a42c64731fb3f5d -r eeb5923f215ee949f30f4160e7aeecf9d96bb37a yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1188,6 +1188,35 @@
         import yt.utilities.lodgeit as lo
         lo.main( None, download=args.number )
 
+class YTNotebookUploadCmd(YTCommand):
+    args = (dict(short="file", type=str),)
+    description = \
+        """
+        Upload an IPython notebook to hub.yt-project.org.
+        """
+
+    name = "upload_notebook"
+    def __call__(self, args):
+        filename = args.file
+        if not os.path.isfile(filename):
+            raise IOError(filename)
+        if not filename.endswith(".ipynb"):
+            print "File must be an IPython notebook!"
+            return 1
+        import json
+        try:
+            t = json.loads(open(filename).read())['metadata']['name']
+        except (ValueError, KeyError):
+            print "File does not appear to be an IPython notebook."
+        from yt.utilities.minimal_representation import MinimalNotebook
+        mn = MinimalNotebook(filename, t)
+        rv = mn.upload()
+        print "Upload successful!"
+        print
+        print "To view your notebook go here:"
+        print "  %s" % (rv['url'].replace("/go/", "/nb/"))
+        print
+
 class YTPlotCmd(YTCommand):
     args = ("width", "unit", "bn", "proj", "center",
             "zlim", "axis", "field", "weight", "skip",


diff -r af06f14fcd9eab09d59a8f065a42c64731fb3f5d -r eeb5923f215ee949f30f4160e7aeecf9d96bb37a yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -141,3 +141,8 @@
 
     def __str__(self):
         return "This parameter file doesn't recognize %s" % self.unit
+
+class YTHubRegisterError(YTException):
+    def __str__(self):
+        return "You must create an API key before uploading.  See " + \
+               "https://data.yt-project.org/getting_started.html"


diff -r af06f14fcd9eab09d59a8f065a42c64731fb3f5d -r eeb5923f215ee949f30f4160e7aeecf9d96bb37a yt/utilities/minimal_representation.py
--- a/yt/utilities/minimal_representation.py
+++ b/yt/utilities/minimal_representation.py
@@ -30,6 +30,7 @@
 from tempfile import TemporaryFile
 from yt.config import ytcfg
 from yt.funcs import *
+from yt.utilities.exceptions import *
 
 from .poster.streaminghttp import register_openers
 from .poster.encode import multipart_encode
@@ -93,6 +94,7 @@
     def upload(self):
         api_key = ytcfg.get("yt","hub_api_key")
         url = ytcfg.get("yt","hub_url")
+        if api_key == '': raise YTHubRegisterError
         metadata, (final_name, chunks) = self._generate_post()
         if hasattr(self, "_pf_mrep"):
             self._pf_mrep.upload()
@@ -216,3 +218,22 @@
         metadata = self._attrs
         chunks = []
         return (metadata, ("chunks", []))
+
+class MinimalNotebook(MinimalRepresentation):
+    type = "notebook"
+    _attr_list = ("title",)
+
+    def __init__(self, filename, title = None):
+        # First we read in the data
+        if not os.path.isfile(filename):
+            raise IOError(filename)
+        self.data = open(filename).read()
+        if title is None:
+            title = json.loads(self.data)['metadata']['name']
+        self.title = title
+        self.data = np.fromstring(self.data, dtype='c')
+
+    def _generate_post(self):
+        metadata = self._attrs
+        chunks = [ ("notebook", self.data) ]
+        return (metadata, ("chunks", chunks))



https://bitbucket.org/yt_analysis/yt/changeset/878a54e77a4f/
changeset:   878a54e77a4f
branch:      yt
user:        MatthewTurk
date:        2012-09-18 22:39:48
summary:     Merge
affected #:  3 files

diff -r eeb5923f215ee949f30f4160e7aeecf9d96bb37a -r 878a54e77a4feef3d03a0417ede10fab4a7998d6 yt/data_objects/grid_patch.py
--- a/yt/data_objects/grid_patch.py
+++ b/yt/data_objects/grid_patch.py
@@ -210,8 +210,6 @@
             LE, RE = self.hierarchy.grid_left_edge[id,:], \
                      self.hierarchy.grid_right_edge[id,:]
             self.dds = np.array((RE - LE) / self.ActiveDimensions)
-        if self.pf.dimensionality < 2: self.dds[1] = 1.0
-        if self.pf.dimensionality < 3: self.dds[2] = 1.0
         self.field_data['dx'], self.field_data['dy'], self.field_data['dz'] = self.dds
 
     @property


diff -r eeb5923f215ee949f30f4160e7aeecf9d96bb37a -r 878a54e77a4feef3d03a0417ede10fab4a7998d6 yt/frontends/flash/data_structures.py
--- a/yt/frontends/flash/data_structures.py
+++ b/yt/frontends/flash/data_structures.py
@@ -143,6 +143,9 @@
         for i in range(nlevels+1):
             dxs[i,:ND] = rdx[:ND]/self.parameter_file.refine_by**i
        
+        if ND < 3:
+            dxs[:,ND:] = rdx[ND:]
+
         for i in xrange(self.num_grids):
             dx = dxs[self.grid_levels[i],:]
             self.grid_left_edge[i] = np.rint(self.grid_left_edge[i]/dx)*dx


diff -r eeb5923f215ee949f30f4160e7aeecf9d96bb37a -r 878a54e77a4feef3d03a0417ede10fab4a7998d6 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -809,7 +809,7 @@
                 raise RuntimeError("Colormap '%s' does not exist!" % str(cmap))
             self.plots[field].image.set_cmap(cmap)
 
-    def save(self,name=None):
+    def save(self, name=None, mpl_kwargs=None):
         """saves the plot to disk.
 
         Parameters
@@ -817,12 +817,17 @@
         name : string
            the base of the filename.  If not set the filename of 
            the parameter file is used
+        mpl_kwargs : dict
+           A dict of keyword arguments to be passed to matplotlib.
+           
+        >>> slc.save(mpl_kwargs={'bbox_inches':'tight'})
 
         """
         if name == None:
             name = str(self.pf)
         elif name.endswith('.png'):
             return v.save(name)
+        if mpl_kwargs is None: mpl_kwargs = {}
         axis = axis_names[self.data_source.axis]
         weight = None
         if 'Slice' in self.data_source.__class__.__name__:
@@ -841,7 +846,7 @@
                 n = "%s_%s_%s" % (name, type, k)
             if weight:
                 n += "_%s" % (weight)
-            names.append(v.save(n))
+            names.append(v.save(n,mpl_kwargs))
         return names
 
     def _send_zmq(self):
@@ -1255,14 +1260,23 @@
     def __init__(self, field, size):
         self._plot_valid = True
         fsize, axrect, caxrect = self._get_best_layout(size)
-        # Hardcoding the axis dimensions for now
         
-        self.figure = matplotlib.figure.Figure(figsize = fsize, 
-                                               frameon = True)
-        self.axes = self.figure.add_axes(axrect)
-        self.cax = self.figure.add_axes(caxrect)
-
-    def save(self, name, canvas = None):
+        if np.any(np.array(axrect) < 0):
+            self.figure = matplotlib.figure.Figure(figsize = size, 
+                                                   frameon = True)
+            self.axes = self.figure.add_axes((.07,.10,.8,.8))
+            self.cax = self.figure.add_axes((.87,.10,.04,.8))
+            mylog.warning('The axis ratio of the requested plot is very narrow.  '
+                          'There is a good chance the plot will not look very good, '
+                          'consider making the plot manually using FixedResolutionBuffer '
+                          'and matplotlib.')
+        else:
+            self.figure = matplotlib.figure.Figure(figsize = fsize, 
+                                                   frameon = True)
+            self.axes = self.figure.add_axes(axrect)
+            self.cax = self.figure.add_axes(caxrect)
+            
+    def save(self, name, mpl_kwargs, canvas = None):
         if name[-4:] == '.png':
             suffix = ''
         else:
@@ -1279,7 +1293,7 @@
             else:
                 mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
                 canvas = FigureCanvasAgg(self.figure)
-        canvas.print_figure(fn)
+        canvas.print_figure(fn,**mpl_kwargs)
         return fn
 
     def _get_best_layout(self, size):

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