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

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) ↗