drift.core.kltransform
Functions
|
|
|
|
|
Solve the generalised eigenvalue problem. |
|
Find the inverse of A. |
Classes
|
Perform KL transform. |
- class drift.core.kltransform.KLTransform(bt, subdir=None)
Bases:
Reader
Perform KL transform.
- subset
If True, throw away modes below a S/N threshold.
- Type:
boolean
- threshold
S/N threshold to cut modes at.
- Type:
scalar
- inverse
If True construct and cache inverse transformation.
- Type:
boolean
- use_thermal, use_foregrounds
Whether to use instrumental noise/foregrounds (default: both True)
- Type:
boolean
- _foreground_regulariser
The regularisation constant for the foregrounds. Adds in a diagonal of size reg * cf.max(). Default is 2e-15
- Type:
scalar
- evals_all()
Collects the full eigenvalue spectrum for all m-modes.
Reads in from files on disk.
- Returns:
evarray – The full set of eigenvalues across all m-modes.
- Return type:
np.ndarray
- evals_m(mi, threshold=None)
Fetch the KL-modes for a particular m.
This attempts to read in the results from disk, if available and if not will create them.
Also, it will cache the previous m-mode in memory, so as to avoid disk access in many cases. However this is not sensitive to changes in the threshold, be careful.
- Parameters:
mi (integer) – m to fetch KL-modes for.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
evals – KL-modes with S/N greater than some threshold. Both evals and evecs are potentially None, if there are no modes either in the file, or satisfying S/N > threshold.
- Return type:
np.ndarray
- foreground()
Compute the foreground covariance matrix (on the sky).
- Returns:
cv_fg
- Return type:
np.ndarray[pol2, pol1, l, freq1, freq2]
- generate(regen=False)
Perform the KL-transform for all m-modes and save the result.
Uses MPI to distribute the work (if available).
- Parameters:
mlist (array_like, optional) – Set of m’s to calculate KL-modes for By default do all m-modes.
- invmodes_m(mi, threshold=None)
Get the inverse modes.
If the true inverse has been cached, return the modes for the current threshold. Otherwise generate the Moore-Penrose pseudo-inverse.
- Parameters:
mi (integer) – m-mode to generate for.
threshold (scalar) – S/N threshold to use.
- Returns:
invmodes
- Return type:
np.ndarray
- modes_m(mi, threshold=None)
Fetch the KL-modes for a particular m.
This attempts to read in the results from disk, if available and if not will create them.
Also, it will cache the previous m-mode in memory, so as to avoid disk access in many cases. However this is not sensitive to changes in the threshold, be careful.
- Parameters:
mi (integer) – m to fetch KL-modes for.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
evals, evecs – KL-modes with S/N greater than some threshold. Both evals and evecs are potentially None, if there are no modes either in the file, or satisfying S/N > threshold.
- Return type:
np.ndarray
- project_matrix_sky_to_kl(mi, mat, threshold=None)
Project a covariance matrix from the sky into the eigenbasis.
- Parameters:
mi (integer) – Mode index to fetch for.
mat (np.ndarray) – Sky matrix to project.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
projmatrix – The matrix projected into the eigenbasis.
- Return type:
np.ndarray
- project_matrix_svd_to_kl(mi, mat, threshold=None)
Project a matrix from the telescope basis into the eigenbasis.
- Parameters:
mi (integer) – Mode index to fetch for.
mat (np.ndarray) – Telescope matrix to project.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
projmatrix – The matrix projected into the eigenbasis.
- Return type:
np.ndarray
- project_vector_kl_to_svd(mi, vec, threshold=None)
Project a vector in the Eigenbasis back into the telescope space.
- Parameters:
mi (integer) – Mode index to fetch for.
vec (np.ndarray) – Eigenbasis data vector.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
projvector – The vector projected into the eigenbasis.
- Return type:
np.ndarray
- project_vector_sky_to_kl(mi, vec, threshold=None)
Project an m-vector from the sky into the eigenbasis.
- Parameters:
mi (integer) – Mode index to fetch for.
vec (np.ndarray) – Sky data vector packed as [freq, pol, l]
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
projvector – The vector projected into the eigenbasis.
- Return type:
np.ndarray
- project_vector_svd_to_kl(mi, vec, threshold=None)
Project a telescope data vector into the eigenbasis.
- Parameters:
mi (integer) – Mode index to fetch for.
vec (np.ndarray) – Telescope data vector.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
projvector – The vector projected into the eigenbasis.
- Return type:
np.ndarray
- signal()
Compute the signal covariance matrix (on the sky).
- Returns:
cv_fg
- Return type:
np.ndarray[pol2, pol1, l, freq1, freq2]
- skymodes_m(mi, threshold=None)
Find the representation of the KL-modes on the sky.
Use the beamtransfers to rotate the SN-modes onto the sky. This routine is based on modes_m, as such the same caching and caveats apply.
- Parameters:
mi (integer) – Mode index to fetch for.
threshold (real scalar, optional) – Returns only KL-modes with S/N greater than threshold. By default return all modes saved in the file (this maybe be a subset already, see transform_save).
- Returns:
skymodes – The modes as found in \(a_{lm}(\nu)\) space. Note this routine does not return the evals.
- Return type:
np.ndarray
See also
- sn_covariance(mi)
Compute the signal and noise covariances (on the telescope).
The signal is formed from the 21cm signal, whereas the noise includes both foregrounds and instrumental noise. This is for a single m-mode.
- Parameters:
mi (integer) – The m-mode to calculate at.
- Returns:
s, n – Signal and noice covariance matrices.
- Return type:
np.ndarray[nfreq, ntel, nfreq, ntel]
- transform_save(mi)
Save the KL-modes for a given m.
Perform the transform and cache the results for later use.
- Parameters:
mi (integer) – m-mode to calculate.
Results
-------
evals (np.ndarray) – See transfom_m for details.
evecs (np.ndarray) – See transfom_m for details.
- drift.core.kltransform.eigh_gen(A, B, message='')
Solve the generalised eigenvalue problem. \(\mathbf{A} \mathbf{v} = \lambda \mathbf{B} \mathbf{v}\)
This routine will attempt to correct for when B is not positive definite (usually due to numerical precision), by adding a constant diagonal to make all of its eigenvalues positive.
- Parameters:
A (np.ndarray) – Matrices to operate on.
B (np.ndarray) – Matrices to operate on.
message (string, optional) – Optional string to print if an exception is thrown. Default: “”.
- Returns:
evals (np.ndarray) – Eigenvalues of the problem.
evecs (np.ndarray) – 2D array of eigenvectors (packed column by column).
add_const (scalar) – The constant added on the diagonal to regularise.
- drift.core.kltransform.inv_gen(A)
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