| |
- ens_stat_cl
class ens_stat_cl |
|
Class for state vector used to assimilate observations
Members:
-------------------------------------------------------------
1. attr_dict:<dict>: attributes
2. step_tag_lst:<list>: ID for run step
# I. variables at current time window
3. wnd_mean_x0:<array, (wnd_nx)>: prior coefficient values for lag window
4. wnd_mean_x:<array, (wnd_nx)>: posterior (prior) coefficient values for lag window
5. wnd_dx:<array, (wnd_nx, wnd_ne)>: perturbations ensemble for coefficients
6. wnd_inc_m:<array, (wnd_ne>: increment matrix for ETKF data assimilation
7. wnd_xtm: <array, (wnd_nx, wnd_ne)>: transform matrix for ETKF data assimilation
8. wnd_xinc: <array, (wnd_nx)>: increment for ETKF data assimilation
# II: variables for the step
9. inc_m:<array, (wnd_nx)>: increment matrix for current step
10. xtm: <array, (wnd_nx, wnd_ne)>: transform matrix for current step
11. xinc: <array, (wnd_nx)>: increment for ETKF data assimilation
# III: list of objects:
12. x2flux_lst: <list, t:obj>: class for projecting x back to flux
13. wnd_mean_x_lst:<list, t:array>: list of wnd_mean_x at beginning of each step
14. wnd_mean_x0_lst:<list, t:array>: list of wnd_mean_x0 at beginning of each step
15. wnd_xtm_lst:<list, t:array>: list of wnd_xtm at beginning of each step
16. wnd_dx_lst:<list, t:array>: list of wnd_dx at beginning of each step
# IV: Settings
17. cur_yyyy:<int>: starting year
18. cur_mm:<int>: starting month
19. cur_dd:<int>: starting dd
20. cur_doy:<int>: starting doy
21 .next_yyyy:<int>: next year
22. max_doy:<int>: max doy
23. cur_step:<int>: time step
24. wnd_step:<int>: step inside window
25. max_step:<int>: maximum step
26. lag_window:<int>: length of lag_window (max steps inside the window)
# V: time and size
27. tau_st_lst:<list, t:float>: starting time
28. tau_end_lst:<list, t:float>: end time
29. x_st_lst:<list, t:int>: starting position of the current period when it becomes the first of the window
30. x_end_lst: <list, t:int>: ending position of the current period when it becomes the first of the window
31. en_st_lst:<list, t:int>: ensemble starting position of the current period when it becomes the first of the window
32. en_end_lst: <list, t:int>: ensemble ending position of the current period when it becomes the first of the window
33. nbias:<int>: size of bias correction terms
34. mod_bias:<array, (nbias)>: first guess of bias correction terms
35. bias_err:<array, (nbias)>: uncertainty of bias correction terms
.
# VI scaling matrix (or spatial correction)
36. wnd_scale_m:<array, (wnd_ne, wnd_ne)>:
# VII: # temporal correlation
37. use_tcor:<T/F>: whether to include temporal correlation
38. tcor_len:<int>: length of temporal correlation
39. tcor_factor:<float>: scaling factor for temporal correlation
40. tcor_inc_m:<wnd_ne, wnd_ne>: increment matrix due to last temporal correlation
41. wnd_tcor_inc_m::<wnd_ne, wnd_ne>: increment matrix due to all temporal correlations inside the window
42. tcor_m:<wnd_ne, wnd_ne>: correlation matrix due to last temporal correlation
43. wnd_tcor_m:<wnd_ne, wnd_ne>: correlation matrix due to temporal correlations inside the window
44. wnd_nx, wnd_ne:<int>: size of self.wnd_dx
Functions
==========================================================
1. __init__: initialization
2. join_vector: joint two arrays together
3. fifo_vector: push out first part of long array
4. join_matrix: join two matrices along diagonal together
5. fifo_matrix: push out first part of a matrix
6. construct_tcor_matrix: Create temporal correlation matrix
7. add_new_x_to_window: Add new apriori to assimilation window
8. init_x_dx: initializing for first time period
9. append_x_dx: Append prior variable to the end of lag window
10. do_assim: assimilate observations and update state vector
11. vf_construct_aprior: construct x and dx
12. shift_y_dy: update model mean and model uncertainty in observation space
13. fifo_x_dx: Append variable to the end, and remove the first one from window
14. convolve_y_dy: tranfer model mean_y and transform dy to reflect changes on mean_x and dx.
Notes:
==============================================================
1. A sequential data assimilation approach is assumed in this module. y and dy must be kept (by convolve_y_dy_
must be consistent with x and dx (and wnd_xtm) |
|
Methods defined here:
- __init__(self, yyyy_st, mm_st, dd_st, max_step, lag_window, mod_bias=[], mod_bias_err=[], use_tcor=False, tcor_len=720.0, tcor_factor=0.5, xnorm=1.0, **keywords)
- Inputs:
=========================================
1. yyyy_st:<int>: starting year
2. mm_st:<int>: starting month
3. dd_st:<int>: starting day
4. max_step:<int>: maximum step
5. lag_window:<int>: steps inside the lag window
6. mod_bias:<array/list>: bias to be estimated
7. mod_bias_err:<array/list>: mod_bias_uncertainty
8. use_tcor:<T/F>: whether to turn on temporal correlation
9. tcor_len:<float>: temporal correlation length
10. tcor_factor:<float>: scaling factor for temporal correlation
11. keyword:<dict>: attributes
- add_new_x_to_window(self, apr_x, apr_dx, tau_st, tau_end, step_tag='new', enlarge_factor=1.0, scale_m=None, lag_window=None, cl_x2flux=None)
- Add new apriori to assimilation window
Inputs:
============================================
1. apr_x:<array>: prior x
2. apr_dx:<array, (nx, ne)>: prior dx
3. tau_st, tau_end:<float>: start and end time
3. enlarge_factor:<float>: factor used to enlarge xtm
4. scale_m:<array, (ne, ne)>: matrix for scaling dx,
which can be spatial correlation
between 'basis functions'
5. lag_window:<integer>: lag window length
6. cl_x2flux:<x2flux_cl>: project coefficient back to flux
Returns:
============================================
1. wnd_nx:<int>: size of x inside window
2. wnd_ne:<int>: size of ensemble inside window
Notes:
--------------------------------------------
1. temporal correlation is assumed to be in the shape of:
|I 0 I |
|TS*TC, TS*I |
TC is the correlation matrix, TS is scaling matrix.
- append_x_dx(self, mean_x, dx, tau_st, tau_end, enlarge_factor, scale_m)
- Append variable to the end
It will be called when wnd_step<lag_window
1. Inputs:
-----------------------------------------------------
1. mean_x:<array, (nx)>: mean_x
2. dx:<array, (nx, ne)>: 'prior' dx
3. tau_st, tau_end:<float>: start and end time
4. enlarge_factor:<float>: factor used to enlarge xtm
5. scale_m:<array, (ne, ne)>: matrix for scaling dx, which can be spatial correlation
between regions
Returns:
-----------------------------------------------------
1. shape(self.wnd_dx):<array, (wnd_nx, wnd_ne)>: shape of the dx
- construct_tcor_matrix(self, dx, tau_st, first_shift=1, use_wnd_inc_m=True)
- Create temporal correlation matrix
Inputs:
---------------------------------
1. dx:<array, (nx,ne)>: sampling x
2. tau_st:<float>: starting time
3. keep_first:<int>: if first_shift is the starting step inside (previous) window
4. use_wnd_inc_m:<T/F>: if True, wnd_inc_m will be considered to be able to reproduce
mean_x-mean_x0=self.wnd_dx*wnd_inc_m
returns:
--------------------------------------
1. tcor_m:<array, (ne, wnd_ne-first_ne)>: temporal correlation matrix
2. tcor_scale:<array, (ne, ne)>: scaling matrix
3. tcor_inc_m:<array, (ne)>: tmporal correlation increment
Notes:
1. this functions are only approximations
Temporal correlation between old (A) and new (B) is in the form of
| A 0 | | A 0 | | I 0 |
| B*TS*TC B*TS |------------> | 0 B | X | TS*TC TS |
TS=tcor_scale: re-scaling (ne, ne)
TC=tcor_m: correlation matrix (ne, old_ne)
tcor_inc_m: increment matrix due to correlation:
tcor_inc_m=TC*inc_m(A). inc_m(A) is the increment matrix for old A
tcor_x_inc=B*TS*tcor_inc_m
- convolve_y_dy(self, mean_y, dy, use_wnd_xtm=1, use_wnd_inc_m=0)
- tranfer model mean_y and transform dy to reflect changes on mean_x and dx.
Inputs:
-------------------------------------
1. mean_y: <array, (ny (nobs),) >: mean model observation
2. dy: <array, (ny, ne)>: aprior dy (before any scaling)
3. use_wnd_xtm:<T/F>: if ture wnd_xtm will be applied to dy
(means that no such transform be made before)
4. use_wnd_inc_m:<T/F>: if ture (no adjust made to mean_y before)
Returns
sdy:<array, (ny, ne)>: sdy if the dy matrix transformed
- do_assim(self, dy, mean_y, yobs, yerr, full_r=None, use_sparse=True)
- assimilating observation and update state vector
Inputs:
------------------------------------------------
1. dy:<array, (nobs(ny), ne)>: ensemble for model
observation perturbation. (see Note 1)
2. mean_y:<array, (ny)>: model observations (see Note 2)
3. yobs: <array, (ny)>: observations
4. yerr: <array, (ny)>: observation error^2
5. full_r: <array, (ny, ny)>: observation error covariance
6. use_sparse:<T/F>: if True etkf_cor will be used.
Returns:
-----------------------------------------------------
1. xinc:<array, (nx)>: increment from current observations
2. sum_inc_m:<array, (ne, nx)>: increment matrix (associated with self.wnd_dx)
3. inc_m:<array, (ne, nx)>: increment matrix (associated with self.wnd_dx*xtm(old))
4. xtm:<array, (ne, ne)>: transform matrix.
Notes:
--------------------------------------------------
1. It is assumed shift y_dy has been called so that
dy=H(self.wnd_dx*self.wnd_xtm), and mean_y=H(self.wnd_mean_x)
2. self.wnd_dx=self.wnd_x0*self.wnd_scale_m*self.wnd_tcor_m
self_wnd_dx0 is a quasi-diagonal matrix
- fifo_matrix(self, x1, x2, retain_xid, retain_yid)
- relpace the first part of matrix
Inputs:
---------------------------------
1. x1:<array, (old_nx, old_ny)>: matrix one
2. x2:<array, (nx,ny)>: matrix two
3. retain_xid:<array, (nsel_x)>: x index for values to be kept
4. retain_yid:<array, (nsel_y)>: y index for values to be kept
Returns
--------------------------------
1. new_x:<array, (nse_x+nx, nsel_y+ny)>: jointed matrix along diagonal
- fifo_vector(self, x1, x2, retain_idx)
- replace first parts of x1
Inputs:
---------------------------------
1. x1:<array, (old_nx)>: array one
2. x2:<array, (nx)>: array two
3. retain_idx:<array, (nsel)>: index for elements to be retained
Returns
--------------------------------
1. new_x:<array, (nse+nx)>: jointed array
- fifo_x_dx(self, mean_x, dx, tau_st, tau_end, enlarge_factor, scale_m)
- Append variable to the end, and remove the first one from window
It will be called when wnd_step<lag_window
1. Inputs:
-----------------------------------------------------
1. mean_x:<array, (nx)>: mean_x
2. dx:<array, (nx, ne)>: 'prior' dx
3. enlarge_factor:<float>: factor used to enlarge xtm
4. scale_m:<array, (ne, ne)>: matrix for scaling dx, which can be spatial correlation
between regions
5. cl_x2flux:<x2flux_cl>: project coefficient back to flux
- init_x_dx(self, mean_x, dx, tau_st, tau_end, enlarge_factor, scale_m)
- The first time period o be included
It will be called when wnd_step<lag_window
1. Inputs:
-----------------------------------------------------
1. mean_x:<array, (nx)>: prior mean_x
2. dx:<array, (nx, ne)>: 'prior' dx
3. enlarge_factor:<float>: factor used to enlarge xtm
4. scale_m:<array, (ne, ne)>: matrix for scaling dx, which can be spatial correlation
between regions
- join_matrix(self, x1, x2)
- join two matrix along diagonal together
Inputs:
---------------------------------
1. x1:<array, (old_nx, old_ny)>: matrix one
2. x2:<array, (nx,ny)>: matrix two
Returns
--------------------------------
1. new_x:<array, (old_nx+nx, old_ny+ny)>: jointed matrix along diagonal
- join_vector(self, x1, x2)
- joint two arrays together
Inputs:
---------------------------------
1. x1:<array, (old_nx)>: array one
2. x2:<array, (nx)>: array two
4 Returns
--------------------------------
1. new_x:<array, (old_nx+nx)>: jointed array
- vf_construct_aprior(self, nx, ne, cfg=None)
- Construction prior and error
Inputs:
-------------------------------------------------
1. nx:<int>: size of x
2. ne:<int>: size of ensemble
3. cfg:<menu>: configuration
Returns:
-------------------------------------------------
1. x:<array, (nx)>: aprior
2. dx:<array, (nx, ne)>:
| |