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

Bitbucket commits-noreply at bitbucket.org
Thu Aug 23 08:59:18 PDT 2012


2 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/6ab3cf9ed978/
changeset:   6ab3cf9ed978
branch:      yt
user:        MatthewTurk
date:        2012-08-23 17:47:56
summary:     Adding set_axes_unit to the plot window.
affected #:  2 files

diff -r b73d49ef9875f1a49e14ac2d05e1cdb3ebed3849 -r 6ab3cf9ed978ae39cca57fbea9ce9e0b1798c956 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -110,3 +110,10 @@
         return "You have not declared yourself to be inside the IPython" + \
                "Notebook.  Do so with this command:\n\n" + \
                "ytcfg['yt','ipython_notebook'] = 'True'"
+
+class YTUnitNotRecognized(YTException):
+    def __init__(self, unit):
+        self.unit = unit
+
+    def __str__(self):
+        return "This parameter file doesn't recognize %s" % self.unit


diff -r b73d49ef9875f1a49e14ac2d05e1cdb3ebed3849 -r 6ab3cf9ed978ae39cca57fbea9ce9e0b1798c956 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -554,13 +554,47 @@
             callback.__doc__ = CallbackMaker.__init__.__doc__
             self.__dict__['annotate_'+cbname] = types.MethodType(callback,self)
 
+    _unit = None
+    @invalidate_plot
+    def set_axes_unit(self, unit_name):
+        r"""Set the unit for display on the x and y axes of the image.
+
+        Parameters
+        ----------
+        unit_name : string
+            A unit, available for conversion in the parameter file, that the
+            image extents will be displayed in.
+
+        Raises
+        ------
+        YTUnitNotRecognized
+            If the unit is not known, this will be raised.
+
+        Examples
+        --------
+
+        >>> p = ProjectionPlot(pf, "y", "Density")
+        >>> p.show()
+        >>> p.set_axes_unit("kpc")
+        >>> p.show()
+        """
+        # blind except because it could be in conversion_factors or units
+        try:
+            self.pf[unit_name]
+        except KeyError: 
+            raise YTUnitNotRecognized(unit_name)
+        self._unit = unit_name
+
     def get_metadata(self, field, strip_mathml = True, return_string = True):
         fval = self._frb[field]
         mi = fval.min()
         ma = fval.max()
         x_width = self.xlim[1] - self.xlim[0]
         y_width = self.ylim[1] - self.ylim[0]
-        unit = get_smallest_appropriate_unit(x_width, self.pf)
+        if self._unit is None:
+            unit = get_smallest_appropriate_unit(x_width, self.pf)
+        else:
+            unit = self._unit
         units = self.get_field_units(field, strip_mathml)
         center = getattr(self._frb.data_source, "center", None)
         if center is None or self._frb.axis == 4:



https://bitbucket.org/yt_analysis/yt/changeset/7a7c32a24138/
changeset:   7a7c32a24138
branch:      yt
user:        MatthewTurk
date:        2012-08-23 17:55:16
summary:     Adding an axes unit reset, by setting the unit_name to None for axes_units.
affected #:  1 file

diff -r 6ab3cf9ed978ae39cca57fbea9ce9e0b1798c956 -r 7a7c32a24138a2430741e8c39438856893d0fe3b yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -563,7 +563,8 @@
         ----------
         unit_name : string
             A unit, available for conversion in the parameter file, that the
-            image extents will be displayed in.
+            image extents will be displayed in.  If set to None, any previous
+            units will be reset.
 
         Raises
         ------
@@ -577,12 +578,15 @@
         >>> p.show()
         >>> p.set_axes_unit("kpc")
         >>> p.show()
+        >>> p.set_axes_unit(None)
+        >>> p.show()
         """
         # blind except because it could be in conversion_factors or units
         try:
             self.pf[unit_name]
         except KeyError: 
-            raise YTUnitNotRecognized(unit_name)
+            if unit_name is not None:
+                raise YTUnitNotRecognized(unit_name)
         self._unit = unit_name
 
     def get_metadata(self, field, strip_mathml = True, return_string = True):

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