python-awips/examples/notebooks/METAR_Station_Plot_with_MetPy.ipynb

529 lines
360 KiB
Text
Raw Normal View History

2018-10-04 17:25:20 -06:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Python-AWIPS Tutorial Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"\n",
"# Objectives\n",
"\n",
"* Use python-awips to connect to an edex server\n",
"* Define and filter data request for METAR surface obs\n",
"* Extract necessary data and reformat it for plotting\n",
"* Stylize and plot METAR station data using Cartopy, Matplotlib, and MetPy\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of Contents\n",
"\n",
2022-06-02 18:45:49 -04:00
"[1 Imports](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#imports)<br> \n",
"[2 Function: get_cloud_cover()](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#function-get-cloud-cover)<br> \n",
"[3 Initial Setup](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#initial-setup)<br> \n",
"&nbsp;&nbsp;&nbsp;&nbsp;[3.1 Initial EDEX Connection](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#initial-edex-connection)<br> \n",
2022-06-03 16:08:15 -04:00
"&nbsp;&nbsp;&nbsp;&nbsp;[3.2 Setting Connection Location Names](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#setting-connection-location-names)<br> \n",
2022-06-02 18:45:49 -04:00
"[4 Filter by Time](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#filter-by-time)<br> \n",
"[5 Use the Data!](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#use-the-data)<br> \n",
"&nbsp;&nbsp;&nbsp;&nbsp;[5.1 Get the Data!](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#get-the-data)<br> \n",
"&nbsp;&nbsp;&nbsp;&nbsp;[5.2 Extract all Parameters](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#extract-all-parameters)<br> \n",
"&nbsp;&nbsp;&nbsp;&nbsp;[5.3 Populate the Data Dictionary](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#populate-the-data-dictionary)<br> \n",
"[6 Plot the Data!](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#plot-the-data)<br> \n",
"[7 See Also](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#see-also)<br> \n",
"&nbsp;&nbsp;&nbsp;&nbsp;[7.1 Related Notebooks](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#related-notebooks)<br> \n",
"&nbsp;&nbsp;&nbsp;&nbsp;[7.2 Additional Documentation](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html#additional-documentation)<br> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1 Imports\n",
"\n",
"The imports below are used throughout the notebook. Note the first two imports are coming directly from python-awips and allow us to connect to an EDEX server, and define a timrange used for filtering the data. The subsequent imports are for data manipulation and visualization. "
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "code",
"execution_count": 10,
2018-10-04 17:25:20 -06:00
"metadata": {},
"outputs": [],
"source": [
"from awips.dataaccess import DataAccessLayer\n",
"from dynamicserialize.dstypes.com.raytheon.uf.common.time import TimeRange\n",
"from datetime import datetime, timedelta\n",
"import numpy as np\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"import matplotlib.pyplot as plt\n",
"from metpy.calc import wind_components\n",
"from metpy.plots import StationPlot, StationPlotLayout, sky_cover\n",
"from metpy.units import units"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2 Function: get_cloud_cover()\n",
2018-10-04 17:25:20 -06:00
"\n",
"Returns the cloud fraction values as integer codes (0 through 8)."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
2018-10-04 17:25:20 -06:00
"def get_cloud_cover(code):\n",
" if 'OVC' in code:\n",
" return 8\n",
2018-10-04 17:25:20 -06:00
" elif 'BKN' in code:\n",
" return 6\n",
2018-10-04 17:25:20 -06:00
" elif 'SCT' in code:\n",
" return 4\n",
2018-10-04 17:25:20 -06:00
" elif 'FEW' in code:\n",
" return 2\n",
2018-10-04 17:25:20 -06:00
" else:\n",
" return 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3 Initial Setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.1 Initial EDEX Connection\n",
"\n",
"First we establish a connection to Unidata's public EDEX server. With that connection made, we can create a [new data request object](http://unidata.github.io/python-awips/api/IDataRequest.html) and set the data type to ***obs***.\n",
"\n",
"Then, because we're going to uses MetPy's [StationPlot](https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.StationPlot.html) and [StationPlotLayout](https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.StationPlotLayout.html) we need to define several parameters, and then set them on the data request object."
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "code",
"execution_count": 12,
2018-10-04 17:25:20 -06:00
"metadata": {},
"outputs": [],
"source": [
"# EDEX Request\n",
"edexServer = \"edex-cloud.unidata.ucar.edu\"\n",
"DataAccessLayer.changeEDEXHost(edexServer)\n",
"request = DataAccessLayer.newDataRequest(\"obs\")\n",
"\n",
"# define desired parameters\n",
2018-10-04 17:25:20 -06:00
"single_value_params = [\"timeObs\", \"stationName\", \"longitude\", \"latitude\", \n",
" \"temperature\", \"dewpoint\", \"windDir\",\n",
" \"windSpeed\"]\n",
"multi_value_params = [\"skyCover\"]\n",
"\n",
2018-10-04 17:25:20 -06:00
"params = single_value_params + multi_value_params\n",
"\n",
"# set all parameters on the request\n",
"request.setParameters(*(params))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3.2 Setting Connection Location Names\n",
"\n",
"We are also going to define specific station IDs so that our plot is not too cluttered. "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Define a list of station IDs to plot\n",
"selected = ['KPDX', 'KOKC', 'KICT', 'KGLD', 'KMEM', 'KBOS', 'KMIA', 'KMOB', 'KABQ', 'KPHX', 'KTTF',\n",
" 'KORD', 'KBIL', 'KBIS', 'KCPR', 'KLAX', 'KATL', 'KMSP', 'KSLC', 'KDFW', 'KNYC', 'KPHL',\n",
" 'KPIT', 'KIND', 'KOLY', 'KSYR', 'KLEX', 'KCHS', 'KTLH', 'KHOU', 'KGJT', 'KLBB', 'KLSV',\n",
" 'KGRB', 'KCLT', 'KLNK', 'KDSM', 'KBOI', 'KFSD', 'KRAP', 'KRIC', 'KJAN', 'KHSV', 'KCRW',\n",
" 'KSAT', 'KBUY', 'K0CO', 'KZPC', 'KVIH', 'KBDG', 'KMLF', 'KELY', 'KWMC', 'KOTH', 'KCAR',\n",
" 'KLMT', 'KRDM', 'KPDT', 'KSEA', 'KUIL', 'KEPH', 'KPUW', 'KCOE', 'KMLP', 'KPIH', 'KIDA', \n",
" 'KMSO', 'KACV', 'KHLN', 'KBIL', 'KOLF', 'KRUT', 'KPSM', 'KJAX', 'KTPA', 'KSHV', 'KMSY',\n",
" 'KELP', 'KRNO', 'KFAT', 'KSFO', 'KNYL', 'KBRO', 'KMRF', 'KDRT', 'KFAR', 'KBDE', 'KDLH',\n",
" 'KHOT', 'KLBF', 'KFLG', 'KCLE', 'KUNV']\n",
"\n",
"# set the location names to the desired station IDs \n",
2018-10-04 17:25:20 -06:00
"request.setLocationNames(*(selected))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4 Filter by Time\n",
"\n",
"Here we decide how much data we want to pull from EDEX. By default we'll request 1 hour, but that value can easily be modified by [adjusting the `timedelta(hours = 1)`](https://docs.python.org/3/library/datetime.html#timedelta-objects) in line `2`. The more data we request, the longer this section will take to run."
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "code",
"execution_count": 14,
2018-10-04 17:25:20 -06:00
"metadata": {},
"outputs": [],
"source": [
"# Time range\n",
"lastHourDateTime = datetime.utcnow() - timedelta(hours = 1)\n",
"start = lastHourDateTime.strftime('%Y-%m-%d %H')\n",
"beginRange = datetime.strptime( start + \":00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"endRange = datetime.strptime( start + \":59:59\", \"%Y-%m-%d %H:%M:%S\")\n",
"timerange = TimeRange(beginRange, endRange)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
2018-10-04 17:25:20 -06:00
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5 Use the Data!\n",
"### 5.1 Get the Data!\n",
"\n",
"Now that we have our `request` and TimeRange `timerange` objects ready, we're ready to get the data array from EDEX."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# Get response\n",
2018-10-04 17:25:20 -06:00
"response = DataAccessLayer.getGeometryData(request,timerange)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5.2 Extract all Parameters\n",
"\n",
"In this section we start gathering all the information we'll need to properly display our data. First we create an empty dictionary and array to keep track of all data and unique station IDs. We also create a boolean to help us only grab the first entry for `skyCover` related to a station id.\n",
"\n",
"<br>\n",
"<div class=\"alert-info\">\n",
" <b>Note:</b> The way the data responses are returned, we recieve many <code>skyCover</code> entries for each station ID, but we only want to keep track of the most recent one (first one returned).\n",
"</div>\n",
"\n",
"After defining these variables, we are ready to start looping through our response data. If the response is an entry of `skyCover`, and this is a new station id, then set the skyCover value in the obs dictionary. If this is not a skyCover entry, then explicitly set the `timeObs` variable (because we have to manipulate it slightly), and dynamically set all the remaining parameters."
]
},
2018-10-04 17:25:20 -06:00
{
"cell_type": "code",
"execution_count": 16,
2018-10-04 17:25:20 -06:00
"metadata": {},
"outputs": [],
"source": [
"# define a dictionary and array that will be populated from our for loop below\n",
"obs = dict({params: [] for params in params})\n",
2018-10-04 17:25:20 -06:00
"station_names = []\n",
"\n",
"# only grab the first skyCover record related to a station \n",
"new_station_id = True\n",
"# cycle through all the data in the response\n",
2018-10-04 17:25:20 -06:00
"for ob in response:\n",
" avail_params = ob.getParameters()\n",
" # if it has cloud information and is the first entry for this station id\n",
" if \"skyCover\" in avail_params and new_station_id:\n",
" # store the associated cloud cover int for the skyCover string\n",
" obs['skyCover'].append(get_cloud_cover(ob.getString(\"skyCover\")))\n",
" new_station_id = False\n",
" elif \"stationName\" in avail_params:\n",
" new_station_id=True\n",
2018-10-04 17:25:20 -06:00
" # If we already have a record for this stationName, skip\n",
" if ob.getString('stationName') not in station_names:\n",
" station_names.append(ob.getString('stationName'))\n",
" for param in single_value_params: \n",
" if param in avail_params:\n",
" if param == 'timeObs':\n",
" obs[param].append(datetime.fromtimestamp(ob.getNumber(param)/1000.0))\n",
" else:\n",
" try:\n",
" obs[param].append(ob.getNumber(param))\n",
" except TypeError:\n",
" obs[param].append(ob.getString(param))\n",
" else:\n",
" obs[param].append(None)"
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5.3 Populate the Data Dictionary\n",
2018-10-04 17:25:20 -06:00
"\n",
"Next grab the variables out of the obs dictionary we just populated, attach correct units, (calculate their components, in the instance of wind) and put them into a new dictionary that we will hand the plotting function later."
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "code",
"execution_count": 17,
2018-10-04 17:25:20 -06:00
"metadata": {},
"outputs": [],
"source": [
"data = dict()\n",
"data['stid'] = np.array(obs['stationName'])\n",
"data['latitude'] = np.array(obs['latitude'])\n",
"data['longitude'] = np.array(obs['longitude'])\n",
"data['air_temperature'] = np.array(obs['temperature'], dtype=float)* units.degC\n",
"data['dew_point_temperature'] = np.array(obs['dewpoint'], dtype=float)* units.degC\n",
"\n",
"direction = np.array(obs['windDir'])\n",
"direction[direction == -9999.0] = 'nan'\n",
"\n",
"u, v = wind_components(np.array(obs['windSpeed']) * units('knots'),\n",
" direction * units.degree)\n",
"data['eastward_wind'], data['northward_wind'] = u, v\n",
"data['cloud_coverage'] = np.array(obs['skyCover'])"
2018-10-04 17:25:20 -06:00
]
},
2018-10-05 17:09:43 -06:00
{
"cell_type": "markdown",
2018-10-05 17:09:43 -06:00
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
"\n",
"---"
2018-10-05 17:09:43 -06:00
]
},
2018-10-04 17:25:20 -06:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6 Plot the Data!\n",
"\n",
"Now we have all the data we need to create our plot! First we'll assign a projection and create our figure and axes.\n",
"\n",
"Next, we use Cartopy to add common features (land, ocean, lakes, borders, etc) to help give us a more contextual map of the United States to plot the METAR stations on. We create and add a title for our figure as well.\n",
"\n",
"Additionally, we use [MetPy's StationPlotLayout](https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.StationPlotLayout.html) to instantiate a custom layout and define all the attributes we want displayed. We need to then set the data dictionary (containing all of our data values) on the custom layout so it knows what to draw.\n",
"\n",
"Finally, we display the plot!"
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "code",
"execution_count": 18,
2018-10-04 17:25:20 -06:00
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA2UA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xQwA3iysPCK7yHqbHnE3vCculbEvkiSlIluGmiJvIBRc43uF3qs/I1v6rJAt0KXhDSTfYEm+BPiU4TpvdS0VoXBsZTbXNwjKPK8QwkYI8YvJnS8d2A04iZLjJxFCvCmEOCtkt8lU5LjLkjZmSsOPEu65yUq9w2TJTgPGFTNHTAnjBiDHgBa8J84iuzx7It8Pcz+T50FSBWRXUFC4x1GUMgWF+xCT2+E85EXDo5Ik6QqdPg20KNTWFqhLITc/IcRY4B2gtyRJRRQRIYQlsvtSHPIOshlJkppIRRM8nAbqCFPMl4kWheYKAYpVmiQ541vBWAWueTfKXgd5V/18oWPTgAFAX0mS0osbuyxIkpQsSdJTkiTVMs2vAg6XZwiuuz+2QLasnDft1G8C4pFd226cN8V0rrD7Y+F7dhpobnqNC2jO7blpIklSNrLr13hKVsoqwrPI9+GkEOIKcMh0/KbMmCbl/21kpe3hCs4XA3x2g/JoI0nS38j31eeGe+dfxr4F7rpjkRX0WYXk/rzQe3UccA3IRf5clcZlwOWGz4c/8mcLZJc7m0LnahX6/1bXciOljVUebjXvm8hWrg6SJDkA3U3HC9oX+bybNm/eRnaddDYp52mF2t9IadcRQ8n3fDGwBvCTJMkR2ZJ+4xwlbeDEAANueF9YSZIUh3w//Apdjw2yC2NZ5FVQULiPUJQyBYX7kznIsRFDinHFWQk0FUI8aorb+BA5RikMQAjxFPA58KAkSZGFO5rcIZchW5CekSSpVDcdSZLOI8d0fCSEsBJCPIKsQCwvJIuzEOJZIYRaCDEc2Uqwr4QhFwFDTFY0W+BjYEW
2018-10-04 17:25:20 -06:00
"text/plain": [
"<Figure size 1440x720 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"proj = ccrs.LambertConformal(central_longitude=-95, central_latitude=35,\n",
" standard_parallels=[35])\n",
2018-10-05 17:09:43 -06:00
"# Create the figure\n",
2018-10-04 17:25:20 -06:00
"fig = plt.figure(figsize=(20, 10))\n",
"ax = fig.add_subplot(1, 1, 1, projection=proj)\n",
2018-10-05 17:09:43 -06:00
"\n",
"# Add various map elements\n",
2018-10-04 17:25:20 -06:00
"ax.add_feature(cfeature.LAND)\n",
"ax.add_feature(cfeature.OCEAN)\n",
"ax.add_feature(cfeature.LAKES)\n",
"ax.add_feature(cfeature.COASTLINE)\n",
"ax.add_feature(cfeature.STATES)\n",
"ax.add_feature(cfeature.BORDERS, linewidth=2)\n",
2018-10-05 17:09:43 -06:00
"\n",
2018-10-04 17:25:20 -06:00
"# Set plot bounds\n",
"ax.set_extent((-118, -73, 23, 50))\n",
"ax.set_title(str(ob.getDataTime()) + \" | METAR | \" + edexServer)\n",
"\n",
"# Winds, temps, dewpoint, station id\n",
"custom_layout = StationPlotLayout()\n",
"custom_layout.add_barb('eastward_wind', 'northward_wind', units='knots')\n",
"custom_layout.add_value('NW', 'air_temperature', fmt='.0f', units='degF', color='darkred')\n",
"custom_layout.add_value('SW', 'dew_point_temperature', fmt='.0f', units='degF', color='darkgreen')\n",
"custom_layout.add_symbol('C', 'cloud_coverage', sky_cover)\n",
"\n",
2018-10-04 17:25:20 -06:00
"stationplot = StationPlot(ax, data['longitude'], data['latitude'], clip_on=True,\n",
" transform=ccrs.PlateCarree(), fontsize=10)\n",
"stationplot.plot_text((2, 0), data['stid'])\n",
2018-10-05 17:09:43 -06:00
"custom_layout.plot(stationplot, data)\n",
"\n",
2018-10-05 17:09:43 -06:00
"plt.show()"
2018-10-04 17:25:20 -06:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
"\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7 See Also\n",
"\n",
"- [Aviation Weather Center Static METAR Plots Information](https://www.aviationweather.gov/metar/help?page=plot)\n",
"\n",
"### 7.1 Related Notebooks\n",
"\n",
"- [Grid Levels and Parameters](http://unidata.github.io/python-awips/examples/generated/Grid_Levels_and_Parameters.html)\n",
"- [Colored Surface Temperature Plot](http://unidata.github.io/python-awips/examples/generated/Colored_Surface_Temperature_Plot.html)\n",
"\n",
"### 7.2 Additional Documentation\n",
"\n",
"**python-awips:**\n",
"\n",
"- [DataAccessLayer.changeEDEXHost()](http://unidata.github.io/python-awips/api/DataAccessLayer.html#awips.dataaccess.DataAccessLayer.changeEDEXHost)\n",
"- [DataAccessLayer.newDataRequest()](http://unidata.github.io/python-awips/api/DataAccessLayer.html#awips.dataaccess.DataAccessLayer.newDataRequest)\n",
"- [IDataRequest](http://unidata.github.io/python-awips/api/IDataRequest.html)\n",
"- [DataAccessLayer.getGeometryData](http://unidata.github.io/python-awips/api/PyGeometryData.html)\n",
"\n",
"**datetime:**\n",
"\n",
"- [datetime.datetime](https://docs.python.org/3/library/datetime.html#datetime-objects)\n",
"- [datetime.utcnow()](https://docs.python.org/3/library/datetime.html?#datetime.datetime.utcnow)\n",
"- [datetime.timedelta](https://docs.python.org/3/library/datetime.html#timedelta-objects)\n",
"- [datetime.strftime() and datetime.strptime()](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior)\n",
"\n",
"**numpy:**\n",
"\n",
"- [np.array](https://numpy.org/doc/stable/reference/generated/numpy.array.html)\n",
"\n",
"**cartopy:**\n",
"\n",
"- [cartopy projection list](https://scitools.org.uk/cartopy/docs/v0.14/crs/projections.html?#cartopy-projection-list)\n",
"- [cartopy feature interface](https://scitools.org.uk/cartopy/docs/v0.14/matplotlib/feature_interface.html)\n",
"\n",
"**matplotlib:**\n",
"\n",
"- [matplotlib.pyplot()](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.html)\n",
"- [matplotlib.pyplot.figure()](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html)\n",
"- [matplotlib.pyplot.figure.add_subplot](https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.add_subplot)\n",
"- [ax.set_extent](https://matplotlib.org/stable/api/image_api.html?highlight=set_extent#matplotlib.image.AxesImage.set_extent)\n",
"- [ax.set_title](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_title.html)\n",
"\n",
"\n",
"**metpy:**\n",
"\n",
"- [metpy.calc.wind_components](https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.wind_components.html)\n",
"- [metpy.plots.StationPlot()](https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.StationPlot.html)\n",
"- [metpy.plots.StationPlotLayout()](https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.StationPlotLayout.html)\n",
"- [metpy.units](https://unidata.github.io/MetPy/latest/api/generated/metpy.units.html)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Top](https://unidata.github.io/python-awips/examples/generated/METAR_Station_Plot_with_MetPy.html)\n",
"\n",
"---"
]
2018-10-04 17:25:20 -06:00
}
],
"metadata": {
"kernelspec": {
2022-06-03 16:08:15 -04:00
"display_name": "Python 3 (ipykernel)",
2018-10-04 17:25:20 -06:00
"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",
2022-06-03 16:08:15 -04:00
"version": "3.9.13"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": false,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {
"height": "calc(100% - 180px)",
"left": "10px",
"top": "150px",
"width": "287.9779357910156px"
},
"toc_section_display": false,
"toc_window_display": false
2018-10-04 17:25:20 -06:00
}
},
"nbformat": 4,
"nbformat_minor": 1
}