Recompute an E/B split and a two-frequency dust cleaning
Sandbox Physics ·
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 150GHz map with a 353GHz 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.
Download the script, the saved inputs and the expected output 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.
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×64 grid, 16∘ 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 ℓ=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 H0=67.36, τ=0.0544 and ns=0.9649. Tensors use nt=0 at a pivot of 0.05Mpc−1, the convention BK18 uses. The script interpolates between nodes in log-log.
The dust block holds Ad=4.4μK2 at 353GHz and ℓ=80 from BK18, Td=19.6K and βd=1.53 from Planck, and a band-power slope of −0.54, which is Planck's Cℓ∝ℓ−2.54. Dust EE is twice dust BB, as BK18 assumes.
Units follow the units block: spectra in μK2 of microwave-background temperature, band powers Dℓ in μK2, angles in degrees, frequencies in GHz, noise in μ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, 2/Nb 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×10−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 χ2=7.06 over seven bands. The script then subtracts the expected lensing in the first four bands, 30≤ℓ<220, and fits the remainder with the tensor shape, weighting each band by 1/σ2. The block tensorRatioEstimate gives r=0.0290±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∘ before the split. BBOverEE is 0.0049 in every band, and the output stores the prediction predictedBBOverEE =tan24∘=0.00489. The rotation moves sin24∘ of the power into B and leaves cos24∘ 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 φℓ in place of 2φℓ. E falls to about half of its model value, for example 0.266 instead of 0.487μK2 in the band 60≤ℓ<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.1B/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 ℓ≈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 150GHz with noise 2.8μK-arcmin and at 353GHz with noise 20μ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 150GHz, and cleaningCoefficient a=0.0477, its square root. Under combinations, the 150GHz map alone gives r=0.274±0.011: dust looks like nine times the true signal. The combination with weights 1.050 and −0.0501, which is (m150−am353)/(1−a), gives r=0.0335±0.0118. Its noise rises from 2.8 to 3.11μK-arcmin, and its dustResidualBB is at most 3×10−33μK2, 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 βd=1.63. Its coefficient becomes 0.0438 instead of 0.0477. The residual dust is 8.1×10−5μK2 in the lowest band and r rises to 0.0361.
The run dust-decorrelated keeps the right index, but the 150GHz dust pattern is correlated with the 353GHz one by only ρd=0.95. The residual dust is 4.3×10−4 to 1.3×10−3μK2 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±0.0097
dust-two-frequencies
150GHz alone
0.274±0.011
dust-two-frequencies
cleaned
0.0335±0.0118
dust-wrong-index
cleaned with βd=1.63
0.0361±0.0118
dust-decorrelated
cleaned, ρd=0.95
0.0425±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 σ(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
Set rotationDegrees to 0.5 and check that BBOverEE becomes tan21∘≈3.0×10−4.
Set dustCorrelation to 0.99 and see how much of the bias in Step 7 disappears.
Raise the 353GHz noise to 60μ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 ℓ=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.
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±0.08 times the reference. The dust amplitude at 353 GHz and ℓ=80 is 4.18±0.41μKCMB2. 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.
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μKCMB2 when the full-covariance fit with a free tensor template gives 0.41μKCMB2. Shared sky and instrument contributions matter to the uncertainty.
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