@@ -29,6 +29,12 @@ def __init__(self,x0=[],yo=[],t0=0,dt=0,alpha=0.5,state_vector=[],obs_data=[],ac
2929 self .SqrtB = []
3030 self .state_vector = state_vector
3131 self .obs_data = obs_data
32+ self .method = ''
33+ self .KH = []
34+ self .khidx = []
35+ self .edim = 0
36+ self .das_bias_init = 0
37+ self .das_sigma_init = 1
3238
3339 def __str__ (self ):
3440 print ('xdim = ' , self .xdim )
@@ -51,6 +57,8 @@ def __str__(self):
5157 print (self .state_vector )
5258 print ('obs_data = ' )
5359 print (obs_data )
60+ print ('method = ' )
61+ print (self .method )
5462 return 'type::da_system'
5563
5664 def setMethod (self ,method ):
@@ -80,6 +88,12 @@ def update(self,B=[0],R=[0],H=[0],t=[0],x0=[0]):
8088 self .t = t
8189 self .x0 = x0
8290
91+ def getC (self ):
92+ return self .C
93+
94+ def setC (self ,C ):
95+ self .C = np .matrix (C )
96+
8397 def getB (self ):
8498 return self .B
8599
@@ -119,12 +133,22 @@ def setH(self,H):
119133# if (nc != self.xdim):
120134# error('H must be ydim x xdim, but instead H is %d x %d'%(nr,nc))
121135
136+ def getKH (self ):
137+ return self .KH , self .khidx
138+
139+ def setKH (self ,KH ,khidx ):
140+ self .KH = KH
141+ self .khidx = khidx
142+
122143 def reduceYdim (self ,yp ):
123144# print('reduceYdim:')
124145# print('yp = ', yp)
125146 self .ydim = len (yp )
126147 self .setH (self .H [yp ,:])
127- self .setR (self .R [yp ,yp ])
148+ R = self .R
149+ R = R [yp ,:]
150+ R = R [:,yp ]
151+ self .setR (R )
128152
129153 def compute_analysis (self ,xb ,yo ,params = [0 ]):
130154 # (params needed for 4D-Var)
@@ -190,16 +214,30 @@ def nudging(self,xb,yo):
190214#---------------------------------------------------------------------------------------------------
191215# Use observations at predefined points to drive the model system to the observed nature system
192216
217+ verbose = False
218+
193219 xb = np .matrix (xb ).flatten ().T
194220 yo = np .matrix (yo ).flatten ().T
221+ Hl = np .matrix (self .H )
222+ Ht = np .matrix (self .Ht )
195223
196- const = np .diagonal (self .B )
224+ C = self .C
225+ xa = xb + C * (yo - Hl * xb )
197226
198- xa = xb + const * (yo - xb )
227+ if verbose :
228+ print ('xb = ' )
229+ print (xb )
230+ print ('C = ' )
231+ print (C )
232+ print ('yo = ' )
233+ print (yo )
234+ print ('Hl = ' )
235+ print (Hl )
236+ print ('xa = ' )
237+ print (xa )
238+ print ('Ht = ' )
239+ print (Ht )
199240
200- C = np .diag (const )
201- Hl = self .H
202- Ht = self .Ht
203241 KH = Ht * C * Hl
204242
205243 return xa .A1 ,KH
@@ -255,10 +293,10 @@ def _3DVar(self,xb,yo):
255293
256294 # 'preconditioning with B'
257295 I = np .identity (xdim )
258- BHt = B * Ht
259- BHtRinv = BHt * Rinv
260- A = I + BHtRinv * Hl
261- b1 = xb + BHtRinv * yo
296+ BHt = np . dot ( B , Ht )
297+ BHtRinv = np . dot ( BHt , Rinv )
298+ A = I + np . dot ( BHtRinv , Hl )
299+ b1 = xb + np . dot ( BHtRinv , yo )
262300
263301 # Use minimization algorithm to minimize cost function:
264302 xa ,ierr = sp .sparse .linalg .cg (A ,b1 ,x0 = xb ,tol = 1e-05 ,maxiter = 1000 )
0 commit comments