{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Skew-T's\n",
"## Requesting Upper Air Data from Siphon and Plotting a Skew-T with MetPy\n",
"### Based on Unidata's MetPy Monday \\# 15 -17 YouTube links:
https://www.youtube.com/watch?v=OUTBiXEuDIU;
https://www.youtube.com/watch?v=oog6_b-844Q;
https://www.youtube.com/watch?v=b0RsN9mCY5k"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import the libraries we need"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from mpl_toolkits.axes_grid1.inset_locator import inset_axes\n",
"import metpy.calc as mpcalc\n",
"from metpy.plots import Hodograph, SkewT\n",
"from metpy.units import units, pandas_dataframe_to_unit_arrays\n",
"from datetime import datetime, timedelta\n",
"import pandas as pd\n",
"from siphon.simplewebservice.wyoming import WyomingUpperAir"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Next we use methods from the datetime library to determine the latest time, and then use it to select the most recent date and time that we'll use for our selected Skew-T."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"now = datetime.utcnow()\n",
"\n",
"curr_year = now.year\n",
"curr_month = now.month\n",
"curr_day = now.day\n",
"curr_hour = now.hour\n",
"\n",
"print(f\"Current time is: {now}\")\n",
"print(f\"Current year, month, date, hour: {curr_year}, {curr_month}, {curr_day}, {curr_hour}\")\n",
"\n",
"if (curr_hour > 13) :\n",
" raob_hour = 12\n",
" hr_delta = curr_hour - 12\n",
"elif (curr_hour > 1):\n",
" raob_hour = 0\n",
" hr_delta = curr_hour - 0\n",
"else:\n",
" raob_hour = 12\n",
" hr_delta = curr_hour + 12\n",
"\n",
"raob_time = now - timedelta(hours=hr_delta)\n",
"\n",
"raob_year = raob_time.year\n",
"raob_month = raob_time.month\n",
"raob_day = raob_time.day\n",
"raob_hour = raob_time.hour\n",
"\n",
"print(f\"Time of RAOB is: {raob_year}, {raob_month}, {raob_day}, {raob_hour}\")\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Construct a datetime object that we will use in our query to the data server. Note what it looks like."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"query_date = datetime(raob_year,raob_month,raob_day,raob_hour)\n",
"query_date"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### If desired, we can choose a past date and time."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#current = True\n",
"current = False"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"if (current == False):\n",
" query_date = datetime(2012, 10, 29, 12)\n",
" \n",
"raob_timeStr = query_date.strftime(\"%Y-%m-%d %H UTC\")\n",
"raob_timeTitle = query_date.strftime(\"%H00 UTC %-d %b %Y\")\n",
"print(raob_timeStr)\n",
"print(raob_timeTitle)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Select our station and query the data server."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"station = 'ALB'\n",
"\n",
"df = WyomingUpperAir.request_data (query_date,station)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Possible data retrieval errors:
\n", "No data available for YYYY-MM-DD HHZ for station XXX
, you may have specified an incorrect date or location, or there just might not have been a successful RAOB at that date and time.503 Server Error
, try requesting the sounding again. The Wyoming server does not handle simultaneous requests well. Usually the request will eventually work. Note:
\n", " Annoyingly, when specifying the color of the dry/moist adiabats, and mixing ratio lines, the parameter must be colors, not color. In other Matplotlib-related code lines in the cell below where we set the color, such asskew.ax.axvline
, color must be singular.\n",
"What's next:
\n", " Try different RAOB locations and dates (for example, draw a skew-t relevant to your class project).