Пример #1
0
	def setUp ( self ):
		"""Initialisation des tests."""
		self.rfile = '../data/restart_10years.nc'
		self.refile = 'test0.nc'
		self.para = {'hphy','hdyn','uphy','udyn','uforc','uparam'}
		self.ds = xr.open_dataset(self.refile)
		SW = SWmodel(nx=80, ny=80)
		SW.inistate_rst(self.rfile)
		SW.set_time(0)
		endtime = 12 * 30 * 12 * 1
		SW.save(time=np.arange(1, endtime, 12 * 7), para=self.para, name='test.nc')
		for i in range(endtime):
			SW.next()
		self.ds2 = xr.open_dataset('test.nc')
Пример #2
0
from shalw import SWmodel
import numpy as np
import xarray as xr
try:
	import matplotlib.pyplot as plt
	PLOT = True
except:
	PLOT = False
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()
Пример #3
0
    #Run 2 versions of the model
    # - one with the old z limit condition
    # - one with the changed z limit condition
    files2run = {outfile_chg, outfile_nochg}
    #files2run = {} #comment to rerun
    for outfile in files2run:
        para = {'hphy', 'vphy', 'uphy'}
        if 'nochange' in outfile:
            SW = SWmodel(nx=80, ny=80)
        else:
            SW = SWz0(nx=80, ny=80)
        SW.inistate_rst(rfile)
        SW.set_time(0)

        endtime = 12 * 30 * 12 * 10
        SW.save(time=np.arange(0, endtime, 12 * 7), para=para, name=outfile)
        for i in tqdm(range(endtime + 1)):
            SW.next()
    ds_chg = xr.open_dataset(outfile_chg)
    ds_nochg = xr.open_dataset(outfile_nochg)
    out = ds_nochg.assign(dh=ds_chg.hphy - ds_nochg.hphy)
    out = out.assign(du=ds_chg.uphy - ds_nochg.uphy)
    out = out.assign(dv=ds_chg.vphy - ds_nochg.vphy)
    f2plot = {'dh', 'du', 'dv'}

    for par in f2plot:
        fig, ax = plt.subplots(nrows=2)
        out[par].isel(time=1).plot(ax=ax[0])
        out[par].isel(time=-1).plot(ax=ax[1])
        plt.tight_layout()
        plt.show()
Пример #4
0
from tqdm import tqdm

try:
    import matplotlib.pyplot as plt
    PLOT = True
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
Пример #5
0
	PLOT = True
except:
	PLOT = False

rfile = '../data/restart_20years_mr.nc'
outfile = '../data/base_40years_mr.nc'
testfile = '../data/test_image.nc'
para = {'ufil', 'vfil', 'hfil',
	'hphy', 'uphy', 'vphy',
	'hdyn', 'udyn', 'vdyn',
	'uparam', 'vparam', 'hdyn'}
SW = SWmodel(nx=80,ny=80)
SW.inistate_rst(rfile)
SW.set_time(0)

nseq = 2
freq = 12*30*1 #1 month
endtime = 12*30*12*40 #10 years
testime = 12*30*10 #one year after test
# Create time vector
starts = np.arange(0, endtime, freq)
time = np.empty(shape=(0,), dtype=int)
for s in starts:
	time = np.concatenate((time, np.arange(s,s+nseq)), axis=0)

SW.save(time=time, para=para,name=outfile)
SW.save(time=range(endtime+testime-nseq,endtime+testime),
	para=para,name=testfile)
for i in tqdm(range(endtime+testime)):
	SW.next()
Пример #6
0
SW0 = SWmodel(nx=80, ny=80)
SW = SWparnnim(nnupar=nnufile,nnvpar=nnvfile,nx=80,ny=80)
#SW = SWparnnhdyn(nnupar=nnufile,nnvpar=nnvfile,nnhdyn=nhdynfile, nx=80,ny=80)
SW.inistate_rst(rfile)
SW.set_time(0)
SW0.inistate_rst(rfile)
SW0.set_time(0)
# time of the spinup
# endtime = 12*30*12*10 #10 years
endtime = 48 * 30 * 12 * 15
#endtime = 48 * 30 * 12 *10
# Declare to save all phy parameters (default) every 12*30 time step(1 month)
# 10000 is approximatively 13 months
para = { 'hphy', 'hdyn', 'uphy', 'udyn', 'uparam','vparam','vphy' }
SW.save(time=np.arange(0, endtime,48*7 ), para=para, name='../data/egu/test-nn-new.nc')
SW0.save(time=np.arange(0, endtime,48*7 ), para=para, name='../data/egu/test-00-new.nc')

# Run the model
start = time.time()

for i in tqdm(range(endtime)):
	SW.next()
	SW0.next()
end = time.time()
print('run duration', end - start, 'seconds')
# SW.save_rst(name='restart.nc')
# Plot the final state
if PLOT:
	ds = xr.open_dataset('test.nc')
	plt.imshow(SW.get_state('vor'))
	plt.colorbar()
Пример #7
0
                fact = 1
                outname = '../../data/restartrun_20years_lr.nc'
                #SW = SWmodel(nx=40,ny=40,dx = 40e3, dy=40e3, nu=1.44, dt=3600//fact)
            else:
                fact = 2
                outname = '../../data/restartrun_20years_mr.nc'
            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))