Strong Lens

strong_lens

class mejiro.strong_lens.StrongLens(name, coords, kwargs_model, kwargs_params, physical_params, use_jax)[source]

Bases: ABC

Parent class for strong lenses.

At minimum, a unique name and the parameterization in lenstronomy (kwargs_model and kwargs_params) must be provided. If the light models have amplitudes (amp), they will be used. If not, magnitudes with their corresponding filters must be provided in the ‘physical_params’ dictionary. If both are provided, the amp values will be used.

Parameters:
  • name (str) – The name of the galaxy-galaxy strong lens. Should be unique.

  • coords (astropy.coordinates.SkyCoord or None) – The coordinates of the system.

  • kwargs_model (dict) – In Lenstronomy format: see Lenstronomy documentation.

  • kwargs_params (dict) – In Lenstronomy format: see Lenstronomy documentation.

  • physical_params (dict) –

    A dictionary of physical parameters. The following are populated when importing from SLSim:
    • ’lens_stellar_mass’: the stellar mass of the lens galaxy in solar masses.

    • ’lens_velocity_dispersion’: the velocity dispersion of the lens galaxy in km/s.

    • ’magnification’: the magnification of the source galaxy.

    • ’magnitudes’: a dictionary of magnitudes for the lens and source galaxies, with keys ‘lens’ and ‘source’, respectively. Each value should be a dictionary with keys corresponding to the filter names (e.g., ‘F062’, ‘F087’, etc.) and values as the magnitudes in those filters.

  • use_jax (bool, or list of bool) – Whether to use JAXtronomy for calculations. Default is None, then set to False in the constructor for all lens model element(s). See the lenstronomy documentation for details.

Notes

  • Note that JAXtronomy is disabled by default. To enable it, either set use_jax to True (which will enable it for all lens model elements) or provide a list of booleans specifying which lens model(s) to enable JAXtronomy for.

Examples

Here is a sample physical_params dictionary:

{
    "lens_stellar_mass": 977409654003.7206,
    "lens_velocity_dispersion": 318.1035069180407,
    "magnification": 2.1572878148080696,
    "magnitudes": {
        "lens": {
            "F062": 25.31638290929369,
            "F087": 24.96369787259651,
            "F106": 23.9596060901365,
            "F129": 22.97223751280789,
            "F146": 22.29807037949136,
            "F158": 21.906108678706293,
            "F184": 21.45793326374795,
            "F213": 21.118396579379453
        },
        "lensed_source": {
            "F062": 25.500925653675434,
            "F087": 25.177803863752867,
            "F106": 25.00159434812006,
            "F129": 24.8952958657035,
            "F146": 24.766725445488536,
            "F158": 24.667238282726974,
            "F184": 24.465433844571177,
            "F213": 24.029905125404884
        },
        "source": {
            "F062": 26.33569587971921,
            "F087": 26.012574089796644,
            "F106": 25.836364574163838,
            "F129": 25.730066091747275,
            "F146": 25.601495671532312,
            "F158": 25.50200850877075,
            "F184": 25.300204070614953,
            "F213": 24.86467535144866
        }
    }
}
add_realization(realization, add_mass_sheet_correction=True, use_jax=False)[source]

Add a pyHalo dark matter subhalo realization to the mass model of the system. See the pyHalo documentation for details.

Parameters:
  • realization (pyHalo realization object) – See the pyHalo documentation for details.

  • add_mass_sheet_correction (bool, optional) – See the pyHalo documentation for details. Default is True.

  • use_jax (bool, optional) – Whether to use JAXtronomy for calculations. Default is False.

get_einstein_radius()[source]

Returns the Einstein radius.

Returns:

The Einstein radius (theta_E) in angular units (often, arcseconds).

Return type:

float

Raises:

ValueError – This method currently does not calculate the Einstein radius. Rather, it retrieves it from the attributes. If it has not been stored in these attributes, a ValueError will be raised.

get_f_sub(fov_arcsec=5, num_pix=100, plot=False)[source]
get_kappa(fov_arcsec=5, num_pix=100)[source]

Computes the convergence (kappa) map of the lens model over a specified field of view.

Parameters:
  • fov_arcsec (float, optional) – The field of view in arcseconds. Default is 5.

  • num_pix (int, optional) – The number of pixels along each axis for the output grid. Default is 100.

Returns:

kappa_map – A 2D array of shape (num_pix, num_pix) representing the convergence (kappa) values computed over the grid.

Return type:

ndarray

Notes

The method creates a square grid centered at (0, 0) in arcseconds, evaluates the lens model’s convergence at each grid point, and returns the resulting map.

get_lens_cosmo()[source]

Get or create the LensCosmo instance, a lenstronomy class that supports physical unit calculations.

Returns:

The lenstronomy.Cosmo.lens_cosmo.LensCosmo instance for the system.

Return type:

LensCosmo

get_lens_magnitude(band)[source]
Parameters:

band (str) – The name of the photometric band for which to retrieve the lens magnitude.

Returns:

Magnitude of the lens in the specified photometric band.

Return type:

float

get_lensed_source_magnitude(band)[source]

Returns the magnitude of the lensed source in the specified photometric band.

Parameters:

band (str) – The name of the photometric band for which to retrieve the lensed source magnitude.

Returns:

The magnitude of the lensed source in the specified band.

Return type:

float

get_maggies(kind, band)[source]

Retrieve the maggies value for a specified kind and photometric band from the physical parameters dictionary.

Parameters:
  • kind (str) – Options are ‘lens’, ‘source’, ‘lensed_source’.

  • band (str) – e.g., ‘F129’ (Roman), ‘J’ (HWO), etc.

Returns:

Maggies

Return type:

float

Raises:

ValueError – If magnitudes are not provided in the physical_params dictionary. If the specified kind is not present in the magnitudes. If the specified band is not present for the given kind.

get_magnitude(kind, band)[source]

Retrieve the magnitude value for a specified kind and photometric band from the physical parameters dictionary.

Parameters:
  • kind (str) – Options are ‘lens’, ‘source’, ‘lensed_source’.

  • band (str) – e.g., ‘F129’ (Roman), ‘J’ (HWO), etc.

Returns:

Magnitude

Return type:

float

Raises:

ValueError – If magnitudes are not provided in the physical_params dictionary. If the specified kind is not present in the magnitudes. If the specified band is not present for the given kind.

get_main_halo_mass()[source]

Returns the main halo mass of the lensing galaxy in solar masses.

This method first attempts to retrieve the main halo mass from the physical_params dictionary using the main_halo_mass key. If this value is not present, it will attempt to estimate the main halo mass using the stellar mass (lens_stellar_mass) and the lens redshift (z_lens) via the cosmo.stellar_to_main_halo_mass method, if available.

Returns:

The mass of the main halo in solar masses.

Return type:

float

Raises:

ValueError – If neither main_halo_mass nor lens_stellar_mass are present in physical_params.

get_realization_kappa(fov_arcsec=5, num_pix=100, add_mass_sheet_correction=False)[source]

Computes the convergence (kappa) map for the current realization over a specified field of view.

Parameters:
  • fov_arcsec (float, optional) – The field of view in arcseconds for the kappa map. Default is 5.

  • num_pix (int, optional) – The number of pixels per side for the output kappa map. Default is 100.

  • add_mass_sheet_correction (bool, optional) – Whether to include the mass sheet correction in the realization. Default is False.

Returns:

kappa_map – A 2D array of shape (num_pix, num_pix) representing the convergence (kappa) map.

Return type:

numpy.ndarray

Raises:

ValueError – If no realization has been added prior to calling this method.

Notes

This method requires a pyHalo realization to be added using add_realization().

get_source_magnitude(band)[source]

Returns the magnitude of the source in the specified photometric band.

Parameters:

band (str) – The name of the photometric band for which to retrieve the source magnitude.

Returns:

The magnitude of the source in the specified band.

Return type:

float

get_stellar_mass()[source]

Get the stellar mass of the lensing galaxy in solar masses.

Returns:

The stellar mass of the lensing galaxy in solar masses.

Return type:

float

Raises:

ValueError – If ‘lens_stellar_mass’ is not present in self.physical_params.

get_velocity_dispersion()[source]

Get the velocity dispersion of the lensing galaxy in km/s.

Returns:

The velocity dispersion of the lensing galaxy in km/s.

Return type:

float

Raises:

ValueError – If ‘lens_velocity_dispersion’ is not present in self.physical_params.

property kwargs_extinction
property kwargs_lens
property kwargs_lens_light
property kwargs_ps
property kwargs_source
property kwargs_special
property lens_light_model
property lens_light_model_list
property lens_model
property lens_model_list
property lens_redshift_list
quick_add(model='CDM', model_kwargs=None, add_mass_sheet_correction=True, use_jax=False)[source]

Add a pyHalo dark matter subhalo realization to the mass model of the system. See the pyHalo documentation for details.

Parameters:
  • model (str, optional) – The name of the pyHalo preset model to use. Default is ‘CDM’.

  • model_kwargs (dict, optional) – Additional keyword arguments to pass to the model class.

  • add_mass_sheet_correction (bool, optional) – Whether to add a mass sheet correction. Default is True.

  • use_jax (bool, optional) – Whether to use JAXtronomy for calculations. Default is False.

property source_light_model
property source_light_model_list
property source_redshift_list
validate_light_models()[source]

Validates the presence of the lenstronomy amplitude (‘amp’) parameter in all lens and source light model keyword arguments. If magnitude information is not present in self.physical_params, or if it is incomplete (missing ‘lens’ or ‘source’ magnitudes), the method ensures that each light model dictionary in self.kwargs_lens_light and self.kwargs_source contains an ‘amp’ key. If any light model is missing the ‘amp’ parameter, a ValueError is raised.

Returns:

amps_provided – True if all required amplitude parameters are provided. False if magnitudes are provided for both the lens and source.

Return type:

bool

Raises:

ValueError – If any light model dictionary is missing the ‘amp’ parameter.

galaxy_galaxy

class mejiro.galaxy_galaxy.GalaxyGalaxy(name, coords, kwargs_model, kwargs_params, physical_params={}, use_jax=None)[source]

Bases: StrongLens

static from_slsim(slsim_gglens, name=None, coords=None, bands=None, use_jax=None)[source]
get_image_positions(ignore_substructure=True)[source]

Compute and return the extended source image positions.

Parameters:

ignore_substructure (bool, optional) – If True (default), ignores substructure in the lens model when computing image positions. If False, includes substructure in the calculation.

Returns:

A tuple containing arrays of x and y coordinates of the image positions in lenstronomy angle units (typically arcseconds).

Return type:

tuple of numpy.ndarray

Notes

  • The source position is taken from the first element of kwargs_source.

  • Uses lenstronomy’s LensEquationSolver to solve the lens equation.

  • The solver is chosen automatically: “analytical” if supported by the lens model, otherwise “lenstronomy”.

  • The search window and minimum distance are set based on the Einstein radius.

  • If a lens model realization exists and ignore_substructure is True, only the macromodel is used for the calculation.

get_magnification()[source]
class mejiro.galaxy_galaxy.Sample1[source]

Bases: GalaxyGalaxy

This is a simulated strong lens from SLSim with a real source galaxy from the COSMOS real galaxy dataset (galaxy ID: 52643).

class mejiro.galaxy_galaxy.Sample2[source]

Bases: GalaxyGalaxy

This is a simulated strong lens from SLSim with a real source galaxy from the COSMOS real galaxy dataset (galaxy ID: 125125).

class mejiro.galaxy_galaxy.SampleBELLS[source]

Bases: GalaxyGalaxy

This system, SDSSJ1159-0007, from the BELLS sample (Brownstein et al. 2012, Shu et al. 2016) was modeled by Tan et al. (2024).

class mejiro.galaxy_galaxy.SampleGG[source]

Bases: GalaxyGalaxy

This is a simulated strong lens from SLSim.

class mejiro.galaxy_galaxy.SampleSL2S[source]

Bases: GalaxyGalaxy

This system, SL2SJ1411+5651, from the SL2S sample (Gavazzi et al. 2012) was modeled by Tan et al. (2024).