pycif.plugins.controlvects.standard — API reference#

Configuration reference: standard plugin

pycif.plugins.controlvects.standard.build_full_b.build_b_block(controlvect, tracer)[source]#

Build the B matrix block corresponding to ‘tracer’

Parameters:
  • controlvect (ControlVect) – the controlvector plugin

  • tracer (tracer plugin) – the tracer to compute the corresping B block

Returns:

B matrix block

Return type:

2D array

pycif.plugins.controlvects.standard.build_full_b.build_b(controlvect, component=None, parameter=None)[source]#

Compute the full B matrix

Parameters:
  • controlvect (ControlVect) – the controlvector plugin

  • component (str, optional) – only compute B block for a given tracer (‘component’, ‘tracer’). Must be used with the ‘tracer’ argument. Defaults to None.

  • parameter (str, optional) – only compute B block for a given tracer (‘component’, ‘tracer’). Must be used with the ‘component’ argument. Defaults to None.Defaults to None.

Returns:

B matrix

Return type:

2D array

pycif.plugins.controlvects.standard.crop.crop(self, datei, datef)[source]#

Crop the control vector temporally

Parameters:
  • self

  • datei

  • datef

pycif.plugins.controlvects.standard.dump.dump(self, cntrl_file, to_netcdf=False, dir_netcdf=None, ensemble=False, **kwargs)[source]#

Dumps a control vector into a pickle file. Does not save large correlations.

Parameters:
  • self (pycif.utils.classes.controlvects.ControlVect) – the Control Vector to dump

  • cntrl_file (str) – path to the file to dump as pickle

  • to_netcdf (bool) – save to netcdf files if True

  • dir_netcdf (str) – root path for the netcdf directory

pycif.plugins.controlvects.standard.dump.load(self, cntrl_file, component2load=None, tracer2load=None, target_tracer=None, ensemble=False, **kwargs)[source]#
pycif.plugins.controlvects.standard.init_bprod.init_bprod(cntrlv, options={}, **kwargs)[source]#

Initilializes the product of chi by sqrt-B. It allows translating information from the minimization space to the control space. This first needs to initialize correlation matrices

Parameters:

cntrlv (dict) – definition of the control vector

Return type:

updated control vector

pycif.plugins.controlvects.standard.init_structure.init_structure(cntrlv, **kwargs)[source]#

Initializes the prior control vector. Loops over all components and tracers and process temporal and horizontal resolution.

Parameters:
  • cntrlv (Plugin) – definition of the control vector.

  • datei (datetime) – initial date of the inversion window

  • datei – end date of the inversion window

pycif.plugins.controlvects.standard.init_xb.init_xb(cntrlv, trid, **kwargs)[source]#

Initializes the prior control vector. Loops over all components and tracers and process temporal and horizontal resolution.

Parameters:
  • cntrlv (Plugin) – definition of the control vector.

  • datei (datetime) – initial date of the inversion window

  • datei – end date of the inversion window

pycif.plugins.controlvects.standard.sqrtbprod.sqrtbprod(cntrlv, chi, inverse=False, ensemble=False, **kwargs)[source]#

Multiplies Chi by B**0.5.

pycif.plugins.controlvects.standard.sqrtbprod.sqrtbprod_ad(cntrlv, dx, inverse=False, compute_sqrt=True, **kwargs)[source]#
pycif.plugins.controlvects.standard.utils.build_hcorr.build_hcorrelations(hresol, hresoldim, zlat, zlon, lsm, landseamask, sigma_land, sigma_sea, evalmin=0.0, dump=False, dir_dump='', projection='gps', is_lbc=False, crop_chi=False, tracer=None, glob_err=None, use_sparse=False, sparse_crop_threshold=0.1, **kwargs)[source]#

Build horizontal correlation matrix based on distance between grid cells. For cells i and j, the corresponding correlation is: c(i,j) = exp(-dist(i, j) / sigma) sigma depends on the land-sea mask: land and sea cells are assumed un-correlated

Parameters:
  • zlat (np.array) – 2D array of latitudes

  • zlon (np.array) – 2D array of longitudes

  • file_lsm (str) – path to NetCDF file with land-sea mask (grid must be

  • stored (consistent with LMDZ grid); the land-sea mask is assumed to be)

  • 'lsm' (in the varible)

  • sigma_land (float) – decay distance for correlation between land cells

  • sigma_sea (float) – idem for sea

  • evalmin (float) – flag out all eigenvalues below this value. Default

  • 0.5 (is)

  • dump (bool) – dumps computed correlations if True

  • dir_dump (str) – directory where correlation matrices are stored

  • projection (str) – the projection used for the longitudes and latitudes

  • is_lbc (bool) – True if boundary of a 2D domain

  • use_sparse (bool) – True if convert correlation matrix to a sparse matrix

  • sparse_crop_threshold (float) – Threshold on correlation to exclude values from the sparse array

Returns:

  • square roots of eigenvalues

  • eigenvectors

Return type:

tuple with

pycif.plugins.controlvects.standard.utils.build_hcorr.dump_hcorr(hresol, hresoldim, nlon, nlat, sigma_sea, sigma_land, evalues, evectors, dir_dump, is_lbc=False, overwrite=False)[source]#

Dumps eigenvalues and vectors to a binary file. The default file format is: f”{dir_dump}/horcor_{hresol}_{hresoldim}_{nlon}x{nlat}_cs{sigma_sea}_cl{sigma_land}{‘_lbc’ if is_lbc else ‘’}.bin”

pycif.plugins.controlvects.standard.utils.build_hcorr.read_hcorr(hresol, hresoldim, nlon, nlat, sigma_sea, sigma_land, dir_dump, is_lbc=False)[source]#

Reads horizontal correlations from existing text file

Parameters:
  • nlon (ints) – dimensions of the domain

  • nlat (ints) – dimensions of the domain

  • sigma_land (floats) – horizontal correlation distances

  • sigma_sea (floats) – horizontal correlation distances

  • dir_dump (str) – where the horizontal correlations have been stored

pycif.plugins.controlvects.standard.utils.build_lsm.build_lsm(corr, hresol, tracer)[source]#
pycif.plugins.controlvects.standard.utils.build_tcorr.build_tcorrelations(period, subperiod, dates, sigma_t, sigma_type, evalmin=0.5, dump=False, dir_dump='', crop_chi=False, corr_plg=None, tracer=None, **kwargs)[source]#

Build temporal correlation matrix based on timedelta between periods. For period i and j, the corresponding correlation is: c(i,j) = exp(-timedelta(i, j) / sigma)

Parameters:
  • period (int) – period duration

  • subperiod (int) – sub-period duration

  • dates (np.array) – dates sub-dividing the control vector periods

  • sigma_t (float) – decay distance for correlation between periods (in days)

  • evalmin (float) – flag out all eigenvalues below this value. Default is 0.5

  • dump (bool) – dumps computed correlations if True

  • dir_dump (str) – directory where correlation matrices are stored

Returns:

  • square roots of eigenvalues

  • eigenvectors

Return type:

tuple with

pycif.plugins.controlvects.standard.utils.build_tcorr.dump_tcorr(period, subperiod, dates, sigma_t, sigma_type, evalues, evectors, dir_dump, overwrite=False)[source]#

Dumps eigenvalues and vectors to a bin file. The default file format is: f”{dir_dump}/tempcor_{datei.strftime(‘%Y%m%d%H%M’)}_{datef.strftime(‘%Y%m%d%H%M’)}_per{period}-{subperiod}_ct{sigma_t}_{sigma_type}.bin”

Parameters:
  • period (int) – period duration

  • subperiod (int) – subperiod duration

  • dates (np.array) – dates sub-dividing the control vector periods

  • sigma_t (float) – decay distance for correlation between periods (in days)

pycif.plugins.controlvects.standard.utils.build_tcorr.read_tcorr(period, subperiod, dates, sigma_t, sigma_type, dir_dump)[source]#

Reads temporal correlations from existing bin file

Parameters:
  • period (int) – period duration

  • subperiod (int) – subperiod duration

  • dates (np.array) – dates sub-dividing the control vector periods

  • sigma_t (float) – decay distance for correlation between periods (in days)

  • dir_dump (str) – where the horizontal correlations have been stored

pycif.plugins.controlvects.standard.utils.build_vcorr.build_vcorrelations(vresol, nlev, sigma_lev, method, corr_plg=None, tracer=None, dump=False, dir_dump='', evalmin=0, crop_chi=False, **kwargs)[source]#

Build vertical correlation matrix based on distance between levels

Returns:

  • square roots of eigenvalues

  • eigenvectors

Return type:

tuple with

pycif.plugins.controlvects.standard.utils.build_vcorr.dump_vcorr(vresol, nlev, sigma_lev, method, evalues, evectors, dir_dump, overwrite=False)[source]#

Dumps eigenvalues and vectors to a binary file. The default file format is: f”{dir_dump}/vertcor_{vresol}_{nlev}_{method}.bin” )

pycif.plugins.controlvects.standard.utils.build_vcorr.read_vcorr(vresol, nlev, sigma_lev, method, dir_dump)[source]#

Reads vertical correlations from existing text file

pycif.plugins.controlvects.standard.utils.dimensions.hresol2dim(tracer, dom, **kwargs)[source]#

Computes the horizontal size of a control vector from its resolution

Parameters:
  • tracer (Plugin) – definition of the tracer, including the resolution and additional information on the resolution

  • domain (dict) – the domain grid

Returns

int: the size of the control vector for this component

pycif.plugins.controlvects.standard.utils.dimensions.vresol2dim(tracer, dom, **kwargs)[source]#

Computes the horizontal size of a control vector from its resolution

Parameters:
  • tracer (Plugin) – definition of the tracer, including the resolution and additional information on the resolution

  • domain (dict) – the domain grid

Returns

int: the size of the control vector for this component

pycif.plugins.controlvects.standard.utils.get_correlations.get_hcorr(cntrlv, tracer)[source]#
pycif.plugins.controlvects.standard.utils.get_correlations.get_tcorr(cntrlv, tracer, corr)[source]#
pycif.plugins.controlvects.standard.utils.get_correlations.get_vcorr(cntrlv, tracer)[source]#
pycif.plugins.controlvects.standard.utils.get_physical.get_physical(controlvect, tracer, comp, trcr, **kwargs)[source]#
pycif.plugins.controlvects.standard.utils.rescale_std.rescale_std(controlvect, tracer, comp, trcr, glob_err, **kwargs)[source]#

Re-scale errors for a given tracer depending on the specied total budget

Parameters:
  • controlvect – reference control vector

  • tracer – tracer object

  • glob_err – error on global budget

Returns: