pyimcom.lakernel

Linear algebra kernels to solve linear systems.

Classes

_LAKernel

Abstract base class of linear algebra kernels.

EigenKernel

LA kernel using eigendecomposition.

CholKernel

LA kernel using Cholesky decomposition.

IterKernel

LA kernel using iterative method.

EmpirKernel

Fake LA kernel using empirical relation.

Functions

conjugate_gradient

Simplified version of scipy.sparse.linalg.cg.

_extract_submatrix

Extract a submatrix from a symmetric matrix.

_extract_subvector

Extract a subvector from a vector.

_assign_subvector

Assign values to a subvector of a vector.

Classes

_LAKernel

Abstract base class of linear algebra kernels.

EigenKernel

LA kernel using eigendecomposition.

CholKernel

LA kernel using Cholesky decomposition.

IterKernel

LA kernel using iterative method.

EmpirKernel

Fake LA kernel using empirical relation.

Functions

conjugate_gradient(→ numpy.array)

Simplified version of scipy.sparse.linalg.cg.

_extract_submatrix(→ numpy.array)

Extract a submatrix from a symmetric matrix.

_extract_subvector(→ numpy.array)

Extract a subvector from a vector.

_assign_subvector(→ None)

Assign values to a subvector of a vector.

Module Contents

class _LAKernel(outst)[source]

Abstract base class of linear algebra kernels.

Parameters:

outst (coadd.OutStamp) – Output postage stamp to which this kernel instance is attached.

__init__()[source]

Constructor.

__call__()[source]

Solve linear systems.

outst[source]
n_out[source]
m[source]
n[source]
n2f[source]
kappaC_arr[source]
nv[source]
ucmin[source]
smax[source]
__call__() None[source]

Solve linear systems.

Return type:

None

Notes

This produces the following arrays for self.outst:

  • T = coaddition matrix, shape = (n_out, m, n)

  • UC = fractional squared error in PSF, shape = (n_out, m)

  • Sigma = output noise amplification, shape = (n_out, m)

  • kappa = Lagrange multiplier per output pixel, shape = (n_out, m)

class EigenKernel(outst)[source]

Bases: _LAKernel

LA kernel using eigendecomposition.

_call_single_kappa()[source]

Solve linear systems for single kappa node.

_call_multi_kappa()[source]

Solve linear systems for multiple kappa nodes.

_call_single_kappa() None[source]

Solve linear systems for single kappa node.

_call_multi_kappa(nbis: int = 13) None[source]

Solve linear systems for multiple kappa nodes.

Parameters:

nbis (int, optional) – Number of bisections.

Return type:

None

Notes

Based on pyimcom_lakernel.CKernelMulti of furry-parakeet. This one generates multiple images. there can be n_out target PSFs.

class CholKernel(outst)[source]

Bases: _LAKernel

LA kernel using Cholesky decomposition.

_cholesky_wrapper()[source]

Wrapper for cholesky (staticmethod)

_call_single_kappa()[source]

Solve linear systems for single kappa node.

_call_multi_kappa()[source]

Solve linear systems for multiple kappa nodes.

static _cholesky_wrapper(AA: numpy.array, di: tuple[numpy.array, numpy.array], A: numpy.array) numpy.array[source]

Wrapper for cholesky, rectifies negative eigenvalue(s) if needed.

Parameters:
  • AA (np.array) – System matrix A plus kappa times noise; shape (n,n).

  • di ((np.array, np.array)) – Indices to main diagonal of AA; each has shape (n,).

  • A (np.array) – Original system matrix; shape (n,n).

Returns:

L – Cholesky results; shape (n,n).

Return type:

np.array

_call_single_kappa() None[source]

Solve linear systems for single kappa node.

_call_multi_kappa() None[source]

Solve linear systems for multiple kappa nodes.

Return type:

None

Notes

Based on pyimcom_lakernel.get_coadd_matrix_discrete of furry-parakeet: alternative to CKernelMulti, almost same functionality but has a range of kappa.

conjugate_gradient(A: numpy.array, b: numpy.array, rtol: float = 0.0015, maxiter: int = 30) numpy.array[source]

Simplified version of scipy.sparse.linalg.cg.

Parameters:
  • A (np.array) – System matrix A, shape (n,n)

  • b (np.array) – Column vector b, shape (n,).

  • rtol (float, optional) – Relative tolerance.

  • maxiter (int, optional) – Maximum number of iterations.

Returns:

x – Solution vector b, shape (n,).

Return type:

np.array

_extract_submatrix(mat_orig: numpy.array, selection: numpy.array) numpy.array[source]

Extract a submatrix from a symmetric matrix.

Parameters:
  • mat_orig (np.array) – Symmetric matrix to be extracted, shape (n,n).

  • selection (np.array) – Integer array of indices of rows and columns to extract, shape (n,).

Returns:

mat_copy – Extracted submatrix. Shape (n_,n_), where n_ is number of selected rows or columns.

Return type:

np.array

_extract_subvector(vec_orig: numpy.array, selection: numpy.array) numpy.array[source]

Extract a subvector from a vector.

Parameters:
  • vec_orig (np.array) – Vector to be extracted, shape (n,).

  • selection (np.array) – Integer array of indices of elements to extract, shape (n,).

Returns:

vec_copy – Extracted subvector. Shape (n_,) where n_ is number of selected elements.

Return type:

np.array

_assign_subvector(vec_left: numpy.array, vec_right: numpy.array, selection: numpy.array) None[source]

Assign values to a subvector of a vector.

Parameters:
  • vec_left (np.array) – Vector to be assigned to.

  • vec_right (np.array) – Subvector of values to assign.

  • selection (np.array) – Integer array of indices of elements to assign to; same length as vec_left.

Return type:

None

class IterKernel(outst)[source]

Bases: _LAKernel

LA kernel using iterative method.

_iterative_wrapper()[source]

Wrapper for iterative method (staticmethod).

_call_single_kappa()[source]

Solve linear systems for single kappa node.

_call_multi_kappa()[source]

Solve linear systems for multiple kappa nodes.

static _iterative_wrapper(AA: numpy.array, mBhalf: numpy.array, relevant_matrix: numpy.array, rtol: float = 0.0015, maxiter: int = 30) numpy.array[source]

Wrapper for conjugate gradient method.

Parameters:
  • AA (np.array) – System matrix A plus kappa times noise. Shape (n,n).

  • mBhalf (np.array) – System matrix -B/2 (for a single target PSF). Shape (n,n).

  • relevant_matrix (np.array) – Boolean array indicating whether to use an input pixel for an output pixel. Shape (m,n).

  • rtol (float, optional) – Relative tolerance.

  • maxiter (int, optional) – Maximum number of iteration.

Returns:

Output T matrix (for a single target PSF). Shape (m,n).

Return type:

np.array

_call_single_kappa(exact_UC: bool = False) None[source]

Solve linear systems for single kappa node.

Parameters:

exact_UC (bool, optional) – Whether to use exact expression for U/C. The default is False, as this is slow and the gain is very small.

Return type:

None

_call_multi_kappa(exact_UC: bool = True) None[source]

Solve linear systems for multiple kappa nodes.

Parameters:

exact_UC (bool, optional) – Whether to use exact expression for U/C. The default is True, as the approximation does not work. KC: Please avoid this whenever possible as this is SUPER slow.

Return type:

None

class EmpirKernel(outst)[source]

Bases: _LAKernel

Fake LA kernel using empirical relation.

_call_single_kappa()[source]

Produce the T matrix without solving linear systems.

_call_multi_kappa()[source]

Pathway to _call_single_kappa.

_call_single_kappa() None[source]

Produce the T matrix without solving linear systems.

_call_multi_kappa() None[source]

Pathway to _call_single_kappa, since the empirical kernel doesn’t use kappa.