---
title: "Measure a correlation function from a DESI data patch"
description: "Run one Python script on 15,699 real DESI galaxies, get the correlation function with jackknife errors, and see why this small patch cannot find the BAO."
canonical_url: "https://sandboxphysics.com/stories/baryon-acoustic-oscillations/measure-a-desi-patch-correlation-function/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/baryon-acoustic-oscillations/measure-a-desi-patch-correlation-function/"
last_modified: "2026-11-14"
---

[Baryon acoustic oscillations](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/)

# Measure a correlation function from a DESI data patch

Sandbox Physics · 2026-11-14

By the end of this guide you will have measured the galaxy correlation function of 15,699 real DESI galaxies, estimated its covariance with a jackknife, tried a BAO fit, and seen four ways the measurement goes wrong. One Python script does it all from saved files in about a minute and a half. The honest result is a non-detection: this patch is far too small to show the BAO bump, and the guide explains why. The galaxies are real DESI Data Release 1 data. The fit template is an offline theory calculation, not data.

Read the [chapter on counting pairs with randoms](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/counting-galaxy-pairs-with-randoms/) first. It derives the estimator and the jackknife used here.

## Get the files

Download these into one empty folder:

- [The measurement script](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/measure_desi_patch_correlation.py) `measure_desi_patch_correlation.py`
- [Its pinned requirements](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/requirements.txt) `requirements.txt`
- [The galaxy catalogue (real DESI DR1 data)](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/desi-dr1-bgs-sgc-patch-galaxies.csv) `desi-dr1-bgs-sgc-patch-galaxies.csv`
- [The random catalogue (DESI DR1 randoms)](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/desi-dr1-bgs-sgc-patch-randoms.csv) `desi-dr1-bgs-sgc-patch-randoms.csv`
- [The BAO template (offline theory calculation)](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/bao-template-desi-fiducial.csv) `bao-template-desi-fiducial.csv`
- [The expected output](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/desi-patch-expected-output.json) `desi-patch-expected-output.json`
- [The provenance record](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/desi-patch-provenance.json) `desi-patch-provenance.json`
- [The README with the data licence and acknowledgment](https://sandboxphysics.com/tutorials/baryon-acoustic-oscillations/README.md) `README.md`

The expected output was made with Python 3.9.6, NumPy 2.0.2 and SciPy 1.13.1. From the folder, run:

```
python3 -m venv bao-env
bao-env/bin/pip install -r requirements.txt
bao-env/bin/python -I measure_desi_patch_correlation.py --output my-result.json
```

The flag -I keeps Python from importing anything from the current folder. Add --skip-failures to run only the main measurement, which takes about 20 seconds.

## What is in the data

The galaxies come from the DESI DR1 large-scale structure catalogue BGS\_BRIGHT-21.5 in the South Galactic Cap: bright galaxies with an absolute magnitude cut, the same sample DESI used for its lowest-redshift BAO measurement. The patch keeps right ascension $-20^\circ$ to $20^\circ$, declination $-10^\circ$ to $10^\circ$ and redshift $0.1 \le z < 0.4$. The randoms come from the first of DESI's random files for the same sample. Inside the patch that file holds 1,043,189 points. The download keeps a random subsample three times the galaxy count, 47,097 points, to stay small.

Each row holds ra\_deg, dec\_deg, z, weight and weight\_fkp. The weight column combines DESI's corrections for completeness and imaging systematics. The FKP column balances the sample against its changing number density. DESI 2024 III says the first is meant for any calculation and the second is included in all two-point measurements, so the script uses their product.

The provenance file records the SHA-256 hashes of both DESI input files and both outputs, and every change made: columns dropped, rows cut to the patch, randoms subsampled with a fixed seed, values rounded. The data are released under CC BY 4.0. If you reuse them, cite the DESI DR1 paper and keep the acknowledgment in the README.

## Step 1: redshifts to distances

The script converts each redshift to a comoving distance in DESI's fiducial flat cosmology, $\Omega_m = 0.31519$, using

$$
D_C(z) = \frac{c}{100\,\mathrm{km\,s^{-1}\,Mpc^{-1}}}\int_0^z \frac{dz'}{\sqrt{\Omega_m(1+z')^3 + 1 - \Omega_m}} .
$$

The prefactor makes distances come out in $h^{-1}\,\mathrm{Mpc}$, the unit DESI uses for separations. Radiation is left out, which changes distances below $z = 0.4$ by less than 0.01 percent. Right ascension, declination and distance then give Cartesian positions.

## Step 2: weighted pair counts

The script builds k-d trees with SciPy and counts weighted pairs in twenty bins of $10\,h^{-1}\,\mathrm{Mpc}$ out to $200\,h^{-1}\,\mathrm{Mpc}$. It counts data with data, data with randoms and randoms with randoms, normalises each by its total weight of pairs, and forms the Landy-Szalay estimate.

For the jackknife it divides the patch into an 8 by 4 grid on the sky. Two of the 32 cells contain no randoms, because they fall outside the DESI footprint, so 30 regions are used. Leaving out an empty region would just repeat the full sample and shrink the error bars.

## Step 3: read the correlation function

Open my-result.json at correlation. Each row gives $s$, $\xi$, its jackknife error, and the same in $s^2\xi$.

**Table 5.1** The measured correlation function near the BAO scale, from the expected output. Units of $s$ are $h^{-1}\,\mathrm{Mpc}$.

| $s$ | $\xi$ | $s^2\xi$ | Error in $s^2\xi$ |
| --- | --- | --- | --- |
| $5$ | $1.868$ | $46.7$ | $1.6$ |
| $45$ | $0.0446$ | $90.3$ | $25.3$ |
| $85$ | $0.0089$ | $64.0$ | $45.4$ |
| $105$ | $0.0052$ | $56.9$ | $74.6$ |
| $125$ | $0.0017$ | $26.5$ | $102.4$ |
| $145$ | $-0.0002$ | $-4.4$ | $126.6$ |

At small separations the signal is strong and the errors are tiny. Near $100\,h^{-1}\,\mathrm{Mpc}$ the error in $s^2\xi$ is larger than the value itself. Any bump there is hidden.

## Step 4: the BAO fit

The fit uses the CLASS template computed for DESI's fiducial cosmology at $z = 0.295$, with the linear power spectrum multiplied by $\exp(-k^2\Sigma^2/2)$. Here $\Sigma = 7.84\,h^{-1}\,\mathrm{Mpc}$ is the root mean square of DESI's pre-reconstruction BGS damping scales, $6.5$, $6.5$ and $10.0\,h^{-1}\,\mathrm{Mpc}$. DESI's own model damps only the oscillating part of the spectrum; this simpler template damps all of it. In $s^2\xi$ its bump peaks at $102\,h^{-1}\,\mathrm{Mpc}$. The model is

$$
\xi_{\mathrm{model}}(s) = B\,\xi_{\mathrm{t}}(\alpha s) + a_0 + a_1\frac{100}{s} + a_2\left(\frac{100}{s}\right)^2 ,
$$

fitted over $50$ to $150\,h^{-1}\,\mathrm{Mpc}$, ten bins, with the jackknife covariance and the Hartlap factor $0.621$. For each $\alpha$ from $0.80$ to $1.20$ the script solves for $B \ge 0$ and the broadband terms.

The block fit in the output gives the answer. The best $\alpha$ is $0.80$, at the edge of the grid. The $\Delta\chi^2 = 1$ interval covers the whole grid, so intervalTouchesGridEdge is true. The profile in $\Delta\chi^2$ never rises above $0.15$. Adding the template improves $\chi^2$ from $1.08$ to $0.89$, a naive significance of $0.44$. This patch leaves $\alpha$ free across the whole grid.

## Compare with DESI

DESI 2024 III reports $D_V/r_d = 7.93 \pm 0.15$ at $z_{\mathrm{eff}} = 0.30$ for the full BGS sample. The script converts this with the fiducial cosmology, $D_V^{\mathrm{fid}}/r_d^{\mathrm{fid}} = 8.057$, into $\alpha_{\mathrm{iso}} = 0.984 \pm 0.019$, close to the $0.9829 \pm 0.0185$ that the paper prints in its Table 15. The small difference comes from our use of $z = 0.295$ where Table 18 prints the rounded $0.30$, and from our CLASS value of $r_d^{\mathrm{fid}}$.

DESI's measurement used 300,017 galaxies over the whole DR1 footprint, an effective volume the paper gives as $1.7\,\mathrm{Gpc^3}$, and reconstruction. The patch holds 15,699 galaxies in a geometric volume below $0.1\,h^{-3}\,\mathrm{Gpc^3}$, which is $0.33\,\mathrm{Gpc^3}$. For scale, the 2005 SDSS detection used $0.72\,h^{-3}\,\mathrm{Gpc^3}$ and reached $3.4\sigma$. The patch has too few pairs at $100\,h^{-1}\,\mathrm{Mpc}$, and its own sample variance is large. That is the lesson of this guide: the BAO is a volume-limited measurement.

## Four ways the measurement fails

Each failure case in the output changes one step and repeats the measurement.

**Table 5.2** Change in $s^2\xi$ relative to the correct measurement, from the expected output.

| Case | At $s = 85$ | At $s = 105$ | What went wrong |
| --- | --- | --- | --- |
| no-weights | $+32.9$ | $-8.3$ | completeness and FKP weights dropped |
| one-third-of-the-randoms | $+50.6$ | $+66.3$ | random catalogue cut to the galaxy count |
| unnormalised-pair-counts | $+3132$ | $+4839$ | counts not divided by total pairs |
| distances-in-mpc-not-hinv-mpc | $+97.4$ | $+90.8$ | distances in Mpc against an $h^{-1}\,\mathrm{Mpc}$ template |

Dropping the weights shifts the curve by up to about $33$ inside the fit range, comparable to the errors. In a full survey, where errors are ten times smaller, that bias would dominate. Using too few randoms adds noise from the random catalogue itself. The changes of up to $66$ are within the errors here, and they grow as the random catalogue shrinks.

Forgetting the normalisation adds the constant offset $(m-1)^2/m^2 \approx 0.44$ derived in the pair-counting chapter. Multiplied by $s^2$ it grows into thousands.

Mixing units is the subtlest. With distances in Mpc, every separation is $1/h = 1.48$ times larger, so the bin labelled $100$ holds pairs that are really at $67\,h^{-1}\,\mathrm{Mpc}$, where $\xi$ is higher. Against a template in $h^{-1}\,\mathrm{Mpc}$, a fit would read a dilation near $0.67$ even with perfect data.

None of these fits bound $\alpha$. In a larger sample, the last two would give wrong answers with small error bars.

## What the numbers can support

The measured $\xi(s)$ at separations below about $50\,h^{-1}\,\mathrm{Mpc}$ is a real, well-measured property of these galaxies. The covariance comes from 30 jackknife regions that are not identical in size, so it is itself uncertain at the tens-of-percent level. The fit result is only that the patch cannot bound $\alpha$. The script has no reconstruction, no redshift-space modelling, no systematics weights beyond those in the catalogue, and a monopole-only fit. Those simplifications would matter for a real measurement. They do not change the conclusion here.

Sources: [DESI 2024 III, sections 2 and 4 and tables 15 and 18](https://arxiv.org/abs/2404.03000v1), [DESI DR1 data release paper](https://arxiv.org/abs/2503.14745v2), [DESI DR1 large-scale structure catalogue documentation](https://data.desi.lbl.gov/doc/releases/dr1/vac/lss/), [DESI data licence and acknowledgment](https://data.desi.lbl.gov/doc/acknowledgments/), [Eisenstein et al. 2005, volume and significance of the first detection](https://arxiv.org/abs/astro-ph/0501171v1).

[Export the Lab record and compare its galaxy count and error bars with the DESI patch output.](https://sandboxphysics.com/labs/baryon-acoustic-ruler/)

## Sources

1. [DESI 2024 III, sections 2 and 4 and tables 15 and 18](https://arxiv.org/abs/2404.03000v1)
2. [DESI DR1 data release paper](https://arxiv.org/abs/2503.14745v2)
3. [DESI DR1 large-scale structure catalogue documentation](https://data.desi.lbl.gov/doc/releases/dr1/vac/lss/)
4. [DESI data licence and acknowledgment](https://data.desi.lbl.gov/doc/acknowledgments/)
5. [Eisenstein et al. 2005, volume and significance of the first detection](https://arxiv.org/abs/astro-ph/0501171v1)

## Keep reading

Baryon acoustic oscillations · Reading path

### From a sound wave to galaxy pair counts and DESI distances

1. [Article **How can pairs of galaxies measure the universe?**](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/how-galaxy-pairs-measure-the-universe/)
2. [Article **How far sound travelled before the drag epoch**](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/how-far-sound-travelled-before-the-drag-epoch/)
3. [Article **Counting galaxy pairs against a random catalogue**](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/counting-galaxy-pairs-with-randoms/)
4. [Article **Reading the ruler along and across the line of sight**](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/along-and-across-the-line-of-sight/)
5. [You are here **Measure a correlation function from a DESI data patch**](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/measure-a-desi-patch-correlation-function/)
6. [Article **How to read the DESI BAO results**](https://sandboxphysics.com/stories/baryon-acoustic-oscillations/reading-desi-bao-results/)
