caustics.sims package#

Submodules#

caustics.sims.lens_source module#

class caustics.sims.lens_source.LensSource(lens: Annotated[Lens, 'caustics lens mass model object'], source: Annotated[Source, 'caustics light object which defines the background source'], pixelscale: Annotated[float, 'pixelscale of the sampling grid'], pixels_x: Annotated[int, 'number of pixels on the x-axis for the sampling grid'], lens_light: Annotated[Source | None, "caustics light object which defines the lensing object's light"] = None, pixels_y: Annotated[int | None, 'number of pixels on the y-axis for the sampling grid'] = None, upsample_factor: Annotated[int, 'Amount of upsampling to model the image'] = 1, quad_level: Annotated[int | None, 'sub pixel integration resolution'] = None, psf_mode: Annotated[Literal['fft', 'conv2d'], 'Mode for convolving psf'] = 'fft', psf_shape: Annotated[tuple[int, ...] | None, 'The shape of the psf'] = None, psf: Annotated[ArrayLike | list | None, 'An image to convolve with the scene', True] = [[1.0]], x0: Annotated[ArrayLike | float | None, 'center of the fov for the lens source image', True] = 0.0, y0: Annotated[ArrayLike | float | None, 'center of the fov for the lens source image', True] = 0.0, name: Annotated[str | None, 'Name of the simulator'] = 'sim')[source]#

Bases: Module

Lens image of a source.

Straightforward simulator to sample a lensed image of a source object. Constructs a sampling grid internally based on the pixelscale and gridding parameters. It can automatically upscale and fine sample an image. This is the most straightforward simulator to view the image if you already have a lens and source chosen.

Example usage:

import matplotlib.pyplot as plt
import caustics

cosmo = caustics.FlatLambdaCDM()
lens = caustics.lenses.SIS(cosmology=cosmo, x0=0.0, y0=0.0, th_ein=1.0)
source = caustics.sources.Sersic(x0=0.0, y0=0.0, q=0.5, phi=0.4, n=2.0, Re=1.0, Ie=1.0)
sim = caustics.sims.LensSource(
    lens, source, pixelscale=0.05, pixels_x=100, upsample_factor=2, z_s=1.0
)

img = sim()
plt.imshow(img, origin="lower")
plt.show()
lens: Lens

caustics lens mass model object

source: Source

caustics light object which defines the background source

pixelscale: float

pixelscale of the sampling grid.

pixels_x: int

number of pixels on the x-axis for the sampling grid

lens_light: Source, optional

caustics light object which defines the lensing object’s light

psf: ArrayLike, optional

An image to convolve with the scene. Note that if upsample_factor > 1 the psf must also be at the higher resolution.

pixels_y: Optional[int]

number of pixels on the y-axis for the sampling grid. If left as None then this will simply be equal to gridx

upsample_factor (default 1)

Amount of upsampling to model the image. For example upsample_factor = 2 indicates that the image will be sampled at double the resolution then summed back to the original resolution (given by pixelscale and gridx/y).

quad_level: int (default None)

sub pixel integration resolution. This will use Gaussian quadrature to sample the image at a higher resolution, then integrate the image back to the original resolution. This is useful for high accuracy integration of the image, but may increase memory usage and runtime.

e
name: string (default “sim”)

a name for this simulator in the parameter DAG.

  • The simulator will automatically pad the image to half the PSF size to ensure valid convolution. This is done by default, but can be turned off by setting psf_pad = False. This is only relevant if you are using a PSF.

  • The upsample factor will increase the resolution of the image by the given factor. For example, upsample_factor = 2 will sample the image at double the resolution, then sum back to the original resolution. This is used when a PSF is provided at high resolution than the original image. Not that the when a PSF is used, the upsample_factor must equal the PSF upsampling level.

  • For arbitrary pixel integration accuracy using the quad_level parameter. This will use Gaussian quadrature to sample the image at a higher resolution, then integrate the image back to the original resolution. This is useful for high accuracy integration of the image, but is not recommended for large images as it will be slow. The quad_level and upsample_factor can be used together to achieve high accuracy integration of the image convolved with a PSF.

  • A Pixelated light source is defined by bilinear interpolation of the provided image. This means that sub-pixel integration is not required for accurate integration of the pixels. However, if you are using a PSF then you should still use upsample_factor (if your PSF is supersampled) to ensure that everything is sampled at the PSF resolution.

property pixels_x#
property pixels_y#
property pixelscale#
property psf_mode#
property psf_shape#
property quad_level#
to(device=None, dtype=None)[source]#

Moves and/or casts the values of the Node to a particular device and/or dtype.

Parameters:
  • device ((optional)) – The device to move the values to. Defaults to None.

  • dtype ((optional)) – The desired data type. Defaults to None.

property upsample_factor#

caustics.sims.microlens module#

class caustics.sims.microlens.Microlens(lens: Annotated[Lens, 'caustics lens mass model object'], source: Annotated[Source, 'caustics light object which defines the background source'], name: Annotated[str | None, 'Name of the simulator'] = 'sim')[source]#

Bases: Module

Computes the total flux from a microlens system within an fov.

Straightforward simulator to compute the total flux a lensed image of a source object within a given field of view. Constructs a sampling points internally based on the user settings.

Example usage:: python

import matplotlib.pyplot as plt import torch import caustics

cosmo = caustics.FlatLambdaCDM() lens = caustics.lenses.SIS(cosmology = cosmo, x0 = 0., y0 = 0., th_ein = 1.) source = caustics.sources.Sersic(x0 = 0., y0 = 0., q = 0.5, phi = 0.4, n = 2., Re = 1., Ie = 1.) sim = caustics.sims.Microlens(lens, source, z_s = 1.)

fov = torch.tensor([-1., 1., -1., 1.]) print(“Flux and uncertainty: “, sim(fov=fov))

lens#

caustics lens mass model object

Type:

Lens

source#

caustics light object which defines the background source

Type:

Source

name#

a name for this simulator in the parameter DAG.

Type:

string (default “sim”)

caustics.sims.simulator module#

caustics.sims.simulator.build_simulator(config: str | TextIO) Module[source]#

Module contents#

class caustics.sims.LensSource(lens: Annotated[Lens, 'caustics lens mass model object'], source: Annotated[Source, 'caustics light object which defines the background source'], pixelscale: Annotated[float, 'pixelscale of the sampling grid'], pixels_x: Annotated[int, 'number of pixels on the x-axis for the sampling grid'], lens_light: Annotated[Source | None, "caustics light object which defines the lensing object's light"] = None, pixels_y: Annotated[int | None, 'number of pixels on the y-axis for the sampling grid'] = None, upsample_factor: Annotated[int, 'Amount of upsampling to model the image'] = 1, quad_level: Annotated[int | None, 'sub pixel integration resolution'] = None, psf_mode: Annotated[Literal['fft', 'conv2d'], 'Mode for convolving psf'] = 'fft', psf_shape: Annotated[tuple[int, ...] | None, 'The shape of the psf'] = None, psf: Annotated[ArrayLike | list | None, 'An image to convolve with the scene', True] = [[1.0]], x0: Annotated[ArrayLike | float | None, 'center of the fov for the lens source image', True] = 0.0, y0: Annotated[ArrayLike | float | None, 'center of the fov for the lens source image', True] = 0.0, name: Annotated[str | None, 'Name of the simulator'] = 'sim')[source]#

Bases: Module

Lens image of a source.

Straightforward simulator to sample a lensed image of a source object. Constructs a sampling grid internally based on the pixelscale and gridding parameters. It can automatically upscale and fine sample an image. This is the most straightforward simulator to view the image if you already have a lens and source chosen.

Example usage:

import matplotlib.pyplot as plt
import caustics

cosmo = caustics.FlatLambdaCDM()
lens = caustics.lenses.SIS(cosmology=cosmo, x0=0.0, y0=0.0, th_ein=1.0)
source = caustics.sources.Sersic(x0=0.0, y0=0.0, q=0.5, phi=0.4, n=2.0, Re=1.0, Ie=1.0)
sim = caustics.sims.LensSource(
    lens, source, pixelscale=0.05, pixels_x=100, upsample_factor=2, z_s=1.0
)

img = sim()
plt.imshow(img, origin="lower")
plt.show()
lens: Lens

caustics lens mass model object

source: Source

caustics light object which defines the background source

pixelscale: float

pixelscale of the sampling grid.

pixels_x: int

number of pixels on the x-axis for the sampling grid

lens_light: Source, optional

caustics light object which defines the lensing object’s light

psf: ArrayLike, optional

An image to convolve with the scene. Note that if upsample_factor > 1 the psf must also be at the higher resolution.

pixels_y: Optional[int]

number of pixels on the y-axis for the sampling grid. If left as None then this will simply be equal to gridx

upsample_factor (default 1)

Amount of upsampling to model the image. For example upsample_factor = 2 indicates that the image will be sampled at double the resolution then summed back to the original resolution (given by pixelscale and gridx/y).

quad_level: int (default None)

sub pixel integration resolution. This will use Gaussian quadrature to sample the image at a higher resolution, then integrate the image back to the original resolution. This is useful for high accuracy integration of the image, but may increase memory usage and runtime.

e
name: string (default “sim”)

a name for this simulator in the parameter DAG.

  • The simulator will automatically pad the image to half the PSF size to ensure valid convolution. This is done by default, but can be turned off by setting psf_pad = False. This is only relevant if you are using a PSF.

  • The upsample factor will increase the resolution of the image by the given factor. For example, upsample_factor = 2 will sample the image at double the resolution, then sum back to the original resolution. This is used when a PSF is provided at high resolution than the original image. Not that the when a PSF is used, the upsample_factor must equal the PSF upsampling level.

  • For arbitrary pixel integration accuracy using the quad_level parameter. This will use Gaussian quadrature to sample the image at a higher resolution, then integrate the image back to the original resolution. This is useful for high accuracy integration of the image, but is not recommended for large images as it will be slow. The quad_level and upsample_factor can be used together to achieve high accuracy integration of the image convolved with a PSF.

  • A Pixelated light source is defined by bilinear interpolation of the provided image. This means that sub-pixel integration is not required for accurate integration of the pixels. However, if you are using a PSF then you should still use upsample_factor (if your PSF is supersampled) to ensure that everything is sampled at the PSF resolution.

property pixels_x#
property pixels_y#
property pixelscale#
property psf_mode#
property psf_shape#
property quad_level#
to(device=None, dtype=None)[source]#

Moves and/or casts the values of the Node to a particular device and/or dtype.

Parameters:
  • device ((optional)) – The device to move the values to. Defaults to None.

  • dtype ((optional)) – The desired data type. Defaults to None.

property upsample_factor#
class caustics.sims.Microlens(lens: Annotated[Lens, 'caustics lens mass model object'], source: Annotated[Source, 'caustics light object which defines the background source'], name: Annotated[str | None, 'Name of the simulator'] = 'sim')[source]#

Bases: Module

Computes the total flux from a microlens system within an fov.

Straightforward simulator to compute the total flux a lensed image of a source object within a given field of view. Constructs a sampling points internally based on the user settings.

Example usage:: python

import matplotlib.pyplot as plt import torch import caustics

cosmo = caustics.FlatLambdaCDM() lens = caustics.lenses.SIS(cosmology = cosmo, x0 = 0., y0 = 0., th_ein = 1.) source = caustics.sources.Sersic(x0 = 0., y0 = 0., q = 0.5, phi = 0.4, n = 2., Re = 1., Ie = 1.) sim = caustics.sims.Microlens(lens, source, z_s = 1.)

fov = torch.tensor([-1., 1., -1., 1.]) print(“Flux and uncertainty: “, sim(fov=fov))

lens#

caustics lens mass model object

Type:

Lens

source#

caustics light object which defines the background source

Type:

Source

name#

a name for this simulator in the parameter DAG.

Type:

string (default “sim”)

caustics.sims.build_simulator(config: str | TextIO) Module[source]#