:param lag: an integer indicating the time step in the lag order

:param covariancematrix: a list of matrices specifying the covariance distribution to draw from

:rtype: None

Make a new ensemble, the attribute lag refers to the position in the state vector.

Note that lag=1 means an index of 0 in python, hence the notation lag-1 in the indexing below.

The argument is thus referring to the lagged state vector as [1,2,3,4,5,..., nlag]

The covariance list object to be passed holds a list of matrices with a total number of dimensions [nparams, nparams], which is

used to draw ensemblemembers from. Each draw is done on a matrix from the list, to make the computational burden smaller when

the StateVector nparams becomes very large.

"""

try:

importmatplotlib.pyplotasplt

except:

pass

ifnotisinstance(covariancematrixlist,list):

logging.error("The covariance matrix or matrices must be passed as a list of array objects, exiting...")

raiseValueError

# Check dimensions of covariance matrix list, must add up to nparams

dims=1# start from 1.0 to account for the last parameter that scales Ice+Non-optimized, we have no covariance matrix for this though

formatrixincovariancematrixlist:

dims+=matrix.shape[0]

ifdims!=self.nparams:

logging.error("The total dimension of the covariance matrices passed (%d) does not add up to the prescribed nparams (%d), exiting..."%(dims,self.nparams))

raiseValueError

# Loop over list if identity matrices and create a matrix of (nparams,nmembers) with the deviations