lib.Fitting.QanalysisMC module

lib.Fitting.QanalysisMC.Cp2Cp_prime(Cp, verbose=True)[source]

Average the covariance matrices over pixels. A normalization by the 00 element is done before averaging. :type Cp: :param Cp: The covariance matrices for each pixel.

Shape (#bands, #bands, #stokes, #pixels)

Parameters:

verbose (bool)

Returns:

Cp_prime – The covariance matrices for each pixel.

Return type:

array of shape (#bands, #bands, #Stokes, #pixels)

lib.Fitting.QanalysisMC.Cp2Cp_prime_viaCorr(Cp, verbose=True)[source]

Average the covariance matrices over pixels. A normalization is done on pixels before the average. :type Cp: :param Cp: The covariance matrices for each pixel.

Shape: (#bands, #bands, #Stokes, #pixels)

Parameters:

verbose (bool)

Returns:

Cp_prime – The covariance matrices for each pixel.

Return type:

array of shape (#bands, #bands, #Stokes, #pixels)

lib.Fitting.QanalysisMC.average_pix_sig2(sig2, ang, ang_threshold)[source]

Average the variances over pixels in a given angle.

lib.Fitting.QanalysisMC.covariance_IQU_subbands(allmaps, stokesjoint=False)[source]

Returns the mean maps, averaged over pixels and realisations and the covariance matrices of the maps.

Parameters:
  • allmaps (list) – List of arrays of shape (nreals, nsub, npix, 3) List of maps for each number of sub-bands.

  • stokesjoint (if True return Stokes parameter together) – I0,I1,…, Q0,Q1,…, U0,U1, … . Otherwise will return I0,Q0,U0, I1,Q1,U1, … Default: False

Returns:

  • allmean (list of arrays of shape 3*nsub) – mean for I, Q, U for each subband

  • allcov (list of arrays of shape (3*nsub, 3*nsub)) – covariance matrices between stokes parameters and sub frequency bands

lib.Fitting.QanalysisMC.distance_square(matrix)[source]

Return a distance associated to a matrix (n*n). Sum of the square elements normalized by n**2.

lib.Fitting.QanalysisMC.distance_sup(matrix)[source]

Return a distance associated to a matrix (n*n). Normalized by n.

lib.Fitting.QanalysisMC.get_Cp(patch, verbose=True, doplot=True)[source]

Returns covariance matrices between subbands for each Stokes parameter and each pixel.

Parameters:
  • patch (ndarray) – Shape (#reals, #bands, #pixels, 3)

  • verbose (Bool) – If True makes a lot of prints.

  • doplot (Bool) – If True, plot the mean cov and corr matrices over pixels.

Returns:

Cp – The covariance matrices.

Return type:

array of shape (#bands, #bands, 3, #pixels)

lib.Fitting.QanalysisMC.get_corrections(nf_sub, nf_recon, band=150, relative_bandwidth=0.25)[source]

The reconstructed subbands have different widths. Here, we compute the corrections you can applied to the variances and covariances to take this into account.

Parameters:
  • nf_sub (int) – Number of input subbands

  • nf_recon (int) – Number of reconstructed subbands

  • band (int) – QUBIC frequency band, in GHz. 150 by default Typical values: 150, 220.

  • relative_bandwidth (float) – Ratio of the difference between the edges of the frequency band over the average frequency of the band Typical value: 0.25

Returns:

  • corrections (list) – Correction coefficients for each subband.

  • correction_mat (array of shape (3xnf_recon, 3xnf_recon)) – Matrix containing the corrections. It can be multiplied term by term to a covariance matrix.

lib.Fitting.QanalysisMC.get_covcorr1pix(maps, ipix, verbose=False, stokesjoint=False)[source]

This function return the covariance matrix for one pixel given a list of maps. Each of the Nreal maps has the shape (nfrec, npix, 3) (see save_simu_fits() ).

Parameters:
  • maps (array) – Input maps with shape (nrealizations, nfrecons, npix, 3)

  • ipix (int) – pixel where the covariance will be computed

  • verbose (bool) – If True, print information. False by default.

  • stokesjoint (bool) – If True return Stokes parameter together I0,I1,…, Q0,Q1,…, U0, U1, … . Otherwise will return I0,Q0,U0, I1,Q1,U1, … Default: False

Returns:

  • cov1pix (np.array) – covariance matrix for a given pixel (ipix) with shape 3*nfrec x 3*nfrec

  • corr1pix (np.array) – correlation matrix for a given pixel (ipix) with shape 3*nfrec x 3*nfrec

lib.Fitting.QanalysisMC.get_covcorr_between_pix(maps, verbose=False)[source]

Compute the pixel covariance matrix and correlation matrix minus the identity over many realisations. You will obtain nsub x 3 matrices of shape (npix x npix).

Parameters:
  • maps (array) – Input maps with shape (nreal, nsub, npix, 3)

  • verbose (bool) – If True, print information. False by default.

Returns:

  • cov_pix (array of shape (nsub, nstokes, npix, npix)) – The covariance matrices for each subband and I, Q, U.

  • corr_pix (array of shape (nsub, nstokes, npix, npix)) – The correlation matrices minus the identity (0. on the diagonal).

lib.Fitting.QanalysisMC.get_covcorr_patch(patch, stokesjoint=False, doplot=False)[source]

This function computes the covariance matrix and the correlation matrix for a given patch in the sky. It uses get_covcorr1pix() to compute the covariance and correlation matrix for each pixel (ipix).

Asumptions: patch.shape = (nreals, nbands, npix_patch, nstokes) –> to be able to use get_covcorr1pix

lib.Fitting.QanalysisMC.get_mean_cov(vals, invcov)[source]

This function does the same as: get_weighted_correlation_average

lib.Fitting.QanalysisMC.get_residuals(fits_noise, fits_noiseless, residuals_way)[source]

Compute residuals in a given way.

Parameters:
  • fits_noise (list) – List containing the reconstructed noisy maps (fits files)

  • fits_noiseless (str) – Fits file containing the noiseless reconstruction

  • residuals_way (str) – Way to compute residuals. 3 keywords : noiseless, conv or mean_recon

Returns:

residuals : array of shape (#reals, #bands, #pixels, 3)

lib.Fitting.QanalysisMC.get_rms_covar(nsubvals, seenmap, allmapsout)[source]

Test done by Matthieu Tristram : Calculate the variance map in each case accounting for the band-band covariance matrix for each pixel from the MC. This is pretty noisy so it may be interesting to get the average matrix. We calculate all the matrices for each pixel and normalize them to average 1 and then calculate the average matrix over the pixels.

variance_map : array of shape (len(nsubvals), 3, npixok)

allmeanmatlist of arrays (nsub, nsub, 3)

Mean over pixels of the cov matrices freq-freq

allstdmatlist of arrays (nsub, nsub, 3)

Std over pixels of the cov matrices freq-freq

lib.Fitting.QanalysisMC.get_rms_covarmean(nsubvals, seenmap, allmapsout, allmeanmat)[source]

RMS map and mean map over the realisations using the pixel averaged freq-freq covariance matrix computed with get_rms_covar meanmap_cov : array of shape (len(nsubvals), 3, npixok)

rmsmap_cov : array of shape (len(nsubvals), 3, npixok)

lib.Fitting.QanalysisMC.get_weighted_correlation_average(x, cov)[source]

Compute a weighted average taking into account the correlations between the variables. The mean obtained is the one that has the minimal variance possible.

Parameters:
  • x (1D array) – Values you want to average.

  • cov (2D array) – Covariance matrix associated to the values in x.

Return type:

The weighted mean and the variance on that mean.

lib.Fitting.QanalysisMC.make_weighted_av(patch, Cp, verbose=False)[source]

Average the maps over subbands using the covariance matrix between subbands. :type patch: :param patch: Shape (#reals, #bands, #pixels, #nstks) :type patch: array :type Cp: :param Cp: The covariance matrices.

Shape (#bands, #bands, #nstks, #pixels)

Parameters:

verbose (bool)

Returns:

  • weighted_av (map averaged over bands)

  • sig2 (variances over realisations on the map)

lib.Fitting.QanalysisMC.plot_hist(mat_npix, bins, title_prefix, ymax=0.5, color='b')[source]

Plots the histograms of each element of the matrix. Each histogram represents the distribution of a given term over the pixels..

Parameters:
  • mat_npix (array of shape (3 x nfreq, 3 x nfreq, npix)) – Cov or corr matrix for each pixel.

  • bins (int) – Numbers of bins for the histogram

  • title_prefix (str) – Prefix for the title of the plot.

  • ymax (float) – Limit max on the y axis (between 0 and 1)

  • color (str) – Color of the histogram

lib.Fitting.QanalysisMC.rms_method(name, residuals_way, zones=1, simulation_dir=None)[source]

Get the std of the residuals from one simulation. STD are computed over realisations and pixels for I, Q, U separately.

Parameters:
  • name (str) – Simulation file.

  • residuals_way (str) – Way to compute residuals. 3 keywords : noiseless, conv or mean_recon

  • zones (int) – Number of zones to divide the patch.

Returns:

  • rms_I, rms_Q, rms_U (dictionarys containing RMS for IQU)

  • setpar (a dict with some parameters of the simu.)

lib.Fitting.QanalysisMC.std_profile(many_patch, nbins, nside, center, seenmap)[source]

Get the std profile of a patch over pixels and realisations from the center to the border.

Parameters:
  • many_patch (array of shape (nreal, nsub, npixok, 3)) – Many realisations of one patch.

  • nbins (int) – Number of bins.

  • nside (int) – NSIDE in the patch.

  • center (array) – Coordinates of the center of the patch in degree (lon, lat)

  • seenmap (array) – Array of booleans of shape #pixels, True inside the patch and False outside.

Returns:

  • bin_centers (array with angles associated to each bin.)

  • ang (array with angles associated to each pixel)

  • std_bin (array of shape (nbins, nsub, 3)) – Std value in each bin, for each subband and IQU.

  • std_profile (array of shape (npixok, nsub, 3)) – Quadratic interpolation of the std_bin.