From e2a0d935c9b0fb648d0a10012ceff4e176d542ae Mon Sep 17 00:00:00 2001 From: Christopher Holmes Date: Mon, 9 Sep 2024 14:59:41 -0400 Subject: [PATCH] =?UTF-8?q?Add=20St=C3=BCve,=20Emagram=20plots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stüve and Emagram plots are enabled as child classes of SkewT parent class. The child classes inherit plotting capabilities from SkewT (e.g. data, wind barbs, dry and saturated adiabats, and mixing ratio lines). --- src/metpy/plots/skewt.py | 104 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 3 deletions(-) diff --git a/src/metpy/plots/skewt.py b/src/metpy/plots/skewt.py index a349067b9d3..ce42c9c685b 100644 --- a/src/metpy/plots/skewt.py +++ b/src/metpy/plots/skewt.py @@ -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 @@ -744,6 +744,104 @@ 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, fig=None, subplot=None, rect=None, aspect='auto'): + 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. + 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__(fig=fig, rotation=0, subplot=subplot, rect=rect, 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, fig=None, subplot=None, rect=None, aspect='auto'): + 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. + 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__(fig=fig, rotation=0, subplot=subplot, rect=rect, aspect=aspect) + + @exporter.export class Hodograph: r"""Make a hodograph of wind data.