lenstronomy.PointSource package

Submodules

lenstronomy.PointSource.point_source module

class PointSource(point_source_type_list, lensModel=None, fixed_magnification_list=None, additional_images_list=None, flux_from_point_source_list=None, magnification_limit=None, save_cache=False, kwargs_lens_eqn_solver=None, index_lens_model_list=None, point_source_frame_list=None)[source]

Bases: object

__init__(point_source_type_list, lensModel=None, fixed_magnification_list=None, additional_images_list=None, flux_from_point_source_list=None, magnification_limit=None, save_cache=False, kwargs_lens_eqn_solver=None, index_lens_model_list=None, point_source_frame_list=None)[source]
Parameters:
  • point_source_type_list – list of point source types
  • lensModel – instance of the LensModel() class
  • fixed_magnification_list – list of booleans (same length as point_source_type_list). If True, magnification ratio of point sources is fixed to the one given by the lens model. This option then requires to provide a ‘source_amp’ amplitude of the source brightness instead of ‘point_amp’ the list of image brightnesses.
  • additional_images_list – list of booleans (same length as point_source_type_list). If True, search for additional images of the same source is conducted.
  • flux_from_point_source_list – list of booleans (optional), if set, will only return image positions (for imaging modeling) for the subset of the point source lists that =True. This option enables to model imaging data with transient point sources, when the point source positions are measured and present at a different time than the imaging data
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those images will be computed that exceed the lensing magnification (absolute value) limit
  • save_cache – bool, saves image positions and only if delete_cache is executed, a new solution of the lens equation is conducted with the lens model parameters provided. This can increase the speed as multiple times the image positions are requested for the same lens model. Attention in usage!
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver see LensEquationSolver() class for details, such as: min_distance=0.01, search_window=5, precision_limit=10**(-10), num_iter_max=100
  • index_lens_model_list – list (length of different patches/bands) of integer lists, e.g., [[0, 1], [2, 3]]; evaluating a subset of the lens models per individual bands. If this keyword is set, the image positions need to have a specified band/frame assigned to it
  • point_source_frame_list – list of lists mirroring the structure of the image positions. Integers correspond to the i’th list entry of index_lens_model_list indicating in which frame/band the image is appearing, e.g., four images and four cutouts, you can do [[0], [1], [2], [3]] when the frames (ordered as the list) are in the same order as the point sources (indices)
check_image_positions(kwargs_ps, kwargs_lens, tolerance=0.001)[source]

Checks whether the point sources in kwargs_ps satisfy the lens equation with a tolerance (computed by ray-tracing in the source plane)

Parameters:
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
  • tolerance – Euclidian distance between the source positions ray-traced backwards to be tolerated
Returns:

bool: True, if requirement on tolerance is fulfilled, False if not.

classmethod check_positive_flux(kwargs_ps)[source]

Check whether inferred linear parameters are positive.

Parameters:kwargs_ps – point source keyword argument list
Returns:bool, True, if all ‘point_amp’ parameters are positive semi-definite
delete_lens_model_cache()[source]

Deletes the variables saved for a specific lens model.

Returns:None
image_amplitude(kwargs_ps, kwargs_lens, k=None)[source]

Returns the image amplitudes.

Parameters:
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
  • k – None, int or list of int’s to select a subset of the point source models in the return
Returns:

list of image amplitudes per model component

image_position(kwargs_ps, kwargs_lens, k=None, original_position=False, additional_images=False)[source]

Image positions as observed on the sky of the point sources.

Parameters:
  • kwargs_ps – point source parameter keyword argument list
  • kwargs_lens – lens model keyword argument list
  • k – None, int or boolean list; only returns a subset of the model predictions
  • original_position – boolean (only applies to ‘LENSED_POSITION’ models), returns the image positions in the model parameters and does not re-compute images (which might be differently ordered) in case of the lens equation solver
  • additional_images (bool) – if True, solves the lens equation for additional images
Returns:

list of: list of image positions per point source model component

k_list(k)[source]
Parameters:k – index of point source model
Returns:list of lengths of images with corresponding lens models in the frame (or None if not multi-frame)
linear_param_from_kwargs(kwargs_list)[source]

Inverse function of update_linear() returning the linear amplitude list for the keyword argument list.

Parameters:kwargs_list (list of keyword arguments) – model parameters including the linear amplitude parameters
Returns:list of linear amplitude parameters
Return type:list
linear_response_set(kwargs_ps, kwargs_lens=None, with_amp=False)[source]
Parameters:
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
  • with_amp – bool, if True returns the image amplitude derived from kwargs_ps, otherwise the magnification of the lens model
Returns:

ra_pos, dec_pos, amp, n

num_basis(kwargs_ps, kwargs_lens)[source]

Number of basis functions for linear inversion.

Parameters:
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
Returns:

int

point_source_list(kwargs_ps, kwargs_lens, k=None, with_amp=True)[source]

Returns the coordinates and amplitudes of all point sources in a single array.

Parameters:
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
  • k – None, int or list of int’s to select a subset of the point source models in the return
  • with_amp – bool, if False, ignores the amplitude parameters in the return and instead provides ones for each point source image
Returns:

ra_array, dec_array, amp_array

set_amplitudes(amp_list, kwargs_ps)[source]

Translates the amplitude parameters into the convention of the keyword argument list currently only used in SimAPI to transform magnitudes to amplitudes in the lenstronomy conventions.

Parameters:
  • amp_list – list of model amplitudes for each point source model
  • kwargs_ps – list of point source keywords
Returns:

overwrites kwargs_ps with new amplitudes

set_save_cache(save_cache)[source]

Set the save cache boolean to new value.

Parameters:save_cache – bool, if True, saves (or uses a previously saved) values
Returns:updated class and sub-class instances to either save or not save the point source information in cache
source_amplitude(kwargs_ps, kwargs_lens)[source]

Intrinsic (unlensed) point source amplitudes.

Parameters:
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
Returns:

list of intrinsic (unlensed) point source amplitudes

source_position(kwargs_ps, kwargs_lens)[source]

Intrinsic source positions of the point sources.

Parameters:
  • kwargs_ps – keyword argument list of point source models
  • kwargs_lens – keyword argument list of lens models
Returns:

list of source positions for each point source model

update_lens_model(lens_model_class)[source]
Parameters:lens_model_class – instance of LensModel class
Returns:update instance of lens model class
update_linear(param, i, kwargs_ps, kwargs_lens)[source]
Parameters:
  • param – list of floats corresponding ot the parameters being sampled
  • i – index of the first parameter relevant for this class
  • kwargs_ps – point source keyword argument list
  • kwargs_lens – lens model keyword argument list
Returns:

kwargs_ps with updated linear parameters, index of the next parameter relevant for another class

update_search_window(search_window, x_center, y_center, min_distance=None, only_from_unspecified=False)[source]

Update the search area for the lens equation solver.

Parameters:
  • search_window – search_window: window size of the image position search with the lens equation solver.
  • x_center – center of search window
  • y_center – center of search window
  • min_distance – minimum search distance
  • only_from_unspecified – bool, if True, only sets keywords that previously have not been set
Returns:

updated self instances

lenstronomy.PointSource.point_source_cached module

class PointSourceCached(point_source_model, save_cache=False)[source]

Bases: object

This class is the same as PointSource() except that it saves image and source positions in cache.

This speeds-up repeated calls for the same source and lens model and avoids duplicating the lens equation solving. Attention: cache needs to be deleted before calling functions with different lens and point source parameters.

__init__(point_source_model, save_cache=False)[source]

Initialize self. See help(type(self)) for accurate signature.

delete_lens_model_cache()[source]
image_amplitude(kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None)[source]

Image brightness amplitudes.

Parameters:
  • kwargs_ps – keyword arguments of the point source model
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation solver
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those images will be computed that exceed the lensing magnification (absolute value) limit
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver see LensEquationSolver() class for details
Returns:

array of image amplitudes

image_position(kwargs_ps, kwargs_lens=None, magnification_limit=None, kwargs_lens_eqn_solver=None, additional_images=False)[source]

On-sky image positions.

Parameters:
  • kwargs_ps – keyword arguments of the point source model
  • kwargs_lens – keyword argument list of the lens model(s), only used when requiring the lens equation solver
  • magnification_limit – float >0 or None, if float is set and additional images are computed, only those images will be computed that exceed the lensing magnification (absolute value) limit
  • kwargs_lens_eqn_solver – keyword arguments specifying the numerical settings for the lens equation solver see LensEquationSolver() class for details
  • additional_images (bool) – if True, solves the lens equation for additional images
Returns:

image positions in x, y as arrays

set_save_cache(save_bool)[source]
source_amplitude(kwargs_ps, kwargs_lens=None)[source]

Intrinsic brightness amplitude of point source.

Parameters:
  • kwargs_ps – keyword arguments of the point source model
  • kwargs_lens – keyword argument list of the lens model(s), only used when positions are defined in image plane and have to be ray-traced back
Returns:

brightness amplitude (as numpy array)

source_position(kwargs_ps, kwargs_lens=None)[source]

Original source position (prior to lensing)

Parameters:
  • kwargs_ps – point source keyword arguments
  • kwargs_lens – lens model keyword argument list (only used when required)
Returns:

x, y position

update_lens_model(lens_model_class)[source]

lenstronomy.PointSource.point_source_param module

class PointSourceParam(model_list, kwargs_fixed, num_point_source_list=None, linear_solver=True, fixed_magnification_list=None, kwargs_lower=None, kwargs_upper=None)[source]

Bases: object

Point source parameters.

__init__(model_list, kwargs_fixed, num_point_source_list=None, linear_solver=True, fixed_magnification_list=None, kwargs_lower=None, kwargs_upper=None)[source]
Parameters:
  • model_list – list of point source model names
  • kwargs_fixed – list of keyword arguments with parameters to be held fixed
  • num_point_source_list – list of number of point sources per point source model class
  • linear_solver – bool, if True, does not return linear parameters for the sampler (will be solved linearly instead)
  • fixed_magnification_list – list of booleans, if entry is True, keeps one overall scaling among the point sources in this class
add_fix_linear(kwargs_fixed)[source]

Updates fixed keyword argument list with linear parameters.

Parameters:kwargs_fixed – list of keyword arguments held fixed during sampling
Returns:updated keyword argument list
get_params(args, i)[source]
Parameters:
  • args – sorted list of floats corresponding to the parameters being sampled
  • i – int, index of first entry relevant for being managed by this class
Returns:

keyword argument list of point sources, index relevant for the next class

num_param()[source]

Number of parameters and their names.

Returns:int, list of parameter names
num_param_linear()[source]
Returns:number of linear parameters
set_params(kwargs_list)[source]
Parameters:kwargs_list – keyword argument list
Returns:sorted list of parameters being sampled extracted from kwargs_list

Module contents