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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri May 10 15:33:07 PDT 2013


13 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/dd6acf314502/
Changeset:   dd6acf314502
Branch:      yt
User:        ngoldbaum
Date:        2013-05-09 08:50:32
Summary:     Adding an alias useful for duck typing on numeric data types.
Affected #:  1 file

diff -r c27c264ed585c6406269737053dac0da51af195d -r dd6acf314502e694380ba96df409cb86a8fdc653 yt/utilities/definitions.py
--- a/yt/utilities/definitions.py
+++ b/yt/utilities/definitions.py
@@ -64,3 +64,5 @@
                   'days'  : sec_per_day}
 
 axis_labels = [('y','z'),('x','z'),('x','y')]
+
+numeric = (int, long, float)


https://bitbucket.org/yt_analysis/yt/commits/c5d810237838/
Changeset:   c5d810237838
Branch:      yt
User:        ngoldbaum
Date:        2013-05-09 09:15:57
Summary:     Removing ProjectionPlot's max_level keyword.
Affected #:  1 file

diff -r dd6acf314502e694380ba96df409cb86a8fdc653 -r c5d8102378389d68a3ec3a0c5bceffa539e83c55 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1237,8 +1237,6 @@
          entire simulation.
     weight_field : string
          The name of the weighting field.  Set to None for no weight.
-    max_level: int
-         The maximum level to project to.
     fontsize : integer
          The size of the fonts for the axis, colorbar, and tick labels.
     field_parameters : dictionary
@@ -1258,7 +1256,7 @@
     _frb_generator = FixedResolutionBuffer
 
     def __init__(self, pf, axis, fields, center='c', width=None, axes_unit=None,
-                 weight_field=None, max_level=None, origin='center-window', fontsize=18,
+                 weight_field=None, origin='center-window', fontsize=18,
                  field_parameters=None, data_source=None):
         ts = self._initialize_dataset(pf)
         self.ts = ts
@@ -1268,8 +1266,8 @@
         if axes_unit is None  and units != ('1', '1'):
             axes_unit = units
         if field_parameters is None: field_parameters = {}
-        proj = pf.h.proj(axis, fields, weight_field=weight_field, max_level=max_level,
-                         center=center, source=data_source, **field_parameters)
+        proj = pf.h.proj(axis, fields, weight_field=weight_field, center=center,
+                         source=data_source, **field_parameters)
         PWViewerMPL.__init__(self, proj, bounds, origin=origin, fontsize=fontsize)
         self.set_axes_unit(axes_unit)
 


https://bitbucket.org/yt_analysis/yt/commits/a6ee22577cfb/
Changeset:   a6ee22577cfb
Branch:      yt
User:        ngoldbaum
Date:        2013-05-09 09:17:28
Summary:     Making set_width a bit more resilient to possible user input.
Affected #:  3 files

diff -r c5d8102378389d68a3ec3a0c5bceffa539e83c55 -r a6ee22577cfb26dc7d49dd9005f2230e93b87906 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -208,3 +208,10 @@
         s = "There are too many vertices (%s) to upload to Sketchfab. " % (self.nv)
         s += "Your model has been saved as %s .  You should upload manually." % (self.fn)
         return s
+
+class YTInvalidWidthError(YTException):
+    def __init__(self, error):
+        self.error = error
+
+    def __str__(self):
+        return str(self.error)

diff -r c5d8102378389d68a3ec3a0c5bceffa539e83c55 -r a6ee22577cfb26dc7d49dd9005f2230e93b87906 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -60,12 +60,13 @@
     x_dict, x_names, \
     y_dict, y_names, \
     axis_names, \
-    axis_labels
+    axis_labels, \
+    numeric
 from yt.utilities.math_utils import \
     ortho_find
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     GroupOwnership
-from yt.utilities.exceptions import YTUnitNotRecognized
+from yt.utilities.exceptions import YTUnitNotRecognized, YTInvalidWidthError
 from yt.data_objects.time_series import \
     TimeSeriesData
 
@@ -152,6 +153,17 @@
 log_transform = FieldTransform('log10', np.log10, LogLocator())
 linear_transform = FieldTransform('linear', lambda x: x, LinearLocator())
 
+def assert_valid_width_tuple(width):
+    try:
+        assert iterable(width) and len(width) == 2,
+               "width (%s) is not a two element tuple" % width
+        valid = isinstance(width[0], numeric) and isinstance(width[1], str)
+        msg = "width (%s) is invalid " % str(width)
+        msg += "valid widths look like this: (12, 'au')"
+        assert valid, msg
+    except AssertionError, e:
+        raise YTInvalidWidthError(e)
+
 def StandardWidth(axis, width, depth, pf):
     if width is None:
         # Default to code units
@@ -164,17 +176,25 @@
             width = ((pf.domain_width.min(), '1'),
                      (pf.domain_width.min(), '1'))
     elif iterable(width):
-        if isinstance(width[1], str):
+        if isinstance(width[0], tuple) and isinstance(width[1], tuple):
+            assert_valid_width_tuple(width[0])
+            assert_valid_width_tuple(width[1])
+        elif isinstance(width[0], numeric) and isinstance(width[1], numeric):
+            width = ((width[0], '1'), (width[1], '1'))
+        else:
+            assert_valid_width_tuple(width)
             width = (width, width)
-        elif isinstance(width[1], (long, int, float)):
-            width = ((width[0], '1'), (width[1], '1'))
     else:
+        try:
+            assert isinstance(width, numeric), "width (%s) is invalid" % str(width)
+        except AssertionError, e:
+            raise YTInvalidWidthError(e)
         width = ((width, '1'), (width, '1'))
     if depth is not None:
         if iterable(depth) and isinstance(depth[1], str):
             depth = (depth,)
         elif iterable(depth):
-            raise RuntimeError("Depth must be a float or a (width,\"unit\") tuple")
+            assert_valid_width_tuple(depth)
         else:
             depth = ((depth, '1'),)
         width += depth
@@ -447,18 +467,31 @@
              in code units.  If units are provided the resulting plot axis labels will
              use the supplied units.
         unit : str
-             the unit the width has been specified in.
-             defaults to code units.  If width is a tuple this
-             argument is ignored
-
+             the unit the width has been specified in. If width is a tuple, this
+             argument is ignored. Defaults to code units.
         """
         if width is not None:
             set_axes_unit = True
         else:
             set_axes_unit = False
 
-        if isinstance(width, (int, long, float)):
+        if isinstance(width, numeric):
             width = (width, unit)
+        elif iterable(width):
+            if isinstance(width[0], tuple) and isinstance(width[1], tuple):
+                assert_valid_width_tuple(width[0])
+                assert_valid_width_tuple(width[1])
+            elif isinstance(width[0], numeric) and isinstance(width[1], numeric):
+                width = ((width[0], '1'), (width[1], '1'))
+            else:
+                assert_valid_width_tuple(width)
+                # If width and unit are both valid width tuples, we
+                # assume width controls x and unit controls y
+                try:
+                    assert_valid_width_tuple(unit)
+                    width = (width, unit)
+                except YTInvalidWidthError:
+                    width = (width, width)
 
         width = StandardWidth(self._frb.axis, width, None, self.pf)
 

diff -r c5d8102378389d68a3ec3a0c5bceffa539e83c55 -r a6ee22577cfb26dc7d49dd9005f2230e93b87906 yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -147,6 +147,13 @@
          (-5/pf['kpc'], 5/pf['kpc']),
          (15/pf['kpc'], 10/pf['kpc'])], 15
 
+    slc.set_width((15,'kpc'),(10000,'pc'))
+
+    yield assert_rel_equal, [slc.xlim, slc.ylim, slc.width], \
+        [(-7.5/pf['kpc'], 7.5/pf['kpc']),
+         (-5/pf['kpc'], 5/pf['kpc']),
+         (15/pf['kpc'], 10/pf['kpc'])], 15
+
 def test_save():
     """Test plot window creation and saving to disk."""
     # Perform I/O in safe place instead of yt main dir


https://bitbucket.org/yt_analysis/yt/commits/3edff4f5f43f/
Changeset:   3edff4f5f43f
Branch:      yt
User:        ngoldbaum
Date:        2013-05-09 10:16:49
Summary:     Making it possible to set the text color for a plot via set_font. Closes #536.
Affected #:  1 file

diff -r a6ee22577cfb26dc7d49dd9005f2230e93b87906 -r 3edff4f5f43fc1b974780bd79056513502ba3fb7 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -155,8 +155,8 @@
 
 def assert_valid_width_tuple(width):
     try:
-        assert iterable(width) and len(width) == 2,
-               "width (%s) is not a two element tuple" % width
+        assert iterable(width) and len(width) == 2, \
+            "width (%s) is not a two element tuple" % width
         valid = isinstance(width[0], numeric) and isinstance(width[1], str)
         msg = "width (%s) is invalid " % str(width)
         msg += "valid widths look like this: (12, 'au')"
@@ -776,6 +776,7 @@
         font_size = kwargs.pop("fontsize", 18)
         font_path = matplotlib.get_data_path() + '/fonts/ttf/STIXGeneral.ttf'
         self._font_properties = FontProperties(size=font_size, fname=font_path)
+        self._font_color = None
         PWViewer.__init__(self, *args, **kwargs)
 
     def _setup_origin(self):
@@ -921,6 +922,16 @@
 
             self.run_callbacks(f)
 
+            if self._font_color is not None:
+                ax = self.plots[f].axes
+                cbax = self.plots[f].cb.ax
+                labels = \
+                  ax.xaxis.get_ticklabels() + ax.yaxis.get_ticklabels() + \
+                  cbax.yaxis.get_ticklabels() + \
+                  [ax.xaxis.label, ax.yaxis.label, cbax.yaxis.label]
+                for label in labels:
+                    label.set_color(self._font_color)
+
         self._plot_valid = True
 
     def run_callbacks(self, f):
@@ -942,28 +953,49 @@
         ----------
         font_dict : dict
         A dict of keyword parameters to be passed to
-        matplotlib.font_manager.FontProperties.  See the matplotlib font
-        manager documentation for more details.
+        matplotlib.font_manager.FontProperties.
+
+        Possible keys include
+        * family - The font family. Can be serif, sans-serif, cursive, 'fantasy' or
+          'monospace'.
+        * style - The font style. Either normal, italic or oblique.
+        * color - A valid color string like 'r', 'g', 'red', 'cobalt', and
+          'orange'.
+        * variant: Either normal or small-caps.
+        * size: Either an relative value of xx-small, x-small, small, medium,
+          large, x-large, xx-large or an absolute font size, e.g. 12
+        * stretch: A numeric value in the range 0-1000 or one of
+          ultra-condensed, extra-condensed, condensed, semi-condensed, normal,
+          semi-expanded, expanded, extra-expanded or ultra-expanded
+        * weight: A numeric value in the range 0-1000 or one of ultralight,
+          light, normal, regular, book, medium, roman, semibold, demibold, demi,
+          bold, heavy, extra bold, or black
+
+        See the matplotlib font manager API documentation for more details.
         http://matplotlib.org/api/font_manager_api.html
 
         Notes
         -----
-        Mathtext axis labels will only obey the `size` keyword.
+        Mathtext axis labels will only obey the `size` and `color` keyword.
 
         Examples
         --------
-        This sets the font to be 24-pt, sans-serif, italic, and bold-face.
+        This sets the font to be 24-pt, blue, sans-serif, italic, and
+        bold-face.
 
         >>> slc = SlicePlot(pf, 'x', 'Density')
         >>> slc.set_font({'family':'sans-serif', 'style':'italic',
-                          'weight':'bold', 'size':24})
+                          'weight':'bold', 'size':24, 'color':'blue'})
 
         """
         if font_dict is None:
             font_dict = {}
+        if 'color' in font_dict:
+            self._font_color = font_dict.pop('color')
         self._font_properties = \
             FontProperties(**font_dict)
 
+
     @invalidate_plot
     def set_cmap(self, field, cmap):
         """set the colormap for one of the fields


https://bitbucket.org/yt_analysis/yt/commits/1f9bf12e30c6/
Changeset:   1f9bf12e30c6
Branch:      yt
User:        ngoldbaum
Date:        2013-05-09 10:24:03
Summary:     Very minor formatting change to an error.
Affected #:  1 file

diff -r 3edff4f5f43fc1b974780bd79056513502ba3fb7 -r 1f9bf12e30c66d899c4a193e011589d21f4d81bf yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -158,8 +158,8 @@
         assert iterable(width) and len(width) == 2, \
             "width (%s) is not a two element tuple" % width
         valid = isinstance(width[0], numeric) and isinstance(width[1], str)
-        msg = "width (%s) is invalid " % str(width)
-        msg += "valid widths look like this: (12, 'au')"
+        msg = "width (%s) is invalid. " % str(width)
+        msg += "Valid widths look like this: (12, 'au')"
         assert valid, msg
     except AssertionError, e:
         raise YTInvalidWidthError(e)


https://bitbucket.org/yt_analysis/yt/commits/4f765ccba659/
Changeset:   4f765ccba659
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 01:26:24
Summary:     Using the base numeric class to validate.

See http://docs.python.org/2/library/numbers.html
and http://www.python.org/dev/peps/pep-3141/
Affected #:  2 files

diff -r 1f9bf12e30c66d899c4a193e011589d21f4d81bf -r 4f765ccba659e26ce0a59b0811032cffd860eb9e yt/utilities/definitions.py
--- a/yt/utilities/definitions.py
+++ b/yt/utilities/definitions.py
@@ -64,5 +64,3 @@
                   'days'  : sec_per_day}
 
 axis_labels = [('y','z'),('x','z'),('x','y')]
-
-numeric = (int, long, float)

diff -r 1f9bf12e30c66d899c4a193e011589d21f4d81bf -r 4f765ccba659e26ce0a59b0811032cffd860eb9e yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -35,6 +35,7 @@
 from matplotlib.font_manager import FontProperties
 from distutils import version
 from functools import wraps
+from numbers import Number
 
 from ._mpl_imports import \
     FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
@@ -60,8 +61,7 @@
     x_dict, x_names, \
     y_dict, y_names, \
     axis_names, \
-    axis_labels, \
-    numeric
+    axis_labels
 from yt.utilities.math_utils import \
     ortho_find
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
@@ -157,7 +157,7 @@
     try:
         assert iterable(width) and len(width) == 2, \
             "width (%s) is not a two element tuple" % width
-        valid = isinstance(width[0], numeric) and isinstance(width[1], str)
+        valid = isinstance(width[0], Number) and isinstance(width[1], str)
         msg = "width (%s) is invalid. " % str(width)
         msg += "Valid widths look like this: (12, 'au')"
         assert valid, msg
@@ -186,7 +186,7 @@
             width = (width, width)
     else:
         try:
-            assert isinstance(width, numeric), "width (%s) is invalid" % str(width)
+            assert isinstance(width, Number), "width (%s) is invalid" % str(width)
         except AssertionError, e:
             raise YTInvalidWidthError(e)
         width = ((width, '1'), (width, '1'))
@@ -475,7 +475,7 @@
         else:
             set_axes_unit = False
 
-        if isinstance(width, numeric):
+        if isinstance(width, Number):
             width = (width, unit)
         elif iterable(width):
             if isinstance(width[0], tuple) and isinstance(width[1], tuple):


https://bitbucket.org/yt_analysis/yt/commits/de875bf4152c/
Changeset:   de875bf4152c
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 01:27:09
Summary:     Defining a new function to avoid repeating myself.
Affected #:  1 file

diff -r 4f765ccba659e26ce0a59b0811032cffd860eb9e -r de875bf4152cb3c47df932ccb39f0abc1e73b215 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -164,6 +164,22 @@
     except AssertionError, e:
         raise YTInvalidWidthError(e)
 
+def validate_iterable_width(width, unit=None):
+    if isinstance(width[0], tuple) and isinstance(width[1], tuple):
+        assert_valid_width_tuple(width[0])
+        assert_valid_width_tuple(width[1])
+    elif isinstance(width[0], Number) and isinstance(width[1], Number):
+        width = ((width[0], '1'), (width[1], '1'))
+    else:
+        assert_valid_width_tuple(width)
+        # If width and unit are both valid width tuples, we
+        # assume width controls x and unit controls y
+        try:
+            assert_valid_width_tuple(unit)
+            width = (width, unit)
+        except YTInvalidWidthError:
+            width = (width, width)
+
 def StandardWidth(axis, width, depth, pf):
     if width is None:
         # Default to code units
@@ -176,14 +192,7 @@
             width = ((pf.domain_width.min(), '1'),
                      (pf.domain_width.min(), '1'))
     elif iterable(width):
-        if isinstance(width[0], tuple) and isinstance(width[1], tuple):
-            assert_valid_width_tuple(width[0])
-            assert_valid_width_tuple(width[1])
-        elif isinstance(width[0], numeric) and isinstance(width[1], numeric):
-            width = ((width[0], '1'), (width[1], '1'))
-        else:
-            assert_valid_width_tuple(width)
-            width = (width, width)
+        validate_iterable_width(width)
     else:
         try:
             assert isinstance(width, Number), "width (%s) is invalid" % str(width)
@@ -196,6 +205,10 @@
         elif iterable(depth):
             assert_valid_width_tuple(depth)
         else:
+            try:
+                assert isinstance(depth, Number), "width (%s) is invalid" % str(depth)
+            except: AssertionError, e
+                raise YTInvalidWidthError(e)
             depth = ((depth, '1'),)
         width += depth
     return width
@@ -478,20 +491,7 @@
         if isinstance(width, Number):
             width = (width, unit)
         elif iterable(width):
-            if isinstance(width[0], tuple) and isinstance(width[1], tuple):
-                assert_valid_width_tuple(width[0])
-                assert_valid_width_tuple(width[1])
-            elif isinstance(width[0], numeric) and isinstance(width[1], numeric):
-                width = ((width[0], '1'), (width[1], '1'))
-            else:
-                assert_valid_width_tuple(width)
-                # If width and unit are both valid width tuples, we
-                # assume width controls x and unit controls y
-                try:
-                    assert_valid_width_tuple(unit)
-                    width = (width, unit)
-                except YTInvalidWidthError:
-                    width = (width, width)
+            validate_iterable_width(width, unit)
 
         width = StandardWidth(self._frb.axis, width, None, self.pf)
 


https://bitbucket.org/yt_analysis/yt/commits/9ba87ebaed1e/
Changeset:   9ba87ebaed1e
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 01:27:25
Summary:     Using intersphinx to resolve the reference to a maptlotlib class.
Affected #:  1 file

diff -r de875bf4152cb3c47df932ccb39f0abc1e73b215 -r 9ba87ebaed1e17f0b579d58c49261eb57785bafb yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -953,7 +953,7 @@
         ----------
         font_dict : dict
         A dict of keyword parameters to be passed to
-        matplotlib.font_manager.FontProperties.
+        :py:class:`matplotlib.font_manager.FontProperties`.
 
         Possible keys include
         * family - The font family. Can be serif, sans-serif, cursive, 'fantasy' or


https://bitbucket.org/yt_analysis/yt/commits/70016c04e488/
Changeset:   70016c04e488
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 01:42:17
Summary:     validate_iterable_width needs to return a width as well.
Affected #:  1 file

diff -r 9ba87ebaed1e17f0b579d58c49261eb57785bafb -r 70016c04e48870cfd1a27bdd6fadf1c628ba1b07 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -168,17 +168,18 @@
     if isinstance(width[0], tuple) and isinstance(width[1], tuple):
         assert_valid_width_tuple(width[0])
         assert_valid_width_tuple(width[1])
+        return width
     elif isinstance(width[0], Number) and isinstance(width[1], Number):
-        width = ((width[0], '1'), (width[1], '1'))
+        return ((width[0], '1'), (width[1], '1'))
     else:
         assert_valid_width_tuple(width)
         # If width and unit are both valid width tuples, we
         # assume width controls x and unit controls y
         try:
             assert_valid_width_tuple(unit)
-            width = (width, unit)
+            return (width, unit)
         except YTInvalidWidthError:
-            width = (width, width)
+            return (width, width)
 
 def StandardWidth(axis, width, depth, pf):
     if width is None:
@@ -192,7 +193,7 @@
             width = ((pf.domain_width.min(), '1'),
                      (pf.domain_width.min(), '1'))
     elif iterable(width):
-        validate_iterable_width(width)
+        width = validate_iterable_width(width)
     else:
         try:
             assert isinstance(width, Number), "width (%s) is invalid" % str(width)
@@ -207,7 +208,7 @@
         else:
             try:
                 assert isinstance(depth, Number), "width (%s) is invalid" % str(depth)
-            except: AssertionError, e
+            except AssertionError, e:
                 raise YTInvalidWidthError(e)
             depth = ((depth, '1'),)
         width += depth
@@ -491,7 +492,7 @@
         if isinstance(width, Number):
             width = (width, unit)
         elif iterable(width):
-            validate_iterable_width(width, unit)
+            width = validate_iterable_width(width, unit)
 
         width = StandardWidth(self._frb.axis, width, None, self.pf)
 


https://bitbucket.org/yt_analysis/yt/commits/89c774429252/
Changeset:   89c774429252
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 04:16:57
Summary:     Backing out c5d810237838
Affected #:  1 file

diff -r 70016c04e48870cfd1a27bdd6fadf1c628ba1b07 -r 89c774429252921f1468456023c7c3bdd8668cb2 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1303,6 +1303,8 @@
          entire simulation.
     weight_field : string
          The name of the weighting field.  Set to None for no weight.
+    max_level: int
+         The maximum level to project to.
     fontsize : integer
          The size of the fonts for the axis, colorbar, and tick labels.
     field_parameters : dictionary
@@ -1322,7 +1324,7 @@
     _frb_generator = FixedResolutionBuffer
 
     def __init__(self, pf, axis, fields, center='c', width=None, axes_unit=None,
-                 weight_field=None, origin='center-window', fontsize=18,
+                 weight_field=None, max_level=None, origin='center-window', fontsize=18,
                  field_parameters=None, data_source=None):
         ts = self._initialize_dataset(pf)
         self.ts = ts
@@ -1332,8 +1334,8 @@
         if axes_unit is None  and units != ('1', '1'):
             axes_unit = units
         if field_parameters is None: field_parameters = {}
-        proj = pf.h.proj(axis, fields, weight_field=weight_field, center=center,
-                         source=data_source, **field_parameters)
+        proj = pf.h.proj(axis, fields, weight_field=weight_field, max_level=max_level,
+                         center=center, source=data_source, **field_parameters)
         PWViewerMPL.__init__(self, proj, bounds, origin=origin, fontsize=fontsize)
         self.set_axes_unit(axes_unit)
 


https://bitbucket.org/yt_analysis/yt/commits/2bae91f5359d/
Changeset:   2bae91f5359d
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 04:28:20
Summary:     Setting the font for the 'offset text'.

See http://matplotlib.1069221.n5.nabble.com/Axis-font-and-exponent-questions-td11766.html
Affected #:  1 file

diff -r 89c774429252921f1468456023c7c3bdd8668cb2 -r 2bae91f5359db388ed1df9a3cb82771a76253d28 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -905,7 +905,9 @@
             self.plots[f].axes.set_ylabel(labels[1],fontproperties=fp)
 
             for label in (self.plots[f].axes.get_xticklabels() +
-                          self.plots[f].axes.get_yticklabels()):
+                          self.plots[f].axes.get_yticklabels() +
+                          [self.plots[f].axes.xaxis.get_offset_text(),
+                           self.plots[f].axes.yaxis.get_offset_text()]):
                 label.set_fontproperties(fp)
 
             colorbar_label = image.info['label']


https://bitbucket.org/yt_analysis/yt/commits/16d8e27e4f93/
Changeset:   16d8e27e4f93
Branch:      yt
User:        ngoldbaum
Date:        2013-05-10 05:09:53
Summary:     Fixing a typo in the plot window docstrings.
Affected #:  1 file

diff -r 2bae91f5359db388ed1df9a3cb82771a76253d28 -r 16d8e27e4f93677707b52031eb1cccd3018a7422 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1133,7 +1133,7 @@
     fields : string
          The name of the field(s) to be plotted.
     center : two or three-element vector of sequence floats, 'c', or 'center', or 'max'
-         The coordinate of the center of the image.  If left blanck,
+         The coordinate of the center of the image.  If left blank,
          the image centers on the location of the maximum density
          cell.  If set to 'c' or 'center', the plot is centered on
          the middle of the domain.  If set to 'max', will be at the point
@@ -1243,7 +1243,7 @@
     fields : string
         The name of the field(s) to be plotted.
     center : two or three-element vector of sequence floats, 'c', or 'center', or 'max'
-         The coordinate of the center of the image.  If left blanck,
+         The coordinate of the center of the image.  If left blank,
          the image centers on the location of the maximum density
          cell.  If set to 'c' or 'center', the plot is centered on
          the middle of the domain.  If set to 'max', will be at the point
@@ -1361,7 +1361,7 @@
     fields : string
         The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or 'center'
-        The coordinate of the center of the image.  If left blanck,
+        The coordinate of the center of the image.  If left blank,
         the image centers on the location of the maximum density
         cell.  If set to 'c' or 'center', the plot is centered on
         the middle of the domain.
@@ -1444,7 +1444,7 @@
     fields : string
         The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or 'center'
-        The coordinate of the center of the image.  If left blanck,
+        The coordinate of the center of the image.  If left blank,
         the image centers on the location of the maximum density
         cell.  If set to 'c' or 'center', the plot is centered on
         the middle of the domain.


https://bitbucket.org/yt_analysis/yt/commits/eba217216a22/
Changeset:   eba217216a22
Branch:      yt
User:        chummels
Date:        2013-05-11 00:32:50
Summary:     Merged in ngoldbaum/yt (pull request #496)

Plot window improvements: set_width, set_font, and no more max_level for ProjectionPlot.
Affected #:  4 files

diff -r 70ad437a12e2b7593a998f6c47ab3bb3e48cb4d0 -r eba217216a22b7f387685ec1dcf3b0c58ad186d0 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -208,3 +208,10 @@
         s = "There are too many vertices (%s) to upload to Sketchfab. " % (self.nv)
         s += "Your model has been saved as %s .  You should upload manually." % (self.fn)
         return s
+
+class YTInvalidWidthError(YTException):
+    def __init__(self, error):
+        self.error = error
+
+    def __str__(self):
+        return str(self.error)

diff -r 70ad437a12e2b7593a998f6c47ab3bb3e48cb4d0 -r eba217216a22b7f387685ec1dcf3b0c58ad186d0 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -35,6 +35,7 @@
 from matplotlib.font_manager import FontProperties
 from distutils import version
 from functools import wraps
+from numbers import Number
 
 from ._mpl_imports import \
     FigureCanvasAgg, FigureCanvasPdf, FigureCanvasPS
@@ -65,7 +66,7 @@
     ortho_find
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     GroupOwnership
-from yt.utilities.exceptions import YTUnitNotRecognized
+from yt.utilities.exceptions import YTUnitNotRecognized, YTInvalidWidthError
 from yt.data_objects.time_series import \
     TimeSeriesData
 
@@ -152,6 +153,34 @@
 log_transform = FieldTransform('log10', np.log10, LogLocator())
 linear_transform = FieldTransform('linear', lambda x: x, LinearLocator())
 
+def assert_valid_width_tuple(width):
+    try:
+        assert iterable(width) and len(width) == 2, \
+            "width (%s) is not a two element tuple" % width
+        valid = isinstance(width[0], Number) and isinstance(width[1], str)
+        msg = "width (%s) is invalid. " % str(width)
+        msg += "Valid widths look like this: (12, 'au')"
+        assert valid, msg
+    except AssertionError, e:
+        raise YTInvalidWidthError(e)
+
+def validate_iterable_width(width, unit=None):
+    if isinstance(width[0], tuple) and isinstance(width[1], tuple):
+        assert_valid_width_tuple(width[0])
+        assert_valid_width_tuple(width[1])
+        return width
+    elif isinstance(width[0], Number) and isinstance(width[1], Number):
+        return ((width[0], '1'), (width[1], '1'))
+    else:
+        assert_valid_width_tuple(width)
+        # If width and unit are both valid width tuples, we
+        # assume width controls x and unit controls y
+        try:
+            assert_valid_width_tuple(unit)
+            return (width, unit)
+        except YTInvalidWidthError:
+            return (width, width)
+
 def StandardWidth(axis, width, depth, pf):
     if width is None:
         # Default to code units
@@ -164,18 +193,23 @@
             width = ((pf.domain_width.min(), '1'),
                      (pf.domain_width.min(), '1'))
     elif iterable(width):
-        if isinstance(width[1], str):
-            width = (width, width)
-        elif isinstance(width[1], (long, int, float)):
-            width = ((width[0], '1'), (width[1], '1'))
+        width = validate_iterable_width(width)
     else:
+        try:
+            assert isinstance(width, Number), "width (%s) is invalid" % str(width)
+        except AssertionError, e:
+            raise YTInvalidWidthError(e)
         width = ((width, '1'), (width, '1'))
     if depth is not None:
         if iterable(depth) and isinstance(depth[1], str):
             depth = (depth,)
         elif iterable(depth):
-            raise RuntimeError("Depth must be a float or a (width,\"unit\") tuple")
+            assert_valid_width_tuple(depth)
         else:
+            try:
+                assert isinstance(depth, Number), "width (%s) is invalid" % str(depth)
+            except AssertionError, e:
+                raise YTInvalidWidthError(e)
             depth = ((depth, '1'),)
         width += depth
     return width
@@ -447,18 +481,18 @@
              in code units.  If units are provided the resulting plot axis labels will
              use the supplied units.
         unit : str
-             the unit the width has been specified in.
-             defaults to code units.  If width is a tuple this
-             argument is ignored
-
+             the unit the width has been specified in. If width is a tuple, this
+             argument is ignored. Defaults to code units.
         """
         if width is not None:
             set_axes_unit = True
         else:
             set_axes_unit = False
 
-        if isinstance(width, (int, long, float)):
+        if isinstance(width, Number):
             width = (width, unit)
+        elif iterable(width):
+            width = validate_iterable_width(width, unit)
 
         width = StandardWidth(self._frb.axis, width, None, self.pf)
 
@@ -743,6 +777,7 @@
         font_size = kwargs.pop("fontsize", 18)
         font_path = matplotlib.get_data_path() + '/fonts/ttf/STIXGeneral.ttf'
         self._font_properties = FontProperties(size=font_size, fname=font_path)
+        self._font_color = None
         PWViewer.__init__(self, *args, **kwargs)
 
     def _setup_origin(self):
@@ -870,7 +905,9 @@
             self.plots[f].axes.set_ylabel(labels[1],fontproperties=fp)
 
             for label in (self.plots[f].axes.get_xticklabels() +
-                          self.plots[f].axes.get_yticklabels()):
+                          self.plots[f].axes.get_yticklabels() +
+                          [self.plots[f].axes.xaxis.get_offset_text(),
+                           self.plots[f].axes.yaxis.get_offset_text()]):
                 label.set_fontproperties(fp)
 
             colorbar_label = image.info['label']
@@ -888,6 +925,16 @@
 
             self.run_callbacks(f)
 
+            if self._font_color is not None:
+                ax = self.plots[f].axes
+                cbax = self.plots[f].cb.ax
+                labels = \
+                  ax.xaxis.get_ticklabels() + ax.yaxis.get_ticklabels() + \
+                  cbax.yaxis.get_ticklabels() + \
+                  [ax.xaxis.label, ax.yaxis.label, cbax.yaxis.label]
+                for label in labels:
+                    label.set_color(self._font_color)
+
         self._plot_valid = True
 
     def run_callbacks(self, f):
@@ -909,28 +956,49 @@
         ----------
         font_dict : dict
         A dict of keyword parameters to be passed to
-        matplotlib.font_manager.FontProperties.  See the matplotlib font
-        manager documentation for more details.
+        :py:class:`matplotlib.font_manager.FontProperties`.
+
+        Possible keys include
+        * family - The font family. Can be serif, sans-serif, cursive, 'fantasy' or
+          'monospace'.
+        * style - The font style. Either normal, italic or oblique.
+        * color - A valid color string like 'r', 'g', 'red', 'cobalt', and
+          'orange'.
+        * variant: Either normal or small-caps.
+        * size: Either an relative value of xx-small, x-small, small, medium,
+          large, x-large, xx-large or an absolute font size, e.g. 12
+        * stretch: A numeric value in the range 0-1000 or one of
+          ultra-condensed, extra-condensed, condensed, semi-condensed, normal,
+          semi-expanded, expanded, extra-expanded or ultra-expanded
+        * weight: A numeric value in the range 0-1000 or one of ultralight,
+          light, normal, regular, book, medium, roman, semibold, demibold, demi,
+          bold, heavy, extra bold, or black
+
+        See the matplotlib font manager API documentation for more details.
         http://matplotlib.org/api/font_manager_api.html
 
         Notes
         -----
-        Mathtext axis labels will only obey the `size` keyword.
+        Mathtext axis labels will only obey the `size` and `color` keyword.
 
         Examples
         --------
-        This sets the font to be 24-pt, sans-serif, italic, and bold-face.
+        This sets the font to be 24-pt, blue, sans-serif, italic, and
+        bold-face.
 
         >>> slc = SlicePlot(pf, 'x', 'Density')
         >>> slc.set_font({'family':'sans-serif', 'style':'italic',
-                          'weight':'bold', 'size':24})
+                          'weight':'bold', 'size':24, 'color':'blue'})
 
         """
         if font_dict is None:
             font_dict = {}
+        if 'color' in font_dict:
+            self._font_color = font_dict.pop('color')
         self._font_properties = \
             FontProperties(**font_dict)
 
+
     @invalidate_plot
     def set_cmap(self, field, cmap):
         """set the colormap for one of the fields
@@ -1065,7 +1133,7 @@
     fields : string
          The name of the field(s) to be plotted.
     center : two or three-element vector of sequence floats, 'c', or 'center', or 'max'
-         The coordinate of the center of the image.  If left blanck,
+         The coordinate of the center of the image.  If left blank,
          the image centers on the location of the maximum density
          cell.  If set to 'c' or 'center', the plot is centered on
          the middle of the domain.  If set to 'max', will be at the point
@@ -1175,7 +1243,7 @@
     fields : string
         The name of the field(s) to be plotted.
     center : two or three-element vector of sequence floats, 'c', or 'center', or 'max'
-         The coordinate of the center of the image.  If left blanck,
+         The coordinate of the center of the image.  If left blank,
          the image centers on the location of the maximum density
          cell.  If set to 'c' or 'center', the plot is centered on
          the middle of the domain.  If set to 'max', will be at the point
@@ -1293,7 +1361,7 @@
     fields : string
         The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or 'center'
-        The coordinate of the center of the image.  If left blanck,
+        The coordinate of the center of the image.  If left blank,
         the image centers on the location of the maximum density
         cell.  If set to 'c' or 'center', the plot is centered on
         the middle of the domain.
@@ -1376,7 +1444,7 @@
     fields : string
         The name of the field(s) to be plotted.
     center : A two or three-element vector of sequence floats, 'c', or 'center'
-        The coordinate of the center of the image.  If left blanck,
+        The coordinate of the center of the image.  If left blank,
         the image centers on the location of the maximum density
         cell.  If set to 'c' or 'center', the plot is centered on
         the middle of the domain.

diff -r 70ad437a12e2b7593a998f6c47ab3bb3e48cb4d0 -r eba217216a22b7f387685ec1dcf3b0c58ad186d0 yt/visualization/tests/test_plotwindow.py
--- a/yt/visualization/tests/test_plotwindow.py
+++ b/yt/visualization/tests/test_plotwindow.py
@@ -147,6 +147,13 @@
          (-5/pf['kpc'], 5/pf['kpc']),
          (15/pf['kpc'], 10/pf['kpc'])], 15
 
+    slc.set_width((15,'kpc'),(10000,'pc'))
+
+    yield assert_rel_equal, [slc.xlim, slc.ylim, slc.width], \
+        [(-7.5/pf['kpc'], 7.5/pf['kpc']),
+         (-5/pf['kpc'], 5/pf['kpc']),
+         (15/pf['kpc'], 10/pf['kpc'])], 15
+
 def test_save():
     """Test plot window creation and saving to disk."""
     # Perform I/O in safe place instead of yt main dir

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