[yt-svn] commit/yt: 2 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Jun 15 10:55:44 PDT 2016
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/de4d8786658a/
Changeset: de4d8786658a
Branch: yt
User: ngoldbaum
Date: 2016-05-24 20:07:55+00:00
Summary: Cancel terms with identical LaTeX representations in a LaTeX representation of a unit
Affected #: 2 files
diff -r 4898059be9f9314615b7a7df090845dda5bdefe5 -r de4d8786658addde8c89a189e03df368d6524626 yt/units/tests/test_units.py
--- a/yt/units/tests/test_units.py
+++ b/yt/units/tests/test_units.py
@@ -477,6 +477,9 @@
test_unit = Unit('cm**-3', base_value=1.0, registry=ds.unit_registry)
assert_equal(test_unit.latex_repr, '\\frac{1}{\\rm{cm}^{3}}')
+ test_unit = Unit('m_geom/l_geom**3')
+ assert_equal(test_unit.latex_repr, '\\frac{1}{M_\\odot^{2}}')
+
def test_latitude_longitude():
lat = unit_symbols.lat
lon = unit_symbols.lon
diff -r 4898059be9f9314615b7a7df090845dda5bdefe5 -r de4d8786658addde8c89a189e03df368d6524626 yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -110,8 +110,25 @@
symbol_table[ex] = registry.lut[str(ex)][3]
except:
symbol_table[ex] = r"\rm{" + str(ex).replace('_', '\ ') + "}"
+
+ # invert the symbol table dict to look for keys with identical values
+ invert_symbols = {}
+ for key, value in symbol_table.items():
+ if value not in invert_symbols:
+ invert_symbols[value] = [key]
+ else:
+ invert_symbols[value].append(key)
+
+ # if there are any units with identical latex representations, substitute
+ # units to avoid uncanceled terms in the final latex expresion.
+ for val in invert_symbols:
+ symbols = invert_symbols[val]
+ for i in range(1, len(symbols)):
+ expr = expr.subs(symbols[i], symbols[0])
+
latex_repr = latex(expr, symbol_names=symbol_table, mul_symbol="dot",
fold_frac_powers=True, fold_short_frac=True)
+
if latex_repr == '1':
return ''
else:
@@ -258,7 +275,11 @@
def latex_repr(self):
if self._latex_repr is not None:
return self._latex_repr
- self._latex_repr = get_latex_representation(self.expr, self.registry)
+ if self.expr.is_Atom:
+ expr = self.expr
+ else:
+ expr = self.expr.copy()
+ self._latex_repr = get_latex_representation(expr, self.registry)
return self._latex_repr
### Some sympy conventions
https://bitbucket.org/yt_analysis/yt/commits/7c6daf8417b1/
Changeset: 7c6daf8417b1
Branch: yt
User: MatthewTurk
Date: 2016-06-15 17:55:24+00:00
Summary: Merged in ngoldbaum/yt (pull request #2193)
Cancel terms with identical LaTeX representations in a LaTeX representation of a unit
Affected #: 2 files
diff -r f19d649bfe7a6c30793532a99ef17decf9034e5a -r 7c6daf8417b1be008dfa2d7b95a385b449921f4b yt/units/tests/test_units.py
--- a/yt/units/tests/test_units.py
+++ b/yt/units/tests/test_units.py
@@ -477,6 +477,9 @@
test_unit = Unit('cm**-3', base_value=1.0, registry=ds.unit_registry)
assert_equal(test_unit.latex_repr, '\\frac{1}{\\rm{cm}^{3}}')
+ test_unit = Unit('m_geom/l_geom**3')
+ assert_equal(test_unit.latex_repr, '\\frac{1}{M_\\odot^{2}}')
+
def test_latitude_longitude():
lat = unit_symbols.lat
lon = unit_symbols.lon
diff -r f19d649bfe7a6c30793532a99ef17decf9034e5a -r 7c6daf8417b1be008dfa2d7b95a385b449921f4b yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -110,8 +110,25 @@
symbol_table[ex] = registry.lut[str(ex)][3]
except:
symbol_table[ex] = r"\rm{" + str(ex).replace('_', '\ ') + "}"
+
+ # invert the symbol table dict to look for keys with identical values
+ invert_symbols = {}
+ for key, value in symbol_table.items():
+ if value not in invert_symbols:
+ invert_symbols[value] = [key]
+ else:
+ invert_symbols[value].append(key)
+
+ # if there are any units with identical latex representations, substitute
+ # units to avoid uncanceled terms in the final latex expresion.
+ for val in invert_symbols:
+ symbols = invert_symbols[val]
+ for i in range(1, len(symbols)):
+ expr = expr.subs(symbols[i], symbols[0])
+
latex_repr = latex(expr, symbol_names=symbol_table, mul_symbol="dot",
fold_frac_powers=True, fold_short_frac=True)
+
if latex_repr == '1':
return ''
else:
@@ -258,7 +275,11 @@
def latex_repr(self):
if self._latex_repr is not None:
return self._latex_repr
- self._latex_repr = get_latex_representation(self.expr, self.registry)
+ if self.expr.is_Atom:
+ expr = self.expr
+ else:
+ expr = self.expr.copy()
+ self._latex_repr = get_latex_representation(expr, self.registry)
return self._latex_repr
### Some sympy conventions
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