slsim.Microlensing package

Subpackages

Submodules

slsim.Microlensing.lightcurve module

class slsim.Microlensing.lightcurve.MicrolensingLightCurve(magnification_map: MagnificationMap, time_duration: float, point_source_morphology: str = 'gaussian', kwargs_source_morphology: dict = {})[source]

Bases: object

Class to generate microlensing lightcurve(s) for a single source based on the magnification map, source morphology, and lens properties.

generate_lightcurves(source_redshift, cosmo, lightcurve_type='magnitude', effective_transverse_velocity=1000, num_lightcurves=1, x_start_position=None, y_start_position=None, phi_travel_direction=None)[source]

Generate lightcurves for a point source based on the convolved map.

Parameters:
  • source_redshift – Redshift of the source

  • cosmo – astropy.cosmology instance for the lens class

  • lightcurve_type – Type of lightcurve to generate, either ‘magnitude’ or ‘magnification’. If ‘magnitude’, the lightcurve is returned in magnitudes normalized to the macro magnification. If ‘magnification’, the lightcurve is returned in magnification without normalization. Default is ‘magnitude’.

  • effective_transverse_velocity – Transverse velocity in source plane (in km/s). Default is 1000 km/s (typical effective velocity of the source with respect to microlenses/stars).

  • num_lightcurves – Number of lightcurves to generate. Default is 1.

  • x_start_position – Starting x position of the lightcurve on the magnification map in arcsec. A value of 0 indicates the center of the magnification map. Default is None. If None, a random position is chosen.

  • y_start_position – Starting y position of the lightcurve on the magnification map in arcsec. A value of 0 indicates the center of the magnification map. Default is None. If None, a random position is chosen.

  • phi_travel_direction – Angle of the travel direction in degrees. Default is None. If None, a random angle is chosen. A value of 0 implies the positive x-axis of the magnification map.

Returns:

A tuple of lightcurves, tracks, and time arrays.

lightcurves: list of lightcurves

tracks: x and y positions (in pixels) on the magnification map grid for the paths used to generate the lightcurves.

time_arrays: list of time arrays for each lightcurve

get_convolved_map(return_source_morphology=False)[source]

Get the convolved map based on the source morphology.

Parameters:

return_source_morphology – Whether to return the source morphology object or not. Default is False.

Returns:

The convolved map and the source morphology object if requested. Otherwise, only the convolved map is returned.

Return type:

numpy.ndarray or tuple

slsim.Microlensing.lightcurvelensmodel module

class slsim.Microlensing.lightcurvelensmodel.MicrolensingLightCurveFromLensModel[source]

Bases: object

Class to generate microlensing lightcurves based on the microlensing parameters for each image of a source.

effective_transverse_velocity_images(source_redshift, deflector_redshift, ra_lens, dec_lens, cosmo, shear_phi_angle_images, deflector_velocity_dispersion, random_seed=None, magmap_reference_frame=True)[source]

Calculate the effective transverse velocity in the source plane for each image position. Eventually return the effective transverse velocity in frame of the magnification map by using appropriate transformations.

This implementation is based on the works in the following papers [Credits (for suggestions): James Hung-Hsu Chan, Luke Weisenbach and Henry Best]: 1. https://arxiv.org/pdf/2004.13189 2. https://iopscience.iop.org/article/10.1088/0004-637X/712/1/658/pdf 3. https://iopscience.iop.org/article/10.3847/0004-637X/832/1/46/pdf

Parameters:
  • source_redshift – Redshift of the source

  • deflector_redshift – Redshift of the deflector

  • ra_lens – Right Ascension of the lens in degrees.

  • dec_lens – Declination of the lens in degrees.

  • cosmo – Astropy cosmology object to use for the calculations.

  • shear_phi_angle_images – list containing the angle of the shear vector, w.r.t. the x-axis of the image plane, in degrees for each image of the source.

  • deflector_velocity_dispersion – Velocity dispersion of the deflector in km/s.

  • random_seed – Random seed for reproducibility. If None, a random seed will be generated.

Returns:

effective_velocities: list containing the effective transverse velocity in km/s for each image of the source.

Returns:

effective_velocities_angles_deg: list containing the angle of the effective transverse velocity in degrees for each image of the source.

Return type:

tuple

generate_magnification_maps_from_microlensing_params(kappa_star_images, kappa_tot_images, shear_images, kwargs_MagnificationMap={})[source]

Generate magnification maps for each image of the source based on the image positions and the lens model. It requires the following parameters:

Parameters:
  • kappa_star_images – Kappa star for each image of the source.

  • kappa_tot_images – Kappa total for each image of the source.

  • shear_images – Shear for each image of the source.

  • kwargs_MagnificationMap – Keyword arguments for the MagnificationMap class.

Returns: magmaps_images: a list which contains the [magnification map for each image of the source].

generate_point_source_lightcurves(time, source_redshift, deflector_redshift, kappa_star_images, kappa_tot_images, shear_images, shear_phi_angle_images, ra_lens, dec_lens, deflector_velocity_dispersion, cosmology, kwargs_MagnificationMap: dict, point_source_morphology: str, kwargs_source_morphology: dict, lightcurve_type='magnitude', num_lightcurves=1)[source]

Generate lightcurves for one single point source with certain size, but for all images of that source based on the lens model. The point source is simulated as a “gaussian”, “agn” (Accretion Disk) or “supernovae”.

The lightcurves are generated based on the microlensing map convolved with the source morphology kernel.

The generated lightcurves will have the same length of time as the “time” array provided.

Parameters:
  • time – Time array for which the lightcurve is needed.

  • source_redshift – Redshift of the source

  • deflector_redshift – Redshift of the deflector

  • kappa_star_images – list containing the kappa star (stellar convergence) for each image of the source.

  • kappa_tot_images – list containing the kappa total (total convergence) for each image of the source.

  • shear_images – list containing the shear for each image of the source.

  • shear_phi_angle_images – list containing the angle of the shear vector, w.r.t. the x-axis of the image plane, in degrees for each image of the source.

  • ra_lens – Right Ascension of the lens in degrees.

  • dec_lens – Declination of the lens in degrees.

  • deflector_velocity_dispersion – Velocity dispersion of the deflector in km/s.

  • cosmology – Astropy cosmology object to use for the calculations.

  • kwargs_MagnificationMap – Keyword arguments for the MagnificationMap class. An example can look like: kwargs_MagnificationMap = { “theta_star”: theta_star, # arcsec “rectangular”: True, “center_x”: 0, # arcsec “center_y”: 0, # arcsec “half_length_x”: 25 * theta_star, # arcsec “half_length_y”: 25 * theta_star, # arcsec “mass_function”: “kroupa”, “m_solar”: 1.0, “m_lower”: 0.08, “m_upper”: 100, “num_pixels_x”: 500, “num_pixels_y”: 500, } Note that theta_star needs be estimated based on the cosmology model and redshifts for the source and deflector.

  • point_source_morphology – Morphology of the point source. Options are “gaussian”, “agn” (Accretion Disk) or “supernovae”.

  • kwargs_source_morphology – Dictionary of keyword arguments for the source morphology class. (See slsim.Microlensing.source_morphology for more details) For example, for Gaussian source morphology, it will look like: kwargs_source_morphology = {“source_redshift”: source_redshift, “cosmo”: cosmo, “source_size”: source_size, }. For AGN source morphology, it will look like: kwargs_source_morphology = {“source_redshift”: source_redshift, “cosmo”: cosmology, “r_out”: r_out, “r_resolution”: r_resolution, “smbh_mass_exp”: smbh_mass_exp, “inclination_angle”: inclination_angle, “black_hole_spin”: black_hole_spin, “observer_frame_wavelength_in_nm”: observer_frame_wavelength_in_nm, “eddington_ratio”: eddington_ratio, }

  • lightcurve_type – Type of lightcurve to generate, either ‘magnitude’ or ‘magnification’. If ‘magnitude’, the lightcurve is returned in magnitudes normalized to the macro magnification. If ‘magnification’, the lightcurve is returned in magnification without normalization. Default is ‘magnitude’.

  • num_lightcurves – Default is 1. If require multiple lightcurves for each image using the same magnification map, set this parameter to the number of lightcurves required.

Returns:

lightcurves: numpy array of microlensing magnitudes

with the shape (num_images, num_lightcurves, len(time)). The first dimension is the number of images of the source and the second dimension is the length of the time array.

tracks: list of tracks for each image of the source.

Each track is a list of tuples with the x and y positions of the source at each time step.

time_arrays: list of time arrays for each image of the

source. Each time array is a numpy array with the same length as the time array provided.

Return type:

tuple

generate_point_source_microlensing_magnitudes(time, source_redshift, deflector_redshift, kappa_star_images, kappa_tot_images, shear_images, shear_phi_angle_images, ra_lens, dec_lens, deflector_velocity_dispersion, cosmology, kwargs_MagnificationMap: dict, point_source_morphology: str, kwargs_source_morphology: dict)[source]

Generate microlensing lightcurve magnitudes normalized to the mean magnification for various source morphologies. For single source only, it produces the lightcurve magnitudes for all images of the source.

Parameters:
  • time – Time array for which the lightcurve is needed.

  • source_redshift – Redshift of the source

  • deflector_redshift – Redshift of the deflector

  • kappa_star_images – list containing the kappa star (stellar convergence) for each image of the source.

  • kappa_tot_images – list containing the kappa total (total convergence) for each image of the source.

  • shear_images – list containing the shear for each image of the source.

  • shear_phi_angle_images – list containing the angle of the shear vector, w.r.t. the x-axis of the image plane, in degrees for each image of the source.

  • ra_lens – Right Ascension of the lens in degrees.

  • dec_lens – Declination of the lens in degrees.

  • deflector_velocity_dispersion – Velocity dispersion of the deflector in km/s.

  • cosmology – Astropy cosmology object to use for the calculations.

  • kwargs_MagnificationMap – Keyword arguments for the MagnificationMap class.

  • point_source_morphology – Morphology of the point source. Options are “gaussian”, “agn” (Accretion Disk) or “supernovae”.

  • kwargs_source_morphology – Dictionary of keyword arguments for the source morphology class. (See slsim.Microlensing.source_morphology for more details). Note that different parameters are defined for different source morphologies. So check the documentation for each morphology.

Returns:

lightcurves_single: numpy array of microlensing magnitudes with the shape (num_images, len(time)).

property lightcurves

Returns the cached lightcurves generated for the point source.

Has shape (num_images, len(time)).

property magmaps_images

Returns the magnification maps for each image of the source.

property tracks

Returns the cached track coordinates on the magnification map, generated for the point source.

slsim.Microlensing.magmap module

class slsim.Microlensing.magmap.MagnificationMap(magnifications_array: ndarray = None, kappa_tot: float = None, shear: float = None, kappa_star: float = None, theta_star: float = None, mass_function: str = None, m_solar: float = None, m_lower: float = None, m_upper: float = None, center_x: float = None, center_y: float = None, half_length_x: float = None, half_length_y: float = None, num_pixels_x: int = None, num_pixels_y: int = None, kwargs_IPM: dict = {})[source]

Bases: object

Class to generate magnification maps based on the kappa_tot, shear, kappa_star, etc.

get_pixel_size_meters(source_redshift, cosmo)[source]

Returns the pixel size in meters.

Parameters:
  • source_redshift – redshift of the source.

  • cosmo – astropy.cosmology instance.

Returns:

pixel size in meters.

property magnitudes

Returns the magnitudes of the magnification map normalized by the average magnification.

property mu_ave

Returns the average (macro) magnification of the magnification map.

property num_pixels

Returns the number of pixels in the magnification map in (x, y) format.

property pixel_scales

Returns the pixel scales in (x, y) format.

The units are arcseconds.

property pixel_size

Returns the pixel size in arcseconds.

property smooth_fraction

Returns the convergence fraction of that is due to smooth matter.

property stellar_fraction

Returns the convergence fraction of that is due to stars/compact objects.

Module contents