f = ncep_hrrr.variables['Planetary_boundary_layer_height_surface'] a, b, c, d = f.shape[0], f.shape[1], f.shape[2], f.shape[3]
dataset = Dataset('PBLHeight%02d.nc' %num, 'w', format = 'NETCDF4')
                dataset.createDimension('x', d)
                dataset.createDimension('y', c)
                dataset.createDimension('time', b)
                dataset.createDimension('reftime', a)
                dataset.createDimension('units', None)
                dataset.createVariable('temp', 'f4', ('reftime', 'time', 'x', 'y', 'units',))
            np.arange(0, b, 0.5) #times
            np.arange(0, a, 0.5) #reftimes
            np.arange(575843.432, 675843.432, 100) #SGP region x
            np.arange(3989327.467, 4089327.467, 100) #SGP region y
In [1]:
    
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 [ ]:
    
    
In [ ]:
    
    
In [2]:
    
hrrr_dap = netCDF4.Dataset('http://thredds-jumbo.unidata.ucar.edu/thredds/dodsC/grib/HRRR/CONUS_3km/wrfprs')
ncep_hrrr = netCDF4.Dataset('http://thredds-jumbo.unidata.ucar.edu/thredds/dodsC/grib/NCEP/HRRR/CONUS_2p5km/TwoD')
keys_want =['Planetary_boundary_layer_height_surface',
           'u-component_of_wind_height_above_ground',
           'v-component_of_wind_height_above_ground']
arrays = {}
for key in keys_want:
    print key
    arrays.update({key: ncep_hrrr.variables[key]})
dataset = netCDF4.Dataset('/data/testme.nc', 'w', format = 'NETCDF4')                
for dim in ncep_hrrr.dimensions.keys():
    print dim, len(ncep_hrrr.dimensions[dim])
    dataset.createDimension(dim, len(ncep_hrrr.dimensions[dim]))
                            
tt = dataset.createVariable('time', 'f4', ('reftime', 'time'))
tt[:] = ncep_hrrr.variables['time'][:]
tt.units = ncep_hrrr.variables['time'].units
var_dict = {}
for key in keys_want:
    print key
    print ncep_hrrr.variables[key].shape
    var_dict.update({key: dataset.createVariable(key, 'f4',ncep_hrrr.variables[key].dimensions )})
    print var_dict[key].shape
    for i in range(5):#range(arrays[key].shape[0]):
        var_dict[key][i,:] = arrays[key][i, :]
    var_dict[key].units = ncep_hrrr.variables[key].units
dataset.close()
    
    
In [3]:
    
my_new_object = netCDF4.Dataset('/data/testme.nc', 'r')
    
In [4]:
    
print my_new_object.variables['u-component_of_wind_height_above_ground'].shape
print my_new_object.variables['u-component_of_wind_height_above_ground']
    
    
In [5]:
    
plt.pcolormesh(my_new_object.variables['Planetary_boundary_layer_height_surface'][0,0,:,:])
    
    Out[5]:
    
In [40]:
    
mmm= arrays['Planetary_boundary_layer_height_surface'][0, :]
    
In [41]:
    
print mmm.shape
    
    
In [ ]: