From f67e77ffe7a3cc3b584626cb6f721d78c51cac64 Mon Sep 17 00:00:00 2001 From: Steve Decker Date: Fri, 23 Jul 2021 14:48:21 -0400 Subject: [PATCH] Fix xarray tutorial The xarray tutorial called mpcalc.surface_based_cape_cin with a dataset where the pressure increased with increasing index, but the function requires the other order. Here, we correct the order. In addition, the latitude is changed to a location where the CAPE is nonzero. --- tutorials/xarray_tutorial.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tutorials/xarray_tutorial.py b/tutorials/xarray_tutorial.py index b4834fd8121..36f1d8d5272 100644 --- a/tutorials/xarray_tutorial.py +++ b/tutorials/xarray_tutorial.py @@ -260,11 +260,14 @@ ######################################################################### # For profile-based calculations (and most remaining calculations in the ``metpy.calc`` # module), xarray ``DataArray``\s are accepted as inputs, but the outputs remain Pint -# Quantities (typically scalars) +# Quantities (typically scalars). Note that MetPy's profile calculations (such as CAPE and +# CIN) require the sounding to be ordered from highest to lowest pressure. As seen earlier +# in this tutorial, this data is ordered the other way, so we need to reverse the inputs +# to ``mpcalc.surface_based_cape_cin``. data_at_point = data.metpy.sel( time1='2017-09-05 12:00', - latitude=40 * units.degrees_north, + latitude=30 * units.degrees_north, longitude=260 * units.degrees_east ) dewpoint = mpcalc.dewpoint_from_relative_humidity( @@ -272,9 +275,9 @@ data_at_point['Relative_humidity_isobaric'] ) cape, cin = mpcalc.surface_based_cape_cin( - data_at_point['isobaric3'], - data_at_point['Temperature_isobaric'], - dewpoint + data_at_point['isobaric3'][::-1], + data_at_point['Temperature_isobaric'][::-1], + dewpoint[::-1] ) cape