---
title: "Recompute shear correlations and tomography from a simulation"
description: "Measure shear correlations in a restricted simulation, compare them with two predictions, and break the analysis on purpose with rotated shapes and outliers."
canonical_url: "https://sandboxphysics.com/stories/weak-lensing/recompute-shear-correlations/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/weak-lensing/recompute-shear-correlations/"
last_modified: "2026-11-14"
---

[Weak gravitational lensing and mass maps](https://sandboxphysics.com/stories/weak-lensing/)

# Recompute shear correlations and tomography from a simulation

Sandbox Physics · 2026-11-14

This guide measures the shear correlation functions $\xi_\pm$ in two redshift bins from 24 restricted simulations and compares them with two predictions. It recovers the Einstein radius of an isothermal halo from 200 noisy catalogs without measurable bias, then breaks the analysis on purpose: shapes rotated by $45^\circ$ flip the sign of $\xi_-$, and moving 20 percent of far galaxies into the near bin raises the near-bin signal by 42 percent. Every number comes from one script that runs in under ten seconds. Nothing here is survey data.

Read [shear correlation functions and redshift tomography](https://sandboxphysics.com/stories/weak-lensing/shear-correlations-and-tomography/) and [turning a shear field into a mass map](https://sandboxphysics.com/stories/weak-lensing/from-shear-to-a-mass-map/) first.

## Get the files

Put these ten files in one empty folder:

- [README.md](https://sandboxphysics.com/stories/weak-lensing/materials/README.md), run instructions and failure cases
- [simulation-inputs.json](https://sandboxphysics.com/stories/weak-lensing/materials/simulation-inputs.json), every setting, unit and seed
- [lensing\_geometry.py](https://sandboxphysics.com/stories/weak-lensing/materials/lensing_geometry.py), distances and plane weights
- [restricted\_shear\_simulation.py](https://sandboxphysics.com/stories/weak-lensing/materials/restricted_shear_simulation.py), lens planes, shear and galaxy catalogs
- [shear\_two\_point\_estimator.py](https://sandboxphysics.com/stories/weak-lensing/materials/shear_two_point_estimator.py), the pair-sum estimator
- [shear\_theory\_reference.py](https://sandboxphysics.com/stories/weak-lensing/materials/shear_theory_reference.py), the two predictions
- [isothermal\_injection\_recovery.py](https://sandboxphysics.com/stories/weak-lensing/materials/isothermal_injection_recovery.py), the halo recovery and map test
- [reproduce.py](https://sandboxphysics.com/stories/weak-lensing/materials/reproduce.py), runs everything and compares
- [expected-outputs.json](https://sandboxphysics.com/stories/weak-lensing/materials/expected-outputs.json), the numbers quoted on this page
- [provenance.json](https://sandboxphysics.com/stories/weak-lensing/materials/provenance.json), sources, conventions and SHA-256 checksums

Then run:

```
python3 -m pip install numpy scipy
python3 reproduce.py
```

The script writes outputs/computed-outputs.json, compares every number with expected-outputs.json at a relative tolerance of $10^{-6}$ and prints PASS or the mismatches. We ran it with Python 3.9.6, numpy 2.0.2 and scipy 1.13.1. Another numpy version may draw different random numbers; then python3 reproduce.py --write-expected saves your own outputs, and the statistics below should stay close.

## What the simulation contains

**Table 5.1** Units and settings shared by every script.

| Quantity | Setting |
| --- | --- |
| Angles | arcminutes; multipoles $\ell$ per radian |
| Distances | comoving, in units of $c/H_0$, flat universe with $\Omega_{\rm m}=0.3$ |
| Grid | $512\times512$ pixels of $0.5'$, periodic, so a $256'$ square |
| Lens planes | $z=0.25$, $0.5$, $0.8$, independent Gaussian fields |
| Plane spectrum | $P(\ell)=6\times10^{-10}\,(\ell/1000)^{-1.2}\,e^{-(\ell/6000)^2}$ |
| Shear | $\hat\gamma=e^{2i\beta}\hat\kappa$ on the grid, mean set to zero |
| Shapes | $\epsilon=\epsilon^{\rm s}+\gamma$, with $\sigma_\epsilon=0.26$ per component |
| Source bins | $z_{\rm s}=0.6$ and $1.2$, 10 galaxies per square arcminute each |
| Realizations | 24, seeds 6701 to 6724 |

Each bin's convergence is the weighted sum of the three planes, with weight $(1+z_{\rm l})\chi_{\rm l}(\chi_{\rm s}-\chi_{\rm l})/\chi_{\rm s}$ from the lensing kernel. [Cosmology with cosmic shear observations: a review, Eqs. 21-24](https://arxiv.org/abs/1411.0115v2) The overall constant is absorbed into the plane amplitude.

This is a restricted simulation. It has no N-body structure, no nonlinear clustering, no correlation between planes, no masks, no point-spread function, no intrinsic alignments and a single redshift per bin. The shapes use the weak-shear limit, which drops terms of order $\kappa\gamma$.

## The estimator

Each galaxy is assigned to a pixel. Summing ellipticities per pixel and correlating the sums with fast Fourier transforms gives, for every lag $\boldsymbol\Delta$ on the periodic grid,

$$
\xi_+(\theta)=\frac{\mathrm{Re}\sum\epsilon_a^*\,\epsilon_b}{N_{\rm pairs}},\qquad \xi_-(\theta)=\frac{\mathrm{Re}\sum\epsilon_a\,\epsilon_b\,e^{-4i\phi_\Delta}}{N_{\rm pairs}},
$$

summed over lags in each angular bin from $1'$ to $40'$. Zero lag, which holds every galaxy paired with itself and therefore the shape noise, is excluded. This is the pair estimator of the review with unit weights. [Cosmology with cosmic shear observations: a review, Eq. 33](https://arxiv.org/abs/1411.0115v2)

## Two predictions

The grid expectation is the exact mean the estimator must return on this periodic grid. It sums the input power spectrum over the grid's own wave vectors, with the same pair weights per lag. The continuous prediction is the flat-sky Hankel transform $\xi_\pm=(2\pi)^{-1}\int\mathrm d\ell\,\ell\,J_{0,4}(\ell\theta)P(\ell)$, computed with adaptive quadrature. [Cosmology with cosmic shear observations: a review, Eq. 35](https://arxiv.org/abs/1411.0115v2) Both are multiplied by the tomographic weight of each bin pair.

**Table 5.2** Tomographic weights from the plane weights $W_{ip}$.

| Correlation | $\sum_pW_{ip}W_{jp}$ |
| --- | --- |
| Near bin, $z_{\rm s}=0.6$ | 0.319 |
| Far bin, $z_{\rm s}=1.2$ | 2.277 |
| Near with far | 0.606 |

**Table 5.3** Measured against the grid expectation: diagonal $\chi^2$ over 8 angular bins, using the standard error of the 24-field mean.

| Correlation | $\chi^2$ for $\xi_+$ | $\chi^2$ for $\xi_-$ |
| --- | --- | --- |
| Near bin | 6.0 | 7.1 |
| Far bin | 12.3 | 4.1 |
| Near with far | 15.6 | 4.9 |

Neighbouring angular bins share structures, so the eight terms are correlated. These $\chi^2$ values ignore that and are a guide, not a goodness-of-fit test. $15.6$ for 8 independent bins would have $p\approx0.05$; we did not estimate the covariance needed to decide whether the cross-correlation $\xi_+$ is in mild tension or simply correlated.

The two predictions disagree at large separations for $\xi_+$, and they should. At $33'$ the far-bin grid expectation is $2.10\times10^{-5}$ and the Hankel value is $4.51\times10^{-5}$; the measurement is $(2.74\pm0.50)\times10^{-5}$. The $256'$ box contains no wave vector below $\ell=2\pi/256'\approx84$, and $J_0$ gives those long waves a large weight at large $\theta$. $J_4$ suppresses them, so for $\xi_-$ the predictions agree to 2 percent at $33'$. A finite field measures the finite-field expectation.

## Failure cases kept on purpose

**Shapes rotated by 45 degrees.** Replacing every far-bin ellipticity by $i\epsilon$ leaves $\xi_+$ identical to the last digit and flips the sign of $\xi_-$: at $5.2'$ it goes from $+9.77\times10^{-5}$ to $-9.77\times10^{-5}$. A sign or angle error in a shape catalog shows up as a negative $\xi_-$ and, in a map, as mass in the B mode.

**Redshift outliers.** Moving a random 20 percent of far-bin galaxies into the near bin raises the near-bin weight from $0.319$ to $0.453$. The contaminated $\xi_+$ gives $\chi^2=469.5$ against the nominal prediction and $8.2$ against the mixture prediction, both over 8 bins. A wrong redshift distribution does not add noise. It moves the signal.

## Recovering an isothermal halo

The second test is independent of the Lab code. A singular isothermal sphere with $\theta_{\rm E}=0.5'$ sits at the centre of a $40'$ field. Each of 200 trials draws 20 galaxies per square arcminute at random positions and Gaussian intrinsic shapes with $\sigma_\epsilon=0.26$. It applies the exact transformation $\epsilon=(\epsilon^{\rm s}+g)/(1+g^*\epsilon^{\rm s})$ with $g=\gamma/(1-\kappa)$, drops galaxies inside $\theta_{\rm E}$ so that $|g|<1$, bins the tangential ellipticity in annuli from $1'$ to $16'$ and fits $\theta_{\rm E}$ by least squares. [Weak Gravitational Lensing, Eqs. 3.17-3.18](https://arxiv.org/abs/astro-ph/9912508v1)

**Table 5.4** Halo recovery over 200 trials.

| Quantity | Value |
| --- | --- |
| True $\theta_{\rm E}$ | $0.5'$ |
| Mean fitted $\theta_{\rm E}$ | $0.4997'\pm0.0018'$ |
| Scatter of the fits | $0.0253'$ |
| Median quoted uncertainty | $0.0224'$ |
| Standard deviation of the pulls | 1.14 |
| Cross-shear significance, mean and spread | 0.07 and 0.99 |

The fit is unbiased. The quoted uncertainties are about 12 percent too small; we have not traced why. The cross shear behaves like pure noise, as it should for a lens.

The first version of the fit placed each annulus at its arithmetic-mean radius and came out 1.2 percent high. The shear falls as $1/\theta$, so the average shear in an annulus matches the model at the harmonic-mean radius. Switching to that radius removed the bias.

## Testing the map inversion

A noise-free isothermal halo on a $256\times256$ grid, inverted with Kaiser-Squires, checks what the map can recover. In the inner half of the field, excluding the centre, the true convergence has an rms of $0.042$. The reconstruction differs from it by a nearly constant offset of $0.0225$; the true mean convergence of the field is $0.0220$. After removing the offset the residual rms is $0.0036$, and the B mode has an rms of $0.0007$. The lost mode is the field mean, as the mass-sheet argument predicts.

## What this does not show

Nothing here reproduces a survey measurement. The simulation tests the estimator, the tomographic bookkeeping and two failure modes on Gaussian fields with known answers. Real cosmic shear needs nonlinear structure, realistic redshift distributions, masks, weights and calibration of the shape measurement. The [guide to the DES Year 3 analysis](https://sandboxphysics.com/stories/weak-lensing/reading-des-y3-lensing-and-clustering/) shows how one survey handles them.

## Try it in the Lab

[Weak-lensing mass map](https://sandboxphysics.com/labs/weak-lensing-mass-map/): Set the shape scatter to 0.26 and the galaxy density to 10, as in the tutorial, and judge the map noise.

## Sources

1. [Cosmology with cosmic shear observations: a review, Eqs. 21-24](https://arxiv.org/abs/1411.0115v2)
2. [Weak Gravitational Lensing, Eqs. 3.17-3.18](https://arxiv.org/abs/astro-ph/9912508v1)

## Keep reading

Weak gravitational lensing and mass maps · Reading path

### From galaxy shapes to a map of mass

1. [Article **How can galaxies that are barely stretched map dark matter?**](https://sandboxphysics.com/stories/weak-lensing/galaxy-shapes-weigh-dark-matter/)
2. [Article **Convergence, shear and what a galaxy shape measures**](https://sandboxphysics.com/stories/weak-lensing/convergence-shear-and-galaxy-shapes/)
3. [Article **Turning a shear field into a mass map**](https://sandboxphysics.com/stories/weak-lensing/from-shear-to-a-mass-map/)
4. [Article **Shear correlation functions and redshift tomography**](https://sandboxphysics.com/stories/weak-lensing/shear-correlations-and-tomography/)
5. [You are here **Recompute shear correlations and tomography from a simulation**](https://sandboxphysics.com/stories/weak-lensing/recompute-shear-correlations/)
6. [Article **How to read the DES Year 3 lensing and clustering analysis**](https://sandboxphysics.com/stories/weak-lensing/reading-des-y3-lensing-and-clustering/)
