[yt-svn] commit/yt: 6 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Aug 1 12:58:31 PDT 2016
6 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/b2ca92748033/
Changeset: b2ca92748033
Branch: yt
User: ngoldbaum
Date: 2016-07-26 22:06:07+00:00
Summary: Make the latex representation of units like 1e9*cm much nicer
Affected #: 2 files
diff -r 6146c2117de66b1b6eb6c8c486f6d87f5c2d747d -r b2ca927480335e549e8be866d0c571efdbdeddb7 yt/units/tests/test_units.py
--- a/yt/units/tests/test_units.py
+++ b/yt/units/tests/test_units.py
@@ -480,6 +480,9 @@
test_unit = Unit('m_geom/l_geom**3')
assert_equal(test_unit.latex_repr, '\\frac{1}{M_\\odot^{2}}')
+ test_unit = Unit('1e9*cm')
+ assert_equal(test_unit.latex_repr, '1.0 \\times 10^{9}\\ \\rm{cm}')
+
def test_latitude_longitude():
lat = unit_symbols.lat
lon = unit_symbols.lon
diff -r 6146c2117de66b1b6eb6c8c486f6d87f5c2d747d -r b2ca927480335e549e8be866d0c571efdbdeddb7 yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -127,10 +127,20 @@
symbols = invert_symbols[val]
for i in range(1, len(symbols)):
expr = expr.subs(symbols[i], symbols[0])
-
+ prefix = None
+ if isinstance(expr, Mul):
+ coeffs = expr.as_coeff_Mul()
+ if coeffs[0] == 1 or not isinstance(coeffs[0], Float):
+ pass
+ else:
+ expr = coeffs[1]
+ prefix = Float(coeffs[0], 2)
latex_repr = latex(expr, symbol_names=symbol_table, mul_symbol="dot",
fold_frac_powers=True, fold_short_frac=True)
+ if prefix is not None:
+ latex_repr = latex(prefix, mul_symbol="times") + '\\ ' + latex_repr
+
if latex_repr == '1':
return ''
else:
https://bitbucket.org/yt_analysis/yt/commits/b1640026c26f/
Changeset: b1640026c26f
Branch: yt
User: ngoldbaum
Date: 2016-07-26 22:06:24+00:00
Summary: Make the check for comoving units less brittle
Affected #: 1 file
diff -r b2ca927480335e549e8be866d0c571efdbdeddb7 -r b1640026c26fad27f63870ab27c06df9f65612a2 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -828,7 +828,8 @@
h_power = expr.as_coeff_exponent(h_expr)[1]
# un is now the original unit, but with h factored out.
un = str(expr*h_expr**(-1*h_power))
- if str(un).endswith('cm') and un != 'cm':
+ cm = Unit('cm').expr
+ if str(un).endswith('cm') and cm not in Unit(un).expr.atoms():
comoving = True
un = un[:-2]
# no length units besides code_length end in h so this is safe
@@ -846,6 +847,8 @@
if symbol_wo_prefix in prefixable_units:
un = un.replace(pp, "{"+latex_prefixes[pp]+"}", 1)
if un not in ['1', 'u', 'unitary']:
+ un = Unit(un, registry=self.ds.unit_registry)
+ un = un.latex_representation()
if hinv:
un = un + '\,h^{-1}'
if comoving:
https://bitbucket.org/yt_analysis/yt/commits/fdecff62b2c5/
Changeset: fdecff62b2c5
Branch: yt
User: ngoldbaum
Date: 2016-07-26 23:16:01+00:00
Summary: Use a MathText ScalarFormatter for axis offset text in plots
Affected #: 1 file
diff -r b1640026c26fad27f63870ab27c06df9f65612a2 -r fdecff62b2c58379ef766fd4e9be034a8919d51f yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1694,8 +1694,9 @@
class WindowPlotMPL(ImagePlotMPL):
"""A container for a single PlotWindow matplotlib figure and axes"""
- def __init__(self, data, cbname, cblinthresh, cmap, extent, zlim, figure_size,
- fontsize, aspect, figure, axes, cax):
+ def __init__(self, data, cbname, cblinthresh, cmap, extent, zlim,
+ figure_size, fontsize, aspect, figure, axes, cax):
+ from matplotlib.ticker import ScalarFormatter
self._draw_colorbar = True
self._draw_axes = True
self._fontsize = fontsize
@@ -1723,7 +1724,14 @@
self._init_image(data, cbname, cblinthresh, cmap, extent, aspect)
- self.image.axes.ticklabel_format(scilimits=(-2, 3))
+ # In matplotlib 2.1 and newer we'll be able to do this using
+ # self.image.axes.ticklabel_format
+ # See https://github.com/matplotlib/matplotlib/pull/6337
+ formatter = ScalarFormatter(useMathText=True)
+ formatter.set_scientific(True)
+ formatter.set_powerlimits((-2, 3))
+ self.image.axes.xaxis.set_major_formatter(formatter)
+ self.image.axes.yaxis.set_major_formatter(formatter)
if cbname == 'linear':
self.cb.formatter.set_scientific(True)
self.cb.formatter.set_powerlimits((-2, 3))
https://bitbucket.org/yt_analysis/yt/commits/918828f13297/
Changeset: 918828f13297
Branch: yt
User: ngoldbaum
Date: 2016-07-28 20:10:21+00:00
Summary: Rework logic to prevent creating Unit objects from bad data
Affected #: 1 file
diff -r fdecff62b2c58379ef766fd4e9be034a8919d51f -r 918828f13297fabefa1fd7409b5d50ddcc0652e1 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -828,8 +828,9 @@
h_power = expr.as_coeff_exponent(h_expr)[1]
# un is now the original unit, but with h factored out.
un = str(expr*h_expr**(-1*h_power))
+ un_unit = Unit(un, registry=self.ds.unit_registry)
cm = Unit('cm').expr
- if str(un).endswith('cm') and cm not in Unit(un).expr.atoms():
+ if str(un).endswith('cm') and cm not in un_unit.expr.atoms():
comoving = True
un = un[:-2]
# no length units besides code_length end in h so this is safe
@@ -839,20 +840,22 @@
# It doesn't make sense to scale a position by anything
# other than h**-1
raise RuntimeError
- if un in formatted_length_unit_names:
- un = formatted_length_unit_names[un]
- pp = un[0]
- if pp in latex_prefixes:
- symbol_wo_prefix = un[1:]
- if symbol_wo_prefix in prefixable_units:
- un = un.replace(pp, "{"+latex_prefixes[pp]+"}", 1)
if un not in ['1', 'u', 'unitary']:
- un = Unit(un, registry=self.ds.unit_registry)
- un = un.latex_representation()
- if hinv:
- un = un + '\,h^{-1}'
- if comoving:
- un = un + '\,(1+z)^{-1}'
+ if un in formatted_length_unit_names:
+ un = formatted_length_unit_names[un]
+ else:
+ un = Unit(un, registry=self.ds.unit_registry)
+ un = un.latex_representation()
+ if hinv:
+ un = un + '\,h^{-1}'
+ if comoving:
+ un = un + '\,(1+z)^{-1}'
+ pp = un[0]
+ if pp in latex_prefixes:
+ symbol_wo_prefix = un[1:]
+ if symbol_wo_prefix in prefixable_units:
+ un = un.replace(
+ pp, "{"+latex_prefixes[pp]+"}", 1)
axes_unit_labels[i] = '\ \ ('+un+')'
if self.oblique:
https://bitbucket.org/yt_analysis/yt/commits/21f3ebfee867/
Changeset: 21f3ebfee867
Branch: yt
User: ngoldbaum
Date: 2016-07-28 21:06:24+00:00
Summary: Incrementing answer number
incrementing by 2 since matt already took local_pw_002 in a different PR
Affected #: 1 file
diff -r 918828f13297fabefa1fd7409b5d50ddcc0652e1 -r 21f3ebfee867abcd28d71b5afbea1b9b73ebc5e4 tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -39,7 +39,7 @@
local_owls_000:
- yt/frontends/owls/tests/test_outputs.py
- local_pw_001:
+ local_pw_003:
- yt/visualization/tests/test_plotwindow.py:test_attributes
- yt/visualization/tests/test_plotwindow.py:test_attributes_wt
- yt/visualization/tests/test_profile_plots.py:test_phase_plot_attributes
https://bitbucket.org/yt_analysis/yt/commits/2c73913367ac/
Changeset: 2c73913367ac
Branch: yt
User: jzuhone
Date: 2016-08-01 19:58:01+00:00
Summary: Merged in ngoldbaum/yt (pull request #2310)
Make the latex representation of units like 1e9*cm much nicer. Closes #1253
Affected #: 4 files
diff -r bdc1201a3c1b9c07a269452d9b4dbeea8c4f0965 -r 2c73913367acd93482a88841daebdd6cece35d2c tests/tests.yaml
--- a/tests/tests.yaml
+++ b/tests/tests.yaml
@@ -39,7 +39,7 @@
local_owls_000:
- yt/frontends/owls/tests/test_outputs.py
- local_pw_001:
+ local_pw_003:
- yt/visualization/tests/test_plotwindow.py:test_attributes
- yt/visualization/tests/test_plotwindow.py:test_attributes_wt
- yt/visualization/tests/test_profile_plots.py:test_phase_plot_attributes
diff -r bdc1201a3c1b9c07a269452d9b4dbeea8c4f0965 -r 2c73913367acd93482a88841daebdd6cece35d2c yt/units/tests/test_units.py
--- a/yt/units/tests/test_units.py
+++ b/yt/units/tests/test_units.py
@@ -480,6 +480,9 @@
test_unit = Unit('m_geom/l_geom**3')
assert_equal(test_unit.latex_repr, '\\frac{1}{M_\\odot^{2}}')
+ test_unit = Unit('1e9*cm')
+ assert_equal(test_unit.latex_repr, '1.0 \\times 10^{9}\\ \\rm{cm}')
+
def test_latitude_longitude():
lat = unit_symbols.lat
lon = unit_symbols.lon
diff -r bdc1201a3c1b9c07a269452d9b4dbeea8c4f0965 -r 2c73913367acd93482a88841daebdd6cece35d2c yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -127,10 +127,20 @@
symbols = invert_symbols[val]
for i in range(1, len(symbols)):
expr = expr.subs(symbols[i], symbols[0])
-
+ prefix = None
+ if isinstance(expr, Mul):
+ coeffs = expr.as_coeff_Mul()
+ if coeffs[0] == 1 or not isinstance(coeffs[0], Float):
+ pass
+ else:
+ expr = coeffs[1]
+ prefix = Float(coeffs[0], 2)
latex_repr = latex(expr, symbol_names=symbol_table, mul_symbol="dot",
fold_frac_powers=True, fold_short_frac=True)
+ if prefix is not None:
+ latex_repr = latex(prefix, mul_symbol="times") + '\\ ' + latex_repr
+
if latex_repr == '1':
return ''
else:
diff -r bdc1201a3c1b9c07a269452d9b4dbeea8c4f0965 -r 2c73913367acd93482a88841daebdd6cece35d2c yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -828,7 +828,9 @@
h_power = expr.as_coeff_exponent(h_expr)[1]
# un is now the original unit, but with h factored out.
un = str(expr*h_expr**(-1*h_power))
- if str(un).endswith('cm') and un != 'cm':
+ un_unit = Unit(un, registry=self.ds.unit_registry)
+ cm = Unit('cm').expr
+ if str(un).endswith('cm') and cm not in un_unit.expr.atoms():
comoving = True
un = un[:-2]
# no length units besides code_length end in h so this is safe
@@ -838,18 +840,22 @@
# It doesn't make sense to scale a position by anything
# other than h**-1
raise RuntimeError
- if un in formatted_length_unit_names:
- un = formatted_length_unit_names[un]
- pp = un[0]
- if pp in latex_prefixes:
- symbol_wo_prefix = un[1:]
- if symbol_wo_prefix in prefixable_units:
- un = un.replace(pp, "{"+latex_prefixes[pp]+"}", 1)
if un not in ['1', 'u', 'unitary']:
- if hinv:
- un = un + '\,h^{-1}'
- if comoving:
- un = un + '\,(1+z)^{-1}'
+ if un in formatted_length_unit_names:
+ un = formatted_length_unit_names[un]
+ else:
+ un = Unit(un, registry=self.ds.unit_registry)
+ un = un.latex_representation()
+ if hinv:
+ un = un + '\,h^{-1}'
+ if comoving:
+ un = un + '\,(1+z)^{-1}'
+ pp = un[0]
+ if pp in latex_prefixes:
+ symbol_wo_prefix = un[1:]
+ if symbol_wo_prefix in prefixable_units:
+ un = un.replace(
+ pp, "{"+latex_prefixes[pp]+"}", 1)
axes_unit_labels[i] = '\ \ ('+un+')'
if self.oblique:
@@ -1691,8 +1697,9 @@
class WindowPlotMPL(ImagePlotMPL):
"""A container for a single PlotWindow matplotlib figure and axes"""
- def __init__(self, data, cbname, cblinthresh, cmap, extent, zlim, figure_size,
- fontsize, aspect, figure, axes, cax):
+ def __init__(self, data, cbname, cblinthresh, cmap, extent, zlim,
+ figure_size, fontsize, aspect, figure, axes, cax):
+ from matplotlib.ticker import ScalarFormatter
self._draw_colorbar = True
self._draw_axes = True
self._fontsize = fontsize
@@ -1720,7 +1727,14 @@
self._init_image(data, cbname, cblinthresh, cmap, extent, aspect)
- self.image.axes.ticklabel_format(scilimits=(-2, 3))
+ # In matplotlib 2.1 and newer we'll be able to do this using
+ # self.image.axes.ticklabel_format
+ # See https://github.com/matplotlib/matplotlib/pull/6337
+ formatter = ScalarFormatter(useMathText=True)
+ formatter.set_scientific(True)
+ formatter.set_powerlimits((-2, 3))
+ self.image.axes.xaxis.set_major_formatter(formatter)
+ self.image.axes.yaxis.set_major_formatter(formatter)
if cbname == 'linear':
self.cb.formatter.set_scientific(True)
self.cb.formatter.set_powerlimits((-2, 3))
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