{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Skew-T plot of a sounding\n\nThis example shows how to make a Skew-T plot from a sounding\nand calculate stability indicies.\n\nAuthor: Maxwell Grover\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport xarray as xr\nfrom arm_test_data import DATASETS\nfrom matplotlib import pyplot as plt\n\nimport act\n\n# Make sure attributes are retained\nxr.set_options(keep_attrs=True)\n\n# Read data\nfilename_sonde = DATASETS.fetch('twpsondewnpnC3.b1.20060121.231600.custom.cdf')\nsonde_ds = act.io.arm.read_arm_netcdf(filename_sonde)\n\n\n# Calculate stability indicies\nsonde_ds = act.retrievals.calculate_stability_indicies(\n sonde_ds, temp_name='tdry', td_name='dp', p_name='pres'\n)\n\n# Plot the stability index values on the plot\nvariables = [\n 'lifted_index',\n 'surface_based_cape',\n 'surface_based_cin',\n 'most_unstable_cape',\n 'most_unstable_cin',\n 'lifted_condensation_level_temperature',\n 'lifted_condensation_level_pressure',\n]\n\n\n# Add a helper function which will format the text\ndef format_variable(variable, rounding_digits=2):\n \"\"\"Format a sounding variable to displayed on a single line\"\"\"\n return f'{variable}: {np.round(sonde_ds[variable], rounding_digits).values} {sonde_ds[variable].units}'\n\n\n# Setup the plot\nskewt = act.plotting.SkewTDisplay(sonde_ds, figsize=(12, 8))\n\n# Add the stability indices\nax = skewt.axes[0]\nprops = dict(boxstyle='round', facecolor='wheat', alpha=0.5)\nfor i in range(len(variables)):\n ax.text(\n 0.05,\n (0.98 - (0.05 * i)),\n format_variable(variables[i]),\n transform=ax.transAxes,\n fontsize=10,\n verticalalignment='top',\n bbox=props,\n )\n\n# Add data\nskewt.plot_from_u_and_v('u_wind', 'v_wind', 'pres', 'tdry', 'dp', shade_cin=False)\n\nsonde_ds.close()\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }