Example of plotting practically perfect grids

Dr. Victor Gensini (Spring 2020)

Department of Geographic and Atmospheric Sciences


This data was created following the methods described in Gensini et al. (2020). If using this data, please cite:

  • Gensini V. A. , A. M. Haberlie, and P. T. Marsh, 2020: Practically perfect hindcasts of severe convective storms. Bull. Amer. Meteor. Soc., DOI: 10.1175/BAMS-D-19-0321.1
Import Libraries (xarray, matplotlib, and cartopy):
In [1]:
import xarray as xr
import matplotlib.pyplot as plt
import cartopy
%matplotlib inline
Open the data with xarray, check it out:
In [2]:
df = xr.open_dataset('pper_tor_1979_2018.nc') #point to the file on your local system
df
Out[2]:
<xarray.Dataset>
Dimensions:        (time: 14610, x: 93, y: 65)
Coordinates:
  * time           (time) datetime64[ns] 1979-01-01T12:00:00 ... 2018-12-31T12:00:00
  * x              (x) float64 0.0 1.0 2.0 3.0 4.0 ... 88.0 89.0 90.0 91.0 92.0
  * y              (y) float64 0.0 1.0 2.0 3.0 4.0 ... 60.0 61.0 62.0 63.0 64.0
Data variables:
    lat            (y, x) float64 ...
    lon            (y, x) float64 ...
    p_perfect_tor  (time, y, x) float64 ...
Attributes:
    title:         Practically Perfect Tor Hindcasts
    sigma:         1.5
    grid:          80-km NCEP 211
    author:        Dr. Victor Gensini
    author_email:  vgensini@niu.edu
    citation:      https://doi.org/10.1175/BAMS-D-19-0321.1
In [3]:
#Hatching data
sig_df =xr.open_dataset('pper_sig_tor_1979_2018.nc') #point to the file on your local system
Make a plot:
In [5]:
date_sel = '2011-04-27'
selection=df.sel(time=date_sel)
sig_selection=sig_df.sel(time=date_sel)
fig=plt.figure(figsize=(9,6))
plt.style.use('dark_background')
ax = plt.axes(projection = cartopy.crs.LambertConformal())
ax.add_feature(cartopy.feature.LAND,facecolor='grey')
ax.add_feature(cartopy.feature.OCEAN, alpha = 0.5)
ax.add_feature(cartopy.feature.COASTLINE,linewidth=0.5)
ax.add_feature(cartopy.feature.LAKES, alpha = 0.5)
ax.add_feature(cartopy.feature.STATES,linewidth=0.5)

plt.contourf(selection.lon.values, selection.lat.values, selection.p_perfect_tor.values[0,:,:],
             levels=[0,2], colors=['#FFFFFF'],
             transform=cartopy.crs.PlateCarree(), alpha=0.)
try:
    c = plt.contourf(selection.lon.values, selection.lat.values, selection.p_perfect_tor.values[0,:,:],
             levels=[2,5,10,15,30,45,60,100], colors=['#008b00','#8b4726','#ffc800', '#ff0000', '#ff00ff', '#912cee', '#104e8b'],
             transform=cartopy.crs.PlateCarree())
    plt.annotate('PPER Max\n'+str(selection.p_perfect_tor.values[0,:,:].max().round(1))+'%', xy=(0.88, 0.3), xycoords="figure fraction",
                  va="center", ha="center", color='white',fontsize=12,
                  bbox=dict(boxstyle="round", fc="k"))
except:
    plt.annotate("No Reports", xy=(0.5, 0.5), xycoords="figure fraction",
                  va="center", ha="center", color='white',
                  bbox=dict(boxstyle="round", fc="k"))

try:
    plt.contourf(sig_selection.lon.values, sig_selection.lat.values, sig_selection.p_perfect_sig_tor.values[0,:,:],
             levels=[10,100], colors='none', hatches=['////'],
             transform=cartopy.crs.PlateCarree())
    plt.contour(sig_selection.lon.values, sig_selection.lat.values, sig_selection.p_perfect_sig_tor.values[0,:,:],
             levels=[10,100], colors=['k'],
             transform=cartopy.crs.PlateCarree())
except:
    pass
ax.set_extent([-121, -71, 23, 50])
plt.title('24 Hour Practically Perfect Hindcast starting 1200 UTC ' + date_sel)
plt.colorbar(c,orientation="horizontal", pad=0.01, aspect=50,fraction=.1)
plt.savefig('pper_image.png',bbox_inches='tight',dpi=200)