lenstronomy.ImSim.Numerics package

Submodules

lenstronomy.ImSim.Numerics.adaptive_numerics module

class lenstronomy.ImSim.Numerics.adaptive_numerics.AdaptiveConvolution(kernel_super, supersampling_factor, conv_supersample_pixels, supersampling_kernel_size=None, compute_pixels=None, nopython=True, cache=True, parallel=False)[source]

Bases: object

This class performs convolutions of a subset of pixels at higher supersampled resolution Goal: speed up relative to higher resolution FFT when only considering a (small) subset of pixels to be convolved on the higher resolution grid.

strategy: 1. lower resolution convolution over full image with FFT 2. subset of pixels with higher resolution Numba convolution (with smaller kernel) 3. the same subset of pixels with low resolution Numba convolution (with same kernel as step 2) adaptive solution is 1 + 2 - 3

convolve2d(image_high_res)[source]
Parameters:image_high_res – supersampled image/model to be convolved on a regular pixel grid
Returns:convolved and re-sized image
re_size_convolve(image_low_res, image_high_res)[source]
Parameters:image_high_res – supersampled image/model to be convolved on a regular pixel grid
Returns:convolved and re-sized image

lenstronomy.ImSim.Numerics.convolution module

class lenstronomy.ImSim.Numerics.convolution.PixelKernelConvolution(kernel, convolution_type='fft_static')[source]

Bases: object

class to compute convolutions for a given pixelized kernel (fft, grid)

convolution2d(image)[source]
Parameters:image – 2d array (image) to be convolved
Returns:fft convolution
copy_transpose()[source]
Returns:copy of the class with kernel set to the transpose of original one
pixel_kernel(num_pix=None)[source]

access pixelated kernel

Parameters:num_pix – size of returned kernel (odd number per axis). If None, return the original kernel.
Returns:pixel kernel centered
re_size_convolve(image_low_res, image_high_res=None)[source]
Parameters:image_high_res – supersampled image/model to be convolved on a regular pixel grid
Returns:convolved and re-sized image
class lenstronomy.ImSim.Numerics.convolution.SubgridKernelConvolution(kernel_supersampled, supersampling_factor, supersampling_kernel_size=None, convolution_type='fft_static')[source]

Bases: object

class to compute the convolution on a supersampled grid with partial convolution computed on the regular grid

convolution2d(image)[source]
Parameters:image – 2d array (high resoluton image) to be convolved and re-sized
Returns:convolved image
re_size_convolve(image_low_res, image_high_res)[source]
Parameters:image_high_res – supersampled image/model to be convolved on a regular pixel grid
Returns:convolved and re-sized image
class lenstronomy.ImSim.Numerics.convolution.MultiGaussianConvolution(sigma_list, fraction_list, pixel_scale, supersampling_factor=1, supersampling_convolution=False, truncation=2)[source]

Bases: object

class to perform a convolution consisting of multiple 2d Gaussians This is aimed to lead to a speed-up without significant loss of accuracy do to the simplified convolution kernel relative to a pixelized kernel.

convolution2d(image)[source]

2d convolution

Parameters:image – 2d numpy array, image to be convolved
Returns:convolved image, 2d numpy array
pixel_kernel(num_pix)[source]

computes a pixelized kernel from the MGE parameters

Parameters:num_pix – int, size of kernel (odd number per axis)
Returns:pixel kernel centered
re_size_convolve(image_low_res, image_high_res)[source]
Parameters:image_high_res – supersampled image/model to be convolved on a regular pixel grid
Returns:convolved and re-sized image
class lenstronomy.ImSim.Numerics.convolution.FWHMGaussianConvolution(kernel, truncation=4)[source]

Bases: object

uses a two-dimensional Gaussian function with same FWHM of given kernel as approximation

convolution2d(image)[source]

2d convolution

Parameters:image – 2d numpy array, image to be convolved
Returns:convolved image, 2d numpy array
class lenstronomy.ImSim.Numerics.convolution.MGEConvolution(kernel, pixel_scale, order=1)[source]

Bases: object

approximates a 2d kernel with an azimuthal Multi-Gaussian expansion

convolution2d(image)[source]
Parameters:image
Returns:
kernel_difference()[source]
Returns:difference between true kernel and MGE approximation

lenstronomy.ImSim.Numerics.grid module

class lenstronomy.ImSim.Numerics.grid.AdaptiveGrid(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_indexes, supersampling_factor, flux_evaluate_indexes=None)[source]

Bases: lenstronomy.Data.coord_transforms.Coordinates1D

manages a super-sampled grid on the partial image

coordinates_evaluate
Returns:1d array of all coordinates being evaluated to perform the image computation
flux_array2image_low_high(flux_array, high_res_return=True)[source]
Parameters:
  • flux_array – 1d array of low and high resolution flux values corresponding to the coordinates_evaluate order
  • high_res_return – bool, if True also returns the high resolution image (needs more computation and is only needed when convolution is performed on the supersampling level)
Returns:

2d array, 2d array, corresponding to (partial) images in low and high resolution (to be convolved)

class lenstronomy.ImSim.Numerics.grid.RegularGrid(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_factor=1, flux_evaluate_indexes=None)[source]

Bases: lenstronomy.Data.coord_transforms.Coordinates1D

manages a super-sampled grid on the partial image

coordinates_evaluate
Returns:1d array of all coordinates being evaluated to perform the image computation
flux_array2image_low_high(flux_array, **kwargs)[source]
Parameters:flux_array – 1d array of low and high resolution flux values corresponding to the coordinates_evaluate order
Returns:2d array, 2d array, corresponding to (partial) images in low and high resolution (to be convolved)
grid_points_spacing

effective spacing between coordinate points, after supersampling :return: sqrt(pixel_area)/supersampling_factor

num_grid_points_axes

effective number of points along each axes, after supersampling :return: number of pixels per axis, nx*supersampling_factor ny*supersampling_factor

supersampling_factor
Returns:factor (per axis) of super-sampling relative to a pixel

lenstronomy.ImSim.Numerics.numba_convolution module

class lenstronomy.ImSim.Numerics.numba_convolution.NumbaConvolution(kernel, conv_pixels, compute_pixels=None, nopython=True, cache=True, parallel=False, memory_raise=True)[source]

Bases: object

class to convolve explicit pixels only

the convolution is inspired by pyautolens: https://github.com/Jammy2211/PyAutoLens

convolve2d(image)[source]

2d convolution

Parameters:image – 2d numpy array, image to be convolved
Returns:convolved image, 2d numpy array

lenstronomy.ImSim.Numerics.numerics module

class lenstronomy.ImSim.Numerics.numerics.Numerics(pixel_grid, psf, supersampling_factor=1, compute_mode='regular', supersampling_convolution=False, supersampling_kernel_size=5, flux_evaluate_indexes=None, supersampled_indexes=None, compute_indexes=None, point_source_supersampling_factor=1, convolution_kernel_size=None, convolution_type='fft_static', truncation=4)[source]

Bases: lenstronomy.ImSim.Numerics.point_source_rendering.PointSourceRendering

this classes manages the numerical options and computations of an image. The class has two main functions, re_size_convolve() and coordinates_evaluate()

convolution_class
Returns:convolution class (can be SubgridKernelConvolution, PixelKernelConvolution, MultiGaussianConvolution, …)
coordinates_evaluate
Returns:1d array of all coordinates being evaluated to perform the image computation
grid_class
Returns:grid class (can be RegularGrid, AdaptiveGrid)
grid_supersampling_factor
Returns:supersampling factor set for higher resolution sub-pixel sampling of surface brightness
re_size_convolve(flux_array, unconvolved=False)[source]
Parameters:
  • flux_array – 1d array, flux values corresponding to coordinates_evaluate
  • array_low_res_partial – regular sampled surface brightness, 1d array
Returns:

convolved image on regular pixel grid, 2d array

lenstronomy.ImSim.Numerics.partial_image module

class lenstronomy.ImSim.Numerics.partial_image.PartialImage(partial_read_bools)[source]

Bases: object

class to deal with the use of partial slicing of a 2d data array, to be used for various computations where only a subset of pixels need to be know.

array_from_partial(partial_array)[source]
Parameters:partial_array – 1d array of the partial indexes
Returns:full 1d array
image_from_partial(partial_array)[source]
Parameters:partial_array – 1d array corresponding to the indexes of the partial read
Returns:full image with zeros elsewhere
index_array
Returns:2d array with indexes (integers) corresponding to the 1d array, -1 when masked
num_partial
Returns:number of indexes handled in the partial section
partial_array(image)[source]
Parameters:image – 2d array
Returns:1d array of partial list

lenstronomy.ImSim.Numerics.point_source_rendering module

class lenstronomy.ImSim.Numerics.point_source_rendering.PointSourceRendering(pixel_grid, supersampling_factor, psf)[source]

Bases: object

numerics to compute the point source response on an image

point_source_rendering(ra_pos, dec_pos, amp)[source]
Parameters:
  • ra_pos – list of RA positions of point source(s)
  • dec_pos – list of DEC positions of point source(s)
  • amp – list of amplitudes of point source(s)
Returns:

2d numpy array of size of the image with the point source(s) rendered

psf_error_map(ra_pos, dec_pos, amp, data, fix_psf_error_map=False)[source]
Parameters:
  • ra_pos – image positions of point sources
  • dec_pos – image positions of point sources
  • amp – amplitude of modeled point sources
  • data – 2d numpy array of the data
  • fix_psf_error_map – bool, if True, estimates the error based on the imput (modeled) amplitude, else uses the data to do so.
Returns:

2d array of size of the image with error terms (sigma**2) expected from inaccuracies in the PSF modeling

Module contents