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')
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()
# 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() plt.show() x, y = 20, 41 fig, axes = plt.subplots(nrows=3, sharex=True) ds.uphy.isel(x=x, y=y).plot(ax=axes[0]) ds.udyn.isel(x=x, y=y).plot(ax=axes[1]) ds.uparam.isel(x=x, y=y).plot(ax=axes[2]) plt.show()