interfaces package

Submodules

interfaces.deflationlib module

interfaces.deflationlib.arnoldi(A, b, x0=None, tol=1e-05, maxiter=1000, inner_m=30)[source]

Computes an orthonormal basis to get the approximated eigenvalues (Ritz eigenvalues) and eigenvector.

The basis comes from a Gram-Schmidt orthonormalization of the Krylov subspace defined as:

K_m = span( b, Ab, ..., A^{m-1} b )

at the m-th iteration.

Parameters

  • A : {sparse matrix , linear operator}

    matrix we want to approximate eigenvectors;

  • b : {array}

    array to build the Krylov subspace ;

  • x0 : {array}

    initial guess vector to compute residuals;

  • tol : {float}

    tolerance threshold to the Ritz eigenvalue computation;

  • maxiter : {int}

    to validate the result one can compute maxiter times the eigenvalues, to seek the stability of the algorithm;

  • inner_m : {int}

    maximum number of iterations within the Arnoldi algorithm,

    Warning

    inner_m <=N_pix

Returns

  • w : {list of arrays}

    the orthonormal basis m x N_pix;

  • h : {list of arrays}

    the elements of the H_m Hessenberg matrix. At the m-th iteration h_m has got m+1 elements.

interfaces.deflationlib.build_Z(z, y, w, eps)[source]

Build the deflation matrix Z. Its columns are the r selected eigenvectors Z_i=w_m*y_i s.t. their eigenvalues z_i are smaller than a certain threshold eps.

Parameters

  • z : {array}

    eigenvalues of H_m;

  • y : {list of arrays}

    eigenvectors of H_m;

  • w : {list of arrays}

    orthonormal basis (computed with the Arnoldi algorithm);

  • eps : {float}

    threshold to select the smallest eigenvalues.

Returns

  • Z : {matrix}

    deflation subspace matrix;

  • r : {int}

    rank(Z).

interfaces.deflationlib.build_hess(h, m)[source]

Compute and store (as a Hessenberg matrix) the H_m matrix from the output list h of the arnoldi() routine.

Parameters

  • h : {list of arrays}

    matrix coefficients ;

  • m : {int}

    size of H

Returns

  • H :{numpy.matrix}
interfaces.deflationlib.find_ritz_eigenvalues(h, v, threshold=0.01)[source]
interfaces.deflationlib.run_krypy_arnoldi(A, x0, M, tol, maxiter=None)[source]

interfaces.linearoperators module

class interfaces.linearoperators.BlockDiagonalLO(CES, n, pol=1)[source]

Bases: linop.linop.LinearOperator

Explicit implementation of A \, diag(N^{-1}) A^T, in order to save time in the application of the two matrices onto a vector (in this way the leading dimension will be n_{pix} instead of n_t).

Note

it is initialized as the BlockDiagonalPreconditionerLO since it involves computation with the same matrices.

mult(x)[source]

Multiplication of A \, diag(N^{-1}) A^T on to a vector math:x ( n_{pix} array).

class interfaces.linearoperators.BlockDiagonalPreconditionerLO(CES, n, pol=1)[source]

Bases: linop.linop.LinearOperator

Standard preconditioner defined as:

M_{BD}=( A \, diag(N^{-1}) A^T)^{-1}

where A is the pointing matrix (see SparseLO). Such inverse operator could be easily computed given the structure of the matrix A. It could be sparse in the case of Intensity only analysis (pol=1), block-sparse if polarization is included (pol=3,2).

Parameters

  • n:{int}

    the size of the problem, npix;

  • CES:{ProcessTimeSamples}

    the linear operator related to the data sample processing. Its members (counts, masks, sine, cosine, etc... ) are needed to explicitly compute the inverse of the n_{pix} blocks of M_{BD}.

  • pol:{int}

    the size of each block of the matrix.

mult(x)[source]

Action of y=( A \, diag(N^{-1}) A^T)^{-1} x, where x is an n_{pix} array.

class interfaces.linearoperators.BlockLO(blocksize, t, offdiag=False)[source]

Bases: interfaces.blkop.BlockDiagonalLinearOperator

Derived class from blkop.BlockDiagonalLinearOperator. It basically relies on the definition of a block diagonal operator, composed by nblocks diagonal operators. If it does not have any off-diagonal terms (default case ), each block is a multiple of the identity characterized by the values listed in t and therefore is initialized by the BlockLO.build_blocks() as a linop.DiagonalOperator.

Parameters

  • blocksize : {int or list }

    size of each diagonal block, if int it is : blocksize= n/nblocks.

  • t : {array}

    noise values for each block

  • offdiag : {bool, default False}

    strictly related to the way the array t is passed (see notes ).

    Note

    • True : t is a list of array,

      shape(t)= [nblocks,bandsize], to have a Toeplitz band diagonal operator, bandsize != blocksize

    • False : t is an array, shape(t)=[nblocks].

      each block is identified by a scalar value in the diagonal.

build_blocks()[source]

Build each block of the operator either with or without off diagonal terms. Each block is initialized as a Toeplitz (either band or diagonal) linear operator.

self.diag: {numpy array}
the array resuming the diag(N^{-1}).
build_unbalanced_blocks()[source]

Build the list of Diagonal blocks of blk.BlockDiagonalLinearOperator by assuming that the blocks have different size. Of course it is required that:

\sum _{i=1} ^{nblocks} size(block_i) = N_t

isoffdiag[source]

Property saying whether or not the operator has off-diagonal terms.

class interfaces.linearoperators.CoarseLO(Z, Az, r, apply='LU')[source]

Bases: linop.linop.LinearOperator

This class contains all the operation involving the coarse operator E. In this implementation E is always applied to a vector wiht its inverse : E^{-1}. When initialized it performs either an LU or an eigenvalue decomposition to accelerate the performances of the inversion.

Parameters

  • Z : {np.matrix}

    deflation matrix;

  • A : {SparseLO}

    to compute vectors AZ_i;

  • r : {int}

    rank(Z), dimension of the deflation subspace;

  • apply:{str}
    • LU: performs LU decomposition,
    • eig: compute the eigenvalues and eigenvectors of E.
mult(v)[source]

Perform the multiplication of the inverse coarse operator x=E^{-1} v. It exploits the LU decomposition of E to solve the system Ex=v. It first solves y=L^{-1} v and then x=U^{-1}y.

mult_eig(v)[source]

Matrix vector multiplication with E^{-1} computed via setting_inverse_w_eigenvalues().

setting_inverse_w_eigenvalues(E)[source]

This routine computes the inverse of E by a decomposition through an eigenvalue decomposition. It further checks whether it has some degenerate eigenvalues, i.e. 0 to numerical precision (1.e-15), and eventually excludes these eigenvalues from the anaysis.

class interfaces.linearoperators.DeflationLO(z)[source]

Bases: linop.linop.LinearOperator

This class builds the Deflation operator (and its transpose) from the columns of the matrix Z.

Parameters

  • z : {np.matrix}

    the deflation matrix. Its columns are read as arrays in a list self.z.

mult(x)[source]

Performs the matrix vector multiplication Z x with dim(x) = rank(Z).

rmult(x)[source]

Performs the product onto a N_pix vector with Z^T.

class interfaces.linearoperators.FilterLO(size, subscan_nsample, samples_per_bolopair, bolos_per_ces, pix_samples, poly_order=0)[source]

Bases: linop.linop.LinearOperator

When applied to n_t vector, this operator filters out Legendre Polynomial components from it up to a certain order. In the simple case of a 0-th order polynomial the effect

of filter consists of subtracting the offset from the samples.

Parameters

  • size: {int}

    the size of the input array;

  • subscan_nsample: {list of 2 array}
    • subscan_nsample[0], contains the size of each chunk of the samples

      which has to be processed;

    • subscan_nsample[1], contains the starting sample index of each chunk;
  • samples_per_bolopair:{list of int }

    Number of samples observed during one Constant Elevation Scan (CES) for any pair of detectors. If more CES are included it is a list of int;

  • bolos_per_ces:{list of int}

    Number of pairs of detectors that observed during a CES.

  • pix_samples: {array}

    the same argument as in SparseLO, encoding all the pixels observed during observations.

  • poly_order: {int}

    maximum order of polynomials to be subtracted from the samples.

Note

To be consistent with tha analysis FilterLO does not take into account all the flagged samples.

compute_legendres()[source]
mult(d)[source]
polyfilter(d)[source]
polyfilter_multithreads(d)[source]
procsfilter(args)[source]
class interfaces.linearoperators.GroundFilterLO(ground)[source]

Bases: linop.linop.LinearOperator

counts_in_groundbins(g)[source]
mult(v)[source]
class interfaces.linearoperators.InverseLO(A, method=None, preconditioner=None)[source]

Bases: linop.linop.LinearOperator

Construct the inverse operator of a matrix A, as a linear operator.

Parameters

  • A : {linear operator}

    the linear operator of the linear system to invert;

  • method : {function }

    the method to compute A^-1 (see below);

  • P : {linear operator } (optional)

    the preconditioner for the computation of the inverse operator.

converged[source]

provides convergence information:

  • 0 : successful exit;
  • >0 : convergence to tolerance not achieved, number of iterations;
  • <0 : illegal input or breakdown.
isconverged(info)[source]

It returns a Boolean value depending on the exit status of the solver.

Parameters

  • info : {int}

    output of the solver method (usually scipy.sparse.cg()).

method[source]

The method to compute the inverse of A. It can be any scipy.sparse.linalg solver, namely scipy.sparse.linalg.cg(), scipy.sparse.linalg.bicg(), etc.

mult(x)[source]

It returns y=A^{-1}x by solving the linear system Ay=x with a certain scipy routine (e.g. scipy.sparse.linalg.cg()) defined above as method.

preconditioner[source]

Preconditioner for the solver.

class interfaces.linearoperators.SparseLO(n, m, pix_samples, pol=1, angle_processed=None)[source]

Bases: linop.linop.LinearOperator

Derived class from the one from the LinearOperator in linop. It constitutes an interface for dealing with the projection operator (pointing matrix).

Since this can be represented as a sparse matrix, it is initialized by an array of observed pixels which resembles the (i,j) positions of the non-null elements of the matrix,``obs_pixs``.

Parameters

  • n : {int}

    size of the pixel domain ;

  • m : {int}

    size of time domain; (or the non-null elements in a row of A_{i,j});

  • pix_samples : {array}

    list of pixels observed in the time domain, (or the non-null elements in a row of A_{i,j});

  • pol : {int,[default pol=1]}

    process an intensity only (pol=1), polarization only pol=2 and intensity+polarization map (pol=3);

  • angle_processed: {ProcessTimeSamples}

    the class (instantiated befor SparseLO)has already computed the \cos 2\phi and \sin 2\phi, we link the cos and sin attributes of this class to the ProcessTimeSamples ones ;

maptype[source]

Return a string depending on the map you are processing

mult(v)[source]

Performs the product of a sparse matrix Av, with v a numpy array (dim(v)=n_{pix}) .

It extracts the components of v corresponding to the non-null elements of the operator.

mult_iqu(v)[source]

Performs the product of a sparse matrix Av, with v a numpy array containing the three Stokes parameters [IQU] .

Note

Compared to the operation mult this routine returns a n_t-size vector defined as:

d_t= I_p + Q_p \cos(2\phi_t)+ U_p \sin(2\phi_t).

with p is the pixel observed at time t with polarization angle \phi_t.

mult_qu(v)[source]

Performs A * v with v being a polarization vector. The output array will encode a linear combination of the two Stokes parameters, (whose components are stored contiguously).

d_t=  Q_p \cos(2\phi_t)+ U_p \sin(2\phi_t).

rmult(v)[source]

Performs the product for the transpose operator A^T.

rmult_iqu(v)[source]

Performs the product for the transpose operator A^T to get a IQU map-like vector. Since this vector resembles the pixel of 3 maps it has 3 times the size Npix. IQU values referring to the same pixel are contiguously stored in the memory.

rmult_qu(v)[source]

Performs A^T * v. The output vector will be a QU-map-like array.

class interfaces.linearoperators.ToeplitzLO(a, size)[source]

Bases: linop.linop.LinearOperator

Derived Class from a LinearOperator. It exploit the symmetries of an dim x dim Toeplitz matrix. This particular kind of matrices satisfy the following relation:

A_{i,j}=A_{i+1,j+1}=a_{i-j}

Therefore, it is enough to initialize A by mean of an array a of size = dim.

Parameters

  • a : {array, list}

    the array which resembles all the elements of the Toeplitz matrix;

  • size : {int}

    size of the block.

mult(v)[source]

Performs the product of a Toeplitz matrix with a vector x.

Module contents

This module contains the 2 main libraries for COSMOMAP2