# AC67 shear correlation and tomography reproduction package

Everything in this folder is synthetic. The lens planes are Gaussian random fields with a
declared power spectrum, not a cosmological N-body run, and no survey catalog is read.

## Run

    python3 -m pip install numpy scipy
    python3 reproduce.py                   # recompute, write outputs/computed-outputs.json, compare (exit 0 on PASS)
    python3 reproduce.py --write-expected  # overwrite expected-outputs.json

Tested with Python 3.9.6, numpy 2.0.2 and scipy 1.13.1. A full run takes under ten seconds.
The comparison uses a relative tolerance of 1e-6 on every number. A different numpy version
may draw different random numbers; the statistics should then stay close but the strict
comparison will fail.

## Files

| File | Role |
| --- | --- |
| simulation-inputs.json | Grid, lens planes, power spectrum, source bins, shape noise, seeds, angular bins and the halo-injection settings. |
| lensing_geometry.py | Flat Lambda-CDM comoving distance by adaptive quadrature and the thin-plane weight (1 + z_l) chi_l (chi_s - chi_l) / chi_s. |
| restricted_shear_simulation.py | Gaussian lens planes, shear from convergence with the Fourier kernel exp(2 i beta), and galaxy catalogs with e = e_s + gamma. |
| shear_two_point_estimator.py | FFT pair-sum estimator of xi_plus and xi_minus on the periodic grid, zero lag excluded. |
| shear_theory_reference.py | Exact expectation on the grid, and the continuous flat-sky Hankel transforms with J0 and J4. |
| isothermal_injection_recovery.py | Singular isothermal sphere: 200 noisy catalogs with the exact reduced-shear transformation and a tangential-shear fit; plus a noise-free Kaiser-Squires E/B test. Does not import the Lab code. |
| reproduce.py | Runs everything, writes outputs/computed-outputs.json and compares with expected-outputs.json. |
| expected-outputs.json | Outputs of the last --write-expected run, with software versions. |
| provenance.json | Sources, conventions and SHA-256 checksums. |

## Units and conventions

- Angles in arcminutes; multipoles ell per radian.
- Comoving distances in units of c/H0, flat universe, matter density 0.3.
- Shear gamma = gamma1 + i gamma2; tangential shear gamma_t = -Re(gamma exp(-2 i phi)),
  cross shear gamma_x = -Im(gamma exp(-2 i phi)) (Kilbinger 2015, arXiv:1411.0115v2, Eq. 31).
- xi_plus = Re <e_a* e_b>, xi_minus = Re <e_a e_b exp(-4 i phi)> (Kilbinger Eqs. 32-33).
- Plane weights are normalised so the largest entry is one; the constant 3/2 Om (H0/c)^2 and the
  shell thickness are absorbed into the plane amplitude.

## What is checked

1. Tomographic weights: near bin 0.319, far bin 2.277, cross 0.606.
2. Measured xi_plus and xi_minus in three bin combinations against the grid expectation.
   Diagonal chi-square over 8 angular bins: xi_plus 6.0, 12.3, 15.6; xi_minus 7.1, 4.1, 4.9
   (near, far, cross). Angular bins are correlated and no covariance is estimated, so these
   values are indicative only.
3. The continuous Hankel xi_plus exceeds the grid expectation at large separations (far bin at
   33 arcmin: 4.51e-5 against 2.10e-5) because the 256-arcmin box has no modes below ell = 84.
   xi_minus agrees to 2 percent there.
4. Isothermal halo, theta_E = 0.5 arcmin, 200 trials: mean fit 0.4997 +- 0.0018, scatter 0.0253,
   median quoted uncertainty 0.0224, pull standard deviation 1.14, cross-shear significance mean
   0.07 and spread 0.99.
5. Noise-free Kaiser-Squires inversion of the same halo: interior offset 0.0225 against a true field
   mean of 0.0220; residual rms after the offset 0.0036 against a signal rms of 0.042; B-mode rms 0.0007.

## Failure cases kept on purpose

- Every far-bin ellipticity rotated by 45 degrees (e -> i e): xi_plus unchanged, xi_minus changes sign.
- 20 percent of far-bin galaxies moved into the near bin: chi-square 469.5 against the nominal
  near-bin prediction, 8.2 against the mixture prediction (weight 0.319 -> 0.453).
- The first version of the halo fit placed each annulus at its arithmetic-mean radius and was
  biased high by 1.2 percent. Because the shear falls as 1/theta, the annulus average matches the
  model at the harmonic-mean radius; the fit now uses that.
- The quoted halo-fit uncertainties are about 12 percent smaller than the scatter of the fits
  (pull standard deviation 1.14). The cause has not been traced.

## Not modelled

Nonlinear structure, correlated planes, source redshift distributions, masks and weights, the
point-spread function, shape-measurement calibration, intrinsic alignments, baryons and the
reduced-shear correction in the correlation simulation (it is kept in the halo injection).
