dt = 3600. # time step in seconds fhout = 12. # output interval (hours) gridtype = 'gaussian' # 'regular' or 'gaussian' output_file = 'truth_twolevel_t%s_%sh_tst.nc' % (ntrunc, int(fhout)) # create spherical harmonic instance. rsphere = 6.37122e6 # earth radius sp = Spharmt(nlons, nlats, ntrunc, rsphere, gridtype=gridtype) nstart = int((200. * 86400.) / dt) # end of spinup period 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)
nlats = (nlons / 2) + 1 # for regular grid. gridtype = 'regular' dt = 900 # time step in seconds tdiab = 12. * 86400 # thermal relaxation time scale tdrag = 4. * 86400. # lower layer drag efold = 4 * dt # hyperdiffusion time scale rsphere = 6.37122e6 # earth radius jetexp = 2 umax = 40 moistfact = 0.1 # create spherical harmonic instance. sp = Spharmt(nlons, nlats, rsphere=rsphere, gridtype=gridtype) # create model instance. model =\ TwoLevel(sp,dt,ntrunc,efold=efold,tdiab=tdiab,tdrag=tdrag,jetexp=jetexp,umax=umax,moistfact=moistfact) # initial state is equilbrium jet + random noise. vg = np.zeros((sp.nlat, sp.nlon, 2), np.float32) ug = model.uref vrtspec, divspec = sp.getvrtdivspec(ug, vg, model.ntrunc) psispec = np.zeros(vrtspec.shape, vrtspec.dtype) psispec.real += npran.normal(scale=1.e4, size=(psispec.shape)) psispec.imag += npran.normal(scale=1.e4, size=(psispec.shape)) vrtspec = vrtspec + model.lap[:, np.newaxis] * psispec thetaspec = model.nlbalance(vrtspec) divspec = np.zeros(thetaspec.shape, thetaspec.dtype) model.vrt = sp.spectogrd(vrtspec) model.theta = sp.spectogrd(thetaspec) model.heat = np.zeros(model.theta.shape, model.theta.dtype)
np.random.seed(42) # model nature run to sample initial ensemble and draw additive noise. modelclimo_file = 'truth_twolevel_t%s_12h.nc' % ntrunc # 'truth' nature run to sample obs # (these two files can be the same for perfect model expts) # file to sample additive noise. truth_file = 'truth_twolevel_t32_12h.nc' # create spherical harmonic transform instance sp = Spharmt(nlons,nlats,ntrunc,rsphere,gridtype=gridtype) spout = sp models = [] for nanal in range(nanals): models.append(TwoLevel(sp,dt)) # weights for computing global means. globalmeanwts = models[0].globalmeanwts # read nature run, create obs. nct = Dataset(truth_file) lats = nct.variables['lat'][:] lons = nct.variables['lon'][:] spin = Spharmt(len(lons),len(lats),int(nct.ntrunc),rsphere,gridtype=gridtype) samegrid = spin.nlons == spout.nlons and spin.nlats == spout.nlats # find fibonacci points between latmin and latmax if nobs == 1: nobsall = 1 # single ob test. oblonsall = np.array([180.], np.float)
dt = 3600. # time step in seconds fhout = 12. # output interval (hours) gridtype = 'gaussian' # 'regular' or 'gaussian' output_file = 'truth_twolevel_t%s_%sh_tst.nc' % (ntrunc,int(fhout)) # create spherical harmonic instance. rsphere = 6.37122e6 # earth radius sp = Spharmt(nlons,nlats,ntrunc,rsphere,gridtype=gridtype) nstart = int((200.*86400.)/dt) # end of spinup period 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)