Skip to content

Commit

Permalink
rebase and update based on changes to numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Sep 14, 2024
1 parent 9e4d75d commit 1ea239b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,14 @@ class SkewtPanel(PanelTraits, Panel):
ylimits = Tuple(Int(), Int(), default_value=(1000, 100), allow_none=True)
ylimits.__doc__ = """A tuple of y-axis limits to plot the skew-T.
Order is in higher pressure to lower pressure."""
Order is in higher pressure to lower pressure. Assumption is that y-limit values are
hPa."""

xlimits = Tuple(Int(), Int(), default_value=(-40, 40), allow_none=True)
xlimits.__doc__ = """A tuple of x-axis limits to plot the skew-T.
Order is lower temperature to higher temperature."""
Order is lower temperature to higher temperature. Assumption is that x-limit values are
Celsius."""

ylabel = Unicode(default_value='pressure [hPa]')
ylabel.__doc__ = """A string to plot for the y-axis label.
Expand Down
13 changes: 6 additions & 7 deletions src/metpy/plots/skewt.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,21 +622,23 @@ def plot_labeled_skewt_lines(self):
r"""Plot common skewt lines and labels.
This function plots the three common SkewT lines, dry adiabats, moist adiabats,
and mixing ratio lines with labels using a default coloring.
and mixing ratio lines with labels using a default coloring. Function assumes
that temperature value limits are in Celsius and pressure value limits are in
hPa.
"""
from metpy.constants import Cp_d, Rd

# Get axes x, y limits
xmin, xmax = self.ax.get_xlim()
ymax, ymin = self.ax.get_ylim()
ymax, _ = self.ax.get_ylim()

# Pressure for plotting mixing ratio lines
pressure = units.Quantity(np.linspace(500, ymax, 25)[::-1], 'hPa')

# Set plotting certain mixing ratio values
mixing_ratio = units.Quantity(np.array([0.1, 0.2, 0.4, 0.6, 1, 1.5, 2, 3,
4, 6, 8, 10, 13, 16, 20, 25, 30, 36, 42
]).reshape(-1, 1), 'g/kg')
]).reshape(-1, 1)[:, 0], 'g/kg')

# Calculate the dewpoint at 500 hPa based on the mixing ratio (for plotting mixing
# ratio values)
Expand Down Expand Up @@ -674,10 +676,7 @@ def plot_labeled_skewt_lines(self):

# Add saturation mixing ratio labels
for i in range(mixing_ratio.m.size):
if mixing_ratio.m[i, 0] % 1:
val = str(mixing_ratio[i, 0].m)
else:
val = int(mixing_ratio[i, 0].m)
val = str(mixing_ratio[i].m) if mixing_ratio.m[i] % 1 else int(mixing_ratio[i].m)
_ = self.ax.text(plottd.m[i], 500, f'{val}', ha='center', va='bottom',
weight='bold', size=8, color='dodgerblue', clip_on=True,
rotation=30)
Expand Down
6 changes: 2 additions & 4 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -2247,8 +2247,7 @@ def test_declarative_plot_geometry_points(ccrs):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=3.27 if MPL_VERSION.startswith('3.3') else 0.03)
@pytest.mark.mpl_image_compare(remove_text=True, tolerance=0.03)
def test_declarative_skewt_plot():
"""Test plotting of a simple skewT with declarative."""
date = datetime(2016, 5, 22, 0)
Expand Down Expand Up @@ -2276,8 +2275,7 @@ def test_declarative_skewt_plot():
return panel.figure


@pytest.mark.mpl_image_compare(remove_text=True,
tolerance=3.24 if MPL_VERSION.startswith('3.3') else 0.03)
@pytest.mark.mpl_image_compare(remove_text=True, tolerance = 0.03)
def test_declarative_skewt_plot_shade_cape():
"""Test plotting of a skewT with declarative and shading."""
from metpy.calc import parcel_profile
Expand Down

0 comments on commit 1ea239b

Please sign in to comment.