Simulating the Universe in a browser

A few weeks ago Chris North asked me if I'd make something to demonstrate some of the science that comes from ESA's Planck satellite. The aim was to show how tweaking the ingredients of the Universe affects the appearance of the earliest light we can see. That light set off around 400,000 years after the big bang and is called the cosmic microwave background radiation or CMB.

The demo was for a Planck stand at the Royal Society Summer Science Exhibition held in London. Chris and I wanted the demo to have a life beyond the exhibition so we created it as a webpage (and put the code on Github). I've put a copy of it on my site so you can simulate the Universe in your own browser.

The Science Bit

There are three sliders to change the amounts of normal matter (baryons that make up you, me, the Earth, the Sun etc), dark matter (something with gravity that doesn't seem to interact with light) and dark energy (something that makes the Universe's expansion accelerate). As you change the sliders we update the view of the CMB as seen on a patch of sky 10° across. Have a play and see how each of the 3 types of ingredient can change the view. The red patches are slightly hotter directions in the sky and the blue patches are slightly colder directions. The variation in temperature is at the level of 0.00001 degrees Kelvin so is pretty tiny but is measurable with sensitive instruments like those on Planck.

The good thing about the simulator is that you can try out different Universes. If you make a 1960s view of the Universe - not knowing about dark-matter-like or dark-energy-like contributions - you'll see that the result doesn't look like what we now measure our Universe to be like. Making the simulator also made me realise that if you have no normal matter in the Universe you don't see any fluctuations in the CMB as light had nothing to interact with and therefore doesn't show the clumpiness of the dark matter. Thank goodness for normal matter or we'd be in trouble (in many ways).

As you change the ingredients some of the changes can be a bit too subtle to see by eye. It can be more useful to get a mathematical representation of the CMB and that is called the power spectrum. Basically we graph how much change there is in temperature when you compare patches of sky of certain sizes. It is similar to displaying an audio track as a frequency spectrum but this shows you which spatial frequencies are the most dominant. Wayne Hu has a good background to the peaks and troughs seen in the power spectrum if you want to know why each one exists and why their relative heights and locations are what they are.

Building a Universe

To get all this working in a browser requires quite a bit of fiddling with Javascript and a few approximations. To keep it feeling responsive when changing the sliders, a compromise was made to reduce the amount of data sent to the browser. I down-sampled the power spectrum that Chris produced (he used CAMB) so that it only really contains the points for the peaks and troughs and then I draw nice curves through them using Raphael.js. That means the curves are approximate and if you over-plotted a genuine power spectrum on top there would be some minor differences.

To get the image of the sky I do a 2D FFT (thanks to a Javascript FFT library made by wellflat) of Gaussian noise, apply an interpolated version of the down-sampled power spectrum to it and FFT it back into real space. I then apply the Planck colour scale and draw the result to an HTML5 <canvas>. Basically, there is a lot of calculation to do there so these rough approximations were needed to keep it fast. Despite that, the result is good enough to show the point.

I've added keyboard shortcuts: pressing 'b', 'c' or 'l' on your keyboard will focus on the normal matter, dark matter, and dark energy sliders and you can use the arrow keys to slide them. The page should also re-jiggle itself to fit a variety of screen resolutions although the Javascript processing can be a bit slow to update the CMB on underpowered mobile phones.

I had fun making this and hopefully it'll be useful to those trying to get to grips with the CMB. I certainly learned a thing or two whilst making it.

Posted in astro blog by Stuart on Wednesday 10th Jul 2013 (01:01 BST) | Permalink
[an error occurred while processing this directive]
[an error occurred while processing this directive]