lib.data_vector.covariance_matrix.MockCovarianceMatrix¶
- class lib.data_vector.covariance_matrix.MockCovarianceMatrix(covariance, first, second=None, attrs=None)¶
Bases:
lib.data_vector.covariance_matrix.CovarianceMatrixClass representing a covariance matrix built from mocks.
Initialize covariance matrix.
- Parameters
covariance (array) – 2D array holding covariance.
first (DataVector) – Data vector for first coordinate in
covariance.second (DataVector) – Data vector for second coordinate in
covariance.attrs (dict) – Dictionary of other attributes.
Methods
Return shallow copy of
self.deepcopyEstimate covariance matrix from list of data vectors.
Estimate covariance matrix from list of data vector files.
Instantiate and initalize class with state dictionary.
Return correlation matrix.
Return covariance.
Dump header:
Return indices corresponding to input selections (including current view).
Return inverse covariance.
Return standard deviation.
Return title, as
module.class.Return x-coordinates of the data vectors for the two dimensions.
Return mean y-coordinates for the two dimensions.
is_mpi_broadcastis_mpi_gatheredis_mpi_rootis_mpi_scatteredLoad class in numpy binary format from disk.
Load covariance matrix.
Load
CovarianceMatrixfrom disk.log_criticallog_debuglog_errorlog_infolog_warningReset view.
Plot covariance matrix.
Read and decode header.
Decode title
line, splittingmodule.classinto (module,class).Rebin projection of name
proj(list or single projection name).Save class to disk.
Write covariance matrix to disk.
save_txtSet new edges for projection of name
proj(list or single projection name).Set covariance matrix view, i.e. ensemble of selections to apply.
Attributes
Return covariance matrix.
Current view selections.
loggerMPI attributes
mpicommmpirootmpistateReturn shape, i.e. tuple of length along the two dimensions.
Return data vectors for first and second dimensions.
- copy()¶
Return shallow copy of
self.
- property cov¶
Return covariance matrix.
- classmethod from_data(*list_data)¶
Estimate covariance matrix from list of data vectors.
- classmethod from_files(reader, *filenames, **kwargs)¶
Estimate covariance matrix from list of data vector files.
- Parameters
reader (callable) – Function that takes in a file name (string) and
kwargsas input and returns aDataVectorinstance.filenames (list) – List of data vector file names.
kwargs (dict) – Arguments for
reader.
- Returns
covariance
- Return type
- classmethod from_state(state, mpiroot=0, mpicomm=None)¶
Instantiate and initalize class with state dictionary.
- get_corrcoef(*args, **kwargs)¶
Return correlation matrix.
- get_cov(*args, **kwargs)¶
Return covariance.
- get_header_txt(comments='#', ignore_json_errors=True)¶
Dump header:
items in
attrs_kwargs_view(current view selections)
- Parameters
comments (string, default='#') – String to be prepended to the header lines.
ignore_json_errors (bool, default=True) – When trying to dump
attrsusing json, ignore errors.
- Returns
header – List of strings (lines).
- Return type
list
- get_index(*args, permissive=True, concatenate=True, **kwargs)¶
Return indices corresponding to input selections (including current view).
Example
cov.get_index(xlim=(0.1,0.2),proj=0)will return index to obtain covariance of monopole between0.1and0.2.cov.get_index(proj=(0,2))will return indices to obtain covariance of monopole and quadrupole.- Parameters
permissive (bool, default=True) – If
True, include projections which match inputproj(inkwargs) for non-Noneattributes. For example ProjectionName(space=’power’,mode=’multipole’,proj=0) would matchell_0(spacenot specified).concatenate (bool, default=True) – If
True, return index in fullcov. Else, return list of(proj, index, start)tuples, whereprojis projection name, index is the index array (with zero being the first index when no x-selection), and start the first index of the projection in fullcov.args (list) – Dictionary(ies) of selections (i.e. list of
projandxlim) for first and second dimensions.kwargs (dict) – Dictionary of selections (i.e. list of
projandxlim).
- Returns
indices – Indices in full
covfor first and second dimensions, or list of(proj, index, start)tuples.- Return type
list
- get_invcov(*args, block=True, inv=<function inv>, **kwargs)¶
Return inverse covariance.
- get_std(*args, **kwargs)¶
Return standard deviation.
- classmethod get_title_label()¶
Return title, as
module.class.
- get_x(concatenate=False, *args, **kwargs)¶
Return x-coordinates of the data vectors for the two dimensions.
- get_y(concatenate=True, *args, **kwargs)¶
Return mean y-coordinates for the two dimensions.
- property kwview¶
Current view selections.
- classmethod load(filename, mpiroot=0, mpicomm=None)¶
Load class in numpy binary format from disk. If the loaded state contains
__class__and that exists incls._registry, return instance ofcls._registry[__class__](instead ofcls).
- classmethod load_auto(filename, *args, **kwargs)¶
Load covariance matrix.
Note
Returned covariance matrix, if saved with a
CovarianceMatrix-inherited class, will be an instance of that class.- Parameters
filename (string) – File name of covariance matrix. If ends with ‘.txt’, calls
load_txt()Else (numpy binary format), callsload()args (list) – Arguments for load function.
kwargs (dict) – Other arguments for load function.
- classmethod load_txt(filename, data=None, comments='#', usecols=None, skip_rows=0, max_rows=None, mapping_header=None, columns=None, mapping_proj=None, attrs=None, **kwargs)¶
Load
CovarianceMatrixfrom disk.Note
If previously saved using
save_txt(), loading theCovarianceMatrixonly requiresfilename. In this case, the returned instance will be of the class that was used to create it (e.g.MockCovarianceMatrix) - not necessarilyCovarianceMatrix.- Parameters
filename (string) – File name to read in.
data (tuple, DataVector) – Data vector(s) matching the two dimensions of the covariance matrix. If provided, ‘x’ columns of the covariance file are expected to be indices of the data vector.
comments (string, default='#') – Characters used to indicate the start of a comment.
usecols (list, default=None) – Which columns to read, with 0 being the first. If
None, reads all columns. Last column must be the covariance value.skip_rows (int, default=0) – Skip the first
skip_rowslines, including comments.max_rows (int, default=None) – Read
max_rows linesof content afterskip_rowslines. The default is to read all the lines.mapping_header (dict, default=None) – Dictionary holding key:regex mapping or (regex, type) to provide the type. The corresponding values, read in the header, will be saved in the
attrsdictionary.columns (list, default=None) – Column names corresponding to
usecols. Can be a tuple of column lists for two different data vectors. Columns ‘x’ and ‘y’ are used as x- and y-coordinates for each data vector.mapping_proj (dict, list, default=None) – List of projection names (considered of the same size), or dictionary holding a mapping from projection specifier (e.g. ‘ell_0’) to the number of points for this projection (e.g.
{'ell_0':10, 'ell_2':4}for a matrix of total size 14 x 14).attrs (dict, default=None) – Attributes to save in the
attrsdictionary.kwargs (dict) – Other arguments for
BinnedProjection.__init__().
- Returns
data
- Return type
- property mpiattrs¶
MPI attributes
- noview()¶
Reset view.
- plot(style='corr', data_styles=None, **kwargs_style)¶
Plot covariance matrix. See
plotting.MatrixPlotStyle.
- classmethod read_header_txt(file, comments='#', mapping_header=None, pattern_header=None, ignore_json_errors=True)¶
Read and decode header.
- Parameters
file (list, iterator) – List of lines.
comments (string, default='#') – Characters used to indicate the start of a header line.
mapping_header (dict, default=None) – Dictionary holding key:regex mapping or (regex, type) to provide the type. Type can be unspecified (or
None), in which case decoded will be tried with json, a string corresponding to__builtins__, or a callable.pattern_header (string, default=None) – A regex pattern with groups corresponding to key:value.
ignore_json_errors (bool, default=True) – When trying to decode header values using json, ignore errors.
- Returns
attrs
- Return type
dict
- classmethod read_title_label(line)¶
Decode title
line, splittingmodule.classinto (module,class). It loadsmodule, then ifclassis in_registry, return corresponding class. Else returnNone.
- rebin(proj, *args, **kwargs)¶
Rebin projection of name
proj(list or single projection name). SeeBinnedStatistic.rebin()for other arguments.
- save(filename)¶
Save class to disk.
- save_auto(filename, *args, **kwargs)¶
Write covariance matrix to disk.
- Parameters
filename (string) – File name of covariance matrix. If ends with ‘.txt’, calls
save_txt()Else (numpy binary format), callssave()args (list) – Arguments for save function.
kwargs (dict) – Other arguments for save function.
- set_new_edges(proj, *args, **kwargs)¶
Set new edges for projection of name
proj(list or single projection name). SeeBinnedStatistic.set_new_edges()for other arguments.
- property shape¶
Return shape, i.e. tuple of length along the two dimensions.
- view(*args, **kwargs)¶
Set covariance matrix view, i.e. ensemble of selections to apply. This will apply to output of
get_methods.Example
cov.view(xlim=(0.1,0.2)).get_cov(proj=0)will return monopole covariance between0.1and0.2.
- property x¶
Return data vectors for first and second dimensions.