flip.covariance#

Init file of the flip.covariance package.

Submodules#

Classes#

CovMatrix

CovMatrix is a class for managing and manipulating covariance matrices used in cosmological analyses, particularly for models involving density and velocity fields. It provides methods for initialization from various sources, conversion between flat and matrix forms, masking, and file I/O operations.

Package Contents#

class flip.covariance.CovMatrix(model_name=None, model_kind=None, free_par=None, los_definition=None, covariance_dict=None, matrix_form=False, redshift_dict=None, variant=None, coefficients=None, number_densities=None, number_velocities=None, emulator_flag=False)[source]#

CovMatrix is a class for managing and manipulating covariance matrices used in cosmological analyses, particularly for models involving density and velocity fields. It provides methods for initialization from various sources, conversion between flat and matrix forms, masking, and file I/O operations.

model_name#

Name of the covariance model.

Type:

str

model_kind#

Type of covariance (‘density’, ‘velocity’, ‘density_velocity’, ‘full’).

Type:

str

free_par#

Dictionary of free parameters for the model.

Type:

dict

los_definition#

Definition of the line-of-sight.

Type:

str

covariance_dict#

Dictionary containing covariance matrices.

Type:

dict

matrix_form#

Indicates if covariance is in matrix form.

Type:

bool

redshift_dict#

Dictionary of redshift information.

Type:

dict

variant#

Variant of the model.

Type:

str

number_densities#

Number of density bins.

Type:

int

number_velocities#

Number of velocity bins.

Type:

int

coefficients#

Imported module for model coefficients.

Type:

module

compute_covariance_sum#

Function to compute covariance sum.

Type:

callable

compute_covariance_sum_jit#

JIT-compiled function to compute covariance sum (if JAX is installed).

Type:

callable

__init__()[source]#

Initializes a CovMatrix instance.

init_from_flip()[source]#

Class method to initialize from the flip code generator.

init_from_generator()[source]#

Class method to initialize from a model-specific generator.

init_from_file()[source]#

Class method to initialize from a file (pickle, npz, parquet).

kind()#

Property returning the kind of covariance model.

loaded()#

Property indicating if the covariance matrix is loaded.

init_compute_covariance_sum()[source]#

Initializes functions for computing covariance sums.

compute_covariance_sum_eigenvalues()[source]#

Computes eigenvalues of the covariance sum.

compute_matrix_covariance()[source]#

Converts flat covariance to matrix form.

compute_flat_covariance()[source]#

Converts matrix covariance to flat form.

write()[source]#

Writes the covariance matrix to a file (pickle, npz, parquet).

mask()[source]#

Returns a masked CovMatrix instance based on provided masks for density and velocity.

Usage:

CovMatrix can be instantiated directly or via class methods for loading from generators or files. It supports conversion between flat and matrix forms, masking, and saving/loading to disk.

Raises:
model_name = None#
model_kind = None#
free_par = None#
los_definition = None#
covariance_dict = None#
matrix_form = False#
redshift_dict = None#
variant = None#
coefficients = None#
compute_covariance_sum = None#
compute_covariance_sum_jit = None#
number_densities = None#
number_velocities = None#
emulator_flag = False#
classmethod init_from_flip(model_name, model_kind, power_spectrum_dict, coordinates_density=None, coordinates_velocity=None, additional_parameters_values=None, los_definition='bisector', variant=None, **kwargs)[source]#

The init_from_flip function is a function that initializes the covariance matrix from the flip code. It takes as input:

  • model_name: name of the model used to generate the covariance matrix (e.g., ‘lai22’)

  • model_kind: kind of data used to generate the covariance matrix (e.g., ‘density’ or ‘velocity’)

  • power_spectrum_dict: dictionary containing all information about power spectrum, including k and P(k) values, redshift, etc…

    It is generated by calling getPowerSpectrumDict() in

Parameters:
  • cls – Indicate that the function is a class method

  • model_name – Determine which model to use for the covariance matrix

  • model_kind – Determine the kind of model to be used

  • power_spectrum_dict – Pass the power spectrum of the model

  • coordinates_density – Specify the coordinates of the density field

  • coordinates_velocity – Define the velocity coordinates of the covariance matrix

  • additional_parameters_values – Pass the values of additional parameters to the flip code

  • **kwargs – Pass a variable number of keyword arguments to the function

Returns:

A covariancematrix object

classmethod init_from_generator(model_name, model_kind, power_spectrum_dict, coordinates_velocity=None, coordinates_density=None, additional_parameters_values=None, variant=None, **kwargs)[source]#

The init_from_generator function is a helper function that allows the user to initialize a Covariance object from a generator. The init_from_generator function takes in as arguments:

  • cls: the class of the object being initialized (Covariance)

  • model_name: name of covariance model used to generate covariance matrix (e.g., ‘lai22’)

  • model_kind: kind of covariance matrix generated (‘density’ or ‘velocity’)

  • power spectrum dictionary containing keys for each redshift bin and values corresponding to

    power spectra at those red

Parameters:
  • cls – Refer to the class itself

  • model_name – Specify the kind of model used to generate the covariance matrix

  • model_kind – Determine which model to use

  • power_spectrum_dict – Pass the power spectrum to the generate_* functions

  • coordinates_velocity – Generate the velocity covariance matrix

  • coordinates_density – Generate the density field

  • additional_parameters_values – Pass additional parameters to the generator function

  • **kwargs – Pass a variable number of keyword arguments to the function

:param : Generate the covariance matrix from a given model

Returns:

An object of the class covariancematrix

classmethod init_from_emulator(emulator_model_name, model_kind, covariance_list, emulator_parameter_values, parameter_names, **kwargs)[source]#
classmethod init_from_file(filename, file_format)[source]#
property kind#

The kind function is used to determine the kind of covariance model that will be computed. The options are:

  • velocity: The covariance model is computed for velocity only.

  • density: The covariance model is computed for density only.

  • density_velocity: The covariance model is computed for both velocity and density, without cross-term (i.e., the covariances between velocities and densities are zero). This option should be used when computing a full 3D tomography in which we want to compute a separate 1D tomography along each axis (x, y, z

Parameters:

self – Represent the instance of the class

Returns:

The kind of the model

property loaded#

The loaded function checks if the covariance matrix is loaded.

Parameters:

self – Refer to the object itself

Returns:

A boolean

init_compute_covariance_sum()[source]#
compute_covariance_sum_eigenvalues(parameter_values_dict, vector_variance)[source]#
compute_matrix_covariance(verbose=True)[source]#

The compute_matrix_covariance function takes the covariance matrix and fills in all of the missing values.

Parameters:

self – Bind the method to the object

Returns:

A dictionary with the full covariance matrices for each redshift bin

compute_flat_covariance(verbose=True)[source]#
write(filename, file_format)[source]#

The write function writes the covariance matrix to a file.

Parameters:
  • self – Represent the instance of the class

  • filename – Specify the name of the file to be written

:param : Specify the name of the file in which we want to save our covariance matrix

Returns:

Nothing

mask(mask_vel=None, mask_dens=None)[source]#