slitronomy.Optimization package

Submodules

slitronomy.Optimization.algorithms module

slitronomy.Optimization.algorithms.step_FB(x, grad, prox, step_size)

Forward Backward Algorithm

slitronomy.Optimization.algorithms.step_FISTA(x, y, t, grad, prox, step_size)

Fast Iterative Shrinkage-Thresholding Algorithm

slitronomy.Optimization.model_manager module

class slitronomy.Optimization.model_manager.ModelManager(data_class, lensing_operator_class, numerics_class, thread_count=1, random_seed=None)

Bases: object

Utility class for initializing model operators and managing model components

add_lens_light(lens_light_model_class)
add_point_source(fix_model, filter_res, radius_regions, min_scale_regions, check_filtering)
add_source_light(source_model_class)
clean_masked_data(background_rms, init_ps_model=None)

Replace masked pixels with background noise This affects the ORIGINAL imaging data as well!

data_coord2pix(ra, dec)
data_pixel_width
effective_image_data

Input data (possibly pre-processed) data

fixed_point_source_model
image_data

Original input data (no pre-processed)

lensingOperator
likelihood_mask
n_scales_lens_light
n_scales_source
no_lens_light
no_point_source
no_source_light
num_pix_image
num_pix_source
partial_image_data

Most of times contain effective_image_data minus a model component (lens, source). After a call reset_partial_data(), this is the same effective_image_data

point_source_mask(split=True)
reset_partial_data()

cancel any previous call to self.subtract_from_data()

set_lens_wavelet_scales(n_scales_lens)
set_point_source_error_func(point_source_error_func)
set_point_source_solver_func(point_source_solver_func)
set_source_wavelet_scales(n_scales_source)
subtract_from_data(array_2d)

Update ‘partial’ data by subtracting the input array

slitronomy.Optimization.model_operators module

class slitronomy.Optimization.model_operators.ModelOperators(data_class, lensing_operator_class, numerics_class, fixed_spectral_norm_source=None, thread_count=1, random_seed=None)

Bases: slitronomy.Optimization.model_manager.ModelManager

Utility class for access to operator as defined in formal optimization equations

F(source_2d)

alias method for lensing from source plane to image plane

F_T(image_2d)

alias method for ray-tracing from image plane to source plane

H(array_2d)

alias method for convolution with the PSF kernel

H_T(array_2d)

alias method for convolution with the transposed PSF kernel

M(image_2d)

Apply image plane mask

M_s(source_2d)

Apply source plane mask

Phi_T_l(array_2d)

alias method for wavelet transform

Phi_T_s(array_2d)

alias method for wavelet transform

Phi_l(array_2d)

alias method for inverse wavelet transform

Phi_s(array_2d)

alias method for inverse wavelet transform

R(image_2d)

alias for resize to lower resolution (DOWNsampling operation), from finer grid to imaging data grid

R_T(image_2d)

alias for resize to higher resolution (UPsampling operation), from finer grid to imaging data grid

Y_eff

Original imaging data, but possibly pre-processed for masked regions.

Y_p

Partial imaging data. This can be the entire imaging data, or an updated version of it with a component subtracted

Y_tilde

Original imaging data.

compute_spectral_norm_lens()
compute_spectral_norm_source()
psf_kernel
spectral_norm_lens
spectral_norm_source
spectral_norm_source_is_fixed
update_spectral_norm_lens()
update_spectral_norm_source()

slitronomy.Optimization.noise_levels module

class slitronomy.Optimization.noise_levels.NoiseLevels(data_class, subgrid_res_source=1, include_regridding_error=False, include_point_source_error=False)

Bases: object

Handle noise properties and compute noise levels in wavelets space, taking into account lensing and optionally blurring and regridding error for pixelated reconstructions.

background_rms
effective_noise_map

Add quadratically the regridding error map and point source error map

levels_image
levels_source
noise_map
point_source_error_map
re_estimate_noise_map_for_ps(data, ps_mask, ps_model)
regridding_error_map
update_image_levels(num_pix_image, wavelet_transform_image)
update_point_source_error(ps_error_map)
update_regridding_error(magnification_map)
update_source_levels(num_pix_image, num_pix_source, wavelet_transform_source, image2source_transform, upscale_transform, psf_kernel=None)

slitronomy.Optimization.proximals module

slitronomy.Optimization.proximals.full_prox_sparsity_positivity(image, transform, inverse_transform, weights, noise_levels, thresh, thresh_increm, n_scales, l_norm, formulation, force_positivity)
returns the proximal operator of the regularisation term
g = lambda * |Phi^T HG|_0
or
g = lambda * |Phi^T HG|_1
slitronomy.Optimization.proximals.prox_positivity(image_input)
slitronomy.Optimization.proximals.prox_sparsity_wavelets(coeffs_input, step, level_const=None, level_pixels=None, l_norm=1)

Apply soft or hard threshold on all wavelets scales excepts the last one (the coarse scale)

slitronomy.Optimization.solver_base module

class slitronomy.Optimization.solver_base.SparseSolverBase(data_class, image_numerics_class, source_numerics_class, lens_model_class=None, lens_light_mask=None, source_interpolation='bilinear', minimal_source_plane=False, use_mask_for_minimal_source_plane=True, min_num_pix_source=20, min_threshold=3, threshold_increment_high_freq=1, threshold_decrease_type='exponential', fixed_spectral_norm_source=0.98, include_regridding_error=False, include_point_source_error=False, sparsity_prior_norm=1, force_positivity=True, formulation='analysis', external_likelihood_penalty=False, random_seed=None, verbose=False, show_steps=False, thread_count=1)

Bases: slitronomy.Optimization.model_operators.ModelOperators

Base class that generally defines a sparse solver

algorithm
apply_image_plane_mask(image_2d)
apply_source_plane_mask(source_2d)
best_fit_mean_squared_error
best_fit_reduced_chi2
component_names
generate_initial_lens_light()
generate_initial_source()
gradient_loss_lens(array_HG)
gradient_loss_source(array_S)
gradient_loss_source_ps(array_S, array_P)
image_model(unconvolved=False, source_add=True, lens_light_add=True, point_source_add=True)
lens_light_model
loss(S=None, HG=None, P=None)

returns f = || Y - HFS - HG - P ||^2_2

mean_squared_error(S=None, HG=None, P=None)
model_analysis(S=None, HG=None, P=None)
model_synthesis(alpha_S=None, alpha_HG=None, P=None)
static norm_diff(S1, S2)

returns || S1 - S2 ||_2

normalized_residuals(S=None, HG=None, P=None)

returns ( HFS + HG + P - Y ) / sigma

normalized_residuals_model

returns ( HFS + HG + P - Y ) / sigma

num_data_points

number of effective data points (= number of unmasked pixels)

plot_results(**kwargs)
plot_source_residuals_comparison(*args, **kwargs)
point_source_model
prepare_solver(kwargs_lens, kwargs_source, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, init_lens_light_model=None, init_ps_model=None, init_ps_amp=None, ps_error_map=None)

Update state of the solver : operators, noise levels, … The order of the steps matters!

prior_l_norm
project_on_original_grid_source(source)
proximal_sparsity_lens(array_HG, threshold, weights)
proximal_sparsity_source(array_S, threshold, weights)
psf_convolution(array_2d)
reduced_chi2(S=None, HG=None, P=None)
regularization(S=None, HG=None, P=None)

returns p = lambda * || W_S ø alpha_S ||_0,1 + lambda * || W_HG ø alpha_HG ||_0,1

residuals(S=None, HG=None, P=None)
residuals_model

returns ( HFS + HG + P - Y )

set_likelihood_mask(mask=None)
solve(kwargs_lens, kwargs_source, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, init_lens_light_model=None, init_ps_model=None, init_ps_amp=None, ps_error_map=None)

main method to call from outside the class, calling self._solve()

any class that inherits SparseSolverSource should have self._ready() and self._solve() methods implemented, with correct output.

source_model
subtract_lens_from_data(HG)

Update “effective” data by subtracting the input (convolved) lens light estimation

subtract_point_source_from_data(P)

Update “effective” data by subtracting the input (convolved) lens light estimation

subtract_source_from_data(S)

Update “effective” data by subtracting the input source light estimation

track
update_image_noise_levels()
update_source_noise_levels()

slitronomy.Optimization.solver_source module

class slitronomy.Optimization.solver_source.SparseSolverSource(data_class, image_numerics_class, source_numerics_class, source_model_class, lens_model_class, num_iter_source=10, num_iter_weights=3, **base_kwargs)

Bases: slitronomy.Optimization.solver_base.SparseSolverBase

Implements an improved version of the original SLIT algorithm (https://github.com/herjy/SLIT)

slitronomy.Optimization.solver_source_lens module

class slitronomy.Optimization.solver_source_lens.SparseSolverSourceLens(data_class, image_numerics_class, source_numerics_class, source_model_class, lens_light_model_class, lens_model_class, num_iter_global=10, num_iter_source=10, num_iter_lens=10, num_iter_weights=2, lens_light_model_map=None, **base_kwargs)

Bases: slitronomy.Optimization.solver_base.SparseSolverBase

Implements an improved version of the original SLIT algorithm (https://github.com/herjy/SLIT)

slitronomy.Optimization.solver_source_ps module

class slitronomy.Optimization.solver_source_ps.SparseSolverSourcePS(data_class, image_numerics_class, source_numerics_class, source_model_class, lens_model_class, num_iter_source=10, num_iter_global=10, num_iter_weights=3, fix_point_source_model=False, filter_point_source_residuals=False, min_scale_point_source_residuals=2, radius_point_source_residuals=0.2, check_point_source_residuals=False, **base_kwargs)

Bases: slitronomy.Optimization.solver_base.SparseSolverBase

Implements the original SLIT algorithm with point source support

Module contents