In [4]:
import netCDF4
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.basemap import Basemap, pyproj
#from JSAnimation.IPython_display import display_animation
from matplotlib import animation
import time
import datetime
import pyart
%matplotlib inline
In [8]:
hrrr_dap = netCDF4.Dataset('http://thredds-jumbo.unidata.ucar.edu/thredds/dodsC/grib/HRRR/CONUS_3km/wrfprs')
hrrr_dap_sfc = netCDF4.Dataset('http://thredds-jumbo.unidata.ucar.edu/thredds/dodsC/grib/NCEP/HRRR/CONUS_2p5km/TwoD')
In [65]:
print(hrrr_dap.dimensions)
In [7]:
print(hrrr_dap_sfc.variables['time'])
print(hrrr_dap_sfc.variables['time'][-1])
for dt in netCDF4.num2date(hrrr_dap_sfc.variables['time'][-1], hrrr_dap_sfc.variables['time'].units):
print(dt)
datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S %Z %Y")
Out[7]:
In [39]:
fig = plt.figure(figsize = [15,8])
pc = plt.pcolormesh(hrrr_dap_sfc.variables['Planetary_boundary_layer_height_surface'][-20,1,:,:])
plt.colorbar()
Out[39]:
In [9]:
fig = plt.figure(figsize = [15,8])
pc = plt.pcolormesh(hrrr_dap_sfc.variables['Planetary_boundary_layer_height_surface'][-1,-1,:,:])
plt.colorbar()
Out[9]:
In [10]:
today = hrrr_dap_sfc.variables['Planetary_boundary_layer_height_surface'][-1,:,:,:]
In [11]:
print(today.shape)
In [12]:
max_pbl = today.max(axis = 0)
print(max_pbl.shape)
In [13]:
fig = plt.figure(figsize = [15,8])
pc = plt.pcolormesh(max_pbl)
plt.colorbar()
Out[13]:
In [66]:
print(hrrr_dap.variables.keys())
print(hrrr_dap.variables['time'])
print(hrrr_dap.variables['time'][-1])
for dt in netCDF4.num2date(hrrr_dap.variables['time'][-1], hrrr_dap.variables['time'].units):
print(dt)
datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S %Z %Y")
Out[66]:
In [16]:
print(hrrr_dap.variables['Temperature_isobaric'].shape)
print(hrrr_dap.variables.keys())
In [43]:
x = hrrr_dap.variables['x'][:]
y = hrrr_dap.variables['y'][:]
samp = 50
x10 = x[::samp]
y10 = y[::samp]
fig = plt.figure(figsize = [15,8])
pc = plt.pcolormesh(x, y, hrrr_dap.variables['Temperature_isobaric'][-1,0,-1,:,:])
qp = plt.quiver(x10, y10,
hrrr_dap.variables['u-component_of_wind_isobaric'][-1,0,-1,::samp,::samp],
hrrr_dap.variables['v-component_of_wind_isobaric'][-1,0,-1,::samp,::samp],
scale = 100.)
plt.colorbar(mappable = pc)
Out[43]:
In [6]:
def dap_lat_lons(open_dap_dataset, proj_key = 'LambertConformal_Projection'):
xg, yg = np.meshgrid(open_dap_dataset.variables['x'][:]*1000.0, open_dap_dataset.variables['y'][:]*1000.0)
pnyc = pyproj.Proj(proj = 'lcc',
lat_1 = open_dap_dataset.variables[proj_key].latitude_of_projection_origin,
lat_2 = open_dap_dataset.variables[proj_key].latitude_of_projection_origin,
lat_0 = open_dap_dataset.variables[proj_key].latitude_of_projection_origin,
lon_0 = open_dap_dataset.variables[proj_key].longitude_of_central_meridian )
return pnyc(xg, yg, inverse = True)
In [33]:
lon, lat = dap_lat_lons(hrrr_dap)
print(lat.shape)
In [87]:
print(netCDF4.num2date(hrrr_dap.variables['time'][-14, 1], hrrr_dap.variables['time'].units))
print(netCDF4.num2date(hrrr_dap_sfc.variables['time'][-19, 1], hrrr_dap_sfc.variables['time'].units))
In [91]:
f = plt.figure(figsize = [15,10])
m = Basemap(llcrnrlon = -95,llcrnrlat = 35, urcrnrlon = -85,
urcrnrlat = 45 , projection = 'mill', area_thresh =1000 ,
resolution='h')
x, y = m(lon, lat)
my_mesh = m.pcolormesh(x, y,
hrrr_dap.variables['Temperature_isobaric'][-14,1,-1,:,:]-273.15,
vmin = 10, vmax = 30.)
samp = 5
x10 = x[::samp, ::samp]
y10 = y[::samp, ::samp]
qp = m.quiver(x10, y10,
hrrr_dap.variables['u-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
hrrr_dap.variables['v-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
scale = 100)
my_coast = m.drawcoastlines(linewidth=1.25)
my_states = m.drawstates()
m.drawparallels(np.linspace(10,50, 9) ,labels=[1,1,0,0])
m.drawmeridians(np.linspace(-110, -80,7),labels=[0,0,0,1])
plt.colorbar(label='T (C)', mappable = my_mesh)
Out[91]:
In [90]:
slon, slat = dap_lat_lons(hrrr_dap_sfc)
f = plt.figure(figsize = [15,10])
m = Basemap(llcrnrlon = -95,llcrnrlat = 35, urcrnrlon = -85,
urcrnrlat = 45 , projection = 'mill', area_thresh =1000 ,
resolution='h')
x, y = m(lon, lat)
sx, sy = m(slon, slat)
my_mesh = m.pcolormesh(sx, sy,
hrrr_dap_sfc.variables['Planetary_boundary_layer_height_surface'][-19,1,:,:])
samp = 5
x10 = x[::samp, ::samp]
y10 = y[::samp, ::samp]
qp = m.quiver(x10, y10,
hrrr_dap.variables['u-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
hrrr_dap.variables['v-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
scale = 100)
my_coast = m.drawcoastlines(linewidth=1.25)
my_states = m.drawstates()
m.drawparallels(np.linspace(10,50, 9) ,labels=[1,1,0,0])
m.drawmeridians(np.linspace(-110, -80,7),labels=[0,0,0,1])
plt.colorbar(label='Height (m)', mappable = my_mesh)
Out[90]:
In [89]:
slon, slat = dap_lat_lons(hrrr_dap_sfc)
f = plt.figure(figsize = [15,10])
m = Basemap(llcrnrlon = -90,llcrnrlat = 43, urcrnrlon = -87,
urcrnrlat = 45 , projection = 'mill', area_thresh =1000 ,
resolution='h')
x, y = m(lon, lat)
sx, sy = m(slon, slat)
my_mesh = m.pcolormesh(sx, sy,
hrrr_dap_sfc.variables['Planetary_boundary_layer_height_surface'][-19,1,:,:])
samp = 2
x10 = x[::samp, ::samp]
y10 = y[::samp, ::samp]
qp = m.quiver(x10, y10,
hrrr_dap.variables['u-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
hrrr_dap.variables['v-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
scale = 80)
my_coast = m.drawcoastlines(linewidth=1.25)
my_states = m.drawstates()
m.drawparallels(np.linspace(10,50, 9) ,labels=[1,1,0,0])
m.drawmeridians(np.linspace(-110, -80,7),labels=[0,0,0,1])
plt.colorbar(label='Height (m)', mappable = my_mesh)
Out[89]:
In [93]:
slon, slat = dap_lat_lons(hrrr_dap_sfc)
f = plt.figure(figsize = [15,10])
m = Basemap(llcrnrlon = -90,llcrnrlat = 43, urcrnrlon = -87,
urcrnrlat = 45 , projection = 'mill', area_thresh =1000 ,
resolution='h')
x, y = m(lon, lat)
sx, sy = m(slon, slat)
my_mesh = m.pcolormesh(x, y,
hrrr_dap.variables['Dewpoint_temperature_isobaric'][-14,1, -1,:,:] -273 , vmin = 5, vmax = 24)
samp = 2
x10 = x[::samp, ::samp]
y10 = y[::samp, ::samp]
qp = m.quiver(x10, y10,
hrrr_dap.variables['u-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
hrrr_dap.variables['v-component_of_wind_isobaric'][-14,1,-1,::samp,::samp],
scale = 80)
my_coast = m.drawcoastlines(linewidth=1.25)
my_states = m.drawstates()
m.drawparallels(np.linspace(10,50, 9) ,labels=[1,1,0,0])
m.drawmeridians(np.linspace(-110, -80,7),labels=[0,0,0,1])
plt.colorbar(label='T_d (C) ', mappable = my_mesh)
Out[93]:
In [57]:
print(hrrr_dap.variables['isobaric'][:])
In [9]:
from JSAnimation import IPython_display
from matplotlib.animation import FuncAnimation
lon, lat = dap_lat_lons(hrrr_dap)
print(lat.shape)
In [33]:
def update_ax(n):
global ax, fig, m, x, y
ax.cla()
my_mesh = m.pcolormesh(x, y,
hrrr_dap.variables['Dewpoint_temperature_isobaric'][n,1, -1,:,:] -273 ,
vmin = 5, vmax = 24, ax = ax)
m.drawcoastlines()
m.drawcounties()
ax.set_title((netCDF4.num2date(hrrr_dap.variables['time'][n,1],
hrrr_dap.variables['time'].units)).strftime('%Y-%m-%d %H:%M'))
return my_mesh
In [35]:
fig, ax = plt.subplots(figsize=(15, 8))
fig.patch.set_visible(False)
ax.axis([-59, 0, -59, 0])
m = Basemap(llcrnrlon = -95,llcrnrlat = 35, urcrnrlon = -85,
urcrnrlat = 45 , projection = 'mill', area_thresh =1000 ,
resolution='h', ax = ax)
x, y = m(lon, lat)
my_mesh = m.pcolormesh(x, y,
hrrr_dap.variables['Dewpoint_temperature_isobaric'][0,1, -1,:,:] -273 ,
vmin = 5, vmax = 24, ax = ax)
ax.set_title((netCDF4.num2date(hrrr_dap.variables['time'][0,1],
hrrr_dap.variables['time'].units)).strftime('%Y-%m-%d %H:%M'))
fig.colorbar(my_mesh, shrink=0.7)
FuncAnimation(fig, update_ax, interval=100, frames= hrrr_dap.variables['Dewpoint_temperature_isobaric'].shape[0])
Out[35]: