like_cf_gauss module
Likelihood module to evaluate the joint likelihood of a set of tomographic 3x2pt angular-binned correlation functions using a multivariate Gaussian likelihood, where everything (observation, theory, covariance) is calculated via power spectra.
The main functions are setup, which should be called once per analysis, and execute, which is called for every new point in parameter space.
- class like_cf_gauss.Field(field_type, zbin)
Bases:
tuple- property field_type
Alias for field number 0
- property zbin
Alias for field number 1
- class like_cf_gauss.FieldType(value)
Bases:
enum.EnumThe three types of fields: position, shear E and shear B.
- POSITION = 1
- SHEAR_B = 3
- SHEAR_E = 2
- class like_cf_gauss.PowerSpectrum(field_1, field_2)
Bases:
tuple- property field_1
Alias for field number 0
- property field_2
Alias for field number 1
- like_cf_gauss.calculate_cl_cov_l(theory_cl, l, n_fields)
Returns the Gaussian covariance matrix of full-sky Cl estimates for a single l.
- Parameters
theory_cl (1D numpy array) – All Cls for this l, in diagonal ordering.
l (int) – The l value.
n_fields (int) – The number of fields, where the number of spectra = n_fields * (n_fields + 1) / 2.
- Returns
The covariance matrix for this l.
- Return type
2D numpy array
- like_cf_gauss.calculate_cl_covs(fid_cl, n_zbin, keep_spectra, lmin)
Calculate and return all full-sky power spectrum covariance matrices.
- Parameters
fid_cl (2D numpy array) – Fiducial power spectra used to calculate the covariance, with shape (n_spectra, n_ell), with the spectra in diagonal-major order and the ells starting with l = lmin.
n_zbin (int) – Number of redshift bins. 3 fields per redshift bin are assumed: position, shear E, shear B.
keep_spectra (list) – Boolean list of whether each power spectrum should be kept: False if NB or EB, otherwise True.
lmin (int) – Minimum l value.
- Returns
Covariance with shape (n_ell, n_spectra, n_spectra).
- Return type
3D numpy array
- like_cf_gauss.execute(theory_cl, config)
Evaluate log-likelihood at theory_cl.
- Parameters
theory_cl (2D numpy array) – Theory power spectra, as loaded by load_cls_zerob with shape (n_spectra, lmax + 1).
config (dict) – Config dictionary returned by setup.
- Returns
Log-likelihood value.
- Return type
float
- like_cf_gauss.get_cf_noise_variance(n_zbin, theta_min, theta_max, n_theta_bin, survey_area_sqdeg, gals_per_sqarcmin_per_zbin, sigma_e)
Calculate and return the correlation function noise variance vector, which is the diagonal of the noise contribution to the covariance matrix. Off-diagonal elements are zero.
- Parameters
n_zbin (int) – Number of redshift bins, assuming 3 fields per bin: position, shear E, shear B.
theta_min (float) – Minimum theta value in radians.
theta_max (float) – Maximum theta value in radians.
n_theta_bin (int) – Number of log-spaced theta bins.
survey_area_sqdeg (float) – Survey area in square degrees.
gals_per_sqarcmin_per_zbin (float) – Number of galaxies per square arcminute per redshift bin (fixed across all redshift bins).
sigma_e (float) – Intrinsic galaxy ellipticity dispersion per component.
- Returns
Noise variance vector, to be added to the diagonal of the correlation function covariance matrix.
- Return type
1D numpy array
- like_cf_gauss.get_cl2cf_matrices(theta_bin_edges, lmin, lmax)
Returns the set of matrices to go from one entire power spectrum to one binned correlation function.
- Parameters
theta_bin_edges (1D numpy array) – Angular bin edges in radians.
lmin (int) – Minimum l.
lmax (int) – Maximum l.
- Returns
Tuple of matrices to each go from one entire power spectrum to one binned correlation function for different spins: (0-0, 2-2, 0-2). The spin-2-2 matrix is only for xi+, not xi-.
- Return type
(2D numpy array, 2D numpy array, 2D numpy array)
- like_cf_gauss.get_full_cl2cf_matrix(n_zbin, lmax_in, lmin, l_extrap_to, theta_min, theta_max, n_theta_bin)
Return the primary and secondary transformation matrices to go from a full data vector of power spectra to the equivalent data vector of binned correlation functions.
The primary matrix is to be applied to the observed and model power spectrum. The secondary matrix is to be applied to the fiducial power spectrum to obtain a stability vector, which should be added to the result of the primary matrix times the observed/model power spectrum to stabilise the sum over l.
- Parameters
n_zbin (int) – Number of redshift bins. Three fields per redshift bin are assumed: position, shear E, shear B.
lmax_in (int) – Maximum l in the input to the transformation matrix.
lmin (int) – Minimum l in the input to the transformation matrix.
l_extrap_to (int) – l to extrapolate input power spectra to to obtain stable correlation functions (won’t affect likelihood results as long as a consistent value is used).
theta_min (float) – Minimum theta value in radians.
theta_max (float) – Maximum theta value in radians.
n_theta_bin (int) – Number of log-spaced theta bins.
- Returns
Tuple of (primary transformation matrix, secondary transformation matrix), each with shape (n_cf * n_theta_bin, n_spectra * n_ell).
- Return type
(2D numpy array, 2D numpy array)
- like_cf_gauss.idx_to_type(idx)
Returns the field type (position, shear E-mode or shear B-mode) corresponding to a row or column index in the matrix of power spectra, based on the remainder when dividing by 3.
- Parameters
idx (int) – Row or column index.
- Returns
The corresponding field type.
- Return type
- like_cf_gauss.idx_to_zbin(idx)
Returns the redshift bin corresponding to a row or column index in the matrix of power spectra, taking shear B-mode into account. Redshift bins are numbered from 1.
- Parameters
idx (int) – Row or column index.
- Returns
The corresponding redshift bin number.
- Return type
int
- like_cf_gauss.keep_spectrum(spec)
Returns False if the power spectrum is a type we wish to exclude (EB, NB), or True otherwise.
- Parameters
spec (PowerSpectrum) – Power spectrum.
- Returns
True if the power spectrum should be kept (i.e. is not EB or NB), or False otherwise.
- Return type
bool
- like_cf_gauss.load_cls_zerob(n_zbin, pos_pos_dir, she_she_dir, pos_she_dir, lmax, lmin_in=0)
Given the number of redshift bins and relevant directories, load power spectra (position, shear, cross) in the correct order (diagonal / healpy new=True ordering) and insert B-mode power spectra all equal to zero. If lmin is supplied, the output will be padded to begin at l=0.
- Parameters
n_zbin (int) – Number of redshift bins.
pos_pos_dir (str) – Path to directory containing position-position power spectra.
she_she_dir (str) – Path to directory containing shear-shear power spectra.
pos_she_dir (str) – Path to directory containing position-shear power spectra.
lmax (int) – Maximum l to load.
lmin (int, optional) – Minimum l supplied. Output will be padded with zeros below this point.
- Returns
First element of tuple is all Cls, with different spectra along the first axis and increasing l along the second. Second element of tuple is list of indices of spectra that involve shear B-modes, i.e. BB, EB, NB.
- Return type
(2D numpy array, list)
- like_cf_gauss.matrix_indices(vector_idx, matrix_size)
Return matrix indices (of Wishart scale matrix) corresponding to vector index (vector of Cls in diagonal-major order)
- Parameters
vector_idx (int) – Vector index.
matrix_size (int) – Size along one axis of the square matrix to output indices for.
- Returns
Row index, column index.
- Return type
(int, int)
- like_cf_gauss.setup(n_zbin, obs_path, fid_pos_pos_dir, fid_she_she_dir, fid_pos_she_dir, lmax, theta_min, theta_max, n_theta_bin, survey_area_sqdeg, gals_per_sqarcmin_per_zbin, sigma_e, cov_fsky=1, cl_covs=None, return_cl_covs=False)
Load and precompute everything that is fixed throughout parameter space. This should be called once per analysis, prior to any calls to execute.
The cl_covs and return_cl_covs options are designed for repeated likelihood runs with the same set of (n_zbin, fiducial Cls, lmax), to prevent the unnecessary repeated computation of the Cl covariance. On the first run, set (cl_covs=None, return_cl_covs=True), then the function will return (config, cl_covs). The cl_covs can then be passed back to setup in future runs.
- Parameters
n_zbin (int) – Number of redshift bins. Three fields per redshift bin are assumed: position, shear E and shear B.
obs_path (str) – Path to observed power spectra in numpy .npz file containing two arrays: ell containining the ell range, and obs_cls containing the observed Cls including B-modes, with shape (n_spectra, n_ell), with spectra in diagonal-major order.
fid_pos_pos_dir (str) – Path to the directory containing fiducial position-position power spectra.
fid_she_she_dir (str) – Path to the directory containing fiducial shear-shear power spectra.
fid_pos_she_dir (str) – Path to the directory containing fiducial position-shear power spectra.
lmax (int) – Maximum l value.
theta_min (float) – Minimum theta in radians.
theta_max (float) – Maximum theta in radians.
n_theta_bin (int) – Number of log-spaced theta bins.
survey_area_sqdeg (float) – Survey area in square degrees.
gals_per_sqarcmin_per_zbin (float) – Number of galaxies per square arcminute per redshift bin (fixed across all redshift bins).
sigma_e (float) – Intrinsic galaxy ellipticity dispersion per component.
cov_fsky (float, optional) – Sky fraction to multiply the entire covariance by 1/fsky (default 1).
cl_covs (3D numpy array, optional) – Power spectrum covariance returned from a previous call to setup with the same values of n_zbin, lmax, and all fiducial Cls. Calculated if not supplied.
return_cl_covs (bool, optional) – If True, return the power spectrum covariance so that it can be passed to the cl_covs option in a future call to setup. (Default False.)
- Returns
Config dictionary to pass to execute. If return_cl_covs is True, also returns the power spectrum covariance which can be passed to the cl_covs option in a future call to setup.
- Return type
dict if return_cl_covs is False, else (dict, 3D numpy array)
- like_cf_gauss.vector_index(row_idx, col_idx, matrix_size)
Return vector index (vector of Cls in healpy diagonal-major order) corresponding to matrix indices (of Wishart scale matrix).
- Parameters
row_idx (int) – Row index for matrix.
col_idx (int) – Column index for matrix.
matrix_size (int) – Size along one axis of the square matrix that input indices are for.
- Returns
Vector index corresponding to the input matrix indices.
- Return type
int