Namespaces
Automatically generated documentation for darkmappy APIs. All functionality is accessible through a pip installation of the darkmappy package.
- darkmappy.logs.critical_log(message)
Log a critical message (e.g. core code failures etc).
- Parameters
message – Message to log.
- darkmappy.logs.debug_log(message)
Log a debug message (e.g. for background logs to assist debugging).
- Parameters
message – Message to log.
- darkmappy.logs.info_log(message)
Log an information message (e.g. evidence value printing, run completion etc).
- Parameters
message – Message to log.
- darkmappy.logs.setup_logging(custom_yaml_path=None, default_level=10)
initialise and configure logging.
Should be called at the beginning of code to initialise and configure the desired logging level. Logging levels can be ints in [0,50] where 10 is debug logging and 50 is critical logging.
- Parameters
custom_yaml_path (string) – Complete pathname of desired yaml logging configuration. If empty will provide default logging config.
default_level (int) – Logging level at which to configure.
- Raises
ValueError – Raised if logging.yaml is not in ./logs/ directory.
- darkmappy.logs.warning_log(message)
Log a warning (e.g. for internal code warnings such as large dynamic ranges).
- Parameters
message – Warning to log.
- darkmappy.validation.analyse(x, y)
Computes statistics on recovered result
- Parameters
x (complex array) – True map
y (complex array) – Estimated map
- darkmappy.validation.p_correlation(x, y)
Computes pearson correlation coefficient.
- Parameters
x (np.ndarray) – True map
y (np.ndarray) – Estimated map
- Raises
ValueError – Raised if x and y not of the same rank and size
- darkmappy.validation.snr(x, y)
Computes signal to noise ratio in dB
- Parameters
x (np.ndarray) – True map
y (np.ndarray) – Estimated map
- Raises
ValueError – Raised if x and y not of the same rank and size
- class darkmappy.forward_models.PlanarForwardModel(n, mask=None, ngal=None, supersample=1, sigma_e=0.37)
Weak Gravitational Lensing planar Forward model
Supports additional complexity which should simply be appended to the dir_op and adj_op objects appropriately (e.g. psf degridding step, psf deconvolution etc.)
- __init__(n, mask=None, ngal=None, supersample=1, sigma_e=0.37)
Construct class to hold the spherical forward and forward adjoint operators.
- Parameters
n (int) – Pixel count along each axis (square images)
mask (int array) – Map of realspace masking.
ngal (int array) – Map of galaxy observation count.
supersample (float) – Degree of supersampling.
sigma_e (float) – intrinsic ellipticity dispersion
- Raises
ValueError – Raised if map is of size 0.
ValueError – Raised if mask is the wrong shape.
ValueError – Raised if ngal is the wrong shape.
WarningLog – Raised if L is very large.
- adj_op(gamma)
Planar weak lensing adjoint measurement operator
- Parameters
gamma (complex array) – Shear Observations (cov weighted)
- compute_fourier_kernels()
Computes fourier space kernel mappings.
Returns as a tuple {forward, inverse}.
- cov_weight(x)
Applies covariance weighting to observations.
Assumes no intrinsic correlation between pixels.
- Parameters
x (array) – pixel space map to be inverse covariance weighted.
- dir_op(kappa)
Planar weak lensing measurement operator
- Parameters
kappa (complex array) – Convergence signal
- ks_estimate(gamma)
Computes Kaiser-Squires estimator (as a first estimate)
- Parameters
gamma (complex array) – Shear Observations (patch)
- mask_adjoint(x)
Applies given mask adjoint to observations
- Parameters
x (complex array) – Set of observations.
- Raises
ValueError – Raised if signal is nan
- mask_forward(f)
Applies given mask to a field.
- Parameters
f (complex array) – Realspace Signal
- Raises
ValueError – Raised if signal is nan
ValueError – Raised if signal is of incorrect shape.
- ngal_to_inv_cov(ngal)
Converts galaxy number density map to data covariance.
Assumes no intrinsic correlation between pixels.
- Parameters
ngal (real array) – pixel space map of observation counts per pixel.
- class darkmappy.forward_models.SphericalForwardModel(L, mask=None, ngal=None, sigma_e=0.37)
Weak Gravitational Lensing spherical Forward model
Supports additional complexity which should simply be appended to the dir_op and adj_op objects appropriately (e.g. psf degridding step, psf deconvolution etc.)
- __init__(L, mask=None, ngal=None, sigma_e=0.37)
Construct class to hold the spherical forward and forward adjoint operators.
- Parameters
L (int) – Spherical harmonic bandlimit
mask (int array) – Map of realspace masking.
ngal (int array) – Map of galaxy observation count.
sigma_e (float) – intrinsic ellipticity dispersion
- Raises
ValueError – Raised if L is not positive
ValueError – Raised if mask is the wrong shape.
WarningLog – Raised if L is very large.
- adj_op(gamma)
Spherical weak lensing adjoint measurement operator
- Parameters
gamma (complex array) – Shear Observations (cov weighted)
- compute_harmonic_kernel()
Compuptes harmonic space kernel mapping
- Returns
Harmonic space weak lensing kernel
- cov_weight(x)
Applies covariance weighting to observations.
Assumes no correlation between pixels.
- Parameters
x (array) – pixel space map to be inverse covariance weighted.
- Returns
Inverse covariance weighted observations y’ = y * sigma^-1/2
- dir_op(kappa)
Spherical weak lensing measurement operator
- Parameters
kappa (complex array) – Convergence signal
- harmonic_inverse_mapping(flm)
Applys harmonic space inverse mapping.
- Parameters
flm (complex array) – harmonic coefficients.
- Returns
Inverse mapped harmonic coefficients glm = flm / K
- harmonic_mapping(flm)
Applys harmonic space mapping.
- Parameters
flm (complex array) – harmonic coefficients.
- Returns
Mapped harmonic coefficients glm = flm * K
- mask_adjoint(x)
Applies given mask adjoint to observations
- Parameters
x (complex array) – Set of observations.
- Raises
ValueError – Raised if signal is nan
- Returns
Gridded full-sky map of observations
- mask_forward(f)
Applies given mask to a field.
- Parameters
f (complex array) – Realspace Signal
- Raises
ValueError – Raised if signal is nan
ValueError – Raised if signal is of incorrect shape.
- Returns
Array of observations only.
- ngal_to_inv_cov(ngal)
Converts galaxy number density map to data covariance.
Assumes no correlation between pixels.
- Parameters
ngal (real array) – pixel space map of number of observations per pixel
- Returns
Data covariance, assuming no correlations and Gaussian noise
- sks_estimate(gamma)
Computes spherical Kaiser-Squires estimator (as a first estimate)
- Parameters
gamma (complex array) – Shear Observations (full-sky)
- darkmappy.noise_simulations.Gaussian_noise_plane(x, gals_pix, sigma_e, mask=None)
Adds realistic noise based on observational ngal.
- Parameters
x (np.ndarray) – Clean simulated data.
mask (int array) – Sky mask map
gals_pix (float) – Number of observations per pixel
sigma_e (float) – Intrinsic ellipticity dispersion.
- darkmappy.noise_simulations.Gaussian_noise_sphere(x, L, ngal, sigma_e, mask=None)
Adds realistic noise based on observational ngal.
- Parameters
x (np.ndarray) – Clean simulated data.
mask (int array) – Sky mask map
L (int) – Angular bandlimit.
ngal (float) – Number density of galaxy observations to simulate.
sigma_e (float) – Intrinsic ellipticity dispersion.
- Raises
ValueError – Input shape incorrect.
- darkmappy.noise_simulations.simulate_shear_plane(x, sidelength, ngal=30, sigma_e=0.37, mask=None, supersample=1)
Creates a realistic simulation of shear observations from input convergence.
- Parameters
x (np.ndarray) – Input convergence map
mask (int array) – Input convergence mask map
sidelength (int) – Angular span of axes.
ngal (float) – Number density of galaxy observations to simulate.
sigma_e (float) – Intrinsic ellipticity dispersion.
- darkmappy.noise_simulations.simulate_shear_sphere(x, L, ngal=30, sigma_e=0.37, mask=None)
Creates a realistic simulation of shear observations from input convergence.
- Parameters
x (np.ndarray) – Input convergence map
mask (int array) – Input convergence mask map
L (int) – Angular bandlimit.
ngal (float) – Number density of galaxy observations to simulate.
sigma_e (float) – Intrinsic ellipticity dispersion.
- Raises
ValueError – Input shape incorrect.
- class darkmappy.solvers.PrimalDual(data, phi, psi, options={'constrained': True, 'iter': 5000, 'nu': 0, 'positivity': False, 'real': False, 'record_iters': False, 'tol': 1e-05, 'update_iter': 50})
Class which handles all primal dual optimisation paradigms.
- __init__(data, phi, psi, options={'constrained': True, 'iter': 5000, 'nu': 0, 'positivity': False, 'real': False, 'record_iters': False, 'tol': 1e-05, 'update_iter': 50})
Construct primal dual general class.
Any additional details should be here.
- Parameters
() (beta) – Measurement operator (weights for poisson noise)
() – Redundant dictionary (wavelets etc.)
() – (?)
constrained (bool) – Constrained vs unconstrained problem
- Raises
ValueError – Data vector contains NaN values.
- l1_constrained_gaussian(warm_start, sigma, beta=0.01)
Solve constrained l1 regularisation problem with Gaussian noise.
Can be instantiated from warm_start.
- Parameters
() (beta) – Data-set to be optimised over.
() – Initial solution of optimisation.
() – Noise-level present in optimisation.
() – Scaling for l1-norm threshold
- Raises
ValueError – Datavector size is 0 (empty set).
ValueError – Datavector contains NaN values.
- l1_unconstrained_gaussian(warm_start, sigma, beta)
Solve unconstrained l1 regularisation problem with Gaussian noise.
Can be instantiated from warm_start.
- Parameters
() (beta) – Data-set to be optimised over.
() – Initial solution of optimisation.
() – Noise-level present in optimisation.
() – Regularisation parameter
- Raises
ValueError – Datavector size is 0 (empty set).
ValueError – Datavector contains NaN values.
- l1_unconstrained_gaussian_jm(warm_start, sigma, beta)
Solve unconstrained l1 regularisation problem with Gaussian noise.
Can be instantiated from warm_start.
- Parameters
() (beta) – Data-set to be optimised over.
() – Initial solution of optimisation.
() – Noise-level present in optimisation.
() – Regularisation parameter
- Raises
ValueError – Datavector size is 0 (empty set).
ValueError – Datavector contains NaN values.
- class darkmappy.wavelet_wrappers.S2letWavelets(L, B=2, J_min=0, N=1, forward_transform=True, upsample=0)
Linear operator wrapper for Spherical wavelet transforms using pys2let.
All variations of the wavelet transform are supported.
- __init__(L, B=2, J_min=0, N=1, forward_transform=True, upsample=0)
Construct Spherical Wavelet transform class to hold all forward, inverse, and corresponding adjoint wavelet transforms.
- Parameters
L (int) – Spherical harmonic bandlimit
B (int) – Wavelet tiling spread (2 = dyadic)
J_min (int) – Smallest wavelet scale
N (int) – directional samples (wigner space)
upsample (bint) – downscale wavelet scale maps.
Reality (bint) – Reality of signal.
- Raises
ValueError – Raised if L is not positive
ValueError – Raised if B is less than 1.
ValueError – Raised if N is less than 1.
ValueError – Raised if N or B is more than L.
WarningLog – Raised if L is very large.
- forward(f, spin=0)
Compute the forward spherical wavelet transform.
- Parameters
f (np.complexarray) – Realspace Signal
spin (int) – spin of field f
- Raises
ValueError – Raised if signal is nan
- forward_adjoint(fws, spin=0)
Compute the forward_adjoint spherical wavelet transform.
- Parameters
f_ws (np.complexarray) – Wavelet + scaling coefficients
spin (int) – spherical harmonic spin
- Raises
ValueError – Raised if wavelet coefficients nan
ValueError – Raised if scaling coefficients nan
- inverse(fws, spin=0)
Compute the inverse spherical wavelet transform.
- Parameters
f_ws (np.complexarray) – Wavelet + scaling coefficients
spin (int) – spherical harmonic spin
- Raises
ValueError – Raised if wavelet coefficients nan
ValueError – Raised if scaling coefficients nan
- inverse_adjoint(f, spin=0)
Compute the inverse adjoint spherical wavelet transform.
- Parameters
f (np.complexarray) – Realspace Signal
spin (int) – spin of field f
- Raises
ValueError – Raised if signal is nan
- class darkmappy.estimators.DarkMappyPlane(n, data=None, mask=None, ngal=None, viewer=None, wav=['db6'], levels=4, supersample=1, psi=None, constrained=True)
Frontend class which handles dark matter reconstruction.
This class currently supports the planar lensing forward model, a selection of sparsity priors, for Gaussian and Poissonian noise models.
- __init__(n, data=None, mask=None, ngal=None, viewer=None, wav=['db6'], levels=4, supersample=1, psi=None, constrained=True)
Construct class to create and hold the MAP estimator
- Parameters
n (int) – Pixel count along each axis (square image)
data (complex array) – Pixelised map of shear observations.
mask (int array) – Map of realspace masking.
ngal (int array) – Map of galaxy observation count.
wavs (list) – Wavelet dictionaries to use.
levels (int) – Number of levels within each wavelet dictionary.
supersample (float) – Amount of supersampling.
psi (linear operator) – Sparsifying dictionary.
constrained (boolean) – Constrained or unconstrained optimisation
- Raises
ValueError – Raised if n is not positive.
ValueError – Raised if mask is the wrong shape.
ValueError – Raised if no data provided.
WarningLog – Raised if no galaxy number density map provided.
WarningLog – Raised if no masking map provided.
WarningLog – Raised if n is very large.
WarningLog – Raised if N is very large.
- normalise_phi()
Power method normalisation of forward-model
- run_estimator(mu=0.001, sigma=1)
Performs maximum a posteriori inference via proximal primal dual solver.
- Parameters
mu (float) – Regularisation parameter of problem.
sigma (float) – Whitened noise level of problem.
- class darkmappy.estimators.DarkMappySphere(L, N=1, data=None, mask=None, ngal=None, viewer=None, psi=None, constrained=True)
Frontend class which handles dark matter reconstruction.
This class currently supports the spherical lensing forward model, a selection of sparsity priors, for Gaussian and Poissonian noise models.
- __init__(L, N=1, data=None, mask=None, ngal=None, viewer=None, psi=None, constrained=True)
Construct class to create and hold the MAP estimator
- Parameters
L (int) – Spherical harmonic bandlimit.
N (int) – Directionality of wavelet dictionary.
data (complex array) – Pixelised map of shear observations.
mask (int array) – Map of realspace masking.
ngal (int array) – Map of galaxy observation count.
psi (linear operator) – Sparsifying dictionary.
constrained (boolean) – Constrained or unconstrained optimisation
- Raises
ValueError – Raised if L is not positive.
ValueError – Raised if mask is the wrong shape.
ValueError – Raised if no data provided.
WarningLog – Raised if no galaxy number density map provided.
WarningLog – Raised if no masking map provided.
WarningLog – Raised if L is very large.
WarningLog – Raised if N is very large.
- normalise_phi()
Power method normalisation of forward-model
- run_estimator(mu=0.001, sigma=1)
Performs maximum a posteriori inference via proximal primal dual solver.
- Parameters
mu (float) – Regularisation parameter of problem.
sigma (float) – White noise level of problem.