lab 5

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeat
import Nio
%matplotlib inline

file='/scratch/scholar/m/mebaldwi/EAPS433/gfs.t12z.pgrb2.0p50.f000'
gr = Nio.open_file(file,'r')

names=gr.variables.keys()
dims=gr.dimensions
print 'variable names', names

print dims

hgt = gr.variables["HGT_P0_L100_GLL0"][:]
tmp = gr.variables["TMP_P0_L100_GLL0"][:]

print np.mean(hgt[30,:,:])
print np.max(hgt[30,:,:])
print np.min(hgt[30,:,:])

lons=gr.variables["lon_0"][:]
lats=gr.variables["lat_0"][:]
lon_2d, lat_2d = np.meshgrid(lons, lats)

hgt850=hgt[25,:,:]
tmpc850=tmp[25,:,:]-273.15

plt.contour(hgt850)

print lons

fig=plt.figure(figsize=(10,8))
ax=fig.add_subplot(1,1,1,projection=ccrs.LambertConformal())
ax.set_global()
ax.add_feature(cfeat.LAND)
ax.add_feature(cfeat.OCEAN)
ax.add_feature(cfeat.COASTLINE)
ax.add_feature(cfeat.BORDERS, linestyle=':')
ax.add_feature(cfeat.LAKES, alpha=0.5)
states_provinces = cfeat.NaturalEarthFeature(
    category='cultural',
    name='admin_1_states_provinces_lines',
    scale='50m',
    facecolor='none')
ax.add_feature(states_provinces, edgecolor='black', linewidth=0.5)
levels=np.arange(810.,1710.,30.)
ax.set_extent([-120, -70, 20, 50])
CS=ax.contour(lon_2d,lat_2d,hgt850,levels,colors='red',transform=ccrs.PlateCarree())
ax.clabel(CS, inline=1, fontsize=10, fmt="%4.0f")


Comments