%matplotlib inline
import cPickle as pickle
with open('vis_input.pkl', 'rb') as fh:
[mslp, all_cold_fronts, all_warm_fronts, thickness, features] = pickle.load(fh)
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.feature import LAND, OCEAN, LAKES
import numpy as np
import matplotlib.path as mpath
import matplotlib.patches as mpatches
import iris.plot as iplt
from cartopy.mpl.patch import geos_to_path
def turn_into_patch(geom, **kwargs):
result = mpath.Path.make_compound_path(*geos_to_path(geom))
patch = mpatches.PathPatch(result, **kwargs)
return patch
def draw_bigger_figure(ax, mslp, feature_crs, all_cold_fronts, all_warm_fronts, thickness,
features):
sf, bl, sd, wf, wd = features
# Start to produce main frame plot
true_ll = ccrs.PlateCarree()
# get lats and lons for plotting
rlats = mslp.coord('grid_latitude').points
rlons = mslp.coord('grid_longitude').points
rlons, rlats = np.meshgrid(rlons, rlats)
unrotated = true_ll.transform_points(feature_crs, rlons, rlats)
nlons, nlats = unrotated[..., 0], unrotated[..., 1]
# Plot lat/lon overlay
lightgrey = '#C0C0C0'
lonlev = np.linspace(-110,70,19)
latlev = np.linspace(20,80,7)
lonscs = ax.contour(rlons,rlats,nlons,lonlev,colors=lightgrey,linestyles='solid',linewidths=0.5, alpha=0.75, transform=rp)
ax.clabel(lonscs, lonscs.levels, inline=True, fmt='%1.0f', inline_spacing=2, fontsize=6)
latscs = ax.contour(rlons,rlats,nlats,latlev,colors=lightgrey,linestyles='solid',linewidths=0.5, alpha=0.75, transform=rp)
ax.clabel(latscs, latscs.levels, inline=True, fmt='%1.0f', inline_spacing=2, fontsize=6)
# Plot mslp overlay
ALMOST_BLACK = '#262626'
cs = iplt.contour(mslp, np.linspace(908, 1076, 43),colors=ALMOST_BLACK,linewidths=0.5, alpha=0.75)
ax.clabel(cs, cs.levels, inline=True, fmt='%1.0f', inline_spacing=2, fontsize=6)
# Plot 1000-500hPa thickness overlay
tk_levs=[456,474,492,510,528,546,564,582,600]
#tk_cols are 'black','red','purple','brown','blue','green','red','purple','black'
tk_cols=['black','#993333','purple','#996600','#3366FF','#669900','#993333','purple','black']
cs2 = iplt.contour(thickness,tk_levs,colors=tk_cols, linewidths=0.5, linestyles='--', alpha=0.75)
ax.clabel(cs2, cs2.levels, inline=True, fmt='%1.0f', inline_spacing=2, fontsize=6)
# Plot cold fronts
ax.add_patch(turn_into_patch(all_cold_fronts, edgecolor='#000099', lw=2,
facecolor='none', alpha=0.7, transform=feature_crs))
# Plot warm fronts
ax.add_patch(turn_into_patch(all_warm_fronts, edgecolor='#CC0000', lw=2,
facecolor='none', alpha=0.7, transform=feature_crs))
# Plot weak diminutive waves
for point in wd:
ax.plot(point.x, point.y, 'o', color='green', transform=feature_crs, markersize=5, markeredgewidth=0.0)
# Plot weak frontal waves
for point in wf:
ax.plot(point.x, point.y, 'o', color='orange', transform=feature_crs, markersize=5, markeredgewidth=0.0)
# Plot standard diminutive waves
for point in sd:
ax.plot(point.x, point.y, 'o', color='green', transform=feature_crs, markersize=8, markeredgewidth=0.0)
# Plot barotropic lows
for point in bl:
ax.plot(point.x, point.y, 'o', color='black', transform=feature_crs, markersize=8, markeredgewidth=0.0)
# Plot standard frontal waves
for point in sf:
ax.plot(point.x, point.y, 'o', color='orange', transform=feature_crs, markersize=8, markeredgewidth=0.0)
# Add coastlines
ax.coastlines(resolution='50m', linewidth=0.5, color='#01A9DB')
# Coastlines don't include the great lakes (US).
ax.add_feature(LAKES, facecolor='none', linewidth=0.5, edgecolor='#01A9DB')
rp = ccrs.RotatedPole(pole_longitude=160.0, pole_latitude=30.0)
fig = plt.figure(figsize=[14, 8], dpi=100)
ax = plt.axes([0.001, 0.002, 0.998, 0.93], projection=rp)
draw_bigger_figure(ax, mslp, rp, all_cold_fronts, all_warm_fronts, thickness, features)
plt.title('Automated front and feature identification.', fontsize=10)
plt.show()
Automatic front and cyclonic feature identification based on algorithm described by Hewson and Titley 2010 in "Objective identification, typing and tracking of the complete life-cycles of cyclonic features at high spatial resolution" (http://onlinelibrary.wiley.com/doi/10.1002/met.204/abstract).
Front identification algorithm follows Hewson 1998 "Objective fronts" (http://onlinelibrary.wiley.com/doi/10.1017/S1350482798000553/abstract) by:
Fronts are stored as geometries in GeoJSON format.
Cyclonic features (frontal waves, diminutive waves and barotropic lows) are identified by: