drift.core.beamtransfer

Calculation and management of Beam Transfer matrices

Functions

matrix_image(A[, rtol, atol, errmsg])

matrix_nullspace(A[, rtol, atol, errmsg])

svd_gen(A[, errmsg])

Find the inverse of A.

Classes

BeamTransfer(directory[, telescope])

A class for reading and writing Beam Transfer matrices from disk.

BeamTransferFullSVD(directory[, telescope])

BeamTransfer class that performs the old temperature only SVD.

BeamTransferNoSVD(directory[, telescope])

Subclass of BeamTransfer that skips SVD decomposition.

BeamTransferTempSVD(directory[, telescope])

BeamTransfer class that performs the old temperature only SVD.

class drift.core.beamtransfer.BeamTransfer(directory, telescope=None)

Bases: Reader

A class for reading and writing Beam Transfer matrices from disk.

In addition this provides methods for projecting vectors and matrices between the sky and the telescope basis.

Parameters:
  • directory (string) – Path of directory to read and write Beam Transfers from.

  • telescope (drift.core.telescope.TransitTelescope, optional) – Telescope object to use for calculation. If None (default), try to load a cached version from the given directory.

mem_chunk

The amount of memory to use per process in this calculation in GB. This is a target and not a strict upper limit. This will change the number of chunks the calculation is split into. Default is 3 GB.

Type:

float

svcut

The relative precision below the maximum singular value to exclude low sensitivity SVD modes. This can be dynamically changed as it is evaluated when performing projections.

Type:

float

polsvcut

The relative precision below the maximum value to assume the polarisation sensitivity is zero. This is used to find the polarisation null space. This is used to generate the cached SVD modes and so cannot be changed after they are generated.

Type:

float

truncate

Whether precision truncation of the beam transfer matrices should be done.

Type:

bool

truncate_rel

The relative per element precision to use for the truncation.

Type:

float

truncate_maxl

The truncation precision to use relative the maximum value for all l’s of that mode.

Type:

float

chunk_cache_size

The size of the per m-file HDF5 chunk cache. Default is 128 MB.

Type:

int

beam_m(mi: int, fi: int | None = None) ndarray

Fetch the beam transfer matrix for a given m.

Parameters:
  • mi (integer) – m-mode to fetch.

  • fi (integer) – frequency block to fetch. fi=None (default) returns all.

Returns:

beam

Return type:

np.ndarray (nfreq, 2, npairs, npol_sky, lmax+1)

beam_singularvalues(mi: int) ndarray

Fetch the vector of beam singular values for a given m.

Parameters:

mi (integer) – m-mode to fetch.

Returns:

beam

Return type:

np.ndarray (nfreq, svd_len)

beam_svd(mi: int, fi: int | None = None) ndarray

Fetch the SVD beam transfer matrix (S V^H) for a given m. This SVD beam transfer projects from the sky into the SVD basis.

This returns the full SVD spectrum. Cutting based on SVD value must be done by other routines (see project*svd methods).

Parameters:
  • mi (integer) – m-mode to fetch.

  • fi (integer) – frequency block to fetch. fi=None (default) returns all.

Returns:

beam

Return type:

np.ndarray (nfreq, svd_len, npol_sky, lmax+1)

beam_ut(mi: int, fi: int | None = None) ndarray

Fetch the SVD beam transfer matrix (U^H) for a given m. This SVD beam transfer projects from the telescope space into the SVD basis.

This returns the full SVD spectrum. Cutting based on SVD value must be done by other routines (see project*svd methods).

Parameters:
  • mi (integer) – m-mode to fetch.

  • fi (integer) – frequency block to fetch. fi=None (default) returns all.

Returns:

beam

Return type:

np.ndarray (nfreq, svd_len, ntel)

generate(regen=False, skip_svd=False, skip_svd_inv=False)

Save out all beam transfer matrices to disk.

Parameters:
  • regen (boolean, optional) – Force regeneration even if cache files exist (default: False).

  • skip_svd (boolen, optional) – Skip SVD beam generation. Saves time and space if you are only map making.

generate_cache(regen=False, skip_svd=False, skip_svd_inv=False)

Save out all beam transfer matrices to disk.

Parameters:
  • regen (boolean, optional) – Force regeneration even if cache files exist (default: False).

  • skip_svd (boolen, optional) – Skip SVD beam generation. Saves time and space if you are only map making.

invbeam_m(mi)

Pseudo-inverse of the beam (for a given m).

Uses the Moore-Penrose Pseudo-inverse as the optimal inverse for reconstructing the data. No single option as this only makes sense when combined.

Parameters:

mi (integer) – m-mode to calculate.

Returns:

invbeam

Return type:

np.ndarray (nfreq, npol_sky, lmax+1, 2, npairs)

invbeam_svd(mi: int, fi: int | None = None) ndarray

Fetch the SVD beam transfer matrix (S V^H) for a given m. This SVD beam transfer projects from the sky into the SVD basis.

This returns the full SVD spectrum. Cutting based on SVD value must be done by other routines (see project*svd methods).

Parameters:
  • mi (integer) – m-mode to fetch.

  • fi (integer) – frequency block to fetch. fi=None (default) returns all.

Returns:

beam

Return type:

np.ndarray (nfreq, svd_len, npol_sky, lmax+1)

ndof(mi)

The number of degrees of freedom at a given m.

property nfreq

Number of frequencies measured.

property nsky

Degrees of freedom on the sky at each frequency.

property ntel

Degrees of freedom measured by the telescope (per frequency)

project_matrix_diagonal_telescope_to_svd(mi, dmat)

Project a diagonal matrix from the telescope basis into the SVD basis.

This slightly specialised routine is for projecting the noise covariance into the SVD space.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • dmat (np.ndarray) – Sky matrix packed as [nfreq, ntel]

Returns:

tmat – Covariance in SVD basis.

Return type:

np.ndarray [nsvd, nsvd]

project_matrix_forward(mi, mat, temponly=False)

Project a covariance matrix from the sky into the visibility basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • mat (np.ndarray) – Sky matrix packed as [pol, pol, l, freq, freq]

  • temponly (boolean) – Force projection of temperature (TT) part only (default: False)

Returns:

tmat – Covariance in telescope basis, packed as [nfreq, ntel, nfreq, ntel].

Return type:

np.ndarray

project_matrix_sky_to_svd(mi, mat, temponly=False)

Project a covariance matrix from the sky into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • mat (np.ndarray) – Sky matrix packed as [pol, pol, l, freq, freq]. Must have pol indices even if temponly=True.

  • temponly (boolean) – Force projection of temperature (TT) part only (default: False)

Returns:

tmat – Covariance in SVD basis.

Return type:

np.ndarray [nsvd, nsvd]

project_matrix_sky_to_telescope(mi, mat, temponly=False)

Project a covariance matrix from the sky into the visibility basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • mat (np.ndarray) – Sky matrix packed as [pol, pol, l, freq, freq]

  • temponly (boolean) – Force projection of temperature (TT) part only (default: False)

Returns:

tmat – Covariance in telescope basis, packed as [nfreq, ntel, nfreq, ntel].

Return type:

np.ndarray

project_vector_backward(mi, vec)

Invert a vector from the telescope space onto the sky. This is the map-making process.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Telescope data vector, packed as [nfreq, ntel].

Returns:

tvec – Sky vector to return, packed as [nfreq, npol, lmax+1].

Return type:

np.ndarray

project_vector_forward(mi, vec)

Project a vector from the sky into the visibility basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Sky data vector packed as [nfreq, npol, lmax+1]

Returns:

tvec – Telescope vector to return, packed as [nfreq, ntel]

Return type:

np.ndarray

project_vector_sky_to_svd(mi, vec, temponly=False)

Project a vector from the the sky into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Sky data vector packed as [nfreq, lmax+1]

  • temponly (boolean) – Force projection of temperature part only (default: False)

Returns:

svec – SVD vector to return.

Return type:

np.ndarray

project_vector_sky_to_telescope(mi, vec)

Project a vector from the sky into the visibility basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Sky data vector packed as [nfreq, npol, lmax+1]

Returns:

tvec – Telescope vector to return, packed as [nfreq, ntel]

Return type:

np.ndarray

project_vector_svd_to_sky(mi, vec, temponly=False, conj=False)

Project a vector from the the sky into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Sky data vector packed as [nfreq, lmax+1]

  • temponly (boolean) – Force projection of temperature part only (default: False)

  • conj (boolean) – Reverse projection by applying conjugation (as opposed to pseudo- inverse). Default is False.

Returns:

svec – SVD vector to return.

Return type:

np.ndarray

project_vector_svd_to_telescope(mi, svec)

Map a vector from the SVD basis into the original data basis.

This projection may be lose information about the sky, depending on the polarisation filtering. This essentially uses the pseudo-inverse which is simply related to the original projection matrix.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • svec (np.ndarray) – SVD data vector.

Returns:

vec – Data vector to return.

Return type:

np.ndarray[freq, sign, baseline]

project_vector_telescope_to_sky(mi, vec)

Invert a vector from the telescope space onto the sky. This is the map-making process.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Telescope data vector, packed as [nfreq, ntel].

Returns:

tvec – Sky vector to return, packed as [nfreq, npol, lmax+1].

Return type:

np.ndarray

project_vector_telescope_to_svd(mi, vec)

Map a vector from the telescope space into the SVD basis.

This projection may be lose information about the sky, depending on the polarisation filtering.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Telescope data vector packed as [freq, baseline, polarisation]

Returns:

svec – SVD vector to return.

Return type:

np.ndarray[svdnum]

svd_all()

Collects the full SVD spectrum for all m-modes.

Reads in from file on disk.

Returns:

svarray – The full set of singular values across all m-modes.

Return type:

np.ndarray[mmax+1, nfreq, svd_len]

property svd_len

The size of the SVD output matrices.

class drift.core.beamtransfer.BeamTransferFullSVD(directory, telescope=None)

Bases: BeamTransfer

BeamTransfer class that performs the old temperature only SVD.

property svd_len

The size of the SVD output matrices.

class drift.core.beamtransfer.BeamTransferNoSVD(directory, telescope=None)

Bases: BeamTransfer

Subclass of BeamTransfer that skips SVD decomposition.

To use in a driftscan config file, the nosvd flag needs to be set. (In this case, the value of skip_svd is ignored, because the SVD step is automatically skipped.)

beam_svd(mi, *args, **kwargs)

Fetch beam SVD matrix.

Parameters:

mi (integer) – Mode index to fetch for.

Returns:

mat – Beam-SVD matrix, which in this class is just the beam transfer matrix, packed as [nfreq, 2, nbase, npol, lmax+1].

Return type:

np.ndarray

ndof(mi, *args, **kwargs)

Compute number of degrees of freedom in telescope basis.

Parameters:

mi (integer) – Mode index to fetch for.

Returns:

n – N_dof = ntel * nfreq = nbase * 2 * nfreq.

Return type:

int

property ndofmax

Compute number of degrees of freedom in telescope basis.

Parameters:

mi (integer) – Mode index to fetch for.

Returns:

n – N_dof = ntel * nfreq = nbase * 2 * nfreq.

Return type:

int

project_matrix_diagonal_telescope_to_svd(mi, dmat, *args, **kwargs)

Project a diagonal matrix from the telescope basis to the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • dmat (np.ndarray) – Diagonal telescope-basis matrix packed as [nfreq, ntel].

Returns:

tvec – SVD-basis matrix to return, packed as [ndof, ndof].

Return type:

np.ndarray

project_matrix_sky_to_svd(mi, mat, temponly=False)

Project a covariance matrix from the sky into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • mat (np.ndarray) – Sky matrix packed as [pol, pol, l, freq, freq].

  • temponly (boolean) – Force projection of temperature (TT) part only (default: False)

Returns:

tmat – SVD-basis matrix, packed as [ndof, ndof]. Recall that ndof = ntel * nfreq = 2 * nbase * nfreq.

Return type:

np.ndarray

project_matrix_telescope_to_svd(mi, mat)

Map a matrix from the telescope space into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • mat (np.ndarray) – Telescope-basis matrix, packed as [freq, baseline, freq, baseline].

Returns:

out_mat – SVD-basis matrix, packed as [ndof, ndof].

Return type:

np.ndarray

project_vector_sky_to_svd(mi, vec, *args, **kwargs)

Project a vector from the sky into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Sky data vector packed as [nfreq, npol, lmax+1]

Returns:

tvec – Telescope vector to return, packed as [ndof].

Return type:

np.ndarray

project_vector_svd_to_sky(mi, vec, temponly=False, conj=False)

Project a vector from the the SVD basis into the sky basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – SVD vector, packed as [ndof, …]

Returns:

svec – Sky vector to return, packed as [nfreq, npol, lmax+1, …]

Return type:

np.ndarray

project_vector_telescope_to_svd(mi, vec, *args, **kwargs)

Project a vector from the telescope basis into the SVD basis.

Parameters:
  • mi (integer) – Mode index to fetch for.

  • vec (np.ndarray) – Telescope data vector packed as [nfreq, ntel].

Returns:

tvec – SVD vector to return, packed as [ndof].

Return type:

np.ndarray

class drift.core.beamtransfer.BeamTransferTempSVD(directory, telescope=None)

Bases: BeamTransfer

BeamTransfer class that performs the old temperature only SVD.

drift.core.beamtransfer.svd_gen(A, errmsg=None, *args, **kwargs)

Find the inverse of A.

If a standard matrix inverse has issues try using the pseudo-inverse.

Parameters:

A (np.ndarray) – Matrix to invert.

Returns:

inv

Return type:

np.ndarray