---
title: "Recompute an E/B split and a two-frequency dust cleaning"
description: "Run one standard-library Python script on saved CAMB spectra, check that pure E gives no B, clean dust with a 353 GHz map, and read five failure cases."
canonical_url: "https://sandboxphysics.com/stories/cmb-b-modes/recompute-an-e-b-split-and-dust-cleaning/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/cmb-b-modes/recompute-an-e-b-split-and-dust-cleaning/"
last_modified: "2026-11-14"
---

[CMB B-modes, dust and delensing](https://sandboxphysics.com/stories/cmb-b-modes/)

# Recompute an E/B split and a two-frequency dust cleaning

Sandbox Physics · 2026-11-14

By the end of this guide you will have run one Python script that splits synthetic polarization maps into $E$ and $B$, recovers a hidden tensor-to-scalar ratio, shows three ways $E$ leaks into $B$, and removes dust from a $150\ \mathrm{GHz}$ map with a $353\ \mathrm{GHz}$ map. Everything runs from three saved files with the Python standard library, in about a second. The maps are Gaussian random fields drawn from model spectra. None of them is a BICEP/Keck, Planck or SPT map, and nothing here is a reanalysis of published data.

The formulas come from the chapters on [splitting a map into E and B](https://sandboxphysics.com/stories/cmb-b-modes/splitting-a-polarization-map-into-e-and-b/) and on [dust and lensing](https://sandboxphysics.com/stories/cmb-b-modes/how-dust-and-lensing-add-b-modes/). Read those first if a step below is unclear.

## Get the three files

Download the [script](https://sandboxphysics.com/stories/cmb-b-modes/materials/recompute_e_b_and_dust_bands.py), the [saved inputs](https://sandboxphysics.com/stories/cmb-b-modes/materials/tutorial-inputs.json) and the [expected output](https://sandboxphysics.com/stories/cmb-b-modes/materials/tutorial-expected-output.json) into one empty folder. The script imports only cmath, json, math, random and sys, and it carries its own fast Fourier transform. The expected output was produced with Python 3.9.6 and reproduced with Python 3.14.3. The two runs agree in every number except values below $10^{-30}$, which are rounding noise, and the recorded version string.

From that folder, run:

```
python3 -I recompute_e_b_and_dust_bands.py tutorial-inputs.json my-output.json
```

The flag -I keeps Python from loading modules from the current folder or your environment. Running without the two file names stops with an IndexError. A run takes about one second on a laptop.

## Read the inputs and their units

The patch is a $64\times64$ grid, $16^\circ$ on a side, so a pixel is $15$ arcminutes and the smallest non-zero multipole is $22.5$. Band powers are averaged in seven bands with edges $30, 60, 100, 150, 220, 320, 450, 640$. Waves above $\ell = 640$ and the unpaired lines at the grid's highest frequency are dropped.

The block spectra holds a frozen subset of CAMB spectra at 32 multipoles: lensed scalar $EE$, lensed scalar $BB$, and tensor $BB$ for $r = 1$. The generator block records CAMB 1.6.0 and the cosmology, the Planck 2018 values from table 2 of the parameters paper, with $H_0 = 67.36$, $\tau = 0.0544$ and $n_s = 0.9649$. Tensors use $n_t = 0$ at a pivot of $0.05\ \mathrm{Mpc}^{-1}$, the convention BK18 uses. The script interpolates between nodes in log-log.

The dust block holds $A_d = 4.4\ \mu\mathrm{K}^2$ at $353\ \mathrm{GHz}$ and $\ell = 80$ from BK18, $T_d = 19.6\ \mathrm{K}$ and $\beta_d = 1.53$ from Planck, and a band-power slope of $-0.54$, which is Planck's $C_\ell \propto \ell^{-2.54}$. Dust $EE$ is twice dust $BB$, as BK18 assumes.

Units follow the units block: spectra in $\mu\mathrm{K}^2$ of microwave-background temperature, band powers $D_\ell$ in $\mu\mathrm{K}^2$, angles in degrees, frequencies in GHz, noise in $\mu\mathrm{K}$-arcmin in each of $Q$ and $U$. Each run sets its own random seed, so the eight runs do not depend on each other.

Every band row in the output has measured, expected and sigma. The sigma is the scatter expected from the number of waves in the band, $\sqrt{2/N_b}$ times the expected value.

## Step 1: a sky with only E gives no B

Open my-output.json at runs, then pure-e-injection. The script draws $E$ waves, sets $B = 0$, builds $Q$ and $U$ maps with the inverse rotation, and splits them again. BBOverEE is between $10^{-31}$ and $4\times10^{-31}$ in every band. That is floating-point rounding, and it is the check that the two rotations in the script match.

If you change the script and this ratio becomes large, the forward and inverse rotations disagree, for example by a sign. Every later step would then be wrong.

## Step 2: recover a hidden r

The run tensor-and-lensing draws $B$ from lensing plus tensors with $r = 0.03$. Its $B$ band powers scatter around the model with $\chi^2 = 7.06$ over seven bands. The script then subtracts the expected lensing in the first four bands, $30 \le \ell < 220$, and fits the remainder with the tensor shape, weighting each band by $1/\sigma^2$. The block tensorRatioEstimate gives $r = 0.0290 \pm 0.0097$, with input $0.03$.

The uncertainty is about a third of the signal on this small patch, even with no noise and no dust. Lensing B is drawn here as a Gaussian field with the CAMB spectrum, which ignores its real non-Gaussian structure.

## Step 3: rotate the instrument by two degrees

The run angle-miscalibration rotates every rod of the pure-$E$ sky by $2^\circ$ before the split. BBOverEE is $0.0049$ in every band, and the output stores the prediction predictedBBOverEE $= \tan^2 4^\circ = 0.00489$. The rotation moves $\sin^2 4^\circ$ of the power into $B$ and leaves $\cos^2 4^\circ$ in $E$, so their ratio is the tangent squared.

## Step 4: use the wrong angle factor

The run wrong-angle-factor splits the same maps with $\varphi_\ell$ in place of $2\varphi_\ell$. $E$ falls to about half of its model value, for example $0.266$ instead of $0.487\ \mu\mathrm{K}^2$ in the band $60 \le \ell < 100$, and $B/E$ lies between $0.86$ and $1.16$. Half of the $E$ power has moved into $B$. Seeing $B$ comparable to $E$ in a sky expected to be $E$-dominated is the sign of this mistake.

## Step 5: cut the sky with a mask

The run hard-and-tapered-mask multiplies the pure-$E$ maps by a centred square that covers 47 percent of the patch, first with hard edges and then with edges tapered by a cosine over $12$ percent of the patch width. Band powers are divided by the mean square of the mask, the sky fraction in the output.

**Table 5.1** $B/E$ from a sky with no $B$, after masking, as saved in the expected output.

| Band | Hard edge | Tapered edge |
| --- | --- | --- |
| $30$ to $60$ | $0.37$ | $0.51$ |
| $60$ to $100$ | $0.32$ | $0.29$ |
| $100$ to $150$ | $0.10$ | $0.13$ |
| $150$ to $220$ | $0.14$ | $0.058$ |
| $220$ to $320$ | $0.057$ | $0.029$ |
| $320$ to $450$ | $0.024$ | $0.0096$ |
| $450$ to $640$ | $0.024$ | $0.006$ |

Tapering helps above $\ell \approx 150$ and does nothing for the largest scales, where the window is about the size of the waves. On this patch, simple masking leaks far more than the lensing $B$ level of about $0.004$ of $E$. BK18 handles this with a matrix purification step; the script stops at showing the problem.

## Step 6: clean dust with a 353 GHz map

The run dust-two-frequencies builds maps at $150\ \mathrm{GHz}$ with noise $2.8\ \mu\mathrm{K}$-arcmin and at $353\ \mathrm{GHz}$ with noise $20\ \mu\mathrm{K}$-arcmin. Both contain the same microwave background with $r = 0.03$ and the same dust pattern scaled by the frequency law.

The output reports dustPowerFactorTo353 of $0.00228$ at $150\ \mathrm{GHz}$, and cleaningCoefficient $a = 0.0477$, its square root. Under combinations, the $150\ \mathrm{GHz}$ map alone gives $r = 0.274 \pm 0.011$: dust looks like nine times the true signal. The combination with weights $1.050$ and $-0.0501$, which is $(m_{150} - a\,m_{353})/(1 - a)$, gives $r = 0.0335 \pm 0.0118$. Its noise rises from $2.8$ to $3.11\ \mu\mathrm{K}$-arcmin, and its dustResidualBB is at most $3\times10^{-33}\ \mu\mathrm{K}^2$, which is zero up to rounding.

## Step 7: two ways the cleaning fails

The run dust-wrong-index builds the same maps, but the cleaning assumes $\beta_d = 1.63$. Its coefficient becomes $0.0438$ instead of $0.0477$. The residual dust is $8.1\times10^{-5}\ \mu\mathrm{K}^2$ in the lowest band and $r$ rises to $0.0361$.

The run dust-decorrelated keeps the right index, but the $150\ \mathrm{GHz}$ dust pattern is correlated with the $353\ \mathrm{GHz}$ one by only $\rho_d = 0.95$. The residual dust is $4.3\times10^{-4}$ to $1.3\times10^{-3}\ \mu\mathrm{K}^2$ in the first four bands, and $r$ rises to $0.0425$.

**Table 5.2** Fitted $r$ for a sky made with $r = 0.03$, first four bands.

| Run | Map | Fitted $r$ |
| --- | --- | --- |
| tensor-and-lensing | no dust, no noise | $0.0290 \pm 0.0097$ |
| dust-two-frequencies | $150\ \mathrm{GHz}$ alone | $0.274 \pm 0.011$ |
| dust-two-frequencies | cleaned | $0.0335 \pm 0.0118$ |
| dust-wrong-index | cleaned with $\beta_d = 1.63$ | $0.0361 \pm 0.0118$ |
| dust-decorrelated | cleaned, $\rho_d = 0.95$ | $0.0425 \pm 0.0118$ |

The quoted uncertainties count only microwave-background and noise scatter. Each failure shifts $r$ by less than one sigma from the correctly cleaned value on this patch. Both add positive dust power, so the upward bias stays even on a larger patch.

## What the numbers do not mean

The patch is 256 square degrees with one sky realization per run, so the uncertainties are larger than in a real survey and the digits depend on the seeds. BK18 reaches $\sigma(r) = 0.009$ with real maps over about 400 to 600 square degrees at several frequencies, a likelihood that includes foreground parameters, and simulations of its own pipeline. The script has no beam, no filtering, no synchrotron, no instrument systematics and no delensing, and it treats lensing $B$ as Gaussian. Its purpose is to make each step visible and checkable.

## If something goes wrong

A different Python version should change only values below $10^{-30}$. Any other difference means the input file or the script has changed. The grid size must be a power of two, because the Fourier transform is radix-2. Changing a seed changes every measured value in that run but none of the expected values.

## Things to try

1. Set rotationDegrees to $0.5$ and check that BBOverEE becomes $\tan^2 1^\circ \approx 3.0\times10^{-4}$.
2. Set dustCorrelation to $0.99$ and see how much of the bias in Step 7 disappears.
3. Raise the $353\ \mathrm{GHz}$ noise to $60\ \mu\mathrm{K}$-arcmin and predict the cleaned noise from the weights before running.

## Read the same angular band at four frequencies

In the measured BK18 spectra, the B-mode power around $\ell = 72.5$ rises sharply between 95 and 353 GHz. In the left panel below, compare the four dark points with the blue lensing curve. Lensing changes the pattern of the microwave background the same way in every channel. Galactic dust brightens toward the higher frequencies, even after we put all the maps on the same CMB temperature scale.

Start with the 150 GHz point alone. Subtract the reference lensing prediction and assign everything left to primordial waves. The exercise returns an apparent $r = 0.172$. One bandpower gives you one equation for the three contributions. Now use all ten auto and cross spectra of the four maps. Their windows tell you which angular scales contribute to each band. The covariance tells you which measurements move together. Both come from the [October 2021 BK18 data release](https://lambda.gsfc.nasa.gov/product/bicepkeck/bicepkeck_bk18_2021_doi.html).

The replay fits the nine bands per spectrum with a fixed dust colour and a fixed lensing shape. With $r = 0$, the fitted lensing amplitude is $1.07 \pm 0.08$ times the reference. The dust amplitude at 353 GHz and $\ell = 80$ is $4.18 \pm 0.41\ \mu\mathrm{K}_{\rm CMB}^{2}$. Look at the right panel to see how the two contributions change across angular scale. These are conditional Gaussian errors for this set of templates. The published BK18 limit combines more frequency maps and varies the foreground parameters in its own likelihood.

Download and unpack the replay beneath the figure. Save the two original files in an inputs directory, then run this command from the unpacked folder with NumPy and Matplotlib installed.

```
mkdir -p inputs
curl -fL https://lambda.gsfc.nasa.gov/data/suborbital/BICEPK_2021/BK18_cosmomc.tgz -o inputs/BK18_cosmomc.tgz
curl -fL https://lambda.gsfc.nasa.gov/data/suborbital/BICEPK_2021/BK18_bandpowers_20210607.txt -o inputs/BK18_bandpowers_20210607.txt
python3 recompute_observed_bands.py inputs camb-polarization-spectra.json output
```

Open bk18-observed-result.json. It records both source hashes and the agreement between the archive and the independently published bandpower table. Compare the fit with the covariance intact and the fit that discards its correlations. The latter gives a dust error of about $0.23\ \mu\mathrm{K}_{\rm CMB}^{2}$ when the full-covariance fit with a free tensor template gives $0.41\ \mu\mathrm{K}_{\rm CMB}^{2}$. Shared sky and instrument contributions matter to the uncertainty.

Sources: [BICEP/Keck 2021, BK18 constraints on primordial gravitational waves](https://arxiv.org/abs/2110.00483v1), [Planck 2018 results XI, polarized dust foregrounds](https://arxiv.org/abs/1801.04945v2), [Lewis and Challinor 2006, weak gravitational lensing of the CMB, section 5](https://arxiv.org/abs/astro-ph/0601594v4), [Planck 2018 results VI, cosmological parameters, table 2](https://arxiv.org/abs/1807.06209v4).

![Measured BK18 B-mode bandpowers rise strongly toward 353 GHz. At 150 GHz, the nine angular bands track the lensing plus dust model.](https://sandboxphysics.com/_astro/bk18-observed-multifrequency.DTzg4HOY.png)

Points show BK18 measurements. Error bars show marginal standard deviations from the archived covariance. The fit also uses the correlations between the points. Data courtesy of the BICEP/Keck Collaboration and NASA Goddard’s LAMBDA archive.

[Download the BK18 replay](https://sandboxphysics.com/_astro/bk18-observed-replay.CcOraPaR.zip)

[Save a sky record from the Lab and compare its band powers with the script output.](https://sandboxphysics.com/labs/cmb-b-mode-dust-delensing/)

## Sources

1. [October 2021 BK18 data release](https://lambda.gsfc.nasa.gov/product/bicepkeck/bicepkeck_bk18_2021_doi.html)
2. [BICEP/Keck 2021, BK18 constraints on primordial gravitational waves](https://arxiv.org/abs/2110.00483v1)
3. [Planck 2018 results XI, polarized dust foregrounds](https://arxiv.org/abs/1801.04945v2)
4. [Lewis and Challinor 2006, weak gravitational lensing of the CMB, section 5](https://arxiv.org/abs/astro-ph/0601594v4)
5. [Planck 2018 results VI, cosmological parameters, table 2](https://arxiv.org/abs/1807.06209v4)

## Keep reading

CMB B-modes, dust and delensing · Reading path

### From polarized light to E and B, dust, lensing and the BICEP/Keck limit

1. [Article **Can swirls in the microwave sky reveal the first gravitational waves?**](https://sandboxphysics.com/stories/cmb-b-modes/can-microwave-swirls-reveal-the-first-gravitational-waves/)
2. [Article **How scattering polarizes the microwave background**](https://sandboxphysics.com/stories/cmb-b-modes/how-scattering-polarizes-the-microwave-background/)
3. [Article **Splitting a polarization map into E and B modes**](https://sandboxphysics.com/stories/cmb-b-modes/splitting-a-polarization-map-into-e-and-b/)
4. [Article **How dust and lensing add B-modes, and how to take them out**](https://sandboxphysics.com/stories/cmb-b-modes/how-dust-and-lensing-add-b-modes/)
5. [You are here **Recompute an E/B split and a two-frequency dust cleaning**](https://sandboxphysics.com/stories/cmb-b-modes/recompute-an-e-b-split-and-dust-cleaning/)
6. [Article **How to read the BICEP/Keck BK18 limit on primordial gravitational waves**](https://sandboxphysics.com/stories/cmb-b-modes/reading-the-bicep-keck-bk18-limit/)
