flip.covariance.cov_utils#
Attributes#
Functions#
|
The compute_sep function computes the separation between all pairs of objects in a catalog. |
|
The compute_i_j function takes in a number of nodes N and a sequence number seq. |
|
|
|
The compute_i_j_cross_matrix function takes in the number of vertices, Nv, and a sequence of numbers |
|
The compute_phi function computes the angle between the line of sight and |
|
The angle_separation function computes the angle between two points on a sphere. |
|
|
|
Reconstructs a full covariance matrix from a flattened representation. |
|
Flattens a covariance matrix into a one-dimensional array. |
|
The return_matrix_covariance_cross function takes in a covariance matrix and the number of objects in each band. |
The return_correlation_matrix function takes a covariance matrix as input and returns the correlation matrix. |
|
|
The save_matrix function takes a matrix and saves it to the current directory as a .npy file. |
|
The open_matrix function takes in a string as an argument and returns the matrix that is saved under that name. |
|
The generator_need function checks if the coordinates_density and coordinates_velocity inputs are provided. |
|
The check_generator_need function is used to check if the generator_need function |
|
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.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:
- 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.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:
- 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