tjpcov.covariance_builder#

Module Contents#

Classes#

CovarianceBuilder

Base class in charge of building the full covariance.

CovarianceFourier

Parent class for Cell x Cell covariances in Fourier space.

CovarianceReal

Parent class for xi x xi covariances in Real space.

CovarianceProjectedReal

Parent class for xi x xi covariances in Real space.

class tjpcov.covariance_builder.CovarianceBuilder(config)[source]#

Bases: abc.ABC

Base class in charge of building the full covariance.

Class in charge of building the full covariance needed for the sacc file from individual covariance blocks. This is meant to be used as a parent class and the child classes would actually implement the actual computation of the blocks.

Init the base class with a config file or dictionary.

Parameters:

config (dict or str) – If dict, it returns the configuration dictionary directly. If string, it asumes a YAML file and parses it.

property covariance_block_data_type: str[source]#

The covariance block data type for your builder.

Returns:

Covariance block sacc data type

Return type:

str

property _tracer_types[source]#

Tuple with the tracer types (e.g. (“cl”, “cl”)).

This is used to decide if the block covariance should be computed or is zero. For instance, if the class is meant to produce the covariance for Cells and the tracer types are clusters, the class should return 0.

_split_tasks_by_rank(tasks)[source]#

Yield the tasks corresponding to the given process.

Iterate through a list of items, yielding the ones this process is responsible for. The tasks are allocated in a round-robin way.

Parameters:

tasks (iterable) – Tasks to split up

Returns:

Tasks associated to this process

Return type:

generator

_build_matrix_from_blocks(blocks, tracers_cov)[source]#

Build full matrix from blocks.

Parameters:
  • blocks (list) – List of blocks

  • tracers_cov (list) – List of tracer combinations corresponding to each block in blocks. They must have the same order

Returns:

Covariance matrix for all combinations in the sacc file.

Return type:

array

_compute_all_blocks(**kwargs)[source]#

Compute all the independent covariance blocks.

Parameters:

**kwargs – Arguments to pass to the get_covariance_block method. These will depend on the covariance type requested.

Returns:

  • blocks (list): List of all the independent super sample covariance blocks.

  • tracer_blocks (list): List of all tracer combinations in order as the blocks.

Return type:

tuple

get_cosmology()[source]#

Return a CCL Cosmology instance.

The Cosmology is generated with the information passed in the configuration file in the “cosmo” section of “tjpcov”. This can be a file path to a yaml, pickle object or “set” to read the parameters from the “parameters” section.

Returns:

pyccl.Cosmology instance

abstract get_covariance_block(tracer_comb1, tracer_comb2, **kwargs)[source]#

Return the covariance block for the two pair of tracers.

This is what you would get from an external code and could contain data types not present in the sacc file. For Fourier space covariances, we assume the same order as in NaMaster.

Parameters:
  • tracer_comb1 (list) – List of the pair of tracer names of C_ell^1

  • tracer_comb2 (list) – List of the pair of tracer names of C_ell^2

  • **kwargs – extra possible arguments

Returns:

Covariance block

Return type:

array

abstract _get_covariance_block_for_sacc(tracer_comb1, tracer_comb2, **kwargs)[source]#

Return the covariance block as needed for the sacc file.

For instance, if the sacc file does not contain B-modes, the covariance block would only have the EE-EE component). Furthermore, the ordering must be the same as in the sacc file.

Parameters:
  • tracer_comb1 (list) – List of the pair of tracer names of C_ell^1

  • tracer_comb2 (list) – List of the pair of tracer names of C_ell^2

  • **kwargs – Arguments accepted by get_covariance_block

Returns:

Covariance block

Return type:

array

get_covariance_block_for_sacc(tracer_comb1, tracer_comb2, **kwargs)[source]#

Return the covariance block as needed for the sacc file.

For instance, if the sacc file does not contain B-modes, the covariance block would only have the EE-EE component). Furthermore, the ordering must be the same as in the sacc file.

This function returns 0 if the covariance class is not meant to produce covariances for the given tracer combination.

Parameters:
  • tracer_comb1 (list) – List of the pair of tracer names of C_ell^1

  • tracer_comb2 (list) – List of the pair of tracer names of C_ell^2

  • **kwargs – Arguments accepted by get_covariance_block

Returns:

Covariance block

Return type:

array

get_covariance(**kwargs)[source]#

Return the full covariance.

Parameters:

**kwargs – Arguments to pass to _compute_all_blocks.

Returns:

Full covariance

Return type:

array

get_list_of_tracers_for_cov()[source]#

Return the covariance independent tracers combinations.

Returns:

List of independent tracers combinations.

Return type:

list of str

get_mask_names_dict(tracer_names)[source]#

Return a dictionary with the mask names for the given tracers.

Parameters:

tracer_names (dict) – Dictionary of the tracer names of the same form as mask_name. It has to be given as {1: name1, 2: name2, 3: name3, 4: name4}, where 12 and 34 are the pair of tracers that go into the first and second Cell you are computing the covariance for; i.e. <Cell^12 Cell^34>.

Returns:

Dictionary with the mask names assotiated to the fields to be correlated.

Return type:

dict

get_masks_dict(tracer_names, cache=None)[source]#

Return a dictionary with the masks assotiated to the given tracers.

Parameters:
  • tracer_names (dict) – Dictionary of the tracer names of the same form as mask_name. It has to be given as {1: name1, 2: name2, 3: name3, 4: name4}, where 12 and 34 are the pair of tracers that go into the first and second Cell you are computing the covariance for; i.e. <Cell^12 Cell^34>.

  • cache (dict, optional) – Dictionary with cached variables. It will use the cached masks if found. The keys must be ‘m1’, ‘m2’, ‘m3’ or ‘m4’ and the values the loaded maps.

Returns:

Dictionary with the masks assotiated to the fields to be correlated.

Return type:

dict

get_nbpw()[source]#

Return the number of bandpowers in which the data has been binned.

Returns:

Number of bandpowers; i.e. ell_effective.size

Return type:

int

get_tracers_spin_dict(tracer_names)[source]#

Return a dictionary with the spins assotiated to the given tracers.

Parameters:

tracer_names (dict) – Dictionary of the tracer names of the same form as mask_name. It has to be given as {1: name1, 2: name2, 3: name3, 4: name4}, where 12 and 34 are the pair of tracers that go into the first and second Cell you are computing the covariance for; i.e. <Cell^12 Cell^34>.

Returns:

Dictionary with the spins assotiated to the fields to be correlated.

Return type:

dict

get_tracer_comb_spin(tracer_comb)[source]#

Return the spins of a pair of tracers.

Parameters:

tracer_comb (tuple) – List or tuple of a pair of tracer names

Returns:

  • s1 (int): Spin of the first tracer

  • s2 (int): Spin of the second tracer

Return type:

tuple

get_tracer_spin(tracer)[source]#

Return the spin of a given tracer.

Parameters:
  • sacc_data (Sacc) – Data Sacc instance

  • tracer (str) – Tracer name

Returns:

Spin of the given tracer

Return type:

int

get_tracer_nmaps(tracer)[source]#

Return the number of maps assotiated to the given tracer.

Parameters:
  • sacc_data (Sacc) – Data Sacc instance

  • tracer (str) – Tracer name

Returns:

Number of maps assotiated to the tracer.

Return type:

int

get_tracer_comb_data_types(tracer_comb)[source]#

Return the tracer data types associated to the given tracers.

Parameters:

tracer_comb (list) – List of a pair of tracer names in the sacc file

Returns:

List of data types associated to the given tracer pair.

Return type:

list

class tjpcov.covariance_builder.CovarianceFourier(config)[source]#

Bases: CovarianceBuilder

Parent class for Cell x Cell covariances in Fourier space.

This has all the methods common to all the Fourier covariance calculations. The child classes will actually implement the actual computation of the blocks.

Init the base class with a config file or dictionary.

Parameters:

config (dict or str) – If dict, it returns the configuration dictionary directly. If string, it asumes a YAML file and parses it.

space_type = 'Fourier'[source]#
_tracer_types = ('cl', 'cl')[source]#
_get_covariance_block_for_sacc(tracer_comb1, tracer_comb2, **kwargs)[source]#

Return the covariance block as needed for the sacc file.

For instance, if the sacc file does not contain B-modes, the covariance block would only have the EE-EE component). Furthermore, the ordering must be the same as in the sacc file.

Parameters:
  • 1 (tracer_comb) – List of the pair of tracer names of C_ell^1

  • 2 (tracer_comb) – List of the pair of tracer names of C_ell^2

  • **kwargs – Arguments accepted by get_covariance_block

Returns:

Covariance matrix for a pair of C_ell for the data types considered in the sacc file.

Return type:

array

get_datatypes_from_ncell(ncell)[source]#

Return the datatypes (e.g cl_00) for a the number of cells.

Parameters:

ncell (int) – Number of Cell for a pair of tracers

Returns:

List of data types assotiated to the given degrees of freedom

Return type:

list

get_ell_eff()[source]#

Return the effective ell in the sacc file.

It assume that all of them have the same effective ell (true with current TXPipe implementation).

Parameters:

sacc_data (sacc.sacc.Sacc) – Data Sacc instance

Returns:

Array with the effective ell in the sacc file.

Return type:

array

get_sacc_with_concise_dtypes()[source]#

Return a copy of the sacc file with concise data types.

Returns:

Data Sacc instance with concise data types

Return type:

sacc.sacc.Sacc

get_tracer_comb_ncell(tracer_comb, independent=False)[source]#

Return the number of Cell for a pair of tracers.

For instance, for shear-shear, ncell = 4: EE, EB, BE, BB.

Parameters:
  • sacc_data (Sacc) – Data Sacc instance

  • tracer_comb (tuple) – List or tuple of a pair of tracer names

  • independent (bool, optional) – If True, just return the number of independent Cell.

Returns:

Number of Cell for the pair of tracers given

Return type:

int

get_tracer_info(return_noise_coupled=False)[source]#

Returns CCL tracer objects and the noise for all the tracers.

This is done based on the specifications given in the configuration file.

Parameters:

return_noise_coupled (bool, optional) – If True, also return tracers_Noise_coupled. Default False.

Returns:

  • ccl_tracers (pyccl.tracers.Tracer): CCL tracers used to compute the theory vector

  • tracer_Noise (dict): shot (shape) noise for lens (sources) tracers

  • tracer_Noise_coupled (dict): coupled shot (shape) noise for lens (sources). Returned if retrun_noise_coupled is True.

Return type:

tuple

class tjpcov.covariance_builder.CovarianceReal(config)[source]#

Bases: CovarianceBuilder

Parent class for xi x xi covariances in Real space.

This has all the methods common to all the Real covariance calculations. The child classes will actually implement the actual computation of the blocks.

Init the base class with a config file or dictionary.

Parameters:

config (dict or str) – If dict, it returns the configuration dictionary directly. If string, it asumes a YAML file and parses it.

space_type = 'Real'[source]#
_tracer_types = ('xi', 'xi')[source]#
get_theta_eff()[source]#

Return the effective theta in the sacc file.

It assume that all of them have the same effective theta (true with current TXPipe implementation).

Parameters:

sacc_data (sacc.sacc.Sacc) – Data Sacc instance

Returns:

Array with the effective theta in the sacc file.

Return type:

array

class tjpcov.covariance_builder.CovarianceProjectedReal(config)[source]#

Bases: CovarianceReal

Parent class for xi x xi covariances in Real space.

This has all the methods common to all the Real covariance calculations that are computed by projecting the Fourier space ones. The child classes will only have to call a CovarianceFourier child to get the covariance in Fourier space.

Init the base class with a config file or dictionary.

Parameters:

config (dict or str) – If dict, it returns the configuration dictionary directly. If string, it asumes a YAML file and parses it.

property fourier[source]#
get_binning_info(binning='log', in_radians=True)[source]#

Get the theta for bins given the sacc object.

Parameters:
  • binning (str) – Binning type.

  • in_radians (bool) – If the angles must be given in radians. Needed for the Wigner transforms.

Returns:

  • theta (array): All the thetas covered

  • theta_eff (array): The effective thetas

  • theta_edges (array): The bandpower edges

Return type:

tuple

get_cov_WT_spin(tracer_comb)[source]#

Get the Wigner transform factors.

Parameters:

tracer_comb (list of two str) – tracer combination in sacc format

Returns:

WT_factors

get_Wigner_transform()[source]#

Return an instance of the wigner_transform class.

Returns:

WignerTransform instance

abstract _get_fourier_block(tracer_comb1, tracer_comb2)[source]#
get_covariance_block(tracer_comb1, tracer_comb2, xi_plus_minus1='plus', xi_plus_minus2='plus', binned=True)[source]#

Compute a single covariance matrix for a given pair of xi.

Parameters:
  • tracer_comb1 (list) – List of the pair of tracer names of C_ell^1

  • tracer_comb2 (list) – List of the pair of tracer names of C_ell^2

  • xi_plus_minus1 (str) – ‘plus’ if one wants the covariance for the xi+ component or ‘minus’ for the xi-. This is ignored if tracer_comb1 is not a spin 2 (e.g. shear) field.

  • xi_plus_minus2 (str) – As xi_plus_minus1 for tracer_comb2.

Returns:

Covariance matrix

Return type:

array

_get_covariance_block_for_sacc(tracer_comb1, tracer_comb2)[source]#

Compute a the covariance matrix for a given pair of C_ell or xi.

Parameters:
  • tracer_comb1 (list) – List of the pair of tracer names of C_ell^1

  • tracer_comb2 (list) – List of the pair of tracer names of C_ell^2

Returns:

Covariance matrix

Return type:

array