coolest.api.util#
Functions#
|
Rescale an image such that it has units of electrons per second (e/s), |
|
|
|
|
|
|
|
|
|
Convert a 1d array into a 2d array. |
|
Convert a 2d array into a 1d array. |
|
|
|
Computes the effective radius of the 2D surface brightness profile, |
|
|
|
The two point correlation function can be obtained from the covariance matrix of an image and the distances between its pixels. |
|
Computes the 'lensing information' defined in Tan et al. 2023, Equations (8) and (9). |
|
Read several json files already containing a model with the results of this model fitting |
|
Reads the parameters of a coolest.template.classes.profiles.mass.ExternalShear object |
|
Reads the parameters of a coolest.template.classes.profiles.mass.PEMD object |
|
Reads the parameters of a coolest.template.classes.profiles.mass.SIE object |
|
Reads the parameters of a coolest.template.classes.profiles.light.Sersic object |
|
|
|
composable_lens can be an instance of ComposableLens or ComposableMass |
|
composable_lens can be an instance of ComposableLens or ComposableMass |
|
Resample following multi-variate normal distribution |
Module Contents#
- convert_image_to_data_units(image, mag_tot, mag_zero_point=None, coolest_object=None)[source]#
Rescale an image such that it has units of electrons per second (e/s), given a total magnitude and a magnitude zero-point.
After rescaling, the total magnitude of the image_rescaled should corresponds to
-2.5 * np.log10(image_rescaled.sum()) + mag_zero_point = mag_tot
where mag_zero_point corresponds to the magnitude of 1 e/s. :param image: input image, as a 2D array. :param mag_tot: target total magnitude, integrated over the whole image :param mag_zero_point: magnitude zero point of the observation (that corresponds to 1 e/s). If coolest_object is not None, mag_zero_point is ignored. :param coolest_object: if given, will be used to retrieve the zero-point magnitude of the observation.
- array2image(array, nx=0, ny=0)[source]#
Convert a 1d array into a 2d array.
Note: this only works when length of array is a perfect square, or else if nx and ny are provided
- Parameters:
array (array of size n**2) – image values
- Returns:
2d array
- Raises:
AttributeError, KeyError
- image2array(image)[source]#
Convert a 2d array into a 1d array.
- Parameters:
array (array of size (n,n)) – image values
- Returns:
1d array
- Raises:
AttributeError, KeyError
- effective_radius(light_map, x, y, outer_radius=10, initial_guess=1, initial_delta_pix=10, n_iter=10)[source]#
Computes the effective radius of the 2D surface brightness profile, based on a definition similar to the half-light radius. NOTE: This functions assumes that the profile is centered on the grid.
- Parameters:
light_map (ndarray) – 2D array of the light model
x (ndarray) – x-coordinates associated to the light model
y (ndarray) – y-coordinates associated to the light model
outer_radius (int, optional) – outer limit of integration within which half the light is calculated to estimate the effective radius, by default 10
initial_guess (int, optional) – Initial guess for effective radius in arcsecond, by default 1
initial_delta_pix (int, optional) – Initial step size in pixels before shrinking in future iterations, by default 10
n_iter (int, optional) – Number of iterations, by default 5
- Returns:
Effective radius and spacing of the coordinates grid (approximate accuracy)
- Return type:
(float, float)
- Raises:
RuntimeError – If integration loop exceeds outer bound before convergence.
- azim_averaged_two_point_correlation(light_image, dpix, rmax, Nbins)[source]#
The two point correlation function can be obtained from the covariance matrix of an image and the distances between its pixels. By binning the covariance matrix entries in distance (or radial) bins, one can obtain the 1D correlation function. There are two ways to obtain the covariance matrix: 1) it is equivalent to the inverse Fourier transform of the power spectrum, and 2) by calculating explicitly the covariance between any two pixels Here we use the first way.
- Parameters:
light_image (2D ndarray) – Pixels of the image to analyse.
dpix (float) – Pixel size
Nbins (int, optional) – The number of radial bins to use for converting the 2D covariance matrix into a 1D correlation function.
rmax (float, optional) – A value for the maximum extent of the radial bins. If none is given then it is equal to half the diagonal of the provided image.
- Returns:
The location, value, uncertainty and covariance matrix The covariance matrix here is the inverse of fourier transform of power spectrum)
- Return type:
(array, array, array, array)
- lensing_information(data_lens_sub, x, y, theta_E, noise_map, center_x_lens=0, center_y_lens=0, a=16, b=0, arc_mask=None)[source]#
Computes the ‘lensing information’ defined in Tan et al. 2023, Equations (8) and (9). https://ui.adsabs.harvard.edu/abs/2023arXiv231109307T/abstract
- Parameters:
data_lens_sub (np.ndarray) – Imaging data as a 2D array. It is assumed to contain no lens light.
x (np.ndarray) – 2D array of x coordinates, in arcsec.
y (np.ndarray) – 2D array of y coordinates, in arcsec.
theta_E (float) – Einstein radius in arcsec, by default None
noise_map (np.ndarray) – 2D array with 1-sigma noise level per pixel (same units as data_lens_sub), by default None
center_x_lens (int, optional) – x coordinates of the center of the lens, by default 0
center_y_lens (int, optional) – y coordinates of the center of the lens, by default 0
a (int, optional) – Exponent in Eq. (9) from Yi Tan et al. 2023, by default 16
b (int, optional) – Exponent in Eq. (9) from Yi Tan et al. 2023, by default 0
arc_mask (np.ndarray, optional) – Binary 2D array with 1s where there is are lensed arcs, by default None
- Returns:
Lensing information I, Einstein radius, reference azimuthal angle, total mask used for computing I
- Return type:
4-tuple
- split_lens_source_params(coolest_list, name_list, lens_light=False)[source]#
Read several json files already containing a model with the results of this model fitting
INPUT#
file_list: list, list of path or names of the file to read name_list: list, list of shorter names to distinguish the files lens_light: bool, if True, computes the lens light kwargs as well (not yet implemented)
OUTPUT#
param_all_lens, param_all_source: organized dictionaries readable by plotting function
- read_shear(mass, param={}, prefix='SHEAR_0_')[source]#
Reads the parameters of a coolest.template.classes.profiles.mass.ExternalShear object
INPUT#
mass : coolest.template.classes.profiles.mass.ExternalShear object param : dict, already existing dictionnary with ordered parameters readable by plotting function prefix : str, prefix to use in saving parameters names
OUTPUT#
param : updated param
- read_pemd(mass, param={}, prefix='PEMD_0_')[source]#
Reads the parameters of a coolest.template.classes.profiles.mass.PEMD object
INPUT#
mass : coolest.template.classes.profiles.mass.PEMD object param : dict, already existing dictionnary with ordered parameters readable by plotting function prefix : str, prefix to use in saving parameters names
OUTPUT#
param : updated param
- read_sie(mass, param={}, prefix='SIE_0_')[source]#
Reads the parameters of a coolest.template.classes.profiles.mass.SIE object
INPUT#
mass : coolest.template.classes.profiles.mass.SIE object param : dict, already existing dictionnary with ordered parameters readable by plotting function prefix : str, prefix to use in saving parameters names
OUTPUT#
param : updated param
- read_sersic(light, param={}, prefix='Sersic_0_')[source]#
Reads the parameters of a coolest.template.classes.profiles.light.Sersic object
INPUT#
mass : coolest.template.classes.profiles.light.Sersic object param : dict, already existing dictionnary with ordered parameters readable by plotting function prefix : str, prefix to use in saving parameters names
OUTPUT#
param : updated param
- find_caustics(crit_lines, composable_lens)[source]#
composable_lens can be an instance of ComposableLens or ComposableMass