예제 #1
0
파일: restart.py 프로젝트: brajard/sw
except:
    PLOT = False
endtime = 48 * 30 * 12 * 5  #86400 : 5 years
outname = '../data/restartrun.nc'

#Init model
SW = SWmodel(nx=80, ny=80)
SW.initstate_cst(0, 0, 0)

#Save every month
SW.save(time=np.arange(0, endtime, 12 * 15), name=outname)

#run the model
for i in tqdm(range(endtime)):
    SW.next()

#Save the restart
SW.save_rst('../data/restart_10years.nc')

#Plots
ds = xr.open_dataset(outname)

x = 30
y = 30
t = -1

if PLOT:
    fig, axes = plt.subplots(ncols=2)
    ds.hphy.isel(x=x, y=y).plot(ax=axes[0])
    ds.hphy.isel(time=t).plot(ax=axes[1])
    plt.show()
예제 #2
0
endtime = 400
midtime = 200
#Run : one step
SW = SWmodel(nx=80,ny=80)
SW.initstate_cst(0,0,0)
SW.save(time=np.arange(0,endtime,1),name='longrun.nc')
for i in range(endtime):
	SW.next()
SW.remove_save('longrun.nc')

#Run : two steps
SW.initstate_cst(0,0,0)
SW.save(time=np.arange(0,midtime,1),name='firstrun.nc')
for i in range(0,midtime):
	SW.next()
SW.save_rst('restart_'+str(midtime)+'.nc')
SW.remove_save('firstrun.nc')
SW.initstate_cst(0,0,0)
SW.save(time=np.arange(midtime,endtime,1),name='secondrun.nc')
SW.inistate_rst('restart_'+str(midtime)+'.nc')
for i in range(midtime,endtime):
 	SW.next()

#plots
ds_long = xr.open_dataset('longrun.nc')
ds_first = xr.open_dataset('firstrun.nc')
ds_second = xr.open_dataset('secondrun.nc')
x = 0
y = 0

if PLOT:
예제 #3
0
파일: run_hr.py 프로젝트: brajard/sw
            SW = SWmodel(nx=40 * fact,
                         ny=40 * fact,
                         dx=40e3 // fact,
                         dy=40e3 // fact,
                         nu=1.44 / fact,
                         dt=3600 // fact,
                         alpha=0.025)
            SW.initstate_cst(0, 0, 0)
            endtime = (fact * 24) * 30 * 12 * 20  #10 years of spinup
            SW.save(time=np.arange(0, endtime, (fact * 24) * 30),
                    name=outname)  #monthly

            #run the model
            for i in tqdm(range(endtime)):
                SW.next()

            #Save the restart
            SW.save_rst(rfile)

    if False:
        ds = xr.open_dataset('../../data/restartrun_10years_hr.nc')
        block_shape = (4, 4)
        spar = {'hphy', 'uphy', 'vphy'}
        lr = dict()
        for par in spar:
            lr[par] = np.empty((ds.time.size, 80, 80))
            for t in range(ds.time.size):
                temp = view_as_blocks(ds[par][t, :, :].values, block_shape)
                flatten = temp.reshape(temp.shape[0], temp.shape[1], -1)
                lr[par][t] = np.mean(flatten, axis=2)