Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stüve, Emagram plots #3626

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 105 additions & 3 deletions src/metpy/plots/skewt.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2014,2015,2016,2017,2019 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
"""Make Skew-T Log-P based plots.
"""Make thermodynamic diagrams.

Contain tools for making Skew-T Log-P plots, including the base plotting class,
`SkewT`, as well as a class for making a `Hodograph`.
Contain tools for making thermodynamic diagrams, including the base plotting class,
`SkewT`, derived `Stuve` and `Emagram` classes, and a class for making a `Hodograph`.
"""

from contextlib import ExitStack
Expand Down Expand Up @@ -744,6 +744,108 @@ def shade_cin(self, pressure, t, t_parcel, dewpoint=None, **kwargs):
**kwargs)


@exporter.export
class Stuve(SkewT):
r"""Make Stüve plots of data.

Stüve plots are are a thermodynamic diagram with temperature on the x-axis and
pressure scaled by p^(R/cp)=p^0.286 on the y-axis. This class is derived from the
SkewT class and has the same capabilities for plotting data, wind barbs,
dry and saturated adiabats, and mixing ratio lines.

Attributes
----------
ax : `matplotlib.axes.Axes`
The underlying Axes instance, which can be used for calling additional
plot functions (e.g. `axvline`)

"""

def __init__(self, *args, rotation=0, aspect='auto', **kwargs):
r"""Create Stüve plots.

Parameters
----------
fig : matplotlib.figure.Figure, optional
Source figure to use for plotting. If none is given, a new
:class:`matplotlib.figure.Figure` instance will be created.
rotation : float or int, optional
This value is ignored for Stuve plots, but included for compatibility with SkewT
subplot : tuple[int, int, int] or `matplotlib.gridspec.SubplotSpec` instance, optional
Controls the size/position of the created subplot. This allows creating
the skewT as part of a collection of subplots. If subplot is a tuple, it
should conform to the specification used for
:meth:`matplotlib.figure.Figure.add_subplot`. The
:class:`matplotlib.gridspec.SubplotSpec`
can be created by using :class:`matplotlib.gridspec.GridSpec`.
rect : tuple[float, float, float, float], optional
Rectangle (left, bottom, width, height) in which to place the axes. This
allows the user to place the axes at an arbitrary point on the figure.
aspect : float, int, or Literal['auto'], optional
Aspect ratio (i.e. ratio of y-scale to x-scale) to maintain in the plot.
Defaults to ``'auto'`` which tells matplotlib to handle
the aspect ratio automatically.

"""
super().__init__(*args, **kwargs, rotation=0, aspect=aspect)

# Forward (f) and inverse (g) functions for Stuve pressure coordinate scaling
def f(p):
return p**0.286

def g(p):
return p**(1 / 0.286)

# Set the yaxis as Stuve
self.ax.set_yscale('function', functions=(f, g))


@exporter.export
class Emagram(SkewT):
r"""Make Emagram plots of data.

Emagram plots are T log-P thermodynamic diagrams. They differ from SkewT
in that the T axis is not skewed. This class is derived from the SkewT class and
has the same capabilities for plotting data, wind barbs, dry and saturated
adiabats, and mixing ratio lines.

Attributes
----------
ax : `matplotlib.axes.Axes`
The underlying Axes instance, which can be used for calling additional
plot functions (e.g. `axvline`)

"""

def __init__(self, *args, rotation=0, **kwargs):
r"""Create Emagram plots.

Parameters
----------
fig : matplotlib.figure.Figure, optional
Source figure to use for plotting. If none is given, a new
:class:`matplotlib.figure.Figure` instance will be created.
rotation : float or int, optional
This value is ignored for Emagrams, but included for compatibility with SkewT
subplot : tuple[int, int, int] or `matplotlib.gridspec.SubplotSpec` instance, optional
Controls the size/position of the created subplot. This allows creating
the skewT as part of a collection of subplots. If subplot is a tuple, it
should conform to the specification used for
:meth:`matplotlib.figure.Figure.add_subplot`. The
:class:`matplotlib.gridspec.SubplotSpec`
can be created by using :class:`matplotlib.gridspec.GridSpec`.
rect : tuple[float, float, float, float], optional
Rectangle (left, bottom, width, height) in which to place the axes. This
allows the user to place the axes at an arbitrary point on the figure.
aspect : float, int, or Literal['auto'], optional
Aspect ratio (i.e. ratio of y-scale to x-scale) to maintain in the plot.
Defaults to ``'auto'`` tells matplotlib to handle
the aspect ratio automatically.

"""
super().__init__(*args, **kwargs, rotation=0)


@exporter.export
class Hodograph:
r"""Make a hodograph of wind data.
Expand Down
Binary file added tests/plots/baseline/test_emagram_api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_emagram_gridspec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_emagram_subplot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_emagram_units.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_stuve_api.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_stuve_api_units.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_stuve_barb_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_stuve_gridspec.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/plots/baseline/test_stuve_shade_area.png
Binary file added tests/plots/baseline/test_stuve_subplot.png
Binary file added tests/plots/baseline/test_stuve_tight_bbox.png
Binary file added tests/plots/baseline/test_stuve_units.png
Loading