Skip to content

Commit

Permalink
Merge pull request #1282 from dopplershift/more-pint
Browse files Browse the repository at this point in the history
More pint fixes
  • Loading branch information
dopplershift committed Jan 10, 2020
2 parents 0653de8 + 7e8b2bd commit ce7b25f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/sigma_to_pressure_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
lon = data.variables['lon'][:]
time = data.variables['time']
vtimes = num2date(time[:], time.units)
temperature = data.variables['temperature'][:] * units.celsius
pres = data.variables['pressure'][:] * units.pascal
hgt = data.variables['height'][:] * units.meter
temperature = units.Quantity(data.variables['temperature'][:], 'degC')
pres = units.Quantity(data.variables['pressure'][:], 'Pa')
hgt = units.Quantity(data.variables['height'][:], 'meter')

####################################
# Array of desired pressure levels
Expand Down
2 changes: 1 addition & 1 deletion src/metpy/calc/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def potential_temperature(pressure, temperature):
--------
>>> from metpy.units import units
>>> metpy.calc.potential_temperature(800. * units.mbar, 273. * units.kelvin)
<Quantity(290.96653180346203, 'kelvin')>
<Quantity(290.9665329591884, 'kelvin')>
"""
return temperature / exner_function(pressure)
Expand Down
4 changes: 2 additions & 2 deletions src/metpy/plots/station_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def plot_parameter(self, location, parameter, formatter='.0f', **kwargs):
plot_barb, plot_symbol, plot_text
"""
if hasattr(parameter, 'units'):
parameter = parameter.magnitude
text = self._to_string_list(parameter, formatter)
return self.plot_text(location, text, **kwargs)

Expand Down Expand Up @@ -353,8 +355,6 @@ def _to_string_list(vals, fmt):
if not callable(fmt):
def formatter(s):
"""Turn a format string into a callable."""
if hasattr(s, 'units'):
s = s.item()
return format(s, fmt)
else:
formatter = fmt
Expand Down
Binary file modified tests/plots/baseline/test_simple_layout.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/plots/baseline/test_stationlayout_api.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions tests/plots/test_skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from metpy.units import units


@pytest.mark.mpl_image_compare(tolerance=.02, remove_text=True, style='default')
@pytest.mark.mpl_image_compare(tolerance=.0202, remove_text=True, style='default')
def test_skewt_api():
"""Test the SkewT API."""
with matplotlib.rc_context({'axes.autolimit_mode': 'data'}):
Expand Down Expand Up @@ -47,7 +47,7 @@ def test_skewt_api():
return fig


@pytest.mark.mpl_image_compare(tolerance=.027 if matplotlib.__version__ < '3.2' else 34.4,
@pytest.mark.mpl_image_compare(tolerance=.0272 if matplotlib.__version__ < '3.2' else 34.4,
remove_text=True, style='default')
def test_skewt_api_units():
"""#Test the SkewT API when units are provided."""
Expand All @@ -66,6 +66,9 @@ def test_skewt_api_units():
skew.plot_moist_adiabats()
skew.plot_mixing_lines()

# This works around the fact that newer pint versions default to degrees_Celsius
skew.ax.set_xlabel('degC')

return fig


Expand Down
8 changes: 4 additions & 4 deletions tests/plots/test_station_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_station_plot_replace():
return fig


@pytest.mark.mpl_image_compare(tolerance=0.00413, savefig_kwargs={'dpi': 300},
@pytest.mark.mpl_image_compare(tolerance=0, savefig_kwargs={'dpi': 300},
remove_text=True)
def test_stationlayout_api():
"""Test the StationPlot API."""
Expand All @@ -92,7 +92,7 @@ def test_stationlayout_api():
# testing data
x = np.array([1, 5])
y = np.array([2, 4])
data = {'temp': np.array([32., 212.]) * units.degF, 'u': np.array([2, 0]) * units.knots,
data = {'temp': np.array([33., 212.]) * units.degF, 'u': np.array([2, 0]) * units.knots,
'v': np.array([0, 5]) * units.knots, 'stid': ['KDEN', 'KSHV'], 'cover': [3, 8]}

# Set up the layout
Expand Down Expand Up @@ -151,15 +151,15 @@ def test_station_layout_names():
assert sorted(layout.names()) == ['cover', 'stid', 'temp', 'u', 'v']


@pytest.mark.mpl_image_compare(tolerance=0.0072, savefig_kwargs={'dpi': 300}, remove_text=True)
@pytest.mark.mpl_image_compare(tolerance=0, savefig_kwargs={'dpi': 300}, remove_text=True)
def test_simple_layout():
"""Test metpy's simple layout for station plots."""
fig = plt.figure(figsize=(9, 9))

# testing data
x = np.array([1, 5])
y = np.array([2, 4])
data = {'air_temperature': np.array([32., 212.]) * units.degF,
data = {'air_temperature': np.array([33., 212.]) * units.degF,
'dew_point_temperature': np.array([28., 80.]) * units.degF,
'air_pressure_at_sea_level': np.array([29.92, 28.00]) * units.inHg,
'eastward_wind': np.array([2, 0]) * units.knots,
Expand Down

0 comments on commit ce7b25f

Please sign in to comment.