Skip to content

Commit

Permalink
Fix xarray tutorial
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sgdecker committed Jul 23, 2021
1 parent daa954d commit f67e77f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions tutorials/xarray_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,21 +260,24 @@
#########################################################################
# 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(
data_at_point['Temperature_isobaric'],
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

Expand Down

0 comments on commit f67e77f

Please sign in to comment.