Lens Simulation#

The backbone of our modeling code is the lens simulation. Our lens simulation interface is very simple.

class gigalens.simulator.LensSimulatorInterface(phys_model, sim_config, bs)[source]#

A class to simulate batches of lenses given a physical model and camera configuration options (i.e., pixel scale, number of pixels, point spread function, etc.).

phys_model#

The physical model that generated the lensing system. All parameters z that are passed to the simulation methods are expected to correspond to this physical model.

Type

PhysicalModel

sim_config#

Camera configuration settings

Type

SimulatorConfig

bs#

The number of lenses to simulate in parallel

Type

int

abstract simulate(params)[source]#

Simulates lenses with physical parameters params.

Parameters

params (tuple of list of dict) – Parameters of the lensing system to simulate, with format (lens_params, lens_light_params, source_light_params)

Returns

Simulated lenses

abstract lstsq_simulate(params, observed_image, err_map)[source]#

Simulates lenses and fits for their linear parameters based on the observed data.

Parameters
  • params (tuple of list of dict) – Parameters of the lensing system to simulate, with format (lens_params, lens_light_params, source_light_params)

  • observed_image – The observed image, needed for solving the linear parameters

  • err_map – Noise variance map, needed for solving the linear parameters

Returns

Simulated images that have the linear parameters set to the optimal values, minimizing the \(\chi^2\) of the residual using err_map as the variance.

static get_coords(supersample, num_pix, transform_pix2angle)[source]#

Calculates the coordinate grid for the given simulator settings. The default coordinate system in this package is to ensure the mean coordinate is RA, DEC = 0,0.

Parameters
  • supersample (int) – Supersampling factor by which to increase the resolution of the coordinate grid

  • num_pix (int) – Number of pixels in the downsampled image (i.e., with supersample=1)

  • transform_pix2angle (numpy.array) – Array specifying the translation from indices to RA and DEC

Return type

Tuple[float, float, array, array]

Returns

A tuple containing the RA and DEC at the (0,0) index of the coordinate grid (i.e., the bottom left corner), and the coordinate grids (in units of arcseconds) themselves.

There are only two methods that require implementation: a simulate method and a lstsq_simulate method. The only difference between the two is that lstsq_simulate will automatically solve for linear light parameters (such as Sersic half-light \(I_e\)) to minimize the \(\chi^2\) between the simulated image and some observed image (given a fixed error map). Configuration options for LensSimulatorInterface are specified with the SimulatorConfig object.

class gigalens.simulator.SimulatorConfig(delta_pix, num_pix, supersample=1, kernel=None, transform_pix2angle=None)[source]#

Holds parameters for simulation.

delta_pix#

The pixel scale (i.e., the angular resolution)

Type

float

num_pix#

The width of the simulated image in pixels.

Type

int

supersample#

Supersampling factor

Type

int

kernel#

The point spread function with which to convolve simulated images

Type

numpy.array, optional

transform_pix2angle#

An array mapping indices on the coordinate grid to angular units (RA and DEC)

Type

numpy.array, optional

Our lens simulation code is designed to be fast, differentiable, and vectorized/parallelized. We make judicious use of TensorFlow’s tf.function and JAX’s jit compilation. Furthermore, the mass and light profiles that we have implemented are all carefully designed to all stay ‘within’ TensorFlow or JAX – that is, absolutely no use of external libraries such as numpy or scipy in methods that are used during simulation time. Below is a list of currently supported lens and mass profiles. Contributions are welcome!