Static Stability#

Use metpy.calc.static_stability as well as pint’s unit support to perform calculations.

The code below uses example data from our test suite to calculate the static stability for each layer of the provided sounding data.

import pandas as pd

from metpy.calc import static_stability
from metpy.cbook import get_test_data
from metpy.constants import Rd
from metpy.units import units

Upper air data can be obtained using the siphon package, but for this example we will use some of MetPy’s sample data.

# Set column names
col_names = ['pressure', 'height', 'temperature', 'dewpoint', 'direction', 'speed']

# Read in test data using col_names
df = pd.read_fwf(get_test_data('jan20_sounding.txt', as_file_obj=False),
                 skiprows=5, usecols=[0, 1, 2, 3, 6, 7], names=col_names)

Drop any rows with all NaN values for T, Td, winds

df = df.dropna(subset=('temperature', 'dewpoint', 'direction', 'speed'
                       ), how='all').reset_index(drop=True)

Isolate pressure and temperature and add units

p = df['pressure'].values * units.hPa
T = df['temperature'].values * units.degC

Calculate the static stability and convert to K/Pa units

print((static_stability(p, T) * (p / Rd)).to('K/Pa'))
[-4.41283219227208e-05 -2.4492777247121155e-05 9.116458268710324e-05 8.845234936113418e-05 6.224860528096752e-05 0.00015314927360383487 0.00019881695313443988 0.00030101997736649576 0.00026111189622417404 0.001085062948164048 0.003740321802149091 0.004248281970347817 0.0036657831964964018 0.0016752453464420483 0.0007380480366923099 0.00019231433878668947 0.0002557493550907393 0.00024017381030490135 0.0010992754328914723 0.000915641843948739 0.00025827670773766095 0.0008820697439592232 0.0003589161178615257 0.0004817507957698896 0.0006973708206233451 0.0006126559385666097 0.00047078968526674726 0.0004870196826060473 0.0004875042540964733 0.0004723683427336631 0.00018331961002751509 0.00014636894085019007 0.00013915628085254793 -0.0015920843524442835 -0.0015653462261827026 9.863194193151853e-05 0.0001579458273752061 0.00041106154962424813 0.00039799924225680105 0.0006038463463312496 0.0032368837310525183 0.004009490876985825 0.0037125198804787668 0.0023375347706963796 0.001366027873753104 0.0012474317985632058 0.0014544559226790695 0.0024234211184320383 0.0033852295736065785 0.00393333469570616 0.0024998389621420955 0.0026161133002877935 0.0025584158650765487 0.0061453098584766585 0.006346575700474026 0.003115891778520376 0.0028392731739860125 0.0018886781873633822 0.0023835929582128146 0.0013562543705426307 0.0011897088702191683 0.004713351681793958 0.0032926213870648154 0.002904873402537745 0.005189222385428262 0.005480289289528526 0.0014028667954945192 0.005193086215585504 0.005625967270339566 0.005397711905806318 0.01000895177150228 0.011789360222267875 0.0027175297861060685] kelvin / pascal

Total running time of the script: (0 minutes 0.008 seconds)

Gallery generated by Sphinx-Gallery