|
21 | 21 | # (c) Change the forecast length |
22 | 22 | #----------------------------------------------------------------------- |
23 | 23 |
|
24 | | -#----------------------------------------------------------------------- |
25 | | -# Read the L63 nature run |
26 | | -#----------------------------------------------------------------------- |
27 | | -infile = 'x_nature.pkl' |
28 | | -sv = state_vector() |
29 | | -sv = sv.load(infile) |
30 | | -x_nature = sv.getTrajectory() |
31 | | - |
32 | | -#----------------------------------------------------------------------- |
33 | | -# Initialize the timesteps |
34 | | -#----------------------------------------------------------------------- |
35 | | -t_nature = sv.getTimes() |
36 | | -ainc_step = 1 # (how frequently to perform an analysis) |
37 | | -dtau = (t_nature[ainc_step] - t_nature[0]) |
38 | | -tsteps=10 * ainc_step |
39 | | -dt = dtau/tsteps |
40 | | -maxit,xdim = np.shape(x_nature) |
41 | | - |
42 | | -#----------------------------------------------------------------------- |
43 | | -# Read the L63 observations |
44 | | -#----------------------------------------------------------------------- |
45 | | -infile = 'y_obs.pkl' |
46 | | -obs = obs_data() |
47 | | -obs = obs.load(infile) |
48 | | -y_obs = obs.getVal() |
49 | | -y_pts = obs.getPos() |
50 | | -y_err = obs.getErr() |
51 | | -print('y_obs = ') |
52 | | -print(y_obs[0,:]) |
53 | | -print('y_pts = ') |
54 | | -print(y_pts[0,:]) |
55 | | - |
56 | | -#----------------------------------------------------------------------- |
57 | | -# Initialize the model |
58 | | -#----------------------------------------------------------------------- |
59 | | -l63 = lorenz63() |
60 | | - |
61 | | -#----------------------------------------------------------------------- |
62 | | -# Initialize the da system |
63 | | -#----------------------------------------------------------------------- |
64 | | -das = da_system() |
65 | | -I = np.identity(xdim) |
66 | | - |
67 | | -sigma_b = 0.9 |
68 | | -das.setB(sigma_b**2*I) |
69 | | -print('B = ') |
70 | | -print(das.B) |
71 | | - |
72 | | -sigma_r = 1.0 |
73 | | -das.setR(sigma_r**2*I) |
74 | | -print('R = ') |
75 | | -print(das.R) |
76 | | - |
77 | | -das.setH(I) |
78 | | -print('H = ') |
79 | | -print(das.H) |
80 | | - |
81 | | -#----------------------------------------------------------------------- |
82 | | -# Choose DA method: |
83 | | -#----------------------------------------------------------------------- |
84 | | - |
85 | | -#----------- |
86 | | -# Session 0: |
87 | | -# Test basic functionality |
88 | | -#----------- |
89 | | -#method='skip' |
90 | | - |
91 | | -#----------- |
92 | | -# Session 4: |
93 | | -# Hybrid methods |
94 | | -#----------- |
95 | | -# Hybrid gain |
96 | | -method='Hybrid' |
97 | | - |
98 | | -das.setMethod(method) |
99 | | - |
100 | | -#----------------------------------------------------------------------- |
101 | | -# Initialize the ensemble |
102 | | -#----------------------------------------------------------------------- |
103 | | -xa = sv.x0 |
104 | | -bias_init = 0 |
105 | | -sigma_init = 0.1 |
106 | | -edim = 20 |
107 | | -Xa = das.initEns(xa,mu=bias_init,sigma=sigma_init,edim=edim) |
108 | | - |
109 | | -#----------------------------------------------------------------------- |
110 | | -# Test assimilation methods: |
111 | | -#----------------------------------------------------------------------- |
112 | | -xa_history = np.zeros_like(x_nature) |
113 | | -KH_history = [] |
114 | | -for i in range(0,maxit,ainc_step): |
115 | | - |
116 | | - #---------------------------------------------- |
117 | | - # Run forecast model for this analysis cycle: |
118 | | - #---------------------------------------------- |
119 | | - t = np.arange(t_nature[i],t_nature[i]+dtau+dt,dt) |
120 | | -# print('t = ', t) |
121 | | - # Run the model ensemble forecast |
122 | | - Xf = np.zeros_like(Xa) |
123 | | - for k in range(edim): |
124 | | - xf_4D = l63.run(Xa[:,k].A1,t) |
125 | | - # Get last timestep of the forecast |
126 | | - Xf[:,k] = np.transpose(np.matrix(xf_4D[-1,:])) |
127 | | - |
128 | | - #---------------------------------------------- |
129 | | - # Get the observations for this analysis cycle |
130 | | - #---------------------------------------------- |
131 | | - yo = y_obs[i,:] |
132 | | - |
133 | | - #---------------------------------------------- |
134 | | - # Update the error covariances |
135 | | - #---------------------------------------------- |
136 | | -# das.setB(sigma_b**2*I) |
137 | | -# das.setR(sigma_r**2*I) |
138 | | -# das.setH(I) |
139 | | - |
140 | | - #---------------------------------------------- |
141 | | - # Compute analysis |
142 | | - #---------------------------------------------- |
143 | | - Xa, KH = das.compute_analysis(Xf,yo) |
144 | | - xa = np.mean(Xa,axis=1) |
145 | | - |
146 | | -# print('Xa = ') |
147 | | -# print(Xa) |
148 | | -# print('xa = ') |
149 | | -# print(xa) |
150 | | -# print('xn = ') |
151 | | -# print(x_nature[i,:].T) |
152 | | -# print('KH = ') |
153 | | -# print(KH) |
154 | | - |
155 | | - # Archive the analysis |
156 | | - xa_history[i,:] = xa.T |
157 | | - |
158 | | - # Archive the KH matrix |
159 | | - KH_history.append(KH) |
160 | | - |
161 | | -# if ((i+1)%5==0): |
162 | | -# exit() |
163 | | - |
164 | | -sv.setTrajectory(xa_history) |
165 | | -outfile='x_analysis_'+method+'.pkl' |
166 | | -sv.save(outfile) |
167 | | - |
0 commit comments