All projects

Science, gravitational lensing, simulation

LensLab

  • Point-mass flux error < 10⁻⁶ vs independent quadrature

A thin-lens ray-shooting simulator for point-mass and singular isothermal sphere lenses, tested against analytic image solutions and an independent flux calculation.

Code on GitHub: hyh4867/lenslab ↗

Try it

Critical curve (Einstein radius θE; for SIS it also marks the source-plane cut)Unlensed source (2σ)Analytic point-source imagesRuns LensLab's thin-lens equations in the browser; output checked pixel-by-pixel against a CPU reference. Brightness is display-stretched. Field of view 4″, θE = 1″.
Three panels for an SIS lens with b/θE = 0.95 and θE = 1 arcsec: a Gaussian source next to the point caustic and pseudo-caustic, the critical curve with the analytic plus and minus images, and the rendered lensed brightness showing a bright outer image and a faint inner image.
SIS demo, b/θE = 0.95 · source plane, image plane with analytic point-source images, and the rendered finite source · generated by the project's figure script from the SIS demo run.

The question

How accurately does a simple pixel ray-shooting renderer reproduce lensed images and fluxes, and how would I know?

What I built

I built one lens interface shared by a point-mass and a singular isothermal sphere (SIS) model, with the lens equation, deflection, Jacobian eigenvalues, and magnification.

Analytic point-source image solutions provide reference positions. An elliptical Gaussian source is sampled at pixel centres, conserving surface brightness.

A config-driven CLI produces pixel CSVs, figures, and provenance metadata.

Evaluation

Image positions mapped back through the lens equation reproduce the source position to 12 decimal places. For SIS, the two-image separation equals 2θE to 13 decimal places.

Finite-source fluxes are compared with independent source-plane quadrature that never calls the model's magnification functions.

SIS grid convergence is checked with Richardson extrapolation.

Key findings

Point-mass finite-source fluxes agree with the independent quadrature to better than 10⁻⁶ relative error at the tested offsets β/θE = 0, 0.5, and 1.

The SIS renderer converges at second order (observed order 2 ± 0.2), with < 5×10⁻³ total error at N = 1024.

A simple cut-brightness estimate tracks the measured inner-image error within a factor of two.

My role and the agent workflow

I reviewed the model assumptions and verification strategy, then checked the headline results against analytic solutions and independent numerical calculations.

Claude and Codex assist with bounded research and implementation tasks. I review their output and keep responsibility for which claims make it into the project.

Limits

The simulator covers a single thin lens and circular models only: point mass and SIS. It samples source surface brightness at pixel centres.

It does not model a PSF, noise, time delays, multiple lens planes, or infer mass or distance.

Evidence and reproducibility

The lensing equations follow Narayan & Bartelmann's Lectures on Gravitational Lensing (1996). The code and its 29 tests are public.

Narayan & Bartelmann, Lectures on Gravitational Lensing (1996) ↗

Back to all projects