Example #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')
Example #2
0
 def predictfield(self, data, outfield, infield, forcfield, SW=None):
     if SW is None:
         SW = SWmodel()
     nout = (1, 1)
     delta = (1, 1)
     field = mydata(data,
                    outfield=outfield,
                    infield=infield,
                    forcfield=forcfield,
                    nout=nout,
                    delta=delta,
                    dt=1,
                    SW=SW)
     field.make_base()
     y_predict = self.predict(field._X)
     outfield = MakeBigImage(y_predict,
                             ind=(field._indouty, field._indoutx))
     return outfield
Example #3
0
	def __init__( self, fname, outfield,infield, forcfield, nout=(1,1),delta=(1,1),dt=1, SW=None):
		self._outfield = outfield
		self._infield = infield
		self._forcfield = forcfield
		self._nout = nout
		self._delta = delta
		self._dt = dt
		if SW is None:
			self._SW = SWmodel()
		else:
			self._SW = SW
		if isinstance(fname,str):
			self._fname = fname
			self._data = xr.open_dataset(self._fname)
		else:
			self._fname = ''
			self._data = fname

		#define times
		self._t = []
		if self.dt == 0:
			tslice = slice(0,None)
		else:
			tslice = slice(0,-self.dt)
		for t in self.data.time[tslice]:
			if int(t+dt) in self.data.time.values:
				self._t.append((t,t+dt))

		self._X = None
		self._y = None
		self._indinx = None
		self._indiny = None
		self._indoutx = None
		self._indouty = None
		self._indint = None
		self._indoutt = None
Example #4
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()
Example #5
0
import xarray as xr
from tqdm import tqdm

try:
	import matplotlib.pyplot as plt
	PLOT = True
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')
Example #6
0
File: run_hr.py Project: brajard/sw
        if not os.path.isfile(rfile) or rewrite:
            if '_hr' in rfile:
                fact = 8
                outname = '../../data/restartrun_20years_hr.nc'
                #SW = SWmodel(nx=320, ny=320, dx=5e3, dy=5e3,nu=0.18,dt=450)
            elif '_lr' in rfile:
                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)
Example #7
0
File: etkf.py Project: brajard/sw
    # starting time
    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: