rhoz = p/(c.Rd*np.mean(np.mean(T, axis=3), axis=2))
    
    print 'calculating daily averages'
    CRH_tave = np.mean(CRH, axis=0)
    T_tave = np.mean(T, axis=0)
    w_tave = np.mean(w, axis=0)
    rhoz_tave = np.mean(rhoz, axis=0)
    
    
    #number of grid points in a block
    db=16

    PW_tave = np.mean(PW, axis=0)
    PWxy_sorted = blockxysort2D(PW_tave, xx, yy, db)
    PWsort = PWxy_sorted.keys()
    PWxycoords = PWxy_sorted.values()

    mcenter = PWxycoords[-1]
    
    binwidth=5e3
    bins = np.arange(0, domsize*1e3, binwidth)
    
    
    #wrsort = np.zeros(z.size, bins.size)
    psi = np.zeros((z.size, bins.size-1))
    chi = np.zeros((z.size, bins.size-1))
    
    #calculate the stream function in cylindrical coords 
    for i, zlev in enumerate(z):
#time period to look at
#t=-25*ntave3D
#nave=5
#nave2D=5*ntave2D
#nave3D=5*ntave3D
#number of blocks to find PW max
db = 1
print 'calulating max PW, blocked'
#PW_t = np.mean(PW_tave[t-nave:t,:,:], axis=0)
#PW_t = np.mean(PW[t-nave2D:t,:,:], axis=0)

#calculate where the convective center is by using blocked max(PW)
PW_tave = np.mean(PW, axis=0)

PW_blocked = blockave2D(PW_tave, db)
PWxy_sorted = blockxysort2D(PW_tave, xx, yy, db)

PWsort = PWxy_sorted.keys()
PWxycoords = PWxy_sorted.values()

mcenter = PWxycoords[-1]
binwidth = 5e3
rbins = np.arange(0, 1 / np.sqrt(2) * domsize * 1e3, binwidth)

#calculate where the convective 'edge' is by using standard deviation definition
#(other definitions may be better)
PWrbins, PWmeans = radprof(PW_tave, xx, yy, mcenter, rbins)
PWrbin_centers = (PWrbins[1:] + PWrbins[:-1]) / 2.

a = 1.5