Utils
This module contains a bunch of utility functions that may or may not be useful.
- utils.flatten_mlm(wav_lm, scal_lm)
Takes a set of wavelet and scaling coefficients and flattens them into a single vector
- Parameters
wav_lm – array of wavelet coefficients. Gets flattened if has multiple dimensions
scal_lm – array of wavelet coefficients
- Returns
1D array of coefficients, with the scaling coefficients first
- utils.expand_mlm(mlm, nscales=None, nscalcoefs=None, flatten_wavs=False)
Sepatates scaling and wavelet coefficients from a single vector to separate arrays.
- Parameters
mlm – 1D array containing scaling and wavelet coefficients. Assumes the scaling coefficients come first followed by the wavelet coefficients at increasingly smaller scales.
nscales (int) – number of wavlet scales + 1 scaling function. Use only if coefficients do not follow the multiresolution algorithm, otherwise leave as
None
nscalcoefs (int) – number of scaling function coefficients. Use only if coefficients follow the multiresolution algorithm, otherwise leave as
None
flatten_wavs (bool) – flattens the wavelet coefficients into a 1D array, otherwise 2D. Ignored if
nscalcoefs
is notNone
.
- Returns
tuple (wavelet coefficients, scaling coefficients)
- utils.soft(X, T=0.1)
Soft thresholding of a vector X with threshold T. If \(X_i < T\), then \(\mathrm{soft}(X_i) = 0\), otherwise \(\mathrm{soft}(X_i) = X_i-T\).
- Parameters
X – vector of values to threshold
T (float) – threshold. Can be a vector of same size as
X
- Returns
thresholded vector
- utils.suppress_stdout()
Suppresses stdout from some healpy functions :meta private:
- utils.chebyshev1(X, order)
Calculates the Chebyshev polynomial of the first kind of the given order at point X. Uses the recurrence relation
\(T_{k+1}(X) = 2XT_{k}(X) - T_{k-1}(X)\)
\(T_{1}(X) = X\)
\(T_{0}(X) = 1\)
- Parameters
X – point at which to calulate \(T_{k+1}\)
order (int) – polynomial order
- Returns
value of Chebyshev polynomial of the first kind of the given order
- utils.chebyshev2(X, order)
Calculates the Chebyshev polynomial of the second kind of the given order at point X. Uses the recurrence relation
\(U_{k+1}(X) = 2XU_{k}(X) - U_{k-1}(X)\)
\(U_{1}(X) = 2X\)
\(U_{0}(X) = 1\)
- Parameters
X – point at which to calulate \(U_{k+1}\)
order (int) – polynomial order
- Returns
value of Chebyshev polynomial of the second kind of the given order
- utils.cheb1der(X, order)
Evaluates the derivative of the Chebyshev polynomial of the first kind of the given order at point X. Uses the relation
\(dT_{n}/dx = nU_{n-1}\)
- Parameters
X – point at which to calulate \(dT_{n}/dx\)
order (int) – polynomial order
- Returns
derivative of Chebyshev polynomial of the second kind of the given order
- utils.pixel_area(r, theta1, theta2, phi1, phi2)
Calculates area of a spherical rectangle. Angles must be given in radians.
- Params float r
radius
- Params float theta1
starting colatitude
- Params float theta2
ending colatitude
- Params float phi1
starting longitude
- Params float phi2
ending longitude
- Returns
area of rectangle in squared radians
- utils.polar_cap_area(r, theta)
Calculates the area of a polar cap.
- Params float r
radius
- Params float theta
colatitude in radians of bottom of cap
- Returns
area of polar cap in squared radians
- utils.calc_pixel_areas(L, r=1)
Calculates the areas of all the pixels in MW <https://arxiv.org/abs/1110.6298> sampling.
- Parameters
L (int) – bandlimit
r (float) – radius
- Returns
array of pixel areas with shape \((L, 2L-1)\)
- utils.mw_map_weights(L)
Calculates exact quadrature weights for MW <https://arxiv.org/abs/1110.6298> sampling.
- Parameters
L (int) – bandlimit
- Returns
1D array of quadrature weights with shape \((L(2L-1),)\)
- utils.s2_integrate(f, L)
Integrates a spherical image over the whole sphere
- Parameters
f (array) – spherical image as 1D array of shape \((L(2L-1),)\)
L (int) – bandlimit
- Returns
integral of
f
over the sphere
Todo
Infer
L
from shape off
- utils.snr(signal, noise)
Calculates the signal to noise ratio
\(\mathrm{SNR} = 20\log_{10}\left(\frac{\|\mathrm{signal}\|_2}{\|\mathrm{noise}\|_2}\right)\)
- Parameters
signal – signal array
noise – noise array
- Returns
signal-to-noise ratio in decibels
- utils.build_mask(L, size=20)
” Builds a mask for the galactic plane and ecliptic 0 at positions to be masked i.e. to apply mask do map * mask
size is the width of each mask in degrees
Mask in MW format