Toolbox – Utility functions

The toolbox module contains a collection of utility functions related to simple statistical computations or the handling of spherical harmonics based objects.

micmac.toolbox.fisher module

full_fisher(init_mixing_matrix_obj, exact_params_mixing_matrix, Cl_lens, Cl_prim, data_map, lmax, inv_Nl, lmin=2, r_start=0.001, mode='EB', Sc_approx=None)[source]

micmac.toolbox.statistics module

get_1d_recursive_empirical_covariance(iteration_number, last_sample, last_mean_samples, last_empirical_covariance, s_param=5.76, epsilon_param=1e-10)[source]

Compute the 1D empirical covariance recursively, from last sample computed and mean samples

Parameters:
iteration_number : int

number of iterations corresponding to the last sample

last_sample : float or array

last sample computed

last_mean_samples : float or array

mean samples computed from the previous iteration_number samples

last_empirical_covariance : float or array

empirical covariance computed from the previous iteration_number samples

Returns:

empirical_covariance – empirical covariance computed from the iteration_number+1 samples

Return type:

array

get_Gelman_Rubin_statistics(all_chain_samples)[source]

Compute Gelman-Rubin statistics

Parameters:
all_chains_samples : array with dimensions [n_chains, number_iterations, ...]

all chains

Returns:

GR – Gelman-Rubin statistics

Return type:

float

micmac.toolbox.tools module

JAX_almxfl(alm, c_ell_x_, lmax)[source]

Return alms convolved with the covariance matrix c_ell_x_ given as input in the format [lmax+1-lmin, nstokes, nstokes], assuming it’s block diagonal, without the need of a pure callback to Healpy

Parameters:
alm : array

input alms of shape ((lmax + 1) * (lmax // 2 + 1))

c_ell_x : array of shape [lmax+1]

input power spectrum

Returns:

alms_output – updated output alms of shape ((lmax + 1) * (lmax // 2 + 1))

Return type:

array

alm_dot_product_JAX(alm_1, alm_2, lmax)[source]

Return dot product of two alms

Parameters:
alm_1 : array

input alms of shape (…,(lmax + 1) * (lmax // 2 + 1))

alm_2 : array

input alms of shape (…,(lmax + 1) * (lmax // 2 + 1))

lmax : int

maximum ell for the power spectrum

Returns:

dot_product – dot product of the two alms

Return type:

float

alms_x_red_covariance_cell_JAX(alm_Stokes_input, red_matrix, lmin)[source]

Return alms convolved with the input harmonic covariance matrix in the format [lmax+1-lmin, nstokes, nstokes] given as input, assuming it’s block diagonal

The input matrix have to start from ell=lmin, otherwise the lmax associated with the harmonic operations will be wrong

Parameters:
alms_Stokes_input : arary of shape [nstokes, (lmax + 1) * (lmax // 2 + 1)]

input alms

red_matrix : array of shape [lmax+1-lmin, nstokes, nstokes]

input reduced covariance matrix

lmin : int

minimum ell for the spectrum

Returns:

maps_output – output maps

Return type:

array of shape [nstokes, n_pix]

frequency_alms_x_obj_red_covariance_cell_JAX(freq_alm_Stokes_input, freq_red_matrix, lmin, n_iter=8)[source]

Return frequency alms convolved with the covariance matrix given as input, assuming it’s block diagonal

The freq_red_matrix can have its first dimension reprensenting anything, in particular either the number of frequencies or the number of components

Parameters:
freq_alm_Stokes_input : array of shape [frequency, nstokes, (lmax + 1) * (lmax // 2 + 1))]

input alms per frequency

red_matrix : array of shape [first_dim, frequency, lmax+1-lmin, nstokes, nstokes]

input reduced covariance matrix

lmin : int

minimum ell for the power spectrum

n_iter : int

number of iterations for harmonic operations

Returns:

maps_output – output maps

Return type:

array[float] of shape [nstokes, n_pix]

get_bool_array_in_boundary(input_array, boundary)[source]

Return a boolean array of the same shape as the input array, with True values where the input array is within the boundary

Parameters:
input_array : array

array to test

boundary : array of dimension [2,dim(input_array)]

represents the boundary

Returns:

bool_array – boolean array of the same shape as the input array, with True values where the input array is within the boundary

Return type:

array[bool]

get_c_ells_from_red_covariance_matrix(red_cov_mat)[source]

Retrieve the c_ell in the format [number_correlations, lmax+1-lmin], from the reduced covariance matrix format [lmax+1-lmin, nstokes, nstokes], assuming it’s block diagonal

Depending of nstokes, the number of correlations corresponds to:

TT EE, BB, EB TT, EE, BB, TE, EB, TB

get_c_ells_from_red_covariance_matrix_JAX(red_cov_mat, nstokes=0)[source]

Retrieve the c_ell in the format [number_correlations, lmax+1-lmin], from the reduced covariance matrix format [lmax+1-lmin, nstokes, nstokes], assuming it’s block diagonal

Depending of nstokes, the number of correlations corresponds to:

TT EE, BB, EB TT, EE, BB, TE, EB, TB

ATTENTION : Currently not optimised for JAX (the for loops must be replaced by JAX loops)

Parameters:
red_cov_mat : array[float] of dimensions [lmax+1-lmin, nstokes, nstokes]

reduced spectra of the covariance matrix

Returns:

c_ells – power specturm of the input reduced covariance matrix

Return type:

array of dimensions [n_correlations, lmax+1-lmin]

get_cell_from_map_jax(pixel_maps, lmax, n_iter=8)[source]

Return c_ell from pixel_maps with an associated lmax and iteration number of harmonic operations

Parameters:
pixel_maps : array of dimensions [nstokes, n_pix]

input maps

lmax : int

maximum ell for the spectrum

n_iter : int

number of iterations for harmonic operations

Returns:

c_ells – power specturm of the input maps

Return type:

array of dimensions[n_correlations,lmin:lmax+1]

get_reduced_matrix_from_c_ell(c_ells_input)[source]

Returns the input spectra in the format [lmax+1-lmin, nstokes, nstokes] Expect c_ells_input to be sorted as TT, EE, BB, TE, TB, EB if 6 spectra are given or EE, BB, EB if 3 spectra are given or TT if 1 spectrum is given Generate covariance matrix from c_ells assuming it’s block diagonal, in the “reduced” (prefix red) format, i.e. : [ell, nstokes, nstokes] The input spectra doesn’t have to start from ell=0, and the output matrix spectra will start from the same lmin as the input spectra

Parameters:
c_ells_input : array of shape (n_correlations, lmax)

input power spectra

Returns:

reduced_matrix – reduced covariance matrix

Return type:

array of shape (lmax+1-lmin, nstokes, nstokes)

get_reduced_matrix_from_c_ell_jax(c_ells_input)[source]

Returns the input spectra in the format [lmax+1-lmin, nstokes, nstokes]

Expect c_ells_input to be sorted as TT, EE, BB, TE, TB, EB if 6 spectra are given or EE, BB, EB if 3 spectra are given or TT if 1 spectrum is given

Generate covariance matrix from c_ells assuming it’s block diagonal, in the “reduced” (prefix red) format, i.e. : [ell, nstokes, nstokes]

The input spectra doesn’t have to start from ell=0, and the output matrix spectra will start from the same lmin as the input spectra

Parameters:
c_ells_input : array of shape (n_correlations, lmax)

Input c_ells

Returns:

reduced_matrix – Reduced format of the covariance matrix

Return type:

array of shape (lmax+1-lmin, nstokes, nstokes)

get_sqrt_reduced_matrix_from_matrix_jax(red_matrix)[source]

Return matrix square root of covariance matrix in the format [lmax+1-lmin, nstokes, nstokes], assuming it’s block diagonal

The input matrix doesn’t have to start from ell=0, and the output matrix will start from the same lmin as the input matrix

The initial matrix HAVE to be positive semi-definite

Parameters:
red_matrix : array of dimensions [lmax+1-lmin, nstokes, nstokes]

reduced spectra of the covariance matrix

Returns:

reduced_sqrtm – matrix square root of the covariance matrix

Return type:

array of dimensions [lmax+1-lmin, nstokes, nstokes]

maps_x_red_covariance_cell_JAX(maps_input, red_matrix_sqrt, nside, lmin, n_iter=8)[source]

Return maps convolved with the harmonic covariance matrix given as input in the format [lmax+1-lmin, nstokes, nstokes], assuming it’s block diagonal

The input matrix have to start from ell=lmin, otherwise the lmax associated with the harmonic operations will be wrong

Parameters:
maps_input : array[float] of shape [nstokes, n_pix]

input maps

red_matrix_sqrt : array[float] of shape [lmax+1-lmin, nstokes, nstokes]

input reduced spectra

nside : int

nside of the input maps

lmin : int

minimum ell for the spectrum

n_iter : int

number of iterations for harmonic operations

Returns:

maps_output – input maps convolved with input spectra

Return type:

array[float] of shape [nstokes, n_pix]

micmac.toolbox.utils module

generate_power_spectra_CAMB(Nside, r=0, Alens=1, H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0, tau=0.06, ns=0.965, As=2e-09, lens_potential_accuracy=1, nt=0, ntrun=0, type_power='total', typeless_bool=False)[source]

Generate power spectra from CAMB Return [Cl^TT, Cl^EE, Cl^BB, Cl^TE]

Parameters:
Nside : int

Nside of the maps

r : float

tensor to scalar ratio

Alens : float

lensing amplitude

H0 : float

Hubble constant

ombh2 : float

baryon density

omch2 : float

cold dark matter density

mnu : float

sum of neutrino masses

omk : float

curvature density

tau : float

optical depth

ns : float

scalar spectral index

As : float

amplitude of the primordial power spectrum

lens_potential_accuracy : int

lensing potential accuracy

nt : float

tensor spectral index

ntrun : float

tensor running index

type_power : str

type of power spectra to return

typeless_bool : bool

return the full power spectra if True, otherwise only the power spectrum of type type_power

Returns:

powers – dictionary of power spectra if typeless_bool is True, otherwise power spectra of type type_power

Return type:

dictionary or array[float]

get_instr(freqs, depth_p)[source]

Return the instrument dictionary

Parameters:
freqs : array[float] or float

frequency of the instrument

depth_p : array[float] or float, of the same dimension as freqs

depth of the instrument

Returns:

instrument – instrument dictionary with keys ‘frequency’, ‘depth_p’, ‘depth_i’

Return type:

dict

loading_params(directory_save_file, file_ver, MICMAC_sampler_obj)[source]

Load all parameters from the saved files

Parameters:
directory_save_file : str

directory where the files are saved

file_ver : str

run version of the file

MICMAC_sampler_obj : object

MICMAC sampler object, to check which parameters were saved

Returns:

dict_all_params – dictionary of all parameters loaded from the files

Return type:

dict