MetPy logo Unidata logo

MetPy Tutorial - Making a Skew-T!#


Obtain upper air data#

Upper air observations are generally reported as a plain text file in a tabular format that represents the down sampled raw data transmitted by the rawinsonde. Data are reported an mandatory levels and at levels of significant change. An example of sounding data may look like this:

-----------------------------------------------------------------------------
   PRES   HGHT   TEMP   DWPT   RELH   MIXR   DRCT   SKNT   THTA   THTE   THTV
    hPa     m      C      C      %    g/kg    deg   knot     K      K      K 
-----------------------------------------------------------------------------
 1000.0    270                                                               
  991.0    345   -0.3   -2.8     83   3.15      0      0  273.6  282.3  274.1
  984.0    403   10.2   -7.8     27   2.17    327      4  284.7  291.1  285.0
  963.0    581   11.8   -9.2     22   1.99    226     17  288.0  294.1  288.4
  959.7    610   11.6   -9.4     22   1.96    210     19  288.1  294.1  288.5

Data are available to download from the University of Wyoming archive, the Iowa State archive, and the Integrated Global Radiosonde Archive (IGRA). There is no need to download data manually. We can use the siphon library (also developed at Unidata) to request and download these data. Be sure to checkout the documentation on all of siphon’s capabilities.


Imports#

from datetime import datetime
import os
os.environ['TEST_DATA_DIR']="/tmp" # for metpy to grab data on the jupyterhub
os.environ['MPLCONFIGDIR']="/tmp" # for matplotlib on jupyterhub

import matplotlib.pyplot as plt
import metpy.calc as mpcalc

from metpy.plots import SkewT
from metpy.units import units, pandas_dataframe_to_unit_arrays
from siphon.simplewebservice.wyoming import WyomingUpperAir

Getting our data#

First, we need to create a datetime object that has the time of observation we are looking for. We can then request the data for a specific station. Note that if you provide an invalid time or station where no sounding data are present you will receive an error.

request_time = datetime(1999, 5, 3, 12)

#station = 'OUN'
station = '72357'

df = WyomingUpperAir.request_data(request_time, station)
df.head()

We got a Pandas dataframe back, which is great. Sadly, Pandas does not play well with units, so we need to attach units and make some other kind of data structure. We’ve provided a helper function for this - it takes the dataframe with our special .units attribute and returns a dictionary where the keys are column (data series) names and the values are united arrays. This means we can still use the dictionary access syntax and mostly forget that it is not a data frame any longer.

Fist, let’s look at the special attribute siphon added:

df.units

Now let’s get units attached using MetPy’s pandas unit helper.

sounding = pandas_dataframe_to_unit_arrays(df)
sounding

This helper will take each column of our dataframe, create an appropiate Pint Quantity with units, and stuff it into a Python dictionary. Recall accessing any one of these using the original names of the columns and Python’s dictionary notation,

sounding['pressure']

Creating a Skew-T#

For this, we will be relying on metpy.plots.SkewT. With this we can specify a brand new Matplotlib figure and then Skew-ify it!

# Create a new figure. The dimensions here give a good aspect ratio
fig = plt.figure(figsize=(10, 10))
skew = SkewT(fig)

With our new skew object, we have access to many of our usual Matplotlib plotting methods,

# Plot the data using normal plotting functions, all of the transforms
# happen in the background!
skew.plot(sounding['pressure'], sounding['temperature'], color='tab:red')

# Redisplay the figure
fig
skew.ax.axvline(0 * units.degC, color='tab:cyan', linestyle='--')
# Check out skew.ax.axhline for lines of constant pressure!
# Useful for denoting important levels

fig
skew.ax.set_ylim(1050,100)
skew.ax.set_xlim(-50,20)

fig

as well as a few unique methods that MetPy provides to make a great Skew-T.

skew.plot_dry_adiabats()

fig
dir(skew)

(try the Tab key!)


Calculate a new quantity#

mpcalc.parcel_profile?
sounding['profile'] = mpcalc.parcel_profile(sounding['pressure'],
                                            sounding['temperature'][0],
                                            sounding['dewpoint'][0])
skew.plot(sounding['pressure'], sounding['profile'], color='black')

fig

Visualizing CAPE#

skew.shade_cape(sounding['pressure'], sounding['temperature'], sounding['profile'])

fig
Reminder, here is the MetPy SkewT documentation!

EXERCISE: Working with our existing SkewT
  1. Plot the dewpoint quantity from our sounding
  2. Plot moist adiabats and mixing ratio lines in the background using sensible defaults.
  3. Our profile got awfully cut off! Alter our plot x-limits to something more sensible.
  4. Shade any CIN present in our profile.

BONUS:
  • Use the u_wind and v_wind quantities within our sounding to plot_barbs along our Skew-T.
  • You have everything you need to perform some brand new calculations! Pick out some sounding calculations from the documentation and share your results. Put some numbers to your shaded CAPE and CIN or calculate valuable levels like LCL or EL and plot lines on our Skew-T to highlight them.
  • Finally, create a brand new Skew-T from a brand new date and time, or even a new station from a station ID as shown here.