lenstronomy.Workflow package¶
Submodules¶
lenstronomy.Workflow.alignment_matching module¶
- class AlignmentFitting(multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None, align_offset=True, align_rotation=False)[source]¶
Bases:
object
Class which executes the different sampling methods.
- __init__(multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None, align_offset=True, align_rotation=False)[source]¶
Initialise the classes of the chain and for parameter options.
- Parameters:
align_offset (boolean) – aligns shift in Ra and Dec
align_rotation (boolean) – aligns coordinate rotation
- pso(n_particles=10, n_iterations=10, delta_shift=0.2, delta_rot=0.1, threadCount=1, mpi=False, print_key='default')[source]¶
Returns the best fit for the lens model on catalogue basis with particle swarm optimizer.
- Parameters:
n_particles –
n_iterations –
delta_shift – astrometric shift tolerance
delta_rot – rotation angle tolerance [in radian]
threadCount –
mpi –
print_key –
- Returns:
- class AlignmentLikelihood(multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None, align_offset=True, align_rotation=False)[source]¶
Bases:
object
- __init__(multi_band_list, kwargs_model, kwargs_params, band_index=0, likelihood_mask_list=None, align_offset=True, align_rotation=False)[source]¶
Initializes all the classes needed for the chain.
- Parameters:
align_offset (boolean) – aligns shift in Ra and Dec
align_rotation (boolean) – aligns coordinate rotation
- update_multi_band(args)[source]¶
- Parameters:
args – list of parameters
- Returns:
updated multi_band_list
- get_args(kwargs_data)[source]¶
- Parameters:
kwargs_data – keyword arguments for ImageData()
- Returns:
arguments being sampled
- property num_param¶
lenstronomy.Workflow.fitting_sequence module¶
- class FittingSequence(kwargs_data_joint, kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params, mpi=False, verbose=True)[source]¶
Bases:
object
Class to define a sequence of fitting applied, inherit the Fitting class this is a Workflow manager that allows to update model configurations before executing another step in the modelling The user can take this module as an example of how to create their own workflows or build their own around the FittingSequence.
- __init__(kwargs_data_joint, kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params, mpi=False, verbose=True)[source]¶
- Parameters:
kwargs_data_joint – keyword argument specifying the data according to LikelihoodModule
kwargs_model – keyword arguments to describe all model components used in class_creator.create_class_instances()
kwargs_constraints – keyword arguments of the Param() class to handle parameter constraints during the sampling (except upper and lower limits and sampling input mean and width)
kwargs_likelihood – keyword arguments of the Likelihood() class to handle parameters and settings of the likelihood
kwargs_params – setting of the sampling bounds and initial guess mean and spread. The argument is organized as: ‘lens_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘source_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘lens_light_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘point_source_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘extinction_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘special’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘tracer_source_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper]
mpi – MPI option (bool), if True, will launch an MPI Pool job for the steps in the fitting sequence where possible
verbose – bool, if True prints temporary results and indicators of the fitting process
- property kwargs_fixed¶
Returns the updated kwargs_fixed from the update manager.
- Returns:
list of fixed kwargs, see UpdateManager()
- fit_sequence(fitting_list)[source]¶
- Parameters:
fitting_list – list of [[‘string’, {kwargs}], ..] with ‘string being the specific fitting option and kwargs being the arguments passed to this option
- Returns:
fitting results
- best_fit(bijective=False)[source]¶
- Parameters:
bijective – bool, if True, the mapping of image2source_plane and the mass_scaling parameterisation are inverted. If you do not use those options, there is no effect.
- Returns:
best fit model of the current state of the FittingSequence class
- update_state(kwargs_update)[source]¶
Updates current best fit state to the input model keywords specified.
- Parameters:
kwargs_update – format of kwargs_result
- Returns:
None
- property best_fit_likelihood¶
Returns the log likelihood of the best fit model of the current state of this class.
- Returns:
log likelihood, float
- property bic¶
Bayesian information criterion (BIC) of the model.
- Returns:
bic value, float
- property param_class¶
- Returns:
Param() class instance reflecting the current state of FittingSequence
- property likelihoodModule¶
- Returns:
Likelihood() class instance reflecting the current state of FittingSequence
- simplex(n_iterations, method='Nelder-Mead')[source]¶
Downhill simplex optimization using the Nelder-Mead algorithm.
- Parameters:
n_iterations – maximum number of iterations to perform
method – the optimization method used, see documentation in scipy.optimize.minimize
- Returns:
result of the best fit
- mcmc(n_burn, n_run, walkerRatio=None, n_walkers=None, sigma_scale=1, threadCount=1, init_samples=None, re_use_samples=True, sampler_type='EMCEE', progress=True, backend_filename=None, start_from_backend=False, **kwargs_zeus)[source]¶
MCMC routine.
- Parameters:
n_burn – number of burn in iterations (will not be saved)
n_run – number of MCMC iterations that are saved
walkerRatio – ratio of walkers/number of free parameters
n_walkers – integer, number of walkers of emcee (optional, if set, overwrites the walkerRatio input
sigma_scale – scaling of the initial parameter spread relative to the width in the initial settings
threadCount – number of CPU threads. If MPI option is set, threadCount=1
init_samples – initial sample from where to start the MCMC process
re_use_samples – bool, if True, re-uses the samples described in init_samples.nOtherwise starts from scratch.
sampler_type – string, which MCMC sampler to be used. Options are ‘emcee’ and ‘zeus’
progress – boolean, if True shows progress bar in EMCEE
backend_filename (string) – name of the HDF5 file where sampling state is saved (through emcee backend engine)
start_from_backend (bool) – if True, start from the state saved in backup_filename. O therwise, create a new backup file with name backup_filename (any already existing file is overwritten!).
kwargs_zeus – zeus-specific kwargs
- Returns:
list of output arguments, e.g. MCMC samples, parameter names, logL distances of all samples specified by the specific sampler used
- pso(n_particles, n_iterations, sigma_scale=1, print_key='PSO', threadCount=1)[source]¶
Particle Swarm Optimization.
- Parameters:
n_particles – number of particles in the Particle Swarm Optimization
n_iterations – number of iterations in the optimization process
sigma_scale – scaling of the initial parameter spread relative to the width in the initial settings
print_key – string, printed text when executing this routine
threadCount – number of CPU threads. If MPI option is set, threadCount=1
- Returns:
result of the best fit, the PSO chain of the best fit parameter after each iteration [lnlikelihood, parameters, velocities], list of parameters in same order as in chain
- nested_sampling(sampler_type='dynesty', kwargs_run={}, prior_type='uniform', width_scale=1, sigma_scale=1, output_basename='chain', remove_output_dir=True, dypolychord_dynamic_goal=0.8, polychord_settings={}, dypolychord_seed_increment=200, output_dir='nested_sampling_chains', dynesty_bound='multi', dynesty_sample='auto')[source]¶
Run (Dynamic) Nested Sampling algorithms, depending on the type of algorithm.
- Parameters:
sampler_type – ‘MULTINEST’, ‘DYPOLYCHORD’, ‘DYNESTY’
kwargs_run – keywords passed to the core sampling method
prior_type – ‘uniform’ of ‘gaussian’, for converting the unit hypercube to param cube :param width_scale: scale the width (lower/upper limits) of the parameters space by this factor
sigma_scale – if prior_type is ‘gaussian’, scale the gaussian sigma by this factor
output_basename – name of the folder in which the core MultiNest/PolyChord code will save output files
remove_output_dir – if True, the above folder is removed after completion
dypolychord_dynamic_goal – dynamic goal for DyPolyChord (trade-off between evidence (0) and posterior (1) computation) :param polychord_settings: settings dictionary to send to pypolychord. Check dypolychord documentation for details.
dypolychord_seed_increment – seed increment for dypolychord with MPI. Check dypolychord documentation for details.
dynesty_bound – see https://dynesty.readthedocs.io
sampler_type – ‘MULTINEST’, ‘DYPOLYCHORD’, ‘DYNESTY’
kwargs_run – keywords passed to the core sampling method
prior_type – ‘uniform’ of ‘gaussian’, for converting the unit hypercube to param cube
width_scale – scale the width (lower/upper limits) of the parameters space by this factor
sigma_scale – if prior_type is ‘gaussian’, scale the gaussian sigma by this factor
output_basename – name of the folder in which the core MultiNest/PolyChord code will save output files
remove_output_dir – if True, the above folder is removed after completion
dypolychord_dynamic_goal – dynamic goal for DyPolyChord (trade-off between evidence (0) and posterior (1) computation)
polychord_settings – settings dictionary to send to pypolychord. Check dypolychord documentation for details.
dypolychord_seed_increment – seed increment for dypolychord with MPI. Check dypolychord documentation for details.
dynesty_bound – see https://dynesty.readthedocs.io for details
dynesty_sample – see https://dynesty.readthedocs.io for details
- Returns:
list of output arguments : samples, mean inferred values, log- likelihood, log-evidence, error on log-evidence for each sample
- psf_iteration(compute_bands=None, **kwargs_psf_iter)[source]¶
Iterative PSF reconstruction.
- Parameters:
compute_bands – bool list, if multiple bands, this process can be limited to a subset of bands
kwargs_psf_iter – keyword arguments as used or available in PSFIteration.update_iterative() definition
- Returns:
0, updated PSF is stored in self.multi_band_list
- align_images(n_particles=10, n_iterations=10, align_offset=True, align_rotation=False, threadCount=1, compute_bands=None, delta_shift=0.2, delta_rot=0.1)[source]¶
Aligns the coordinate systems of different exposures within a fixed model parameterisation by executing a PSO with relative coordinate shifts as free parameters.
- Parameters:
n_particles – number of particles in the Particle Swarm Optimization
n_iterations – number of iterations in the optimization process
align_offset (boolean) – aligns shift in Ra and Dec
align_rotation (boolean) – aligns coordinate rotation
delta_shift – astrometric shift tolerance
delta_rot – rotation angle tolerance [in radian]
compute_bands – bool list, if multiple bands, this process can be limited to a subset of bands for which the coordinate system is being fit for best alignment to the model parameters
- Returns:
0, updated coordinate system for the band(s)
- flux_calibration(n_particles=10, n_iterations=10, threadCount=1, calibrate_bands=None, scaling_lower_limit=0, scaling_upper_limit=1000)[source]¶
Calibrates flux_scaling between multiple images. This routine only works in ‘join-linear’ model when fluxes are meant to be identical for different bands.
- Parameters:
n_particles – number of particles in the Particle Swarm Optimization
n_iterations – number of iterations in the optimization process
calibrate_bands (list of booleans of length of the imaging bands) – state which bands the flux calibration is applied to
threadCount (integer) – number of CPU threads. If MPI option is set, threadCount=1
scaling_lower_limit – lower limit of flux_scaling
scaling_upper_limit – upper limit of flux scaling
- Returns:
0, updated coordinate system for the band(s)
- update_settings(kwargs_model=None, kwargs_constraints=None, kwargs_likelihood=None, lens_add_fixed=None, source_add_fixed=None, lens_light_add_fixed=None, ps_add_fixed=None, special_add_fixed=None, tracer_source_add_fixed=None, lens_remove_fixed=None, source_remove_fixed=None, lens_light_remove_fixed=None, ps_remove_fixed=None, special_remove_fixed=None, tracer_source_remove_fixed=None, change_source_lower_limit=None, change_source_upper_limit=None, change_lens_lower_limit=None, change_lens_upper_limit=None, change_sigma_lens=None, change_sigma_source=None, change_sigma_lens_light=None)[source]¶
Updates lenstronomy settings “on the fly”.
- Parameters:
kwargs_model – kwargs, specified keyword arguments overwrite the existing ones
kwargs_constraints – kwargs, specified keyword arguments overwrite the existing ones
kwargs_likelihood – kwargs, specified keyword arguments overwrite the existing ones
lens_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
source_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
lens_light_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
ps_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
special_add_fixed – [‘param1’, ‘param2’,…]
special_add_fixed – [‘param1’, ‘param2’,…]
tracer_source_add_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
lens_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
source_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
lens_light_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
ps_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
special_remove_fixed – [‘param1’, ‘param2’,…]
special_remove_fixed – [‘param1’, ‘param2’,…]
tracer_source_remove_fixed – [[i_model, [‘param1’, ‘param2’,…], […]]
change_lens_lower_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_lens_upper_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_source_lower_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_source_upper_limit – [[i_model, [‘’param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_sigma_lens – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_sigma_source – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_sigma_lens_light – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
- Returns:
0, the settings are overwritten for the next fitting step to come
- set_param_value(**kwargs)[source]¶
Set a parameter to a specific value. kwargs are below.
- Parameters:
lens – [[i_model, [‘param1’, ‘param2’,…], […]]
source – [[i_model, [‘param1’, ‘param2’,…], […]]
lens_light – [[i_model, [‘param1’, ‘param2’,…], […]]
ps – [[i_model, [‘param1’, ‘param2’,…], […]]
- Returns:
0, the value of the param is overwritten
- Return type:
- fix_not_computed(free_bands)[source]¶
Fixes lens model parameters of imaging bands/frames that are not computed and frees the parameters of the other lens models to the initial kwargs_fixed options.
- Parameters:
free_bands – bool list of length of imaging bands in order of imaging bands, if False: set fixed lens model
- Returns:
None
lenstronomy.Workflow.psf_fitting module¶
- class PsfFitting(image_model_class)[source]¶
Bases:
object
Class to find subsequently a better psf The method make use of a model and subtracts all the non-point source components of the model from the data. If the model is sufficient, then the data will be a (better) representation of the actual PSF. The method cuts out those point sources and combines them to update the estimate of the PSF. This is done in an iterative procedure as the model components of the extended features is PSF-dependent (hopefully not too much).
Various options can be chosen. There is no guarantee that the method works for specific data and models.
‘stacking_method’: ‘median’, ‘mean’; the different estimates of the PSF are stacked and combined together. The choices are:
‘mean’: mean of pixel values as the estimator (not robust to outliers)
‘median’: median of pixel values as the estimator (outlier rejection robust but needs >2 point sources in the data
- ‘block_center_neighbour’: angle, radius of neighbouring point sources around their centers the estimates is ignored.
Default is zero, meaning a not optimal subtraction of the neighbouring point sources might contaminate the estimate.
- ‘keep_error_map’: bool, if True, does not replace the error term associated with the PSF estimate.
If false, re-estimates the variance between the PSF estimates.
- ‘psf_symmetry’: number of rotational invariant symmetries in the estimated PSF.
=1 mean no additional symmetries. =4 means 90 deg symmetry. This is enforced by a rotatioanl stack according to the symmetry specified. These additional imposed symmetries can help stabelize the PSF estimate when there are limited constraints/number of point sources in the image.
The procedure only requires and changes the ‘point_source_kernel’ in the PSF() class and the ‘psf_error_map’. Any previously set subgrid kernels or pixel_kernels are removed and constructed from the ‘point_source_kernel’.
- static calc_cornermask(kernelsize, psf_symmetry)[source]¶
Calculate the completeness numerically when rotational symmetry is imposed. This is the simplest ‘mask’ which throws away anywhere the rotations are not fully complete ->e.g. in the corners. This ONLY accounts for information loss in corners, not due e.g. to losses at the edges of the images.
- Parameters:
kernelsize – int, size of kernel array
psf_symmetry – int, the symmetry being imposed on the data
- Returns:
mask showing where the psf with symmetry n is incomplete due to rotation.
- update_iterative(kwargs_psf, kwargs_params, num_iter=10, keep_psf_error_map=True, no_break=True, verbose=True, **kwargs_psf_update)[source]¶
- Parameters:
kwargs_psf – keyword arguments to construct the PSF() class
kwargs_params – keyword arguments of the parameters of the model components (e.g. ‘kwargs_lens’ etc)
num_iter – number of iterations in the PSF fitting and image fitting process
keep_psf_error_map – boolean, if True keeps previous psf_error_map
no_break – boolean, if True, runs until the end regardless of the next step getting worse, and then reads out the overall best fit
verbose – print statements informing about progress of iterative procedure
kwargs_psf_update – keyword arguments providing the settings for a single iteration of the PSF, as being passed to update_psf() method
- Returns:
keyword argument of PSF constructor for PSF() class with updated PSF
- update_psf(kwargs_psf, kwargs_params, corner_mask=None, stacking_method='median', psf_symmetry=1, psf_iter_factor=0.2, block_center_neighbour=0, error_map_radius=None, block_center_neighbour_error_map=None, new_procedure=True, corner_symmetry=None)[source]¶
- Parameters:
kwargs_psf – keyword arguments to construct the PSF() class
kwargs_params – keyword arguments of the parameters of the model components (e.g. ‘kwargs_lens’ etc)
stacking_method – ‘median’, ‘mean’; the different estimates of the PSF are stacked and combined together. The choices are: ‘mean’: mean of pixel values as the estimator (not robust to outliers) ‘median’: median of pixel values as the estimator (outlier rejection robust but needs >2 point sources in the data
psf_symmetry – number of rotational invariant symmetries in the estimated PSF. =1 mean no additional symmetries. =4 means 90 deg symmetry. This is enforced by a rotatioanl stack according to the symmetry specified. These additional imposed symmetries can help stabelize the PSF estimate when there are limited constraints/number of point sources in the image.
psf_iter_factor – factor in (0, 1] of ratio of old vs new PSF in the update in the iteration.
block_center_neighbour – angle, radius of neighbouring point sources around their centers the estimates is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might contaminate the estimate.
block_center_neighbour_error_map – angle, radius of neighbouring point sources around their centers the estimates of the ERROR MAP is ignored. If None, then the value of block_center_neighbour is used (recommended)
error_map_radius – float, radius (in arc seconds) of the outermost error in the PSF estimate (e.g. to avoid double counting of overlapping PSF errors), if None, all of the pixels are considered (unless blocked through other means)
new_procedure – boolean, uses post lenstronomy 1.9.2 procedure which is more optimal for super-sampled PSF’s
corner_mask – a mask which tracks completeness due to non 90 degree rotation for PSF symmetry. computed before this function to save time.
corner_symmetry – int, if the imposed symmetry is an odd number, the edges of the reconstructed PSF in its default form will be clipped at the corners. corner_symmetry 1) tracks where the residuals are being clipped by the imposed symmetry and then 2) creates a psf with no symmetry 3) adds the corner_symmetry psf (which has information at the corners) to the odd symmetry PSF, in the regions where the odd-symmetry PSF does not have information
- Returns:
kwargs_psf_new, logL_after, error_map
- image_single_point_source(image_model_class, kwargs_params)[source]¶
Return model without including the point source contributions as a list (for each point source individually)
- Parameters:
image_model_class – ImageModel class instance
kwargs_params – keyword arguments of model component keyword argument lists
- Returns:
list of images with point source isolated
- cutout_psf(ra_image, dec_image, x, y, image_list, kernel_size, kernel_init, block_center_neighbour=0)[source]¶
- Parameters:
ra_image – coordinate array of images in angles
dec_image – coordinate array of images in angles
x – image position array in x-pixel
y – image position array in y-pixel
image_list – list of images (i.e. data - all models subtracted, except a single point source)
kernel_size – width in pixel of the kernel
kernel_init – initial guess of kernel (pixels that are masked are replaced by those values)
block_center_neighbour – angle, radius of neighbouring point sources around their centers the estimates is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might contaminate the estimate.
- Returns:
list of de-shifted kernel estimates
- psf_estimate_individual(ra_image, dec_image, point_amp, residuals, cutout_size, kernel_guess, supersampling_factor, block_center_neighbour)[source]¶
- Parameters:
ra_image – list; position in angular units of the image
dec_image – list; position in angular units of the image
point_amp – list of model amplitudes of point sources
residuals – data - model
cutout_size – pixel size of cutout around single star/quasar to be considered for the psf reconstruction
kernel_guess – initial guess of super-sampled PSF
supersampling_factor – int, super-sampling factor
block_center_neighbour –
- Returns:
list of best-guess PSF’s for each star based on the residual patterns
- static point_like_source_cutouts(x_pos, y_pos, image_list, cutout_size)[source]¶
Cutouts of point-like objects.
- Parameters:
x_pos – list of image positions in pixel units
y_pos – list of image position in pixel units
image_list – list of 2d numpy arrays with cleaned images, with all contaminating sources removed except the point-like object to be cut out.
cutout_size – odd integer, size of cutout.
- Returns:
list of cutouts
- static cutout_psf_single(x, y, image, mask, kernel_size, kernel_init)[source]¶
- Parameters:
x – x-coordinate of point source
y – y-coordinate of point source
image – image (i.e. data - all models subtracted, except a single point source)
mask – mask of pixels in the image not to be considered in the PSF estimate (being replaced by kernel_init)
kernel_size – width in pixel of the kernel
kernel_init – initial guess of kernel (pixels that are masked are replaced by those values)
- Returns:
estimate of the PSF based on the image and position of the point source
- static combine_psf(kernel_list_new, kernel_old, factor=1.0, stacking_option='median', symmetry=1, corner_symmetry=None, corner_mask=None)[source]¶
Updates psf estimate based on old kernel and several new estimates.
- Parameters:
kernel_list_new – list of new PSF kernels estimated from the point sources in the image (un-normalized)
kernel_old – old PSF kernel
factor – weight of updated estimate based on new and old estimate, factor=1 means new estimate, factor=0 means old estimate
stacking_option – option of stacking, mean or median
symmetry – imposed symmetry of PSF estimate
corner_symmetry – int, if the imposed symmetry is an odd number, the edges of the reconstructed PSF in its default form will be clipped at the corners. corner_symmetry 1) tracks where the residuals are being clipped by the imposed symmetry and then 2) creates a psf with symmetry=corner symmetry which is either 1 or 360/symm = n*90. (e.g for a symmetry 6 psf you could use symmetry 2 in the corners). 3) adds the corner_symmetry psf (which has information at the corners) to the odd symmetry PSF, in the regions where the odd-symmetry PSF does not have complete information.
- Returns:
updated PSF estimate
- error_map_estimate_new(psf_kernel, psf_kernel_list, ra_image, dec_image, point_amp, supersampling_factor, error_map_radius=None)[source]¶
Relative uncertainty in the psf model (in quadrature) per pixel based on residuals achieved in the image.
- Parameters:
psf_kernel – PSF kernel (super-sampled)
psf_kernel_list – list of individual best PSF kernel estimates
ra_image – image positions in angles
dec_image – image positions in angles
point_amp – image amplitude
supersampling_factor – super-sampling factor
error_map_radius – radius (in angle) to cut the error map
- Returns:
psf error map such that square of the uncertainty gets boosted by error_map * (psf * amp)**2
- error_map_estimate(kernel, star_cutout_list, amp, x_pos, y_pos, error_map_radius=None, block_center_neighbour=0)[source]¶
Provides a psf_error_map based on the goodness of fit of the given PSF kernel on the point source cutouts, their estimated amplitudes and positions.
- Parameters:
kernel – PSF kernel
star_cutout_list – list of 2d arrays of cutouts of the point sources with all other model components subtracted
amp – list of amplitudes of the estimated PSF kernel
x_pos – pixel position (in original data unit, not in cutout) of the point sources (same order as amp and star cutouts)
y_pos – pixel position (in original data unit, not in cutout) of the point sources (same order as amp and star cutouts)
error_map_radius – float, radius (in arc seconds) of the outermost error in the PSF estimate (e.g. to avoid double counting of overlapping PSF erros)
block_center_neighbour – angle, radius of neighbouring point sources around their centers the estimates is ignored. Default is zero, meaning a not optimal subtraction of the neighbouring point sources might contaminate the estimate.
- Returns:
relative uncertainty in the psf model (in quadrature) per pixel based on residuals achieved in the image
- static mask_point_source(x_pos, y_pos, x_grid, y_grid, radius, i=0)[source]¶
- Parameters:
x_pos – x-position of list of point sources
y_pos – y-position of list of point sources
x_grid – x-coordinates of grid
y_grid – y-coordinates of grid
i – index of point source not to mask out
radius – radius to mask out other point sources
- Returns:
a mask of the size of the image with cutouts around the position
lenstronomy.Workflow.update_manager module¶
- class UpdateManager(kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params)[source]¶
Bases:
object
This class manages the parameter constraints as they may evolve through the steps of the modeling.
This includes: keeping certain parameters fixed during one modelling step
- __init__(kwargs_model, kwargs_constraints, kwargs_likelihood, kwargs_params)[source]¶
- Parameters:
kwargs_model – keyword arguments to describe all model components used in class_creator.create_class_instances()
kwargs_constraints – keyword arguments of the Param() class to handle parameter constraints during the sampling (except upper and lower limits and sampling input mean and width)
kwargs_likelihood – keyword arguments of the Likelihood() class to handle parameters and settings of the likelihood
kwargs_params – setting of the sampling bounds and initial guess mean and spread. The argument is organized as: ‘lens_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘source_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘lens_light_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘point_source_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘extinction_model’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper] ‘special’: [kwargs_init, kwargs_sigma, kwargs_fixed, kwargs_lower, kwargs_upper]
- property init_kwargs¶
- Returns:
keyword arguments for all model components of the initial mean model proposition in the sampling
- property sigma_kwargs¶
- Returns:
keyword arguments for all model components of the initial 1-sigma width proposition in the sampling
- property fixed_kwargs¶
- property parameter_state¶
- Returns:
parameter state saved in this class
- best_fit(bijective=False)[source]¶
Best fit (max likelihood) position for all the model parameters.
- Parameters:
bijective – boolean, if True, returns the parameters in the argument of the sampling that might deviate from the convention of the ImSim module. For example, if parameterized in the image position, the parameters remain in the image plane rather than being mapped to the source plane.
- Returns:
kwargs_result with all the keyword arguments of the best fit for the model components
- update_param_state(kwargs_lens=None, kwargs_source=None, kwargs_lens_light=None, kwargs_ps=None, kwargs_special=None, kwargs_extinction=None, kwargs_tracer_source=None)[source]¶
Updates the temporary state of the parameters being saved. ATTENTION: Any previous knowledge gets lost if you call this function.
- Parameters:
kwargs_lens –
kwargs_source –
kwargs_lens_light –
kwargs_ps –
kwargs_special –
kwargs_extinction –
kwargs_tracer_source –
- Returns:
- update_param_value(lens=None, source=None, lens_light=None, ps=None)[source]¶
Set a model parameter to a specific value.
- Parameters:
lens – [[i_model, [‘param1’, ‘param2’,…], […]]
source – [[i_model, [‘param1’, ‘param2’,…], […]]
lens_light – [[i_model, [‘param1’, ‘param2’,…], […]]
ps – [[i_model, [‘param1’, ‘param2’,…], […]]
- Returns:
0, the value of the param is overwritten
- property param_class¶
Creating instance of lenstronomy Param() class. It uses the keyword arguments in self.kwargs_constraints as __init__() arguments, as well as self.kwargs_model, and the set of kwargs_fixed___, kwargs_lower___, kwargs_upper___ arguments for lens, lens_light, source, point source, extinction and special parameters.
- Returns:
instance of the Param class with the recent options and bounds
- update_options(kwargs_model=None, kwargs_constraints=None, kwargs_likelihood=None)[source]¶
updates the options by overwriting the kwargs with the new ones being added/changed WARNING: some updates may not be valid depending on the model options. Use carefully!
- Parameters:
kwargs_model – keyword arguments to describe all model components used in class_creator.create_class_instances() that are updated from previous arguments
kwargs_constraints –
kwargs_likelihood –
- Returns:
kwargs_model, kwargs_constraints, kwargs_likelihood
- update_limits(change_source_lower_limit=None, change_source_upper_limit=None, change_lens_lower_limit=None, change_lens_upper_limit=None)[source]¶
Updates the limits (lower and upper) of the update manager instance.
- Parameters:
change_source_lower_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_lens_lower_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_source_upper_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_lens_upper_limit – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
- Returns:
updates internal state of lower and upper limits accessible from outside
- update_sigmas(change_sigma_lens=None, change_sigma_source=None, change_sigma_lens_light=None)[source]¶
Updates individual estimated uncertainty levels for the initialization of search and sampling algorithms.
- Parameters:
change_sigma_lens – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_sigma_source – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
change_sigma_lens_light – [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, …]]]
- Returns:
updated internal state of the spread to initialize samplers
- update_fixed(lens_add_fixed=None, source_add_fixed=None, lens_light_add_fixed=None, ps_add_fixed=None, special_add_fixed=None, tracer_source_add_fixed=None, lens_remove_fixed=None, source_remove_fixed=None, lens_light_remove_fixed=None, ps_remove_fixed=None, special_remove_fixed=None, tracer_source_remove_fixed=None)[source]¶
Adds or removes the values of the keyword arguments that are stated in the _add_fixed to the existing fixed arguments. convention for input arguments are: [[i_model, [‘param_name1’, ‘param_name2’, …], [value1, value2, … (optional)], [], …]
- Parameters:
lens_add_fixed – added fixed parameter in lens model
source_add_fixed – added fixed parameter in source model
lens_light_add_fixed – added fixed parameter in lens light model
ps_add_fixed – added fixed parameter in point source model
special_add_fixed – added fixed parameter in special model
tracer_source_add_fixed – added fixed parameter in tracer source model
lens_remove_fixed – remove fixed parameter in lens model
source_remove_fixed – remove fixed parameter in source model
lens_light_remove_fixed – remove fixed parameter in lens light model
ps_remove_fixed – remove fixed parameter in point source model
special_remove_fixed – remove fixed parameter in special model
tracer_source_remove_fixed – remove fixed parameter in tracer source model
- Returns:
updated kwargs fixed