Skip to content

Commit 8af51c0

Browse files
System AdministratorSystem Administrator
authored andcommitted
updates for configuration
1 parent f4296be commit 8af51c0

9 files changed

+318
-32
lines changed

class_da_system.py

Lines changed: 121 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def initEns(self,x0,mu=0,sigma=0.1,edim=4):
165165
# print(Xrand)
166166
# Remove mean to make sure it is properly centered at 0
167167
# (add bias if included)
168-
rand_mean = np.mean(Xrand,axis=1) + mu
168+
rand_mean = np.mean(Xrand,axis=1) - mu
169169
# print('rand_mean = ')
170170
# print(rand_mean)
171171
rmat = np.matlib.repmat(rand_mean,1,edim)
@@ -176,7 +176,7 @@ def initEns(self,x0,mu=0,sigma=0.1,edim=4):
176176
rmat = np.matlib.repmat(x0, 1, edim)
177177
# print('rmat = ')
178178
# print(rmat)
179-
X0 = np.matrix(rmat + Xrand)
179+
X0 = np.matrix(Xrand + rmat)
180180
return X0
181181

182182
# def init4D(self):
@@ -276,6 +276,7 @@ def _3DVar(self,xb,yo):
276276
def ETKF(self,Xb,yo):
277277
#---------------------------------------------------------------------------------------------------
278278
# Use ensemble of states to estimate background error covariance
279+
verbose=False
279280

280281
# Make sure inputs are matrix and column vector types
281282
Xb = np.matrix(Xb)
@@ -291,47 +292,140 @@ def ETKF(self,Xb,yo):
291292
Hl = self.H
292293
Yb = np.matrix(np.zeros([ydim,edim]))
293294
for i in range(edim):
294-
Yb[:,i] = Hl*Xb[:,i]
295+
Yb[:,i] = np.dot(Hl,Xb[:,i])
295296

296297
# Convert ensemble members to perturbations
297298
xm = np.mean(Xb,axis=1)
298-
Xb = Xb - np.matlib.repmat(xm, 1, edim)
299299
ym = np.mean(Yb,axis=1)
300+
Xb = Xb - np.matlib.repmat(xm, 1, edim)
300301
Yb = Yb - np.matlib.repmat(ym, 1, edim)
301302

302303
# Compute R^{-1}
303304
R = self.R
304305
Rinv = np.linalg.inv(R)
305306

306307
# Compute the weights
307-
Ybt = Yb.T
308-
C = Ybt*Rinv
309308

309+
#----
310+
# stage(4) Now do computations for lxk Yb matrix
311+
# Compute Yb^T*R^(-1)
312+
#----
313+
Ybt = np.transpose(Yb)
314+
C = np.dot(Ybt,Rinv)
315+
316+
if verbose:
317+
print ('C = ')
318+
print (C)
319+
320+
#----
321+
# stage(5) Compute eigenvalue decomposition for Pa
322+
# Pa = [(k-1)I/rho + C*Yb]^(-1)
323+
#----
310324
I = np.identity(edim)
311-
rho = 1.0
312-
eigArg = (edim-1)*I/rho + C*Yb
325+
rho = 1.05 #1.0
326+
eigArg = (edim-1)*I/rho + np.dot(C,Yb)
327+
313328
lamda,P = np.linalg.eigh(eigArg)
329+
330+
if verbose:
331+
print ('lamda = ')
332+
print (lamda)
333+
print ('P = ')
334+
print (P)
335+
314336
Linv = np.diag(1.0/lamda)
315-
PLinv = P*Linv
316-
Pt = P.T
317-
Pa = PLinv*Pt
318337

338+
if verbose:
339+
print ('Linv = ')
340+
print (Linv)
341+
342+
PLinv = np.dot(P,Linv)
343+
344+
if verbose:
345+
print ('PLinv = ')
346+
print (PLinv)
347+
348+
Pt = np.transpose(P)
349+
350+
if verbose:
351+
print ('Pt = ')
352+
print (Pt)
353+
354+
Pa = np.dot(PLinv, Pt)
355+
356+
if verbose:
357+
print ('Pa = ')
358+
print (Pa)
359+
360+
#----
361+
# stage(6) Compute matrix square root
362+
# Wa = [(k-1)Pa]1/2
363+
#----
319364
Linvsqrt = np.diag(1/np.sqrt(lamda))
320-
PLinvsqrt = P*Linvsqrt
321-
Wa = np.sqrt(edim-1) * PLinvsqrt*Pt
322365

323-
d = yo - ym
324-
wm = Pa*(C*d)
366+
if verbose:
367+
print ('Linvsqrt = ')
368+
print (Linvsqrt)
369+
370+
PLinvsqrt = np.dot(P,Linvsqrt)
371+
372+
if verbose:
373+
print ('PLinvsqrt = ')
374+
print (PLinvsqrt)
375+
376+
Wa = np.sqrt((edim-1)) * np.dot(PLinvsqrt,Pt)
377+
378+
if verbose:
379+
print ('Wa = ')
380+
print (Wa)
381+
382+
#----
383+
# stage(7) Transform back
384+
# Compute the mean update
385+
# Compute wabar = Pa*C*(yo-ybbar) and add it to each column of Wa
386+
#----
387+
d = yo-ym
388+
Cd = np.dot(C,d)
389+
390+
if verbose:
391+
print ('Cd = ')
392+
print (Cd)
393+
394+
wm = np.dot(Pa,Cd) #k x 1
395+
396+
if verbose:
397+
print ('wm = ')
398+
print (wm)
399+
400+
# Add the same mean vector wm to each column
401+
# Wa = Wa + wm[:,np.newaxis] #STEVE: make use of python broadcasting to add same vector to each column
325402
Wa = Wa + np.matlib.repmat(wm, 1, edim)
326403

404+
if verbose:
405+
print ('Wa = ')
406+
print (Wa)
407+
408+
#----
409+
# stage(8)
410+
# Compute the perturbation update
411+
# Multiply Xb (perturbations) by each wa(i) and add xbbar
412+
#----
413+
327414
# Add the same mean vector wm to each column
328-
Xa = Xb*Wa + np.matlib.repmat(xm, 1, edim)
415+
# Xa = np.dot(Xb,Wa) + xm[:,np.newaxis]
416+
Xa = np.dot(Xb,Wa) + np.matlib.repmat(xm, 1, edim)
417+
418+
if verbose:
419+
print ('Xa = ')
420+
print (Xa)
329421

330422
# Compute KH:
331-
IpYbtRinvYb = ((edim-1)/rho)*I + Ybt*Rinv*Yb
332-
IpYbtRinvYb_inv = IpYbtRinvYb.I
333-
K = Xb*IpYbtRinvYb_inv*Ybt*Rinv
334-
KH = K*Hl
423+
RinvYb = np.dot(Rinv,Yb)
424+
IpYbtRinvYb = ((edim-1)/rho)*I + np.dot(Ybt,RinvYb)
425+
IpYbtRinvYb_inv = np.linalg.inv(IpYbtRinvYb)
426+
YbtRinv = np.dot(Ybt,Rinv)
427+
K = np.dot( Xb, np.dot(IpYbtRinvYb_inv,YbtRinv) )
428+
KH = np.dot(K,Hl)
335429

336430
return Xa, KH
337431

@@ -350,19 +444,23 @@ def ETKF(self,Xb,yo):
350444
# R_4d = self.R ! may need list of R matrices if observations are non-uniform over time
351445
# H_4d = self.H ! may need list of H matrices if observations are non-uniform over time
352446
# M_4d = self.M ! input list of TLMs for each timestep
447+
#
448+
# (work in progress)
353449

354450

355451
#---------------------------------------------------------------------------------------------------
356452
# def _4DEnVar(self,Xb_4d,yo_4d):
357453
#---------------------------------------------------------------------------------------------------
358454
# Use ensemble of states over a time window to estimate temporal correlations
359-
455+
#
456+
# (work in progress)
360457

361458
#---------------------------------------------------------------------------------------------------
362459
# def _4DETKF(self,Xb_4d,yo_4d):
363460
#---------------------------------------------------------------------------------------------------
364461
# Use ensemble of states over a time window to estimate temporal correlations
365-
462+
#
463+
# (work in progress)
366464

367465
#---------------------------------------------------------------------------------------------------
368466
def PF(self,Xb,yo):
@@ -429,7 +527,7 @@ def PF(self,Xb,yo):
429527
if (Neff < edim/2):
430528
# Apply additive inflation (remove sample mean)
431529
const=1.0
432-
rmat=np.rand.randn(xdim,edim) * np.matlib.repmat(np.std(Xa,axis=1),1,edim) * const;
530+
rmat=np.random.randn(xdim,edim) * np.matlib.repmat(np.std(Xa,axis=1),1,edim) * const;
433531
Xa = Xa + rmat - np.matlib.repmat(np.mean(rmat,axis=1),1,edim);
434532

435533
KH = [0] # dummy output

class_lorenz63.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,11 @@ def plot_lines_and_points(self,states,points,cvec,outfile='l63-3d',plot_title='L
290290
mode='lines-and-markers',
291291
marker=dict(
292292
size=1,
293-
color=cvec,
294-
colorscale='Viridis',
293+
color='rgb(0,0,0)',
295294
opacity=0.5,
296295
),
297296
line=dict(
298-
color=cvec,
297+
color='rgb(0,0,0)',
299298
width=1
300299
)
301300
)
@@ -304,10 +303,11 @@ def plot_lines_and_points(self,states,points,cvec,outfile='l63-3d',plot_title='L
304303
x=xp, y=yp, z=zp,
305304
mode='markers',
306305
marker=dict(
307-
size=3,
306+
size=2,
308307
color=cvec,
309308
colorscale='Viridis',
310-
symbol='circle-open',
309+
opacity=0.5,
310+
# symbol='circle-open',
311311
),
312312
# line=dict(
313313
# color=cvec,
@@ -318,7 +318,7 @@ def plot_lines_and_points(self,states,points,cvec,outfile='l63-3d',plot_title='L
318318
data = [trace0, trace1]
319319

320320
layout = dict(
321-
width=800,
321+
width=1200,
322322
height=700,
323323
autosize=False,
324324
title=plot_title,

generate_analysis_3dEns.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,42 @@
7373
# EnKF
7474
#method='ETKF'
7575

76+
#-----------
77+
# Hybrid methods
78+
#-----------
79+
#method='Hybrid'
80+
7681
#das.setMethod(method)
7782

7883
#-----------------------------------------------------------------------
7984
# Initialize the ensemble
8085
#-----------------------------------------------------------------------
8186
xa = sv.x0
87+
edim = 20 #3 #20
8288
bias_init = 0
8389
sigma_init = 0.1
84-
edim = 3 #20
8590
Xa = das.initEns(xa,mu=bias_init,sigma=sigma_init,edim=edim)
8691

92+
print('ensemble dimension = ')
93+
print(edim)
94+
print('initial bias = ')
95+
print(bias_init)
96+
print('initial standard deviation = ')
97+
print(sigma_init)
98+
print('X0 = ')
99+
print(Xa)
100+
101+
#exit()
102+
87103
#-----------------------------------------------------------------------
88104
# Conduct data assimilation process
89105
#-----------------------------------------------------------------------
90106
#
91107
xa = sv.x0
92108
xa_history = np.zeros_like(x_nature)
109+
xa_history[:] = np.nan
93110
KH_history = []
111+
ii=0
94112
for i in range(0,maxit-acyc_step,acyc_step):
95113

96114
#----------------------------------------------
@@ -128,6 +146,14 @@
128146
xa = np.mean(Xa,axis=1).T
129147
# print('xa = ')
130148
# print(xa)
149+
150+
# print('x_nature[i+acyc_step,:] = ')
151+
# print(x_nature[i+acyc_step,:,])
152+
153+
ii=ii+1
154+
# if (ii>4):
155+
# exit()
156+
131157
# print('KH = ')
132158
# print(KH)
133159

generate_analysis_4dDet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# You're on your own.
2+
print('Good luck.')

generate_analysis_4dEns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# You're on your own.
2+
print('Strength and honor')

0 commit comments

Comments
 (0)