Пример #1
0
nmax = int((1300. * 86400.) / dt)  # total duration of run

# create model instance
model = TwoLevel(sp, dt)
print 'pole/equator temp diff = ', model.thetaref.max() - model.thetaref.min()

# vort, div initial conditions
psipert = np.zeros((2, model.nlat, model.nlon), np.float)
psipert[1, :, :] = 5.e6 * np.sin(
    (model.lons - np.pi))**12 * np.sin(2. * model.lats)**12
psipert = np.where(model.lons[np.newaxis, :, :] > 0., 0, psipert)
psipert[1, :, :] += np.random.normal(scale=1.e6, size=(sp.nlats, sp.nlons))
ug = np.zeros((2, model.nlat, model.nlon), np.float)
vg = np.zeros((2, model.nlat, model.nlon), np.float)
ug[1, :, :] = model.umax * np.sin(2. * model.lats)**model.jetexp
vrtspec, divspec = sp.getvrtdivspec(ug, vg)
vrtspec = vrtspec + model.lap * sp.grdtospec(psipert)
thetaspec = model.nlbalance(vrtspec)
divspec = np.zeros(thetaspec.shape, thetaspec.dtype)

# create netcdf file.
nc = Dataset(output_file, 'w', format='NETCDF4_CLASSIC')
nc.rsphere = rsphere
nc.gridtype = gridtype
nc.ntrunc = ntrunc
nc.dt = dt
atts = [
    'grav', 'omega', 'cp', 'rgas', 'p0', 'ptop', 'delth', 'efold', 'ndiss',
    'tdrag', 'tdiab', 'umax', 'jetexp'
]
for att in atts:
Пример #2
0
    nobsall = len(oblatsall)

print '# %s obs to assimilate (out of %s) with ob err stdev = %s' % (nobs,nobsall,oberrstdev)
print '# covlocal_scale=%s km, covinflate1=%s covinflate2=%s' %\
(covlocal_scale/1000., covinflate1, covinflate2)
thetaobsall = np.empty((nassim,nobsall),np.float)
utruth = np.empty((nassim,2,nlats,nlons),np.float)
vtruth = np.empty((nassim,2,nlats,nlons),np.float)
wtruth = np.empty((nassim,nlats,nlons),np.float)
thetatruth = np.empty((nassim,nlats,nlons),np.float)
oberrvar = np.empty(nobs,np.float); oberrvar[:] = oberrstdev**2
obtimes = np.empty((nassim),np.float)
for n in range(nassim):
    # flip latitude direction so lats are increasing (needed for interpolation)
    vrtspec_tmp,divspec_tmp =\
    spin.getvrtdivspec(nct.variables['u'][n],nct.variables['v'][n])
    w = models[0].dp*spin.spectogrd(divspec_tmp[1]-divspec_tmp[0])
    obtimes[n] = nct.variables['t'][n]
    thetaobsall[n] =\
    bilintrp(nct.variables['theta'][n,::-1,:],lons,lats[::-1],oblonsall,oblatsall)
    if samegrid:
       utruth[n] = nct.variables['u'][n]
       vtruth[n] = nct.variables['v'][n]
       thetatruth[n] = nct.variables['theta'][n]
       wtruth[n] = w
    else:
       utruth[n], vtruth[n] =\
       regriduv(spin,spout,nct.variables['u'][n],nct.variables['v'][n])
       thetatruth[n] = regrid(spin,spout,nct.variables['theta'][n],levs=1)
       wtruth[n] = regrid(spin,spout,w,levs=1)
nct.close()
Пример #3
0
            varspect[indxn[n]] += 2.*norm[n]*vrtmag
            varspect[indxn[n]] += 2.*norm[n]*divmag
    return varspect

f = Dataset('/Volumes/Drobo/truth_twolevel_t63_12h.nc')
lats = f.variables['lat'][:]; lons = f.variables['lon'][:]
u = f.variables['u']; v = f.variables['v']
ntimes, nlevs, nlats, nlons = u.shape
print nlons, nlats,  f.ntrunc, f.rsphere
sp = Spharmt(nlons,nlats,int(f.ntrunc),f.rsphere,gridtype='gaussian')
kenorm = (-0.25*sp.invlap).astype(np.float)
kespecmean = None
nout = 0
for ntime in range(ntimes):
    print ntime
    vrtspec, divspec = sp.getvrtdivspec(u[ntime,1,...],v[ntime,1,...])
    kespec = getvarspectrum(vrtspec,divspec,kenorm,sp.order,sp.degree,sp.ntrunc)
    if kespecmean is None:
        kespecmean = kespec
    else:
        kespecmean += kespec
    nout += 1
kespecmean = kespecmean/nout
plt.loglog(np.arange(f.ntrunc+1),kespec,linewidth=2,\
        label='t63')

f.close()
f = Dataset('truth_twolevel_t32_12h_tst.nc')
u = f.variables['u']; v = f.variables['v']
ntimes, nlevs, nlats, nlons = u.shape
print nlons, nlats,  f.ntrunc, f.rsphere
Пример #4
0
    nobs, nobsall, oberrstdev)
print '# covlocal_scale=%s km, covinflate=%s obshr_interval=%s' %\
(covlocal_scale/1000., covinflate, obshr_interval)
thetaobsall = np.empty((nassim, nobsall), np.float)
utruth = np.empty((nassim, 2, nlats, nlons), np.float)
vtruth = np.empty((nassim, 2, nlats, nlons), np.float)
wtruth = np.empty((nassim, nlats, nlons), np.float)
thetatruth = np.empty((nassim, nlats, nlons), np.float)
oberrvar = np.empty(nobs, np.float)
oberrvar[:] = oberrstdev**2
obtimes = np.empty((nassim), np.float)
for n in range(nassim):
    # flip latitude direction so lats are increasing (needed for interpolation)
    theta = nct.variables['theta'][n, ::-1, :]
    vrtspec_tmp,divspec_tmp =\
    spin.getvrtdivspec(nct.variables['u'][n,...],nct.variables['v'][n,...])
    w = models[0].dp * spin.spectogrd(divspec_tmp[1] - divspec_tmp[0])
    obtimes[n] = nct.variables['t'][n]
    thetaobsall[n] = bilintrp(theta, lons, lats[::-1], oblonsall, oblatsall)
    if samegrid:
        utruth[n] = nct.variables['u'][n]
        vtruth[n] = nct.variables['v'][n]
        wtruth[n] = w
        thetatruth[n] = nct.variables['theta'][n]
    else:
        utruth[n], vtruth[n] =\
        regriduv(spin,spout,nct.variables['u'][n],nct.variables['v'][n])
        thetatruth[n] = regrid(spin, spout, nct.variables['theta'][n], levs=1)
        wtruth[n] = regrid(spin, spout, w, levs=1)
nct.close()
Пример #5
0
else:
    nobsall = len(oblatsall)

print "# %s obs to assimilate (out of %s) with ob err stdev = %s" % (nobs, nobsall, oberrstdev)
print "# covlocal_scale=%s km, covinflate1=%s covinflate2=%s" % (covlocal_scale / 1000.0, covinflate1, covinflate2)
thetaobsall = np.empty((nassim, nobsall), np.float)
utruth = np.empty((nassim, 2, nlats, nlons), np.float)
vtruth = np.empty((nassim, 2, nlats, nlons), np.float)
wtruth = np.empty((nassim, nlats, nlons), np.float)
thetatruth = np.empty((nassim, nlats, nlons), np.float)
oberrvar = np.empty(nobs, np.float)
oberrvar[:] = oberrstdev ** 2
obtimes = np.empty((nassim), np.float)
for n in range(nassim):
    # flip latitude direction so lats are increasing (needed for interpolation)
    vrtspec_tmp, divspec_tmp = spin.getvrtdivspec(nct.variables["u"][n], nct.variables["v"][n])
    w = models[0].dp * spin.spectogrd(divspec_tmp[1] - divspec_tmp[0])
    obtimes[n] = nct.variables["t"][n]
    thetaobsall[n] = bilintrp(nct.variables["theta"][n, ::-1, :], lons, lats[::-1], oblonsall, oblatsall)
    if samegrid:
        utruth[n] = nct.variables["u"][n]
        vtruth[n] = nct.variables["v"][n]
        thetatruth[n] = nct.variables["theta"][n]
        wtruth[n] = w
    else:
        utruth[n], vtruth[n] = regriduv(spin, spout, nct.variables["u"][n], nct.variables["v"][n])
        thetatruth[n] = regrid(spin, spout, nct.variables["theta"][n], levs=1)
        wtruth[n] = regrid(spin, spout, w, levs=1)
nct.close()

# create initial ensemble by randomly sampling climatology
Пример #6
0
    # create spherical harmonic instance.
    rsphere = 6.37122e6 # earth radius
    sp = Spharmt(nlons,nlats,ntrunc,rsphere,gridtype=gridtype)

    # create model instance using default parameters.
    model = TwoLevel(sp,dt)

    # vort, div initial conditions
    psipert = np.zeros((2,model.nlat,model.nlon),np.float)
    psipert[1,:,:] = 5.e6*np.sin((model.lons-np.pi))**12*np.sin(2.*model.lats)**12
    psipert = np.where(model.lons[np.newaxis,:,:] > 0., 0, psipert)
    psipert[1,:,:] += np.random.normal(scale=1.e6,size=(sp.nlats,sp.nlons))
    ug = np.zeros((2,model.nlat,model.nlon),np.float)
    vg = np.zeros((2,model.nlat,model.nlon),np.float)
    ug[1,:,:] = model.umax*np.sin(2.*model.lats)**model.jetexp
    vrtspec, divspec = sp.getvrtdivspec(ug,vg)
    vrtspec = vrtspec + model.lap*sp.grdtospec(psipert)
    thetaspec = model.nlbalance(vrtspec)
    divspec = np.zeros(thetaspec.shape, thetaspec.dtype)

    # animate potential temperature

    fig = plt.figure(figsize=(16,8))
    vrtspec, divspec, thetaspec = model.rk4step(vrtspec, divspec, thetaspec)
    thetamean = (model.theta*model.globalmeanwts).sum()
    varplot = 'theta'
    #varplot = 'w'
    #varplot = 'u'
    if varplot == 'theta':
        data = model.theta - thetamean
        vmax = 50; vmin = -vmax
Пример #7
0
print '# %s obs to assimilate (out of %s) with ob err stdev = %s' % (nobs,nobsall,oberrstdev)
print '# covlocal_scale=%s km, covinflate=%s obshr_interval=%s' %\
(covlocal_scale/1000., covinflate, obshr_interval)
thetaobsall = np.empty((nassim,nobsall),np.float)
utruth = np.empty((nassim,2,nlats,nlons),np.float)
vtruth = np.empty((nassim,2,nlats,nlons),np.float)
wtruth = np.empty((nassim,nlats,nlons),np.float)
thetatruth = np.empty((nassim,nlats,nlons),np.float)
oberrvar = np.empty(nobs,np.float); oberrvar[:] = oberrstdev**2
obtimes = np.empty((nassim),np.float)
for n in range(nassim):
    # flip latitude direction so lats are increasing (needed for interpolation)
    theta = nct.variables['theta'][n,::-1,:]
    vrtspec_tmp,divspec_tmp =\
    spin.getvrtdivspec(nct.variables['u'][n,...],nct.variables['v'][n,...])
    w = models[0].dp*spin.spectogrd(divspec_tmp[1]-divspec_tmp[0])
    obtimes[n] = nct.variables['t'][n]
    thetaobsall[n] = bilintrp(theta,lons,lats[::-1],oblonsall,oblatsall)
    if samegrid:
       utruth[n] = nct.variables['u'][n]
       vtruth[n] = nct.variables['v'][n]
       wtruth[n] = w
       thetatruth[n] = nct.variables['theta'][n]
    else:
       utruth[n], vtruth[n] =\
       regriduv(spin,spout,nct.variables['u'][n],nct.variables['v'][n])
       thetatruth[n] = regrid(spin,spout,nct.variables['theta'][n],levs=1)
       wtruth[n] = regrid(spin,spout,w,levs=1)
nct.close()
Пример #8
0

f = Dataset('/Volumes/Drobo/truth_twolevel_t63_12h.nc')
lats = f.variables['lat'][:]
lons = f.variables['lon'][:]
u = f.variables['u']
v = f.variables['v']
ntimes, nlevs, nlats, nlons = u.shape
print nlons, nlats, f.ntrunc, f.rsphere
sp = Spharmt(nlons, nlats, int(f.ntrunc), f.rsphere, gridtype='gaussian')
kenorm = (-0.25 * sp.invlap).astype(np.float)
kespecmean = None
nout = 0
for ntime in range(ntimes):
    print ntime
    vrtspec, divspec = sp.getvrtdivspec(u[ntime, 1, ...], v[ntime, 1, ...])
    kespec = getvarspectrum(vrtspec, divspec, kenorm, sp.order, sp.degree,
                            sp.ntrunc)
    if kespecmean is None:
        kespecmean = kespec
    else:
        kespecmean += kespec
    nout += 1
kespecmean = kespecmean / nout
plt.loglog(np.arange(f.ntrunc+1),kespec,linewidth=2,\
        label='t63')

f.close()
f = Dataset('truth_twolevel_t32_12h_tst.nc')
u = f.variables['u']
v = f.variables['v']