Exemple #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')
Exemple #2
0
    outfile_chg = '../../data/test-z0-change.nc'
    outfile_nochg = '../../data/test-z0-nochange.nc'

    #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])
Exemple #3
0
except:
	PLOT = False

PLOT = False
rfile = '../data/restart_10years.nc'
nnufile = '../data/nn-uparam-im/model_upar-im.pkl'
nnvfile = '../data/nn-vparam-im/model_vpar-im.pkl'
nhdynfile = '../data/nn-hdynparam-amsgrad-long2/model_hdyn-im.pkl'

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()
Exemple #4
0
    t0 = 0

    # Generation of the ensemble
    epsb = dict()
    for par in std_b:
        epsb[par] = np.empty(shape=(m, ) + dr[par][0].shape)

        for im in range(m):
            eps = np.random.normal(0, std_b[par], dr[par][0].shape)
            epsb[par][im] = ndimage.convolve(eps, k, mode='constant')
            epsb[par][im] += dr[par][0]

    #Model load:
    SW = SWmodel()
    SW.inistate_rst(rfile)
    SW.set_time(t0)

    #Reference model (to produce obs)
    SW0 = SWmodel()
    SW0.inistate_rst(rfile)
    SW0.set_time(t0)

    #parameters in control state variable (not all ?)
    cparam = {'hphy', 'uphy', 'vphy', 'ufil', 'vfil', 'hfil'}
    epsa = epsb
    endtime = 3
    for t in tqdm(ds.hphy_o.time[:endtime]):
        #forecast
        if t > t0:
            epsb = forward(SW, epsa, int(t - t0))
            for i in range(int(t0), int(t)):