CosmoMC and GetDist with Planck Likelihood and Chains

The Planck likelihood code (PLC/clik) and parameter chains are available from the Planck Legacy Archive.

Using the Planck likelihood with CosmoMC

Here I assume you have installed CosmoMC in a directory called COSMOMC..PATH, and will install the Planck likelihood code in a directory called PLC..PATH. Note you need to use ifort 13 or higher to build CosmoMC, so make sure you have that configured before you start. A set of .ini files are supplied in ./batch1 which set up standards for Planck runs. Location of data files is set in CAMspec_ACTSPT_defaults, CAMspec_defaults depending on what you want to use. You can try
mpirun -np 2 ./cosmomc test.ini
to see if things are being loaded and start running OK.

Note that the "highL" (ACT/SPT) likelihood file is not included in the first PLC download; hopefully it will be added soon. Meanwhile you can follow the instructions on the Planck likelihood download page for how to make it from the ACT/SPT download.

Using Planck Chains

Planck provide a set of parameter chains produced by CosmoMC, available here. The full grid (2.8GB) download is also available from this US link. You can use CosmoMC's python scripts and getdist to analyse and make plots from them. First download and extract all the chain data. Make a symbolic link from ./cosmomc/PLA to the location of the chains, e.g.
ln -s /scratch/planck/PLA ./PLA
so that ./PLA/base is for example the head directory with the baseline model chains. For the program to know about the structure of the grid you first need to initialize it for the location you have installed in. Do
python python/makeGrid.py PLA settings_planck_nominal
When done it will tell you the commands needed to be run to reproduce the chains. But of course you don't need to do that, you have the chains already. You can now use the python/* scripts on the PLA directory, and they will know about the available data. Settings for the Planck parameter grid are in python/settings_planck_nominal.py.

Calculating derived parameters

For simple calculations like finding the mean and variance of new derived parameters you can use the functions in python/chains.py. For example, if you want to calculate the posterior mean and limits for sigma8*Omegam^0.6 from Planck+WP+highL+lensing you could write a python script
import chains

rootdir = r'./PLA/'

chains = chains.loadGridChain(rootdir, 'base', 'planck_lowl_lowLike_highL', 'lensing')

p = chains.getParams()

derived = p.sigma8 * p.omegam ** 0.6

print 'mean, err = ', chains.mean(derived), chains.std(derived)
print '95% limits: ', chains.twoTailLimits(derived, 0.95)
Here p.omegam is a vector of parameter values, similar p.sigma8; chains.mean and chains.var sum the samples with the corresponding weights to calculate the result. The third argument of loadGridChain specifies any data added by importance sampling.

See python/chains.py for other simple functions you can use. Use GetDist if you want to reproduce Planck results: chains.py only does tail integrals, it does not check for skewness or calculate credible intervals for skewed distributions.

Plotting

To make plots from the grid you need to first run getdist over the grid. To do this make sure you have installed and compiled CosmoMC (with getdist) then run
python python/runGridGetdist.py PLA --burn_removed
This may take a while. It generates a VERY large number of plotting files in PLA/plot_data for the entire grid. You can use optional parameters for runGridGetdist.py if you want to restrict to specific models; run python python/runGridGetdist.py to see the full list of options. For example if you are only interested in models with massive neutrinos using Planck data you could do
python python/runGridGetdist.py PLA --paramtag base_mnu --data planck
Getdist generates .m scripts in each PLA/../../dist subfolder, which you can run in matlab. Or, now usually recommended, use the python scripts. You can use python python/makePlots.py PLA .. to make plots en masse. See batch1/outputs/makeGridPlots for examples.

You can also write your own short python scripts to plot things of interest; many examples are in batch1/outputs/ (note that these use planckStyle.py, which assumed your main grid directory is ./main not ./PLA, and needs output folders called outputs and plots). For example, assuming you've done runGridGetdist on the base planck and WMAP chains, you can do

python batch1/outputs/triangle_planckonly_vs_WMAP.py
to reproduce the figure above.

As an example python script not using planckStyle you can do

import GetDistPlots
g=GetDistPlots.GetDistPlotter('PLA/plot_data')
g.settings.setWithSubplotSize(4)

roots = ['base_nnu_mnu_planck_lowl_lowLike','base_nnu_mnu_planck_lowl_lowLike_highL','base_nnu_mnu_planck_lowl_lowLike_highL_post_BAO']
g.plot_2d(roots, param_pair=['mnu','nnu'], filled=True)
g.add_legend(['Planck+WP','Planck+WP+highL','Planck+WP+highL+BAO'],legend_loc='upper right');
g.export('mnu_nnu.png')
The legend overlaps a bit. You can do "import pylab *" and use standard matplotlib commands. Or you can try things like this
import GetDistPlots
g=GetDistPlots.GetDistPlotter('PLA/plot_data')
g.settings.setWithSubplotSize(4)
g.make_figure(xstretch=1.3)

roots = ['base_nnu_mnu_planck_lowl_lowLike','base_nnu_mnu_planck_lowl_lowLike_highL','base_nnu_mnu_planck_lowl_lowLike_highL_post_BAO']
g.plot_2d(roots, param_pair=['mnu','nnu'], filled=True)
g.add_legend(['Planck+WP','Planck+WP+highL','Planck+WP+highL+BAO'],legend_loc='upper right',colored_text=True);
g.export('mnu_nnu2.png')
Outputs of the two versions should look like this: