lenstronomy.SimulationAPI package¶
Subpackages¶
- lenstronomy.SimulationAPI.ObservationConfig package
Submodules¶
lenstronomy.SimulationAPI.data_api module¶
- class DataAPI(numpix, kwargs_pixel_grid=None, **kwargs_single_band)[source]¶
Bases:
SingleBand
This class is a wrapper of the general description of data in SingleBand() to translate those quantities into configurations in the core lenstronomy Data modules to simulate images according to those quantities.
This class is meant to be an example of a wrapper. More possibilities in terms of PSF and data type options are available. Have a look in the specific modules if you are interested in.
- __init__(numpix, kwargs_pixel_grid=None, **kwargs_single_band)[source]¶
- Parameters:
numpix – number of pixels per axis in the simulation to be modelled
kwargs_pixel_grid – if None, uses default pixel grid option if defined, must contain keyword arguments PixelGrid() class
kwargs_single_band – keyword arguments used to create instance of SingleBand class
- property data_class¶
Creates a Data() instance of lenstronomy based on knowledge of the observation.
- Returns:
instance of Data() class
- property kwargs_data¶
- Returns:
keyword arguments for ImageData class instance
lenstronomy.SimulationAPI.model_api module¶
- class ModelAPI(lens_model_list=None, z_lens=None, z_source=None, lens_redshift_list=None, source_light_model_list=None, lens_light_model_list=None, point_source_model_list=None, source_redshift_list=None, cosmo=None, z_source_convention=None, tabulated_deflection_angles=None, observed_convention_index=None)[source]¶
Bases:
object
This class manages the model choices.
The role is to return instances of the lenstronomy LightModel, LensModel, PointSource modules according to the options chosen by the user. Currently, all other model choices are equivalent to the ones provided by LightModel, LensModel, PointSource. The current options of the class instance only describe a subset of possibilities.
- __init__(lens_model_list=None, z_lens=None, z_source=None, lens_redshift_list=None, source_light_model_list=None, lens_light_model_list=None, point_source_model_list=None, source_redshift_list=None, cosmo=None, z_source_convention=None, tabulated_deflection_angles=None, observed_convention_index=None)[source]¶
# TODO: make inputs follow the kwargs_model of the class_creator instances of ‘kwargs_model’, # i.e. multi-plane options, perhaps others
- Parameters:
lens_model_list – list of strings with lens model names
z_lens – redshift of the deflector (only considered when operating in single plane mode). Is only needed for specific functions that require a cosmology.
z_source – redshift of the source: Needed in multi_plane option only, not required for the core functionalities in the single plane mode. This will be the redshift of the source plane (if not further specified the ‘source_redshift_list’) and the point source redshift (regardless of ‘source_redshift_list’)
lens_redshift_list – list of deflector redshift (corresponding to the lens model list), only applicable in multi_plane mode.
source_light_model_list – list of strings with source light model names (lensed light profiles)
lens_light_model_list – list of strings with lens light model names (not lensed light profiles)
point_source_model_list – list of strings with point source model names
source_redshift_list – list of redshifts of the source profiles (optional)
cosmo – instance of the astropy cosmology class. If not specified, uses the default cosmology.
z_source_convention – float, redshift of a source to define the reduced deflection angles of the lens models. If None, ‘z_source’ is used.
tabulated_deflection_angles – a class that returns deflection angles given a set of (x, y) coordinates. Effectively a fixed lens model. See documentation in Profiles.numerical_alpha
observed_convention_index – a list of indices that correspond to lens models where the center_x,center_y values correspond to the observed (lensed positions), not the physical positions in space
- property lens_model_class¶
- Returns:
instance of lenstronomy LensModel class
- property lens_light_model_class¶
- Returns:
instance of lenstronomy LightModel class describing the non-lensed light profiles
- property source_model_class¶
- Returns:
instance of lenstronomy LightModel class describing the source light profiles
- property point_source_model_class¶
- Returns:
instance of lenstronomy PointSource class describing the point sources (lensed and unlensed)
- physical2lensing_conversion(kwargs_mass)[source]¶
- Parameters:
kwargs_mass – list of keyword arguments of all the lens models. Einstein radius ‘theta_E’ are replaced by ‘sigma_v’, velocity dispersion in km/s, ‘alpha_Rs’ and ‘Rs’ of NFW profiles are replaced by ‘M200’ and ‘concentration’
- Returns:
kwargs_lens in reduced deflection angles compatible with the LensModel instance of this module
lenstronomy.SimulationAPI.observation_api module¶
- class Instrument(pixel_scale, read_noise=None, ccd_gain=None)[source]¶
Bases:
object
Basic access points to instrument properties.
- __init__(pixel_scale, read_noise=None, ccd_gain=None)[source]¶
- Parameters:
read_noise – std of noise generated by read-out (in units of electrons)
pixel_scale – scale (in arcseconds) of pixels
ccd_gain – electrons/ADU (analog-to-digital unit). A gain of 8 means that the camera digitizes the CCD signal so that each ADU corresponds to 8 photoelectrons.
- class Observation(exposure_time, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1)[source]¶
Bases:
object
Basic access point to observation properties.
- __init__(exposure_time, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1)[source]¶
- Parameters:
exposure_time – exposure time per image (in seconds)
sky_brightness – sky brightness (in magnitude per square arcseconds)
seeing – full width at half maximum of the PSF (if not specific psf_model is specified)
num_exposures – number of exposures that are combined
psf_type – string, type of PSF (‘GAUSSIAN’ and ‘PIXEL’ supported)
kernel_point_source – 2d numpy array, model of PSF centered with odd number of pixels per axis (optional when psf_type=’PIXEL’ is chosen)
point_source_supersampling_factor – int, supersampling factor of kernel_point_source (optional when psf_type=’PIXEL’ is chosen)
- update_observation(exposure_time=None, sky_brightness=None, seeing=None, num_exposures=None, psf_type=None, kernel_point_source=None)[source]¶
Updates class instance with new properties if specific argument is not None.
- Parameters:
exposure_time – exposure time per image (in seconds)
sky_brightness – sky brightness (in magnitude per square arcseconds)
seeing – full width at half maximum of the PSF (if not specific psf_model is specified)
num_exposures – number of exposures that are combined
psf_type – string, type of PSF (‘GAUSSIAN’ and ‘PIXEL’ supported)
kernel_point_source – 2d numpy array, model of PSF centered with odd number of pixels per axis (optional when psf_type=’PIXEL’ is chosen)
- Returns:
None, updated class instance
- property exposure_time¶
Total exposure time.
- Returns:
summed exposure time
- property kwargs_psf¶
Keyword arguments to initiate a PSF() class.
- Returns:
kwargs_psf
- property psf_class¶
Creates instance of PSF() class based on knowledge of the observations For the full possibility of how to create such an instance, see the PSF() class documentation.
- Returns:
instance of PSF() class
- class SingleBand(pixel_scale, exposure_time, magnitude_zero_point, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1, data_count_unit='e-', background_noise=None)[source]¶
Bases:
Instrument
,Observation
Class that combines Instrument and Observation.
- __init__(pixel_scale, exposure_time, magnitude_zero_point, read_noise=None, ccd_gain=None, sky_brightness=None, seeing=None, num_exposures=1, psf_type='GAUSSIAN', kernel_point_source=None, truncation=5, point_source_supersampling_factor=1, data_count_unit='e-', background_noise=None)[source]¶
- Parameters:
read_noise – std of noise generated by read-out (in units of electrons)
pixel_scale – scale (in arcseconds) of pixels
ccd_gain – electrons/ADU (analog-to-digital unit). A gain of 8 means that the camera digitizes the CCD signal so that each ADU corresponds to 8 photoelectrons.
exposure_time – exposure time per image (in seconds)
sky_brightness – sky brightness (in magnitude per square arcseconds in units of electrons)
seeing – Full-Width-at-Half-Maximum (FWHM) of PSF
magnitude_zero_point – magnitude corresponding to 1 electron per second
num_exposures – number of exposures that are combined
point_source_supersampling_factor – int, supersampling factor of kernel_point_source (optional when psf_type=’PIXEL’ is chosen)
data_count_unit – string, unit of the data (not noise properties - see other definitions), ‘e-’: (electrons assumed to be IID), ‘ADU’: (analog-to-digital unit)
background_noise – sqrt(variance of background) as a total contribution from readnoise, sky brightness etc. in units of the data_count_units (e- or ADU) If you set this parameter, it will use this value regardless of the values of read_noise, sky_brightness
- property sky_brightness¶
- Returns:
sky brightness (counts per square arcseconds in unit of data (e- or ADU’s) per unit time)
- property background_noise¶
Gaussian sigma of noise level per pixel in counts (e- or ADU) per second.
- Returns:
sqrt(variance) of background noise level in data units
- flux_noise(flux)[source]¶
- Parameters:
flux – float or array, units of count_unit/seconds, needs to be positive semi-definite in the flux value
- Returns:
Gaussian approximation of Poisson statistics in IIDs sqrt(variance)
- flux_iid(flux_per_second)[source]¶
IID counts. This can be used by lenstronomy to estimate the Poisson errors keeping the assumption that the counts are IIDs (even if they are not).
- Parameters:
flux_per_second – flux count per second in the units set in this class (ADU or e-)
- Returns:
IID count number
- noise_for_model(model, background_noise=True, poisson_noise=True, seed=None)[source]¶
- Parameters:
model – 2d numpy array of modelled image (with pixels in units of data specified in class)
background_noise – bool, if True, adds background noise
poisson_noise – bool, if True, adds Poisson noise of modelled flux
seed – int, seed number to be used to render the noise properties. If None, then uses the current numpy.random seed to render the noise properties.
- Returns:
noise realization corresponding to the model
- estimate_noise(image)[source]¶
- Parameters:
image – noisy data, background subtracted
- Returns:
estimated noise map sqrt(variance) for each pixel as estimated from the instrument and observation
- magnitude2cps(magnitude)[source]¶
Converts an apparent magnitude to counts per second (in units of the data)
The zero point of an instrument, by definition, is the magnitude of an object that produces one count (or data number, DN) per second. The magnitude of an arbitrary object producing DN counts in an observation of length EXPTIME is therefore: m = -2.5 x log10(DN / EXPTIME) + ZEROPOINT
- Parameters:
magnitude – magnitude of object
- Returns:
counts per second of object
lenstronomy.SimulationAPI.observation_constructor module¶
lenstronomy.SimulationAPI.point_source_variability module¶
- class PointSourceVariability(source_x, source_y, variability_func, numpix, kwargs_single_band, kwargs_model, kwargs_numerics, kwargs_lens, kwargs_source_mag=None, kwargs_lens_light_mag=None, kwargs_ps_mag=None)[source]¶
Bases:
object
This class enables to plug in a variable point source in the source plane to be added on top of a fixed lens and extended surface brightness model. The class inherits SimAPI and additionally requires the lens and light model parameters as well as a position in the source plane.
The intrinsic source variability can be defined by the user and additional uncorrelated variability in the image plane can be plugged in as well (e.g. due to micro-lensing)
- __init__(source_x, source_y, variability_func, numpix, kwargs_single_band, kwargs_model, kwargs_numerics, kwargs_lens, kwargs_source_mag=None, kwargs_lens_light_mag=None, kwargs_ps_mag=None)[source]¶
- Parameters:
source_x – RA of source position
source_y – DEC of source position
variability_func – function that returns a brightness (in magnitude) as a function of time t
numpix – number of pixels per axis
kwargs_single_band –
kwargs_model –
kwargs_numerics –
kwargs_lens –
kwargs_source_mag –
kwargs_lens_light_mag –
kwargs_ps_mag –
- property delays¶
- Returns:
time delays
- property image_bkg¶
- Returns:
2d numpy array, image of the extended light components without the variable source
lenstronomy.SimulationAPI.sim_api module¶
- class SimAPI(numpix, kwargs_single_band, kwargs_model)[source]¶
-
This class manages the model parameters in regard of the data specified in SingleBand.
In particular, this API translates models specified in units of astronomical magnitudes into the amplitude parameters used in the LightModel module of lenstronomy. Optionally, this class can also handle inputs with cosmology dependent lensing quantities and translates them to the optical quantities being used in the lenstronomy LensModel module. All other model choices are equivalent to the ones provided by LightModel, LensModel, PointSource modules
- __init__(numpix, kwargs_single_band, kwargs_model)[source]¶
- Parameters:
numpix – number of pixels per axis
kwargs_single_band – keyword arguments specifying the class instance of DataAPI
kwargs_model – keyword arguments specifying the class instance of ModelAPI
- image_model_class(kwargs_numerics=None)[source]¶
- Parameters:
kwargs_numerics – keyword arguments list of Numerics module
- Returns:
instance of the ImageModel class with all the specified configurations
- magnitude2amplitude(kwargs_lens_light_mag=None, kwargs_source_mag=None, kwargs_ps_mag=None)[source]¶
‘magnitude’ definition are in APPARENT magnitudes as observed on the sky, not intrinsic!
- Parameters:
kwargs_lens_light_mag – keyword argument list as for LightModel module except that ‘amp’ parameters are ‘magnitude’ parameters.
kwargs_source_mag – keyword argument list as for LightModel module except that ‘amp’ parameters are ‘magnitude’ parameters.
kwargs_ps_mag – keyword argument list as for PointSource module except that ‘amp’ parameters are ‘magnitude’ parameters.
- Returns:
value of the lenstronomy ‘amp’ parameter such that the total flux of the profile type results in this magnitude for all the light models. These keyword arguments conform with the lenstronomy LightModel syntax.