flip.covariance.cov_utils#

Attributes#

log

Functions#

compute_sep(ra, dec, comoving_distance[, ...])

The compute_sep function computes the separation between all pairs of objects in a catalog.

compute_i_j(N, seq)

The compute_i_j function takes in a number of nodes N and a sequence number seq.

flatshape_to_fullshape(flat_shape_non_diagonal)

compute_i_j_cross_matrix(Nv, seq)

The compute_i_j_cross_matrix function takes in the number of vertices, Nv, and a sequence of numbers

compute_phi(ra_0, ra_1, dec_0, dec_1, r_0, r_1, ...)

The compute_phi function computes the angle between the line of sight and

angle_separation(ra_0, ra_1, dec_0, dec_1, r_0, r_1[, ...])

The angle_separation function computes the angle between two points on a sphere.

compute_phi_bisector_theorem(r, theta, r_0, r_1)

return_matrix_covariance(flat_covariance)

Reconstructs a full covariance matrix from a flattened representation.

return_flat_covariance(matrix_covariance)

Flattens a covariance matrix into a one-dimensional array.

return_flat_cross_cov(cov)

return_matrix_covariance_cross(cov, number_objects_g, ...)

The return_matrix_covariance_cross function takes in a covariance matrix and the number of objects in each band.

return_correlation_matrix(cov)

The return_correlation_matrix function takes a covariance matrix as input and returns the correlation matrix.

save_matrix(matrix, name)

The save_matrix function takes a matrix and saves it to the current directory as a .npy file.

open_matrix(name)

The open_matrix function takes in a string as an argument and returns the matrix that is saved under that name.

generator_need([coordinates_density, coordinates_velocity])

The generator_need function checks if the coordinates_density and coordinates_velocity inputs are provided.

check_generator_need(model_kind, coordinates_density, ...)

The check_generator_need function is used to check if the generator_need function

generate_redshift_dict(redshift_dependent_model, ...)

Module Contents#

flip.covariance.cov_utils.log#
flip.covariance.cov_utils.compute_sep(ra, dec, comoving_distance, los_definition='bisector', size_batch=10000)[source]#

The compute_sep function computes the separation between all pairs of objects in a catalog.

Parameters:
  • ra – Store the right ascension of each object

  • dec – Compute the angular separation between two objects

  • comoving_distance – Calculate the separation between two objects

  • size_batch – Control the number of objects that are processed at a time

:param : Set the number of objects in a batch

Returns:

The separation, the perpendicular component of the separation, and

flip.covariance.cov_utils.compute_i_j(N, seq)[source]#

The compute_i_j function takes in a number of nodes N and a sequence number seq. It returns the i, j indices for the upper triangular matrix that correspond to the given sequence number. The function is used to convert between an indexing scheme that uses integers from 0 to (N^2 - N)/2 - 1 and one that uses i,j indices where i = 0,…,N-2 and j = i+ 1,…,N-2.

Parameters:
  • N – Determine the size of the matrix

  • seq – Find the row and column of the element in a matrix

Returns:

The row and column of the lower triangle matrix

flip.covariance.cov_utils.flatshape_to_fullshape(flat_shape_non_diagonal)[source]#
flip.covariance.cov_utils.compute_i_j_cross_matrix(Nv, seq)[source]#

The compute_i_j_cross_matrix function takes in the number of vertices, Nv, and a sequence of numbers and returns two arrays. The first array is an array containing the row indices for each element in the sequence. The second array contains column indices for each element in the sequence.

Parameters:
  • Nv – Determine the number of vertices in a given face

  • seq – Create the i and j arrays

Returns:

The indices of the cross-terms in the matrix

flip.covariance.cov_utils.compute_phi(ra_0, ra_1, dec_0, dec_1, r_0, r_1, los_definition)[source]#

The compute_phi function computes the angle between the line of sight and the separation vector. The line of sight is defined as either:

  • mean: (r_0 + r_2) / 2, where r_0 and r_2 are the radial coordinates at each end of a pair.

  • bisector: (r_0 / |r| + r_2 / |r|), where |r| is the distance between two points in a pair.

  • endpoint: only use one point in a pair to define the line-of-sight direction, i.e., use only one galaxy

Parameters:
  • ra_0 – Compute the x_0, y_0 and z_0 coordinates of a galaxy

  • ra_1 – Compute the phi angle

  • dec_0 – Compute the z_0 parameter in radec2cart function

  • dec_1 – Compute the phi angle

  • r_0 – Compute the distance between two points

  • r_1 – Compute the distance between two points in the sky

  • los_definition – Define the line of sight

Returns:

The angle between the line of sight and the separation vector

flip.covariance.cov_utils.angle_separation(ra_0, ra_1, dec_0, dec_1, r_0, r_1, los_definition='bisector')[source]#

The angle_separation function computes the angle between two points on a sphere.

Parameters:
  • ra_0 – Set the right ascension of the first galaxy

  • ra_1 – Calculate the angle between two points in the sky

  • dec_0 – Define the declination of the first galaxy

  • dec_1 – Calculate the cosine of theta

  • r_0 – Compute the distance between two points

  • r_1 – Compute the distance between two points in space

  • los_definition – Define the line of sight

:param : Define the line of sight

Returns:

The separation between two points in

flip.covariance.cov_utils.compute_phi_bisector_theorem(r, theta, r_0, r_1)[source]#
flip.covariance.cov_utils.return_matrix_covariance(flat_covariance)[source]#

Reconstructs a full covariance matrix from a flattened representation.

The input flat_covariance is expected to have the diagonal value as its first element, followed by the upper-triangular (excluding diagonal) elements of the covariance matrix.

Parameters:

flat_covariance (np.ndarray) – 1D array containing the diagonal value followed by the upper-triangular elements of the covariance matrix.

Returns:

The reconstructed full covariance matrix.

Return type:

np.ndarray

Notes

  • The function uses flatshape_to_fullshape to determine the size of the full matrix.

  • The diagonal is set to the first value in flat_covariance_matrix.

  • The off-diagonal elements are filled symmetrically.

flip.covariance.cov_utils.return_flat_covariance(matrix_covariance)[source]#

Flattens a covariance matrix into a one-dimensional array.

The returned array starts with the variance value (element at position [0, 0]), followed by the upper triangular elements of the covariance matrix (excluding the diagonal).

Parameters:

cov (numpy.ndarray) – A square covariance matrix.

Returns:

A one-dimensional array containing the variance and upper triangular covariance values.

Return type:

numpy.ndarray

flip.covariance.cov_utils.return_flat_cross_cov(cov)[source]#
flip.covariance.cov_utils.return_matrix_covariance_cross(cov, number_objects_g, number_objects_v)[source]#

The return_matrix_covariance_cross function takes in a covariance matrix and the number of objects in each band. It then reshapes the covariance matrix into a full cross-covariance matrix, which is returned.

Parameters:
  • cov – Reshape the covariance matrix

  • number_objects_g – Reshape the covariance matrix into a full covariance matrix

  • number_objects_v – Reshape the covariance matrix into a full covariance matrix

Returns:

The full covariance matrix

flip.covariance.cov_utils.return_correlation_matrix(cov)[source]#

The return_correlation_matrix function takes a covariance matrix as input and returns the correlation matrix. The correlation matrix is calculated by dividing each element of the covariance matrix by the product of its row’s standard deviation and column’s standard deviation.

Parameters:

cov – Calculate the correlation matrix

Returns:

The correlation matrix

flip.covariance.cov_utils.save_matrix(matrix, name)[source]#

The save_matrix function takes a matrix and saves it to the current directory as a .npy file.

Parameters:
  • matrix – Save the matrix to a file

  • name – Save the matrix with a name

Returns:

The name of the file that was saved

flip.covariance.cov_utils.open_matrix(name)[source]#

The open_matrix function takes in a string as an argument and returns the matrix that is saved under that name.

Parameters:

name – Specify the name of the matrix to be loaded

Returns:

A matrix

flip.covariance.cov_utils.generator_need(coordinates_density=None, coordinates_velocity=None)[source]#

The generator_need function checks if the coordinates_density and coordinates_velocity inputs are provided. If they are not, it raises a ValueError exception.

Parameters:
  • coordinates_density – Generate the density covariance matrix

  • coordinates_velocity – Generate the covariance matrix of the velocity field

:param : Check if the coordinates are provided or not

Returns:

A list of the coordinates that are needed to proceed with covariance generation

flip.covariance.cov_utils.check_generator_need(model_kind, coordinates_density, coordinates_velocity)[source]#

The check_generator_need function is used to check if the generator_need function is called with the correct arguments. The model type determines which coordinates are needed, and these are passed as arguments to generator_need.

Parameters:
  • model_kind – Determine if the density, velocity or full model is being used

  • coordinates_density – Check if the density coordinates are needed

  • coordinates_velocity – Determine whether the velocity model is needed

Returns:

A boolean

flip.covariance.cov_utils.generate_redshift_dict(redshift_dependent_model, model_kind, redshift_velocity=None, redshift_density=None, coordinates_velocity=None, coordinates_density=None)[source]#