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

Bitbucket commits-noreply at bitbucket.org
Mon Sep 10 11:15:51 PDT 2012


4 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/3dfdedf7fb12/
changeset:   3dfdedf7fb12
branch:      yt
user:        ngoldbaum
date:        2012-09-09 03:58:00
summary:     Improving the way unit names and display names of derived fields are handled.  Now when PlotWindow is field name or a display name it cannot parse an exception is thrown and a useful error message is printed.  Complicated field names involving arbitrary latex and text is now possible.
affected #:  2 files

diff -r 551e1238ab38bfd9f1951e6a3fe692cc995e5768 -r 3dfdedf7fb1201b2c29d861b8d8d283cc36415ac yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -76,6 +76,30 @@
     def __str__(self):
         return "Simulation time-series type %s not defined." % self.sim_type
 
+class YTCannotParseFieldDisplayName(YTException):
+    def __init__(self, field_name, display_name, mathtext_error):
+        self.field_name = field_name
+        self.display_name = display_name
+        self.mathtext_error = mathtext_error
+
+    def __str__(self):
+        return ("The display name \"%s\" "
+                "of the derived field %s " 
+                "contains the following LaTeX parser errors:\n" ) \
+                % (self.display_name, self.field_name) + self.mathtext_error
+
+class YTCannotParseUnitDisplayName(YTException):
+    def __init__(self, field_name, display_unit, mathtext_error):
+        self.field_name = field_name
+        self.unit_name = unit_name
+        self.mathtext_error = mathtext_error
+
+    def __str__(self):
+        return ("The unit display name \"%s\" "
+                "of the derived field %s " 
+                "contains the following LaTeX parser errors:\n" ) \
+            % (self.unit_name, self.field_name) + self.mathtext_error
+
 class AmbiguousOutputs(YTException):
     def __init__(self, pf):
         YTException.__init__(self, pf)


diff -r 551e1238ab38bfd9f1951e6a3fe692cc995e5768 -r 3dfdedf7fb1201b2c29d861b8d8d283cc36415ac yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -26,6 +26,8 @@
 """
 import base64
 import matplotlib.figure
+from matplotlib.mathtext import MathTextParser
+from matplotlib.pyparsing import ParseFatalException
 import cStringIO
 import types
 import __builtin__
@@ -738,11 +740,33 @@
             self.plots[f].axes.set_ylabel(labels[1])
 
             field_name = self.data_source.pf.field_info[f].display_name
-            if field_name is None: field_name = f
+
+            if field_name is None:
+                field_name = r'$\rm{'+f+r'}$'
+            elif field_name.find('$') == -1:
+                field_name = r'$\rm{'+field_name+r'}$'
+            
+            parser = MathTextParser('Agg')
+            try:
+                parser.parse(field_name)
+            except ParseFatalException, err:
+                raise YTCannotParseFieldDisplayName(f,field_name,str(err))
+
+            try:
+                parser.parse(r'$'+md['units']+r'$')
+            except ParseFatalException, err:
+                raise YTCannotParseUnitDisplayName(f, md['units'],str(err))
+
             if md['units'] == None or md['units'] == '':
+<<<<<<< variant A
                 label = r'$\rm{'+field_name.encode('string-escape')+r'}$'
+>>>>>>> variant B
+                label = field_name
+####### Ancestor
+                label += r'$'
+======= end
             else:
-                label = r'$\rm{'+field_name.encode('string-escape')+r'}\/\/('+md['units']+r')$'
+                label = field_name+r'$\/\/('+md['units']+r')$'
 
             self.plots[f].cb.set_label(label)
 



https://bitbucket.org/yt_analysis/yt/changeset/9926251b1008/
changeset:   9926251b1008
branch:      yt
user:        ngoldbaum
date:        2012-09-09 20:07:57
summary:     Fixing a bad merge.
affected #:  1 file

diff -r 3dfdedf7fb1201b2c29d861b8d8d283cc36415ac -r 9926251b1008f8f68f3af39395cccce635f4b56e yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -758,13 +758,7 @@
                 raise YTCannotParseUnitDisplayName(f, md['units'],str(err))
 
             if md['units'] == None or md['units'] == '':
-<<<<<<< variant A
-                label = r'$\rm{'+field_name.encode('string-escape')+r'}$'
->>>>>>> variant B
                 label = field_name
-####### Ancestor
-                label += r'$'
-======= end
             else:
                 label = field_name+r'$\/\/('+md['units']+r')$'
 



https://bitbucket.org/yt_analysis/yt/changeset/6732a585f969/
changeset:   6732a585f969
branch:      yt
user:        ngoldbaum
date:        2012-09-08 01:49:29
summary:     Updating plot window to accept fields display names that are already
properly formatted mathtext.  Right now this is detected by checking
to see if the first character of the display name is '$' (i.e. the
string begins a latex math macro).  If not, the display name is
assumed to be an improperly formatted latex code and is prepended with
\rm{ and appended with }.  This means that in the future all display
names that include mathematical expressions must be properly formatted
mathtext.
affected #:  3 files

diff -r 9926251b1008f8f68f3af39395cccce635f4b56e -r 6732a585f9699a571263a230d2fa26e48ab6a40f yt/data_objects/universal_fields.py
--- a/yt/data_objects/universal_fields.py
+++ b/yt/data_objects/universal_fields.py
@@ -968,7 +968,7 @@
     return blank
 add_field("particle_density", function=_pdensity,
           validators=[ValidateGridType()], convert_function=_convertDensity,
-          display_name=r"\mathrm{Particle}\/\mathrm{Density})")
+          display_name=r"$\mathrm{Particle}\/\mathrm{Density}$")
 
 def _MagneticEnergy(field,data):
     """This assumes that your front end has provided Bx, By, Bz in


diff -r 9926251b1008f8f68f3af39395cccce635f4b56e -r 6732a585f9699a571263a230d2fa26e48ab6a40f yt/frontends/enzo/fields.py
--- a/yt/frontends/enzo/fields.py
+++ b/yt/frontends/enzo/fields.py
@@ -171,22 +171,22 @@
 # We set up fields for both TotalEnergy and Total_Energy in the known fields
 # lists.  Note that this does not mean these will be the used definitions.
 add_enzo_field("TotalEnergy", function=NullFunc,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 add_enzo_field("Total_Energy", function=NullFunc,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 
 def _Total_Energy(field, data):
     return data["TotalEnergy"] / _convertEnergy(data)
 add_field("Total_Energy", function=_Total_Energy,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 
 def _TotalEnergy(field, data):
     return data["Total_Energy"] / _convertEnergy(data)
 add_field("TotalEnergy", function=_TotalEnergy,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 
 def _NumberDensity(field, data):
@@ -487,7 +487,7 @@
     """
     return na.sqrt(data['Bx']**2 + data['By']**2 + data['Bz']**2)
 
-add_field("Bmag", function=_Bmag,display_name=r"|B|",units=r"\rm{Gauss}")
+add_field("Bmag", function=_Bmag,display_name=r"$|B|$",units=r"\rm{Gauss}")
 
 # Particle functions
 


diff -r 9926251b1008f8f68f3af39395cccce635f4b56e -r 6732a585f9699a571263a230d2fa26e48ab6a40f yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -725,12 +725,12 @@
                 self.plots[f].image, cax = self.plots[f].cax)
 
             if not md['unit'] in ['1', 'u', 'unitary']:
-                axes_unit_label = '\/\/('+md['unit'].encode('string-escape')+')'
+                axes_unit_label = '\/\/('+md['unit']+')'
             else:
                 axes_unit_label = ''
 
             if self.oblique == False:
-                labels = [r'$\rm{'+axis_labels[axis_index][i].encode('string-escape')+
+                labels = [r'$\rm{'+axis_labels[axis_index][i]+
                         axes_unit_label + r'}$' for i in (0,1)]
             else:
                 labels = [r'$\rm{Image\/x'+axes_unit_label+'}$',



https://bitbucket.org/yt_analysis/yt/changeset/86ad53e70660/
changeset:   86ad53e70660
branch:      yt
user:        MatthewTurk
date:        2012-09-10 20:15:49
summary:     Merged in ngoldbaum/yt-cleancopy (pull request #270)
affected #:  4 files

diff -r d87439267be6e6c2d2f2fb4c6a077b6a075c6900 -r 86ad53e706609810e95b989191c85e1365768859 yt/data_objects/universal_fields.py
--- a/yt/data_objects/universal_fields.py
+++ b/yt/data_objects/universal_fields.py
@@ -968,7 +968,7 @@
     return blank
 add_field("particle_density", function=_pdensity,
           validators=[ValidateGridType()], convert_function=_convertDensity,
-          display_name=r"\mathrm{Particle}\/\mathrm{Density})")
+          display_name=r"$\mathrm{Particle}\/\mathrm{Density}$")
 
 def _MagneticEnergy(field,data):
     """This assumes that your front end has provided Bx, By, Bz in


diff -r d87439267be6e6c2d2f2fb4c6a077b6a075c6900 -r 86ad53e706609810e95b989191c85e1365768859 yt/frontends/enzo/fields.py
--- a/yt/frontends/enzo/fields.py
+++ b/yt/frontends/enzo/fields.py
@@ -171,22 +171,22 @@
 # We set up fields for both TotalEnergy and Total_Energy in the known fields
 # lists.  Note that this does not mean these will be the used definitions.
 add_enzo_field("TotalEnergy", function=NullFunc,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 add_enzo_field("Total_Energy", function=NullFunc,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 
 def _Total_Energy(field, data):
     return data["TotalEnergy"] / _convertEnergy(data)
 add_field("Total_Energy", function=_Total_Energy,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 
 def _TotalEnergy(field, data):
     return data["Total_Energy"] / _convertEnergy(data)
 add_field("TotalEnergy", function=_TotalEnergy,
-          display_name = "\rm{Total}\/\rm{Energy}",
+          display_name = "$\rm{Total}\/\rm{Energy}$",
           units=r"\rm{ergs}/\rm{g}", convert_function=_convertEnergy)
 
 def _NumberDensity(field, data):
@@ -487,7 +487,7 @@
     """
     return np.sqrt(data['Bx']**2 + data['By']**2 + data['Bz']**2)
 
-add_field("Bmag", function=_Bmag,display_name=r"|B|",units=r"\rm{Gauss}")
+add_field("Bmag", function=_Bmag,display_name=r"$|B|$",units=r"\rm{Gauss}")
 
 # Particle functions
 


diff -r d87439267be6e6c2d2f2fb4c6a077b6a075c6900 -r 86ad53e706609810e95b989191c85e1365768859 yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -76,6 +76,30 @@
     def __str__(self):
         return "Simulation time-series type %s not defined." % self.sim_type
 
+class YTCannotParseFieldDisplayName(YTException):
+    def __init__(self, field_name, display_name, mathtext_error):
+        self.field_name = field_name
+        self.display_name = display_name
+        self.mathtext_error = mathtext_error
+
+    def __str__(self):
+        return ("The display name \"%s\" "
+                "of the derived field %s " 
+                "contains the following LaTeX parser errors:\n" ) \
+                % (self.display_name, self.field_name) + self.mathtext_error
+
+class YTCannotParseUnitDisplayName(YTException):
+    def __init__(self, field_name, display_unit, mathtext_error):
+        self.field_name = field_name
+        self.unit_name = unit_name
+        self.mathtext_error = mathtext_error
+
+    def __str__(self):
+        return ("The unit display name \"%s\" "
+                "of the derived field %s " 
+                "contains the following LaTeX parser errors:\n" ) \
+            % (self.unit_name, self.field_name) + self.mathtext_error
+
 class AmbiguousOutputs(YTException):
     def __init__(self, pf):
         YTException.__init__(self, pf)


diff -r d87439267be6e6c2d2f2fb4c6a077b6a075c6900 -r 86ad53e706609810e95b989191c85e1365768859 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -26,6 +26,8 @@
 """
 import base64
 import matplotlib.figure
+from matplotlib.mathtext import MathTextParser
+from matplotlib.pyparsing import ParseFatalException
 import cStringIO
 import types
 import __builtin__
@@ -723,12 +725,12 @@
                 self.plots[f].image, cax = self.plots[f].cax)
 
             if not md['unit'] in ['1', 'u', 'unitary']:
-                axes_unit_label = '\/\/('+md['unit'].encode('string-escape')+')'
+                axes_unit_label = '\/\/('+md['unit']+')'
             else:
                 axes_unit_label = ''
 
             if self.oblique == False:
-                labels = [r'$\rm{'+axis_labels[axis_index][i].encode('string-escape')+
+                labels = [r'$\rm{'+axis_labels[axis_index][i]+
                         axes_unit_label + r'}$' for i in (0,1)]
             else:
                 labels = [r'$\rm{Image\/x'+axes_unit_label+'}$',
@@ -738,11 +740,27 @@
             self.plots[f].axes.set_ylabel(labels[1])
 
             field_name = self.data_source.pf.field_info[f].display_name
-            if field_name is None: field_name = f
+
+            if field_name is None:
+                field_name = r'$\rm{'+f+r'}$'
+            elif field_name.find('$') == -1:
+                field_name = r'$\rm{'+field_name+r'}$'
+            
+            parser = MathTextParser('Agg')
+            try:
+                parser.parse(field_name)
+            except ParseFatalException, err:
+                raise YTCannotParseFieldDisplayName(f,field_name,str(err))
+
+            try:
+                parser.parse(r'$'+md['units']+r'$')
+            except ParseFatalException, err:
+                raise YTCannotParseUnitDisplayName(f, md['units'],str(err))
+
             if md['units'] == None or md['units'] == '':
-                label = r'$\rm{'+field_name.encode('string-escape')+r'}$'
+                label = field_name
             else:
-                label = r'$\rm{'+field_name.encode('string-escape')+r'}\/\/('+md['units']+r')$'
+                label = field_name+r'$\/\/('+md['units']+r')$'
 
             self.plots[f].cb.set_label(label)

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