Skip to main content
Sandbox Physics
Kilonovae: heavy elements and diffusing light

Reproducing a two-component kilonova fit to the GW170817 photometry

Sandbox Physics ·

We fitted a constrained two-component grey kilonova model to a fixed set of 394 GW170817 measurements and saved every input, output and failure case. The best fit has an extra scatter of 0.2610.261 magnitudes and a red component of 0.05250.0525 solar masses at 0.152c0.152c with opacity 3.18 cm2 g−13.18\,\mathrm{cm^2\,g^{-1}}, but the red mass and speed are correlated at 0.8880.888 and a second solution sits only 1.91.9 in −ln⁡L-\ln\mathcal L higher. Rerunning the check on our machine reproduced every saved number within 0.20.2 percent in about 75 seconds.

Open the kilonova light-curve Lab

The physics is explained in fitting GW170817 and the trade-off between ejecta mass and speed. This guide is the recipe.

What the authors published

Villar and colleagues compiled the ultraviolet, optical and infrared photometry of GW170817 from 18 papers into one table, which they distribute with the arXiv source of their paper. Villar and colleagues, arXiv:1710.11576v2, §2 and Table 3 They ask that any use of the table cite the original papers as well as their compilation. Our CSV keeps their reference key for every row so that each point can be credited.

Table 4.1 The fixed inputs.
ItemValue
Source archivearXiv e-print of 1710.11576, file phot_table.dat
Table digest, SHA-256a2ec8677f60d096a1347d82f5628377fd206de5596909c161a79d68c70bc6e92
Kept rows394 detections in g r i z J H K and Ks, used by the authors, not outliers
Output digest, SHA-2566e977704480b16314e4794abecf452216848f41e6682d623f53119de646d52fc
Merger timeMJD 57982.528524
Distance39.5 Mpc39.5\,\mathrm{Mpc}, fixed
Milky Way reddeningE(B−V)SFD=0.1228E(B-V)_{\mathrm{SFD}}=0.1228, IRSA dust service, retrieved 2026-11-14
Extinction coefficientsSchlafly and Finkbeiner, Table 6, RV=3.1R_V=3.1

All of this is also in tutorial-inputs.json. Schlafly and Finkbeiner, Table 6

Units

Time is in days since the merger, magnitudes are AB and not corrected for extinction, mass is in solar masses, speed in units of cc, opacity in cm2 g−1\mathrm{cm^2\,g^{-1}}, temperature in kelvin and distance in megaparsecs. Inside the code everything is converted to CGS. The model evaluates each filter at one effective wavelength; that approximation is part of what the extra scatter absorbs.

Step 1: get the table and check it

Keep the download in its own empty folder and the scripts in another.

mkdir -p kilonova-fit/author-data kilonova-fit/scripts
cd kilonova-fit/author-data
curl -L -o villar-source.tar.gz https://arxiv.org/e-print/1710.11576
tar -xzf villar-source.tar.gz
shasum -a 256 phot_table.dat

The digest should be:

a2ec8677f60d096a1347d82f5628377fd206de5596909c161a79d68c70bc6e92  phot_table.dat

The e-print link serves the newest version of the source. If the authors ever post a new version, the table may change. Stop and compare before trusting anything below if the digest differs.

Step 2: extract the fixed subset

Save extract_gw170817_photometry.py in the scripts folder and run it on the table:

cd ../scripts
python3 extract_gw170817_photometry.py ../author-data/phot_table.dat

It writes gw170817-photometry.csv and prints both digests. The output should match our CSV, digest 6e9777...52fc. It spans 0.4520.452 to 25.4425.44 days.

Step 3: fix the software

python3 -m venv .venv
. .venv/bin/activate
pip install numpy==2.0.2 scipy==1.13.1

The versions are listed in requirements.txt. We used Python 3.9.6. The fit script writes the versions it ran with into its output.

Step 4: run the fits and the checks

Save kilonova_model.py, fit_two_component.py, check_independent_limits.py and tutorial-inputs.json next to the CSV, then:

python3 fit_two_component.py --check
python3 check_independent_limits.py

With --check, the fit script recomputes everything and compares it with a saved fit-outputs.json in the same folder, allowing a relative difference of 2×10−32\times10^{-3}. Without the flag it overwrites that file. The second script writes independent-checks.json.

What the fit script does

  1. It builds each component from the radioactive heating law, the thermalization fit of Barnes and colleagues, Arnett's diffusion integral with the factor 2/td2/t_d, and a blackbody photosphere with a temperature floor.
  2. It adds the components' flux in each band, converts to AB magnitudes at 39.5 Mpc39.5\,\mathrm{Mpc}, and adds Milky Way extinction.
  3. It minimises −ln⁡L-\ln\mathcal L, alternating a bounded least-squares step at fixed scatter with a one-dimensional search over the scatter.
  4. It starts from Villar and colleagues' published values and from 16 fixed pseudo-random points, with seed 170817, and keeps every distinct optimum.
  5. It repeats the fit for four variants and maps −ln⁡L-\ln\mathcal L over a grid of red mass and speed, re-fitting the other parameters at each grid point.

Results

Table 4.2 Best two-component fit.
QuantityValueLocal error
Blue mass0.0209 M⊙0.0209\,\mathrm M_\odot0.00050.0005
Blue speed0.385c0.385c0.0160.016
Blue floor5184 K5184\,\mathrm K124124
Red mass0.0525 M⊙0.0525\,\mathrm M_\odot0.00220.0022
Red speed0.152c0.152c0.0050.005
Red floor1014 K1014\,\mathrm K3131
Red opacity3.18 cm2 g−13.18\,\mathrm{cm^2\,g^{-1}}0.120.12
Extra scatter0.2610.261 mag
Diffusion times1.101.10 and 6.966.96 days

The local errors come from the curvature at the optimum and ignore the other branches. Villar and colleagues report 0.0230.023, 0.256c0.256c and 3983 K3983\,\mathrm K for blue and 0.0500.050, 0.149c0.149c, 3.653.65 and 1151 K1151\,\mathrm K for red, with scatter 0.2560.256. Villar and colleagues, Table 2 The two sets of numbers are different optima of closely related likelihoods; see the failure cases below.

The independent checks pass. Arnett's integral agrees with a direct Radau solution of the energy equation within 4.3×10−44.3\times10^{-4}. Energy is conserved to 5×10−55\times10^{-5}. The light-curve peaks satisfy L=QL=Q to 2×10−42\times10^{-4}. For pure t−1.3t^{-1.3} heating the peak falls at 0.7087 td0.7087\,t_d, the value found by quadrature. The radioactive energy from one to ten days matches the closed form within 10−510^{-5}. A blackbody spectrum integrated over frequency returns its luminosity.

Failure cases and how they are handled

  1. The printed light-curve integral. Villar and colleagues' eq. 3 has the kernel t/tdt/t_d instead of 2t/td22t/t_d^2. As printed it has units of energy and depends on the time unit; for our best red component it is 3.483.48 times LL with time in days. We use 2t/td22t/t_d^2 and check it against the energy equation.
  2. The printed photosphere law. Eqs. 4 and 5 put σSB2\sigma_{\mathrm{SB}}^2 inside the fourth root but σSB\sigma_{\mathrm{SB}} in the receded radius. With the square every temperature would be divided by 0.08680.0868, about 4000 K4000\,\mathrm K becoming 46000 K46000\,\mathrm K. We use σSB\sigma_{\mathrm{SB}} throughout.
  3. The printed likelihood. Eq. 6 does not normalise the Gaussian with variance σi2+σ2\sigma_i^2+\sigma^2. We use the normalised form. Constant terms do not move the best parameters, but the normalisation does affect the fitted scatter.
  4. Several optima. The 17 starts land in four distinct optima, at 63.0263.02, 64.9064.90, 82.1382.13 and 137.28137.28. Ten of the 17 starts end at 82.1382.13 and only three reach the best optimum, so a fit with a single start is likely to stop short of it.
  5. A blue speed outside the thermalization table. The best blue speed, 0.385c0.385c, exceeds the table's 0.3c0.3c, so its coefficients are held at the edge values. The fit is valid for this model but the blue speed should not be read as a measurement.
  6. Extinction convention. Schlafly and Finkbeiner's coefficients multiply the original SFD reddening, 0.12280.1228. Using the recalibrated 0.10560.1056 with the same coefficients under-corrects by 14 percent. That variant changes −ln⁡L-\ln\mathcal L by only 0.940.94 and the red mass by 0.00020.0002.
  7. Rejected models. One component, no temperature floor, and a red opacity forced to 1010 are all worse by more than 200200 in BIC. Their outputs are kept in the file for comparison.
  8. The published parameters in our setup. With σ\sigma refitted they give −ln⁡L=106.32-\ln\mathcal L=106.32 and leave the late KK band about 0.200.20 magnitudes too bright. We have not separated the effects of data selection, likelihood normalisation and the authors' MCMC sampling.

What this tutorial does not show

The fit uses only detections and no upper limits, a spherical geometry, one grey opacity per component and blackbody spectra. Villar and colleagues preferred a three-component model, and an asymmetric version changed their masses by about half. Opacities of real r-process mixtures depend on wavelength and change with time. Tanaka and colleagues, §4.2 The numbers here therefore show what this model can and cannot do with these data. They do not measure the ejecta. The Lab draws its curves with a TypeScript port of the same model, which agrees with the Python reference within 3×10−43\times10^{-4} magnitudes. Compare its default with the data in the kilonova light curves Lab.

Try it in the Lab

Keep the default, which uses the published Villar et al. values, and look at the K points after ten days: the model curve runs about 0.2 magnitudes brighter than the data. Open the kilonova light-curve Lab

Sources

  1. Villar and colleagues, arXiv:1710.11576v2, §2 and Table 3
  2. Schlafly and Finkbeiner, Table 6
  3. Tanaka and colleagues, §4.2

Keep reading

What this page links to directly

See this series on the content map →

Kilonovae: heavy elements and diffusing light · Reading path

From radioactive heat to a blue-then-red flash

  1. ArticleHow does a neutron-star collision turn nuclear decay into days of coloured light?
  2. ArticleRadioactive heat and the time light needs to escape merger debris
  3. ArticleFrom the energy equation to kilonova light curves and colours
  4. ArticleFitting GW170817 and the trade-off between ejecta mass and speed
  5. You are hereReproducing a two-component kilonova fit to the GW170817 photometry
  6. ArticleReading Tanaka et al. 2020 on r-process opacities in kilonovae
Something broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy