lenstronomy.ImSim.Numerics package¶
Submodules¶
lenstronomy.ImSim.Numerics.adaptive_numerics module¶
-
class
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
-
__init__
(kernel_super, supersampling_factor, conv_supersample_pixels, supersampling_kernel_size=None, compute_pixels=None, nopython=True, cache=True, parallel=False)[source]¶ Parameters: - kernel_super – convolution kernel in units of super sampled pixels provided, odd length per axis
- supersampling_factor – factor of supersampling relative to pixel grid
- conv_supersample_pixels – bool array same size as data, pixels to be convolved and their light to be blurred
- supersampling_kernel_size – number of pixels (in units of the image pixels) that are convolved with the supersampled kernel
- compute_pixels – bool array of size of image, these pixels (if True) will get blurred light from other pixels
- nopython – bool, numba jit setting to use python or compiled.
- cache – bool, numba jit setting to use cache
- parallel – bool, numba jit setting to use parallel mode
-
lenstronomy.ImSim.Numerics.convolution module¶
-
class
PixelKernelConvolution
(kernel, convolution_type='fft_static')[source]¶ Bases:
object
Class to compute convolutions for a given pixelized kernel (fft, grid)
-
__init__
(kernel, convolution_type='fft_static')[source]¶ Parameters: - kernel – 2d array, convolution kernel
- convolution_type – string, ‘fft’, ‘grid’, ‘fft_static’ mode of 2d convolution
-
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
-
-
class
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.
-
__init__
(kernel_supersampled, supersampling_factor, supersampling_kernel_size=None, convolution_type='fft_static')[source]¶ Parameters: - kernel_supersampled – kernel in supersampled pixels
- supersampling_factor – supersampling factor relative to the image pixel grid
- supersampling_kernel_size – number of pixels (in units of the image pixels) that are convolved with the supersampled kernel
-
-
class
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.
-
__init__
(sigma_list, fraction_list, pixel_scale, supersampling_factor=1, supersampling_convolution=False, truncation=2)[source]¶ Parameters: - sigma_list – list of std value of Gaussian kernel
- fraction_list – fraction of flux to be convoled with each Gaussian kernel
- pixel_scale – scale of pixel width (to convert sigmas into units of pixels)
- truncation – float. Truncate the filter at this many standard deviations. Default is 4.0.
-
convolution2d
(image)[source]¶ 2d convolution.
Parameters: image – 2d numpy array, image to be convolved Returns: convolved image, 2d numpy array
-
-
class
FWHMGaussianConvolution
(kernel, truncation=4)[source]¶ Bases:
object
Uses a two-dimensional Gaussian function with same FWHM of given kernel as approximation.
-
class
MGEConvolution
(kernel, pixel_scale, order=1)[source]¶ Bases:
object
Approximates a 2d kernel with an azimuthal Multi-Gaussian expansion.
lenstronomy.ImSim.Numerics.grid module¶
-
class
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.
-
__init__
(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_indexes, supersampling_factor, flux_evaluate_indexes=None)[source]¶ Parameters: - nx – number of pixels in x-axis
- ny – number of pixels in y-axis
- transform_pix2angle – 2x2 matrix, mapping of pixel to coordinate
- ra_at_xy_0 – ra coordinate at pixel (0,0)
- dec_at_xy_0 – dec coordinate at pixel (0,0)
- supersampling_indexes – bool array of shape nx x ny, corresponding to pixels being super_sampled
- supersampling_factor – int, factor (per axis) of super-sampling
- flux_evaluate_indexes – bool array of shape nx x ny, corresponding to pixels being evaluated (for both low and high res). Default is None, replaced by setting all pixels to being evaluated.
-
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
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.
-
__init__
(nx, ny, transform_pix2angle, ra_at_xy_0, dec_at_xy_0, supersampling_factor=1, flux_evaluate_indexes=None)[source]¶ Parameters: - nx – number of pixels in x-axis
- ny – number of pixels in y-axis
- transform_pix2angle – 2x2 matrix, mapping of pixel to coordinate
- ra_at_xy_0 – ra coordinate at pixel (0,0)
- dec_at_xy_0 – dec coordinate at pixel (0,0)
- supersampling_factor – int, factor (per axis) of super-sampling
- flux_evaluate_indexes – bool array of shape nx x ny, corresponding to pixels being evaluated (for both low and high res). Default is None, replaced by setting all pixels to being evaluated.
-
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.
Returns: sqrt(pixel_area)/supersampling_factor.
-
num_grid_points_axes
¶ Effective number of points along each axes, after supersampling.
Returns: 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
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
-
__init__
(kernel, conv_pixels, compute_pixels=None, nopython=True, cache=True, parallel=False, memory_raise=True)[source]¶ Parameters: - kernel – convolution kernel in units of the image pixels provided, odd length per axis
- conv_pixels – bool array same size as data, pixels to be convolved and their light to be blurred
- compute_pixels – bool array of size of image, these pixels (if True) will get blurred light from other pixels
- nopython – bool, numba jit setting to use python or compiled.
- cache – bool, numba jit setting to use cache
- parallel – bool, numba jit setting to use parallel mode
- memory_raise – bool, if True, checks whether memory required to store the convolution kernel is within certain bounds
-
lenstronomy.ImSim.Numerics.numerics module¶
-
class
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()
-
__init__
(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]¶ Parameters: - pixel_grid – PixelGrid() class instance
- psf – PSF() class instance
- compute_mode – options are: ‘regular’, ‘adaptive’
- supersampling_factor – int, factor of higher resolution sub-pixel sampling of surface brightness
- supersampling_convolution – bool, if True, performs (part of) the convolution on the super-sampled grid/pixels
- supersampling_kernel_size – int (odd number), size (in regular pixel units) of the super-sampled convolution
- flux_evaluate_indexes – boolean 2d array of size of image (or None, then initiated as gird of True’s). Pixels indicated with True will be used to perform the surface brightness computation (and possible lensing ray-shooting). Pixels marked as False will be assigned a flux value of zero (or ignored in the adaptive convolution)
- supersampled_indexes – 2d boolean array (only used in mode=’adaptive’) of pixels to be supersampled (in surface brightness and if supersampling_convolution=True also in convolution). All other pixels not set to =True will not be super-sampled.
- compute_indexes – 2d boolean array (only used in compute_mode=’adaptive’), marks pixel that the response after convolution is computed (all others =0). This can be set to likelihood_mask in the Likelihood module for consistency.
- point_source_supersampling_factor – super-sampling resolution of the point source placing
- convolution_kernel_size – int, odd number, size of convolution kernel. If None, takes size of point_source_kernel
- convolution_type – string, ‘fft’, ‘grid’, ‘fft_static’ mode of 2d convolution
-
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
-
lenstronomy.ImSim.Numerics.partial_image module¶
-
class
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.
-
__init__
(partial_read_bools)[source]¶ Parameters: partial_read_bools – 2d numpy array of bools indicating which indexes to be processed
-
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
-
lenstronomy.ImSim.Numerics.point_source_rendering module¶
-
class
PointSourceRendering
(pixel_grid, supersampling_factor, psf)[source]¶ Bases:
object
Numerics to compute the point source response on an image.
-
__init__
(pixel_grid, supersampling_factor, psf)[source]¶ Parameters: - pixel_grid – PixelGrid() instance
- supersampling_factor – int, factor of supersampling of point source
- psf – PSF() instance
-
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 input (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
-