python-awips/examples/notebooks/Surface_Obs_Plot_with_MetPy.ipynb

557 lines
524 KiB
Text
Raw Normal View History

2016-03-15 20:27:25 -05:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Based on the MetPy example [\"Station Plot with Layout\"](http://metpy.readthedocs.org/en/latest/examples/generated/Station_Plot_with_Layout.html)"
]
},
{
"cell_type": "code",
2016-06-09 16:19:14 -06:00
"execution_count": 1,
2016-03-15 20:27:25 -05:00
"metadata": {
"collapsed": false,
"scrolled": true
},
2016-06-09 16:19:14 -06:00
"outputs": [],
"source": [
"import datetime\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import numpy as np\n",
"import pprint\n",
"\n",
"from awips.dataaccess import DataAccessLayer\n",
"\n",
"from metpy.calc import get_wind_components\n",
"from metpy.cbook import get_test_data\n",
"from metpy.plots.wx_symbols import sky_cover, current_weather\n",
"from metpy.plots import StationPlot, StationPlotLayout, simple_layout\n",
"from metpy.units import units\n",
"\n",
"pp = pprint.PrettyPrinter(depth=1)\n",
"\n",
"def get_cloud_cover(code):\n",
" \n",
" if 'OVC' in code:\n",
" return 1.0\n",
" \n",
" elif 'BKN' in code:\n",
" return 6.0/8.0\n",
" \n",
" elif 'SCT' in code:\n",
" return 4.0/8.0\n",
" \n",
" elif 'FEW' in code:\n",
" return 2.0/8.0\n",
" \n",
" else:\n",
" return 0\n",
"\n",
"state_capital_wx_stations = {'Washington':'KOLM', 'Oregon':'KSLE', 'California':'KSAC',\n",
" 'Nevada':'KCXP', 'Idaho':'KBOI', 'Montana':'KHLN',\n",
" 'Utah':'KSLC', 'Arizona':'KDVT', 'New Mexico':'KSAF',\n",
" 'Colorado':'KBKF', 'Wyoming':'KCYS', 'North Dakota':'KBIS',\n",
" 'South Dakota':'KPIR', 'Nebraska':'KLNK', 'Kansas':'KTOP',\n",
" 'Oklahoma':'KPWA', 'Texas':'KATT', 'Louisiana':'KBTR',\n",
" 'Arkansas':'KLIT', 'Missouri':'KJEF', 'Iowa':'KDSM',\n",
" 'Minnesota':'KSTP', 'Wisconsin':'KMSN', 'Illinois':'KSPI',\n",
" 'Mississippi':'KHKS', 'Alabama':'KMGM', 'Nashville':'KBNA',\n",
" 'Kentucky':'KFFT', 'Indiana':'KIND', 'Michigan':'KLAN',\n",
" 'Ohio':'KCMH', 'Georgia':'KFTY', 'Florida':'KTLH',\n",
" 'South Carolina':'KCUB', 'North Carolina':'KRDU',\n",
" 'Virginia':'KRIC', 'West Virginia':'KCRW',\n",
" 'Pennsylvania':'KCXY', 'New York':'KALB', 'Vermont':'KMPV',\n",
" 'New Hampshire':'KCON', 'Maine':'KAUG', 'Massachusetts':'KBOS',\n",
" 'Rhode Island':'KPVD', 'Connecticut':'KHFD', 'New Jersey':'KTTN',\n",
" 'Delaware':'KDOV', 'Maryland':'KNAK'}"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Initialize\n",
"DataAccessLayer.changeEDEXHost(\"edex-cloud.unidata.ucar.edu\")\n",
"\n",
"request = DataAccessLayer.newDataRequest()\n",
"request.setDatatype(\"obs\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define our parameters, separating those that return single values with those that return multiple values"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"single_value_params = [\"timeObs\", \"stationName\", \"longitude\", \"latitude\", \n",
" \"temperature\", \"dewpoint\", \"windDir\",\n",
" \"windSpeed\", \"seaLevelPress\"]\n",
"\n",
"multi_value_params = [\"presWeather\", \"skyCover\", \"skyLayerBase\"]\n",
"\n",
"all_params = single_value_params + multi_value_params"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build a request object with all of the desired parameters and locations names,\n",
"and then return observation data."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"request.setParameters(*(all_params))\n",
"\n",
"request.setLocationNames(*(state_capital_wx_stations.values()))\n",
"\n",
"response = DataAccessLayer.getGeometryData(request)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build a data dictionary to store all of the information available in the response object.\n",
"\n",
"Each \"row\" in the dictionary should correspond to a single observation for a station.\n",
"\n",
"Because multiple-value variables are returned as unpacked lists from the \"response\" object, \n",
"the following loop has a complicated structure.\n",
"\n",
"For example: for any given station, the loop below would print out the following for \n",
"ob.getParameters(), where each line represents a step in the iteration through 'response':\n",
"\n",
"['presWeather']\n",
"\n",
"['presWeather']\n",
"\n",
"['presWeather']\n",
"\n",
"['presWeather']\n",
"\n",
"['presWeather']\n",
"\n",
"['skyCover', 'skyLayerBase']\n",
"\n",
"[\"timeObs\", \"stationName\", \"longitude\", \"latitude\", \"temperature\", \"dewpoint\", \"windDir\", \"windSpeed\", \"seaLevelPress\"]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
2016-03-15 20:27:25 -05:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-06-09 16:19:14 -06:00
"{'dewpoint': [...],\n",
" 'latitude': [...],\n",
" 'longitude': [...],\n",
" 'presWeather': [...],\n",
" 'seaLevelPress': [...],\n",
" 'skyCover': [...],\n",
" 'skyLayerBase': [...],\n",
" 'stationName': [...],\n",
" 'temperature': [...],\n",
" 'timeObs': [...],\n",
" 'windDir': [...],\n",
" 'windSpeed': [...]}\n"
2016-03-15 20:27:25 -05:00
]
2016-06-09 16:19:14 -06:00
}
],
"source": [
"obs_dict = dict({all_params: [] for all_params in all_params})\n",
"\n",
"pres_weather = []\n",
"sky_cov = []\n",
"sky_layer_base = []\n",
"\n",
"for ob in response:\n",
" \n",
" avail_params = ob.getParameters()\n",
"\n",
" if \"presWeather\" in avail_params:\n",
" pres_weather.append(ob.getString(\"presWeather\"))\n",
"\n",
" elif \"skyCover\" in avail_params and \"skyLayerBase\" in avail_params:\n",
" sky_cov.append(ob.getString(\"skyCover\"))\n",
" sky_layer_base.append(ob.getNumber(\"skyLayerBase\"))\n",
" \n",
" else:\n",
"\n",
" for param in single_value_params:\n",
"\n",
" if param in avail_params:\n",
"\n",
" if param == 'timeObs':\n",
"\n",
" obs_dict[param].append(datetime.datetime.fromtimestamp(ob.getNumber(param)/1000.0))\n",
" \n",
" else:\n",
" \n",
" try:\n",
" obs_dict[param].append(ob.getNumber(param))\n",
"\n",
" except TypeError:\n",
" obs_dict[param].append(ob.getString(param))\n",
" \n",
" else:\n",
" obs_dict[param].append(None)\n",
"\n",
" obs_dict['presWeather'].append(pres_weather);\n",
" obs_dict['skyCover'].append(sky_cov);\n",
" obs_dict['skyLayerBase'].append(sky_layer_base);\n",
"\n",
" pres_weather = []\n",
" sky_cov = []\n",
" sky_layer_base = []\n",
" \n",
"pp.pprint(obs_dict)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now use pandas to retrieve desired subsets of our observations.\n",
"\n",
"In this case, return the most recent observation for each station."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [
2016-03-15 20:27:25 -05:00
{
"data": {
2016-06-09 16:19:14 -06:00
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>timeObs</th>\n",
" <th>stationName</th>\n",
" <th>longitude</th>\n",
" <th>latitude</th>\n",
" <th>temperature</th>\n",
" <th>dewpoint</th>\n",
" <th>windDir</th>\n",
" <th>windSpeed</th>\n",
" <th>seaLevelPress</th>\n",
" <th>presWeather</th>\n",
" <th>skyCover</th>\n",
" <th>skyLayerBase</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>7360</th>\n",
" <td>2016-06-09 14:51:00</td>\n",
" <td>KALB</td>\n",
" <td>-73.800003</td>\n",
" <td>42.759998</td>\n",
" <td>17.0</td>\n",
" <td>3.0</td>\n",
" <td>310.0</td>\n",
" <td>20.0</td>\n",
" <td>1009.000000</td>\n",
" <td>[, , , , ]</td>\n",
" <td>[FEW, SCT, , , , ]</td>\n",
" <td>[4800.0, 6000.0, -9999.0, -9999.0, -9999.0, -9...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3952</th>\n",
" <td>2016-06-09 13:51:00</td>\n",
" <td>KATT</td>\n",
" <td>-97.769997</td>\n",
" <td>30.320000</td>\n",
" <td>31.0</td>\n",
" <td>21.0</td>\n",
" <td>110.0</td>\n",
" <td>7.0</td>\n",
" <td>1012.200012</td>\n",
" <td>[, , , , ]</td>\n",
" <td>[SCT, BKN, BKN, , , ]</td>\n",
" <td>[4400.0, 5500.0, 7000.0, -9999.0, -9999.0, -99...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7382</th>\n",
" <td>2016-06-09 14:53:00</td>\n",
" <td>KTOP</td>\n",
" <td>-95.620003</td>\n",
" <td>39.080002</td>\n",
" <td>33.0</td>\n",
" <td>16.0</td>\n",
" <td>180.0</td>\n",
" <td>15.0</td>\n",
" <td>1010.000000</td>\n",
" <td>[, , , , ]</td>\n",
" <td>[, , , , , ]</td>\n",
" <td>[-9999.0, -9999.0, -9999.0, -9999.0, -9999.0, ...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7394</th>\n",
" <td>2016-06-09 14:53:00</td>\n",
" <td>KTTN</td>\n",
" <td>-74.809998</td>\n",
" <td>40.279999</td>\n",
" <td>23.0</td>\n",
" <td>4.0</td>\n",
" <td>300.0</td>\n",
" <td>14.0</td>\n",
" <td>1009.599976</td>\n",
" <td>[, , , , ]</td>\n",
" <td>[CLR, , , , , ]</td>\n",
" <td>[-9999.0, -9999.0, -9999.0, -9999.0, -9999.0, ...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>48 rows 12 columns</p>\n",
2016-06-09 16:19:14 -06:00
"</div>"
],
2016-03-15 20:27:25 -05:00
"text/plain": [
2016-06-09 16:19:14 -06:00
" timeObs stationName longitude latitude temperature \\\n",
"7360 2016-06-09 14:51:00 KALB -73.800003 42.759998 17.0 \n",
"3952 2016-06-09 13:51:00 KATT -97.769997 30.320000 31.0 \n",
"... ... ... ... ... ... \n",
"7382 2016-06-09 14:53:00 KTOP -95.620003 39.080002 33.0 \n",
"7394 2016-06-09 14:53:00 KTTN -74.809998 40.279999 23.0 \n",
"\n",
" dewpoint windDir windSpeed seaLevelPress presWeather \\\n",
"7360 3.0 310.0 20.0 1009.000000 [, , , , ] \n",
"3952 21.0 110.0 7.0 1012.200012 [, , , , ] \n",
"... ... ... ... ... ... \n",
"7382 16.0 180.0 15.0 1010.000000 [, , , , ] \n",
"7394 4.0 300.0 14.0 1009.599976 [, , , , ] \n",
"\n",
" skyCover skyLayerBase \n",
"7360 [FEW, SCT, , , , ] [4800.0, 6000.0, -9999.0, -9999.0, -9999.0, -9... \n",
"3952 [SCT, BKN, BKN, , , ] [4400.0, 5500.0, 7000.0, -9999.0, -9999.0, -99... \n",
"... ... ... \n",
"7382 [, , , , , ] [-9999.0, -9999.0, -9999.0, -9999.0, -9999.0, ... \n",
"7394 [CLR, , , , , ] [-9999.0, -9999.0, -9999.0, -9999.0, -9999.0, ... \n",
"\n",
"[48 rows x 12 columns]"
2016-03-15 20:27:25 -05:00
]
},
2016-06-09 16:19:14 -06:00
"execution_count": 6,
2016-03-15 20:27:25 -05:00
"metadata": {},
2016-06-09 16:19:14 -06:00
"output_type": "execute_result"
2016-03-15 20:27:25 -05:00
}
],
"source": [
2016-06-09 16:19:14 -06:00
"import pandas\n",
2016-03-15 20:27:25 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"#change if you want to see more than 8 rows\n",
"pandas.set_option(\"display.max_rows\", 4)\n",
2016-03-15 20:27:25 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"df = pandas.DataFrame(data=obs_dict, columns=all_params)\n",
2016-04-20 19:05:36 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"#sort rows with the newest first\n",
"df = df.sort_values(by='timeObs', ascending=False)\n",
"\n",
"#group rows by station\n",
"groups = df.groupby('stationName')\n",
2016-03-15 20:27:25 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"#create a new DataFrame for the most recent values\n",
"df_recent = pandas.DataFrame(columns=all_params)\n",
2016-03-15 20:27:25 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"#retrieve the first entry for each group, which will\n",
"#be the most recent observation\n",
"for rid, station in groups:\n",
" \n",
" row = station.head(1)\n",
" df_recent = pandas.concat([df_recent, row])\n",
"\n",
"df_recent"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert DataFrame to something metpy-readable by \n",
"attaching units and calculating derived values"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
2016-03-15 20:27:25 -05:00
"data = dict()\n",
"\n",
2016-06-09 16:19:14 -06:00
"data['stid'] = np.array(df_recent[\"stationName\"])\n",
"data['latitude'] = np.array(df_recent['latitude'])\n",
"data['longitude'] = np.array(df_recent['longitude'])\n",
"data['air_temperature'] = np.array(df_recent['temperature'], dtype=float)* units.degC\n",
"data['dew_point'] = np.array(df_recent['dewpoint'], dtype=float)* units.degC\n",
2016-03-15 20:27:25 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"data['slp'] = np.array(df_recent['seaLevelPress'])* units('mbar')\n",
"\n",
"u, v = get_wind_components(np.array(df_recent['windSpeed']) * units('knots'),\n",
" np.array(df_recent['windDir']) * units.degree)\n",
"\n",
"data['eastward_wind'], data['northward_wind'] = u, v\n",
2016-03-15 20:27:25 -05:00
"\n",
2016-06-09 16:19:14 -06:00
"data['cloud_frac'] = [int(get_cloud_cover(x)*8) for x in df_recent['skyCover']]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.text.Text at 0xe13b978>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABiIAAAPmCAYAAABpY4e+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzs3Xd4FMUfx/H3pEAoIUDovYUOoXepIqDgT0QQAWkqiICi\nYkdRAUEsKIj0qoIIKkUUROm99yq99xogIbn9/bGXGGJ67jjK5/U8+4Tszc589243JDM73zGWZSEi\nIiIiIiIiIiIiIuIOXp4OQERERERERERERERE7l8aiBAREREREREREREREbfRQISIiIiIiIiIiIiI\niLiNBiJERERERERERERERMRtNBAhIiIiIiIiIiIiIiJuo4EIERERERERERERERFxGw1EiIiIiIiI\niIiIiIiI22ggQkRERERERERERERE3EYDESIiIiIiIiIiIiIi4jYaiBARERERSQFjjMMYM9TTcXiC\n89w/8HQccTHGvGGM2W+MCTfGbPR0PBI/Y0xH5zWVz4V15nfW2d5VdYqIiIhI0mkgQkRERMRNjDEd\nnB1gDmNMjTjKHHW+PttNMeQ0xvQ1xpRNZPnoMTuMMbeMMceMMROMMbncEaM7GWOeMca8ksRjfIwx\nLxtj1hpjrhhjrjr/3dMY4+OuWO9Wxpgmxpi+cbxsObe7jjHmEeBTYBnQEXj3DrTZzBiz2Bhz2hgT\n4hwEmWaMaRStTJLuyTjaie8zSTFjTDljzPfGmCPGmJvGmPPGmAXOgQJ3/g35n+vJGNPNGNPBjW2K\niIiIyB2ggQgRERER97sBtIm50xhTB8gN3HRj27mAvkC5JBxjAX2AdkBX4HfnvxcbY1K5PEL3agMk\neiDCGJMW+AsYApwE3gJ6A8eBr4E/jTFp3BDn3exRIK5ZD2mAAXcwlqSoB0QAz1mW9b1lWfPc2Zgx\npjcwC3AAnwC9gBlAEeDpa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qRNt30HnvocT2d6HzvJX\nsQeE3oktbuK5J1P6mWAPbDmAp2Psb+jc3zqe+Ms4y3yZhPc4dYzvvYGtwIJYrpPE3CORP3/yRdu3\nDVgYS9u+sezL57z+3ou2L3/09xt7cNIBvJbUa0qbNm3atGnTpk1b8jelZhIRERG5M37Cni3Q1BiT\nHnsmwA9xlG2C3fE4LMb+L7Cf2I/MQX/J+bW5McaVOeMN8DdwFjiK/cTxNeBxy7JORCvXELtT70dj\nTGDkhv1E8xrswYzI/PgPAeOs+J+0fhJ74MA7Rn1/OtupEKP8eOv2p7sj00cVSs5JA/7Or1fjKRP5\nWoYY+1dalrU58hvLso5iPyneKNpncwmoaozJGVvFxk7RFARMjXH+/tifR+0Yh1jYT9XHNA2oaIwp\nGG3f09iLos+OFmNotLbTOttahX2NlY8txvgYY7ywr4lfLcs6HK2dU9iDSbWc1370+EfHqGYZdmd2\nfuf3l7A/08eNMa6Yzf2os90hMfZ/4WznsRj7D1qW9VdiKrYs60PsdV82Ao9gP8G/wRizwRhTPJF1\npPQzeQr7Pfs7xjW0CfserhfPsZHXdHzXf3zxZgQyYX+GMe9VSNw9kmiWZd2K1raXMSYz9sDGnjja\nj3QDe7CrbiLTVYmIiIiIC2ggQkREROQOsOwc8X9hd1Q+if17WFyLPucHTliWFRJj/65or4Pd4bwC\nGAOcNsZMNfa6CSkdlLCw0ys9jD0bYi52DvyYi8gGYXfeLsIetIjczmB3SGd1loscGNgRV4POFDwZ\nsXPwn42xRaZAyhbjsKMxvo9Mh5MpvpOLR2QHrH88ZeIarPgnlrJ7sQefIt+HN7EX+j1qjFljjOkb\nY7AgyPl1Mv99P58HUhnn+g7RHIyl3enYn+HT0fY9BfxuWVZUaipjTF5jzERjL0R+zdnWYuexMdtJ\njKzY57s3ltd2YV/zMde
"text/plain": [
"<matplotlib.figure.Figure at 0xeff8400>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2016-03-15 20:27:25 -05:00
"# Set up the map projection\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as feat\n",
"from matplotlib import rcParams\n",
2016-06-09 16:19:14 -06:00
"rcParams['savefig.dpi'] = 100\n",
2016-03-15 20:27:25 -05:00
"proj = ccrs.LambertConformal(central_longitude=-95, central_latitude=35,\n",
" standard_parallels=[35])\n",
"state_boundaries = feat.NaturalEarthFeature(category='cultural',\n",
" name='admin_1_states_provinces_lines',\n",
" scale='110m', facecolor='none')\n",
"# Create the figure\n",
2016-06-09 16:19:14 -06:00
"fig = plt.figure(figsize=(20, 15))\n",
2016-03-15 20:27:25 -05:00
"ax = fig.add_subplot(1, 1, 1, projection=proj)\n",
"\n",
"# Add map elements \n",
"ax.add_feature(feat.LAND, zorder=-1)\n",
"ax.add_feature(feat.OCEAN, zorder=-1)\n",
"ax.add_feature(feat.LAKES, zorder=-1)\n",
"ax.coastlines(resolution='110m', zorder=2, color='black')\n",
"ax.add_feature(state_boundaries)\n",
"ax.add_feature(feat.BORDERS, linewidth='2', edgecolor='black')\n",
2016-06-09 16:19:14 -06:00
"ax.set_extent((-120, -70, 20, 50))\n",
2016-03-15 20:27:25 -05:00
"\n",
"# Start the station plot by specifying the axes to draw on, as well as the\n",
2016-06-09 16:19:14 -06:00
"# lon/lat of the stations (with transform). We also set the fontsize to 12 pt.\n",
2016-03-15 20:27:25 -05:00
"stationplot = StationPlot(ax, data['longitude'], data['latitude'],\n",
" transform=ccrs.PlateCarree(), fontsize=12)\n",
"\n",
"# The layout knows where everything should go, and things are standardized using\n",
"# the names of variables. So the layout pulls arrays out of `data` and plots them\n",
"# using `stationplot`.\n",
2016-06-09 16:19:14 -06:00
"simple_layout.plot(stationplot, data)\n",
"\n",
"# Plot the temperature and dew point to the upper and lower left, respectively, of\n",
"# the center point. Each one uses a different color.\n",
"stationplot.plot_parameter('NW', np.array(data['air_temperature']), color='red')\n",
"stationplot.plot_parameter('SW', np.array(data['dew_point']), color='darkgreen')\n",
"\n",
"# A more complex example uses a custom formatter to control how the sea-level pressure\n",
"# values are plotted. This uses the standard trailing 3-digits of the pressure value\n",
"# in tenths of millibars.\n",
"stationplot.plot_parameter('NE', np.array(data['slp']),\n",
" formatter=lambda v: format(10 * v, '.0f')[-3:])\n",
"\n",
"# Plot the cloud cover symbols in the center location. This uses the codes made above and\n",
"# uses the `sky_cover` mapper to convert these values to font codes for the\n",
"# weather symbol font.\n",
"stationplot.plot_symbol('C', data['cloud_frac'], sky_cover)\n",
"\n",
"# Also plot the actual text of the station id. Instead of cardinal directions,\n",
"# plot further out by specifying a location of 2 increments in x and 0 in y.\n",
"stationplot.plot_text((2, 0), np.array(obs_dict[\"stationName\"]))\n",
"\n",
"plt.title(\"Most Recent Observations for State Capitals\")"
2016-03-15 20:27:25 -05:00
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
2016-06-09 16:19:14 -06:00
"version": "2.7.11"
2016-03-15 20:27:25 -05:00
}
},
"nbformat": 4,
"nbformat_minor": 0
}