{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Wyoming Upper Air Data Request\n", "==============================\n", "\n", "This example shows how to use siphon's `simplewebswervice` support to create a query to\n", "the Wyoming upper air archive.\n", "\n", "The notebook is adopted from Unidata example: https://unidata.github.io/siphon/latest/examples/upperair/Wyoming_Request.html. \n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime\n", "\n", "from metpy.units import units\n", "\n", "from siphon.simplewebservice.wyoming import WyomingUpperAir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a datetime object for the sounding and string of the station identifier.\n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "date = datetime(1999, 5, 3, 12)\n", "station = 'OUN'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the request (a pandas dataframe is returned).\n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "df = WyomingUpperAir.request_data(date, station)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Inspect data columns in the dataframe.\n", "\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['pressure', 'height', 'temperature', 'dewpoint', 'direction', 'speed',\n", " 'u_wind', 'v_wind', 'station', 'station_number', 'time', 'latitude',\n", " 'longitude', 'elevation', 'pw'],\n", " dtype='object')\n" ] } ], "source": [ "print(df.columns)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pull out a specific column of data.\n", "\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0 16.9\n", "1 15.9\n", "2 15.5\n", "3 14.2\n", "4 12.1\n", " ... \n", "71 -71.1\n", "72 -71.7\n", "73 -72.2\n", "74 -72.5\n", "75 -71.7\n", "Name: dewpoint, Length: 76, dtype: float64\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
pressureheighttemperaturedewpointdirectionspeedu_windv_windstationstation_numbertimelatitudelongitudeelevationpw
0966.034518.216.9180.015.0-1.836970e-1515.000000OUN723571999-05-03 12:00:0035.18-97.44345.020.54
1937.261016.815.9190.027.04.688501e+0026.589809OUN723571999-05-03 12:00:0035.18-97.44345.020.54
2925.072516.215.5195.031.08.023390e+0029.943701OUN723571999-05-03 12:00:0035.18-97.44345.020.54
3904.691415.114.2205.034.01.436902e+0130.814465OUN723571999-05-03 12:00:0035.18-97.44345.020.54
4872.6121913.312.1210.038.01.900000e+0132.908965OUN723571999-05-03 12:00:0035.18-97.44345.020.54
................................................
7111.330112-41.1-71.1157.03.0-1.172193e+002.761515OUN723571999-05-03 12:00:0035.18-97.44345.020.54
7210.730480-41.7-71.7170.01.0-1.736482e-010.984808OUN723571999-05-03 12:00:0035.18-97.44345.020.54
7310.230785-42.2-72.2310.04.03.064178e+00-2.571150OUN723571999-05-03 12:00:0035.18-97.44345.020.54
7410.030940-42.5-72.5NaNNaNNaNNaNOUN723571999-05-03 12:00:0035.18-97.44345.020.54
759.931008-42.7-71.7NaNNaNNaNNaNOUN723571999-05-03 12:00:0035.18-97.44345.020.54
\n", "

76 rows × 15 columns

\n", "
" ], "text/plain": [ " pressure height temperature dewpoint direction speed u_wind \\\n", "0 966.0 345 18.2 16.9 180.0 15.0 -1.836970e-15 \n", "1 937.2 610 16.8 15.9 190.0 27.0 4.688501e+00 \n", "2 925.0 725 16.2 15.5 195.0 31.0 8.023390e+00 \n", "3 904.6 914 15.1 14.2 205.0 34.0 1.436902e+01 \n", "4 872.6 1219 13.3 12.1 210.0 38.0 1.900000e+01 \n", ".. ... ... ... ... ... ... ... \n", "71 11.3 30112 -41.1 -71.1 157.0 3.0 -1.172193e+00 \n", "72 10.7 30480 -41.7 -71.7 170.0 1.0 -1.736482e-01 \n", "73 10.2 30785 -42.2 -72.2 310.0 4.0 3.064178e+00 \n", "74 10.0 30940 -42.5 -72.5 NaN NaN NaN \n", "75 9.9 31008 -42.7 -71.7 NaN NaN NaN \n", "\n", " v_wind station station_number time latitude \\\n", "0 15.000000 OUN 72357 1999-05-03 12:00:00 35.18 \n", "1 26.589809 OUN 72357 1999-05-03 12:00:00 35.18 \n", "2 29.943701 OUN 72357 1999-05-03 12:00:00 35.18 \n", "3 30.814465 OUN 72357 1999-05-03 12:00:00 35.18 \n", "4 32.908965 OUN 72357 1999-05-03 12:00:00 35.18 \n", ".. ... ... ... ... ... \n", "71 2.761515 OUN 72357 1999-05-03 12:00:00 35.18 \n", "72 0.984808 OUN 72357 1999-05-03 12:00:00 35.18 \n", "73 -2.571150 OUN 72357 1999-05-03 12:00:00 35.18 \n", "74 NaN OUN 72357 1999-05-03 12:00:00 35.18 \n", "75 NaN OUN 72357 1999-05-03 12:00:00 35.18 \n", "\n", " longitude elevation pw \n", "0 -97.44 345.0 20.54 \n", "1 -97.44 345.0 20.54 \n", "2 -97.44 345.0 20.54 \n", "3 -97.44 345.0 20.54 \n", "4 -97.44 345.0 20.54 \n", ".. ... ... ... \n", "71 -97.44 345.0 20.54 \n", "72 -97.44 345.0 20.54 \n", "73 -97.44 345.0 20.54 \n", "74 -97.44 345.0 20.54 \n", "75 -97.44 345.0 20.54 \n", "\n", "[76 rows x 15 columns]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(df['dewpoint'])\n", "df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Units are stored in a dictionary with the variable name as the key in the `units` attribute\n", "of the dataframe.\n", "\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'pressure': 'hPa', 'height': 'meter', 'temperature': 'degC', 'dewpoint': 'degC', 'direction': 'degrees', 'speed': 'knot', 'u_wind': 'knot', 'v_wind': 'knot', 'station': None, 'station_number': None, 'time': None, 'latitude': 'degrees', 'longitude': 'degrees', 'elevation': 'meter', 'pw': 'millimeter'}\n" ] } ], "source": [ "print(df.units)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hPa\n" ] } ], "source": [ "print(df.units['pressure'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Units can then be attached to the values from the dataframe.\n", "\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[16.9 15.9 15.5 14.2 12.1 10.8 8.6 0.0 -3.6 -4.4 -6.9 -9.5 -12.0 -14.6 -15.8 -16.4 -16.9 -17.1 -27.9 -42.7 -44.1 -45.6 -46.3 -45.5 -47.1 -52.1 -50.4 -47.3 -57.1 -57.9 -58.1 -60.9 -61.4 -62.1 -65.1 -65.6 -66.7 -70.5 -72.3 -72.7 -72.6 -72.5 -78.0 -78.3 -81.1 -83.3 -85.4 -88.1 -85.7 -83.7 -84.7 -85.7 -85.3 -87.0 -87.9 -87.5 -86.1 -86.1 -85.8 -84.9 -82.6 -81.3 -81.3 -81.3 -78.1 -77.1 -77.6 -77.7 -77.7 -77.4 -76.5 -71.1 -71.7 -72.2 -72.5 -71.7] degree_Celsius\n" ] } ], "source": [ "pressure = df['pressure'].values * units(df.units['pressure'])\n", "temperature = df['temperature'].values * units(df.units['temperature'])\n", "dewpoint = df['dewpoint'].values * units(df.units['dewpoint'])\n", "u_wind = df['u_wind'].values * units(df.units['u_wind'])\n", "v_wind = df['v_wind'].values * units(df.units['v_wind'])\n", "print( dewpoint )" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Magnitude
[966.0 937.2 925.0 904.6 872.6 853.0 850.0 836.0 821.0 811.6 782.3 754.2
726.9 700.0 648.9 624.6 601.1 595.0 587.0 576.0 555.7 534.2 524.0 500.0
473.3 400.0 384.5 358.0 343.0 308.3 300.0 276.0 273.0 268.5 250.0 244.2
233.0 200.0 191.8 190.0 174.2 168.0 151.0 150.0 144.0 130.6 118.4 105.0
102.2 100.0 97.3 94.7 80.6 76.0 73.7 70.0 61.8 50.0 48.6 44.1 34.6 30.0
29.9 26.4 21.4 20.0 16.9 16.2 16.1 15.4 13.7 11.3 10.7 10.2 10.0 9.9]
Unitshectopascal
" ], "text/latex": [ "$\\begin{pmatrix}966.0 & 937.2 & 925.0 & 904.6 & 872.6 & 853.0 & 850.0 & 836.0 & 821.0 & 811.6 & 782.3 & 754.2 & 726.9 & 700.0 & 648.9 & 624.6 & 601.1 & 595.0 & 587.0 & 576.0 & 555.7 & 534.2 & 524.0 & 500.0 & 473.3 & 400.0 & 384.5 & 358.0 & 343.0 & 308.3 & 300.0 & 276.0 & 273.0 & 268.5 & 250.0 & 244.2 & 233.0 & 200.0 & 191.8 & 190.0 & 174.2 & 168.0 & 151.0 & 150.0 & 144.0 & 130.6 & 118.4 & 105.0 & 102.2 & 100.0 & 97.3 & 94.7 & 80.6 & 76.0 & 73.7 & 70.0 & 61.8 & 50.0 & 48.6 & 44.1 & 34.6 & 30.0 & 29.9 & 26.4 & 21.4 & 20.0 & 16.9 & 16.2 & 16.1 & 15.4 & 13.7 & 11.3 & 10.7 & 10.2 & 10.0 & 9.9\\end{pmatrix}\\ \\mathrm{hectopascal}$" ], "text/plain": [ "array([966. , 937.2, 925. , 904.6, 872.6, 853. , 850. , 836. , 821. ,\n", " 811.6, 782.3, 754.2, 726.9, 700. , 648.9, 624.6, 601.1, 595. ,\n", " 587. , 576. , 555.7, 534.2, 524. , 500. , 473.3, 400. , 384.5,\n", " 358. , 343. , 308.3, 300. , 276. , 273. , 268.5, 250. , 244.2,\n", " 233. , 200. , 191.8, 190. , 174.2, 168. , 151. , 150. , 144. ,\n", " 130.6, 118.4, 105. , 102.2, 100. , 97.3, 94.7, 80.6, 76. ,\n", " 73.7, 70. , 61.8, 50. , 48.6, 44.1, 34.6, 30. , 29.9,\n", " 26.4, 21.4, 20. , 16.9, 16.2, 16.1, 15.4, 13.7, 11.3,\n", " 10.7, 10.2, 10. , 9.9]) " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pressure" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Magnitude
[18.2 16.8 16.2 15.1 13.3 12.2 12.4 14.0 14.4 13.7 11.4 9.1 6.8 4.4 -1.4
-4.4 -7.3 -8.1 -7.9 -7.7 -8.7 -9.8 -10.3 -13.5 -17.1 -28.1 -30.7 -35.3
-37.1 -43.5 -45.1 -49.9 -50.4 -51.1 -54.1 -55.0 -56.7 -57.5 -59.3 -59.7
-55.3 -53.5 -54.2 -54.3 -56.1 -59.2 -62.3 -66.1 -62.6 -59.7 -60.7 -61.7
-62.3 -64.7 -65.9 -64.5 -62.1 -62.1 -61.8 -60.7 -57.9 -56.3 -56.3 -56.3
-51.6 -50.1 -50.6 -50.7 -50.7 -50.1 -48.5 -41.1 -41.7 -42.2 -42.5 -42.7]
Unitsdegree_Celsius
" ], "text/latex": [ "$\\begin{pmatrix}18.2 & 16.8 & 16.2 & 15.1 & 13.3 & 12.2 & 12.4 & 14.0 & 14.4 & 13.7 & 11.4 & 9.1 & 6.8 & 4.4 & -1.4 & -4.4 & -7.3 & -8.1 & -7.9 & -7.7 & -8.7 & -9.8 & -10.3 & -13.5 & -17.1 & -28.1 & -30.7 & -35.3 & -37.1 & -43.5 & -45.1 & -49.9 & -50.4 & -51.1 & -54.1 & -55.0 & -56.7 & -57.5 & -59.3 & -59.7 & -55.3 & -53.5 & -54.2 & -54.3 & -56.1 & -59.2 & -62.3 & -66.1 & -62.6 & -59.7 & -60.7 & -61.7 & -62.3 & -64.7 & -65.9 & -64.5 & -62.1 & -62.1 & -61.8 & -60.7 & -57.9 & -56.3 & -56.3 & -56.3 & -51.6 & -50.1 & -50.6 & -50.7 & -50.7 & -50.1 & -48.5 & -41.1 & -41.7 & -42.2 & -42.5 & -42.7\\end{pmatrix}\\ \\mathrm{degree\\_Celsius}$" ], "text/plain": [ "array([ 18.2, 16.8, 16.2, 15.1, 13.3, 12.2, 12.4, 14. , 14.4,\n", " 13.7, 11.4, 9.1, 6.8, 4.4, -1.4, -4.4, -7.3, -8.1,\n", " -7.9, -7.7, -8.7, -9.8, -10.3, -13.5, -17.1, -28.1, -30.7,\n", " -35.3, -37.1, -43.5, -45.1, -49.9, -50.4, -51.1, -54.1, -55. ,\n", " -56.7, -57.5, -59.3, -59.7, -55.3, -53.5, -54.2, -54.3, -56.1,\n", " -59.2, -62.3, -66.1, -62.6, -59.7, -60.7, -61.7, -62.3, -64.7,\n", " -65.9, -64.5, -62.1, -62.1, -61.8, -60.7, -57.9, -56.3, -56.3,\n", " -56.3, -51.6, -50.1, -50.6, -50.7, -50.7, -50.1, -48.5, -41.1,\n", " -41.7, -42.2, -42.5, -42.7]) " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "temperature" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import metpy.calc as mpcalc\n", "#print( pressure, temperature, dewpoint )\n", "# Calculate the LCL\n", "lcl_pressure, lcl_temperature = mpcalc.lcl(pressure[0], temperature[0], dewpoint[0])\n", "\n", "# Calculate the LFC\n", "lfc_pressure, lfc_temperature = mpcalc.lfc(pressure, temperature, dewpoint)\n", "\n", "# Calculate the EL\n", "el_pressure, el_temperature = mpcalc.el(pressure, temperature, dewpoint)\n", "\n", "print(lcl_pressure, lcl_temperature)\n", "print(lfc_pressure, lfc_temperature)\n", "print(el_pressure, el_temperature)\n", "lcl_pressure\n", "pressure[0].shape" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "947.5117804436877 hectopascal 16.595809056878068 degree_Celsius\n", "705.3534496823725 hectopascal 4.884899017330216 degree_Celsius\n", "228.15152422388618 hectopascal -56.81015356597061 degree_Celsius\n" ] }, { "data": { "text/plain": [ "()" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1169.354878115879 joule / kilogram -8.162215033975814 joule / kilogram\n" ] } ], "source": [ "parcel_profile = mpcalc.parcel_profile(pressure, temperature[0], dewpoint[0])\n", "\n", "cape, cin = mpcalc.cape_cin(pressure, temperature, dewpoint, parcel_profile, which_lfc='bottom', which_el='top')\n", "print( cape, cin)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.7.11" } }, "nbformat": 4, "nbformat_minor": 1 }