pysersic.rendering

Attributes

base_profile_types

base_profile_params

Exceptions

RMSWarning

Base class for warning categories.

KernelError

Common base class for all non-exit exceptions.

PSFNormalizationWarning

Base class for warning categories.

MaskWarning

Base class for warning categories.

ShapeMatchError

Common base class for all non-exit exceptions.

Classes

BaseRenderer

PixelRenderer

Render class based on rendering in pixel space and then convolving with the PSF

FourierRenderer

Class to render sources based on rendering them in Fourier space. Sersic profiles are modeled as a series of Gaussian following Shajib (2019) (https://arxiv.org/abs/1906.08263) and the implementation in lenstronomy (https://github.com/lenstronomy/lenstronomy/blob/main/lenstronomy/LensModel/Profiles/gauss_decomposition.py)

HybridRenderer

Class to render sources based on the hybrid rendering scheme introduced in Lang (2020). This avoids some of the artifacts introduced by rendering sources purely in Fourier space. Sersic profiles are modeled as a series of Gaussian following Shajib (2019) (https://arxiv.org/abs/1906.08263) and the implementation in lenstronomy (https://github.com/lenstronomy/lenstronomy/blob/main/lenstronomy/LensModel/Profiles/gauss_decomposition.py).

Functions

sersic1D(→ Union[float, jax.numpy.array])

Evaluate a 1D sersic profile

render_gaussian_fourier(→ jax.numpy.array)

Render Gaussian components in the Fourier domain

render_pointsource_fourier(→ jax.numpy.array)

Render a point source in the Fourier domain

render_gaussian_pixel(→ jax.numpy.array)

Render Gaussian components in pixel space

render_sersic_2d(→ jax.numpy.array)

Evalulate a 2D Sersic distribution at given locations

calculate_etas_betas(→ Tuple[jax.numpy.array, ...)

Calculate the weights and nodes for the Gaussian decomposition described in Shajib (2019) (https://arxiv.org/abs/1906.08263)

sersic_gauss_decomp(→ Tuple[jax.numpy.array, ...)

Calculate a gaussian decomposition of a given sersic profile, following Shajib (2019) (https://arxiv.org/abs/1906.08263)

Module Contents

exception pysersic.rendering.RMSWarning

Bases: Warning

Base class for warning categories.

exception pysersic.rendering.KernelError

Bases: Exception

Common base class for all non-exit exceptions.

exception pysersic.rendering.PSFNormalizationWarning

Bases: Warning

Base class for warning categories.

exception pysersic.rendering.MaskWarning

Bases: Warning

Base class for warning categories.

exception pysersic.rendering.ShapeMatchError

Bases: Exception

Common base class for all non-exit exceptions.

pysersic.rendering.base_profile_types = ['sersic', 'doublesersic', 'sersic_exp', 'sersic_pointsource', 'pointsource', 'exp', 'dev']
pysersic.rendering.base_profile_params
class pysersic.rendering.BaseRenderer(im_shape: Iterable, pixel_PSF: jax.numpy.array)

Bases: equinox.Module

im_shape: tuple
psf_shape: tuple
fft_shape: tuple
profile_func_dict: dict
pixel_PSF: jax.numpy.array
PSF_fft: jax.numpy.array
X: jax.numpy.array
Y: jax.numpy.array
FX: jax.numpy.array
FY: jax.numpy.array
x_mid: float
y_mid: float
fft_zeros: jax.numpy.array
img_zeros: jax.numpy.array
conv_img(image)
conv_fft(F_im)
combine_scene(F_im, int_im, obs_im)
abstract render_sersic(params: dict)
render_doublesersic(params: dict)
render_sersic_exp(params: dict)
render_sersic_pointsource(params: dict)
abstract render_pointsource(params: dict)
render_exp(params: dict) jax.numpy.array

Thin wrapper for an exponential profile based on render_sersic

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

  • r_eff (float) – Effective radius

  • ellip (float) – Ellipticity

  • theta (float) – Position angle in radians

Returns:

Rendered Exponential model

Return type:

jax.numpy.array

render_dev(params: dict) jax.numpy.array

Thin wrapper for a De Vaucouleurs profile based on render_sersic

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

  • r_eff (float) – Effective radius

  • ellip (float) – Ellipticity

  • theta (float) – Position angle in radians

Returns:

Rendered Exponential model

Return type:

jax.numpy.array

render_for_model(param_dict, types, suffix)
render_source(params: dict, profile_type: str, suffix: str | None = '') jax.numpy.array

Render an observed source of a given type and parameters

Parameters:
  • params (jax.numpy.array) – Parameters specifying the source

  • profile_type (str) – Type of profile to use

Returns:

Rendered, observed model

Return type:

jax.numpy.array

class pysersic.rendering.PixelRenderer(im_shape: Iterable, pixel_PSF: jax.numpy.array, os_pixel_size: int | None = 6, num_os: int | None = 12)

Bases: BaseRenderer

Render class based on rendering in pixel space and then convolving with the PSF

os_pixel_size: int
num_os: int
w_os: jax.numpy.array
x_os_lo: int
x_os_hi: int
y_os_lo: int
y_os_hi: int
X_os: jax.numpy.array
Y_os: jax.numpy.array
render_int_sersic(xc, yc, flux, r_eff, n, ellip, theta)
render_sersic(params: dict) jax.numpy.array

Render a sersic profile

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

  • r_eff (float) – Effective radius

  • n (float) – Sersic index

  • ellip (float) – Ellipticity

  • theta (float) – Position angle in radians

Returns:

Rendered Sersic model

Return type:

jax.numpy.array

render_pointsource(params: dict) jax.numpy.array

Render a Point source by interpolating given PSF into image. Currently jax only supports linear intepolation.

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

Returns:

rendered pointsource model

Return type:

jax.numpy.array

class pysersic.rendering.FourierRenderer(im_shape: Iterable, pixel_PSF: jax.numpy.array, frac_start: float | None = 0.01, frac_end: float | None = 15.0, n_sigma: int | None = 15, precision: int | None = 10, use_interp_amps: bool | None = True)

Bases: BaseRenderer

Class to render sources based on rendering them in Fourier space. Sersic profiles are modeled as a series of Gaussian following Shajib (2019) (https://arxiv.org/abs/1906.08263) and the implementation in lenstronomy (https://github.com/lenstronomy/lenstronomy/blob/main/lenstronomy/LensModel/Profiles/gauss_decomposition.py)

frac_start: float
frac_end: float
n_sigma: int
precision: int
use_interp_amps: bool
etas: jax.numpy.array
betas: jax.numpy.array
n_ax: jax.numpy.array
amps_n_ax: jax.numpy.array
get_amps_sigmas(flux, r_eff, n)
render_sersic_mog_fourier(xc, yc, flux, r_eff, n, ellip, theta)
render_sersic(params: dict) jax.numpy.array

Render a Sersic profile

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

  • r_eff (float) – Effective radius

  • n (float) – Sersic index

  • ellip (float) – Ellipticity

  • theta (float) – Position angle in radians

Returns:

Rendered Sersic model

Return type:

jax.numpy.array

render_pointsource(params: dict) jax.numpy.array

Render a Point source

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

Returns:

rendered pointsource model

Return type:

jax.numpy.array

class pysersic.rendering.HybridRenderer(im_shape: Iterable, pixel_PSF: jax.numpy.array, frac_start: float | None = 0.01, frac_end: float | None = 15.0, n_sigma: int | None = 15, num_pixel_render: int | None = 3, precision: int | None = 10, use_interp_amps: bool | None = True)

Bases: FourierRenderer

Class to render sources based on the hybrid rendering scheme introduced in Lang (2020). This avoids some of the artifacts introduced by rendering sources purely in Fourier space. Sersic profiles are modeled as a series of Gaussian following Shajib (2019) (https://arxiv.org/abs/1906.08263) and the implementation in lenstronomy (https://github.com/lenstronomy/lenstronomy/blob/main/lenstronomy/LensModel/Profiles/gauss_decomposition.py).

Our scheme is implemented slightly differently than Lang (2020), specifically in how it chooses which gaussian components to render in Fourier vs. Real space. Lang (2020) employs a cutoff based on distance to the edge of the image. However given some of jax’s limitation with dynamic shapes (see more here -> https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#dynamic-shapes), we have not implemented that specific criterion. Instead we use a simpler version where the user must decide how many components to render in real space, starting from the largest ones. While this is not ideal in all circumstances it still overcomes many of the issues of rendering purely in fourier space discussed in Lang (2020).

num_pixel_render: int
w_real: jax.numpy.array
w_fourier: jax.numpy.array
sig_psf_approx: float
render_sersic_hybrid(xc, yc, flux, r_eff, n, ellip, theta)
render_sersic(params: dict) jax.numpy.array

Render a Sersic profile

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

  • r_eff (float) – Effective radius

  • n (float) – Sersic index

  • ellip (float) – Ellipticity

  • theta (float) – Position angle in radians

Returns:

Rendered Sersic model

Return type:

jax.numpy.array

render_pointsource(params: dict) jax.numpy.array

Render a Point source

Parameters:
  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

Returns:

rendered pointsource model

Return type:

jax.numpy.array

pysersic.rendering.sersic1D(r: float | jax.numpy.array, flux: float, re: float, n: float) float | jax.numpy.array

Evaluate a 1D sersic profile

Parameters:
  • r (float) – radii to evaluate profile at

  • flux (float) – Total flux

  • re (float) – Effective radius

  • n (float) – Sersic index

Returns:

Sersic profile evaluated at r

Return type:

jax.numpy.array

pysersic.rendering.render_gaussian_fourier(FX: jax.numpy.array, FY: jax.numpy.array, amps: jax.numpy.array, sigmas: jax.numpy.array, xc: float, yc: float, theta: float, q: float) jax.numpy.array

Render Gaussian components in the Fourier domain

Parameters:
  • FX (jax.numpy.array) – X frequency positions to evaluate

  • FY (jax.numpy.array) – Y frequency positions to evaluate

  • amps (jax.numpy.array) – Amplitudes of each component

  • sigmas (jax.numpy.array) – widths of each component

  • xc (float) – Central x position

  • yc (float) – Central y position

  • theta (float) – position angle

  • q (float) – Axis ratio

Returns:

Sum of components evaluated at FX and FY

Return type:

jax.numpy.array

pysersic.rendering.render_pointsource_fourier(FX: jax.numpy.array, FY: jax.numpy.array, xc: float, yc: float, flux: float) jax.numpy.array

Render a point source in the Fourier domain

Parameters:
  • FX (jax.numpy.array) – X frequency positions to evaluate

  • FY (jax.numpy.array) – Y frequency positions to evaluate

  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux of source

Returns:

Point source evaluated at FX FY

Return type:

jax.numpy.array

pysersic.rendering.render_gaussian_pixel(X: jax.numpy.array, Y: jax.numpy.array, amps: jax.numpy.array, sigmas: jax.numpy.array, xc: float, yc: float, theta: float, q: float | jax.numpy.array) jax.numpy.array

Render Gaussian components in pixel space

Parameters:
  • FX (jax.numpy.array) – X positions to evaluate

  • FY (jax.numpy.array) – Y positions to evaluate

  • amps (jax.numpy.array) – Amplitudes of each component

  • sigmas (jax.numpy.array) – widths of each component

  • xc (float) – Central x position

  • yc (float) – Central y position

  • theta (float) – position angle

  • q (Union[float,jax.numpy.array]) – Axis ratio

Returns:

Sum of components evaluated at X and Y

Return type:

jax.numpy.array

pysersic.rendering.render_sersic_2d(X: jax.numpy.array, Y: jax.numpy.array, xc: float, yc: float, flux: float, r_eff: float, n: float, ellip: float, theta: float) jax.numpy.array

Evalulate a 2D Sersic distribution at given locations

Parameters:
  • X (jax.numpy.array) – x locations to evaluate at

  • Y (jax.numpy.array) – y locations to evaluate at

  • xc (float) – Central x position

  • yc (float) – Central y position

  • flux (float) – Total flux

  • r_eff (float) – Effective radius

  • n (float) – Sersic index

  • ellip (float) – Ellipticity

  • theta (float) – Position angle in radians [now measured from north]

Returns:

Sersic model evaluated at given locations

Return type:

jax.numpy.array

pysersic.rendering.calculate_etas_betas(precision: int) Tuple[jax.numpy.array, jax.numpy.array]

Calculate the weights and nodes for the Gaussian decomposition described in Shajib (2019) (https://arxiv.org/abs/1906.08263)

Parameters:

precision (int) – Precision, higher number implies more precise decomposition but more nodes. Effective upper limit is 12 for 32 bit numbers, 27 for 64 bit numbers.

Returns:

etas and betas array to be use in gaussian decomposition

Return type:

Tuple[jax.numpy.array, jax.numpy.array]

pysersic.rendering.sersic_gauss_decomp(flux: float, re: float, n: float, etas: jax.numpy.array, betas: jax.numpy.array, sigma_start: float, sigma_end: float, n_comp: int) Tuple[jax.numpy.array, jax.numpy.array]

Calculate a gaussian decomposition of a given sersic profile, following Shajib (2019) (https://arxiv.org/abs/1906.08263)

Parameters:
  • flux (float) – Total flux

  • re (float) – half light radius

  • n (float) – Sersic index

  • etas (jax.numpy.array) – Weights for decomposition, can be calcualted using pysersic.rendering_utils.calculate_etas_betas

  • betas (jax.numpy.array) – Nodes for decomposition, can be calcualted using pysersic.rendering_utils.calculate_etas_betas

  • sigma_start (float) – width for the smallest Gaussian component

  • sigma_end (float) – width for the largest Gaussian component

  • n_comp (int) – Number of Gaussian components

Returns:

Amplitudes and sigmas of Gaussian decomposition

Return type:

Tuple[jax.numpy.array, jax.numpy.array]