Getting started with GetDist on Python (and the GUI)

Use of Healpix, camb, CLASS, cosmomc, compilers, etc.
Post Reply
Mason Ng
Posts: 26
Joined: May 17 2017
Affiliation: The University of Auckland

Getting started with GetDist on Python (and the GUI)

Post by Mason Ng » May 17 2017

Hi all, I'm a new student in cosmology. I'll be using CosmoMC [on a cluster, later on] to sample the Planck likelihood (from PR2 in 2015), and in turn will be using the results to compute Bayesian evidence and necessary parameter estimates.

For now, I am just starting off on a 'tutorial' [on a MacBook Pro 2015, OS X El Capitan, 10.11.6], learning to get GetDist to make plots (e.g. contour plots seen in cosmology papers). I have encountered a couple of problems regarding the plotting. First of all, I should note that I obtained the chain files from http://irsa.ipac.caltech.edu/data/Planc ... lary-data/ (using the Full Grid).

I am trying to use this Python code (Python 2.7.13, from the Anaconda distribution, so Spyder IDE):

Code: Select all

g = plots.getSubplotPlotter(chain_dir='/Users/masonng/Documents/Honours Project/Chains/base_nnu_mnu/plikHM_TT_lowTEB/')
roots = ['plikHM_TT_lowTEB']
params = ['omegabh2', 'omegach2', 'theta']
param_3d = None
g.triangle_plot(roots, params, plot_3d_with_param=param_3d, filled_compare=True, shaded=True)
g.export()
where I have edited from the 2nd picture here http://cosmologist.info/cosmomc/readme_gui.html [I do have issues with the GUI, but I will touch on that afterwards]

but I get a "chain not found" error from GetDistPlot

Code: Select all

runfile('/Users/masonng/.spyder/temp.py', wdir='/Users/masonng/.spyder')
Traceback (most recent call last):

  File "<ipython-input-42-fb250905188c>", line 1, in <module>
    runfile&#40;'/Users/masonng/.spyder/temp.py', wdir='/Users/masonng/.spyder'&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
    execfile&#40;filename, namespace&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
    builtins.execfile&#40;filename, *where&#41;

  File "/Users/masonng/.spyder/temp.py", line 11, in <module>
    g.triangle_plot&#40;roots, params, plot_3d_with_param=param_3d, filled_compare=True, shaded=True&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 1784, in triangle_plot
    params = self.get_param_array&#40;roots&#91;0&#93;, params&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 1380, in get_param_array
    return self.paramNamesForRoot&#40;root&#41;.parsWithNames&#40;params, error=True, renames=renames&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 763, in paramNamesForRoot
    labelParams=self.settings.param_names_for_labels&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 576, in paramsForRoot
    samples = self.samplesForRoot&#40;root&#41;

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 462, in samplesForRoot
    raise GetDistPlotError&#40;'chain not found&#58; ' + root&#41;

&#91;b&#93;GetDistPlotError&#58; chain not found&#58; plikHM_TT_lowTEB&#91;/b&#93;
and I am quite sure I have given the right path to the chain files, unless I am mistaken somewhere in the principles. It would be great if someone could please guide me on this.

Regarding the GUI, I tried running GetDistGUI.py itself from the python folder of cosmomc (July 2015 version) but:

Qt (package) wasn’t working it seems; in particular, even though PySide was imported without problem, PySide.QtCore had an issue:

Code: Select all

ImportError&#58; dlopen&#40;/Users/masonng/anaconda2/lib/python2.7/site-packages/PySide/QtCore.so, 2&#41;&#58; Library not loaded&#58; /usr/local/lib/QtCore.framework/Versions/4/QtCore
  Referenced from&#58; /Users/masonng/anaconda2/lib/python2.7/site-packages/PySide/QtCore.so
  Reason&#58; image not found
Tried this too: https://forum.qt.io/topic/8814/solved-p ... -qtcore-so

It turns out that I did not have Qt4/PyQt4 in my system, but conda can’t find this even though

Code: Select all

pip search qt
knows of such a package. I also could only download PySide 1.2.2 – PySide 1.2.4 is not usable. Additionally, PySide is not supported by Qt 5.x, but I also cannot get Qt 4.x (need Qt 4.6 or better).

They are long questions - please feel free to answer in separately if appropriate. Additionally, any input is valuable. Thanks in advance!

Sunny Vagnozzi
Posts: 43
Joined: August 15 2016
Affiliation: Oskar Klein Centre, Stockholm University

Getting started with GetDist on Python (and the GUI)

Post by Sunny Vagnozzi » May 17 2017

What I usually do (which is not necessarily the best choice) is to have the outputs of getdist go in a results/ folder, and the data for plotting going in a results/plot_data/ folder, i.e. in my distparams.ini:

Code: Select all

file_root = chains/pgg_mnu_bias_k03
out_root =
out_dir = results
plot_data_dir = results/plot_data/
Then I run getdist from my main CosmoMC folder via (sorry if all of this might be obvious to you):

Code: Select all

./getdist distparams.ini chains/"file_root"
where you substitute "file_root" with your actual file root. Then to plot I stay in my main CosmoMC folder and (make sure you have loaded any library which might be required to plot):

Code: Select all

python results/"name_of_plotting_script".py
where "name_of_plotting_script" is typically something like file_root, file_root_2D, file_root_3D, file_root_tri. This way I never had problems with paths to the files.

Antony Lewis
Posts: 1385
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Getting started with GetDist on Python (and the GUI)

Post by Antony Lewis » May 17 2017

If you installed the full grid of chains in /Users/masonng/Documents/Honours Project/Chains/, you should have
chain_dir='/Users/masonng/Documents/Honours Project/Chains/'
and use the full chain name "base_plikHM..." to reference whatever you want to plot. The code knows how to find different models in under the grid directory.

There is no need to run getdist to make plots from downloaded chains (and the fortran ./getdist is now superceded by the python version).

Mason Ng
Posts: 26
Joined: May 17 2017
Affiliation: The University of Auckland

Re: Getting started with GetDist on Python (and the GUI)

Post by Mason Ng » May 18 2017

Sunny Vagnozzi wrote:What I usually do (which is not necessarily the best choice) is to have the outputs of getdist go in a results/ folder, and the data for plotting going in a results/plot_data/ folder, i.e. in my distparams.ini:

Code: Select all

file_root = chains/pgg_mnu_bias_k03
out_root =
out_dir = results
plot_data_dir = results/plot_data/
Then I run getdist from my main CosmoMC folder via (sorry if all of this might be obvious to you):

Code: Select all

./getdist distparams.ini chains/"file_root"
where you substitute "file_root" with your actual file root. Then to plot I stay in my main CosmoMC folder and (make sure you have loaded any library which might be required to plot):

Code: Select all

python results/"name_of_plotting_script".py
where "name_of_plotting_script" is typically something like file_root, file_root_2D, file_root_3D, file_root_tri. This way I never had problems with paths to the files.
Hi Sunny, thanks for your input. I'll probably end up coming back to this once I am using CosmoMC proper. For now, I am simply trying to make sample plots from the ready-made chain files using GetDist on Python.
If you installed the full grid of chains in /Users/masonng/Documents/Honours Project/Chains/, you should have

Quote:
chain_dir='/Users/masonng/Documents/Honours Project/Chains/'


and use the full chain name "base_plikHM..." to reference whatever you want to plot. The code knows how to find different models in under the grid directory.
Thanks for the reply, Antony. So under chains, I have many folders like "base", "base_mnu", "base_nnu_mnu" etc. For my example, I am trying to plot from "base_nnu_mnu/plikHM_TT_lowTEB/base_nnu_mnu_plikHM_TT_lowTEB_1.txt" I have adhered to your suggestions, but am still getting "chain not found" errors. After getting the right path for chain_dir, this is what I have tried for the roots:

Code: Select all

roots = &#91;'base_nnu_mnu_plikHM_TT_lowTEB'&#93;
roots = &#91;'base_nnu_mnu_plikHM_TT_lowTEB_1'&#93;
roots = &#91;'base_nnu_mnu/plikHM_TT_lowTEB/plikHM_TT_lowTEB_1'&#93; #&#40;making sure&#41;
roots = &#91;'base_nnu_mnu/plikHM_TT_lowTEB/plikHM_TT_lowTEB'&#93;
and also tried adding '.txt' at the end, to no avail. I think I have not properly set some settings somewhere?

Antony Lewis
Posts: 1385
Joined: September 23 2004
Affiliation: University of Sussex
Contact:

Re: Getting started with GetDist on Python (and the GUI)

Post by Antony Lewis » May 18 2017

The first form should be sufficient.

Make sure you have the latest cosmomc version (not 2015 version). Otherwise you may need to manually run makeGrid.py on the grid directory first as described in the readme.

Mason Ng
Posts: 26
Joined: May 17 2017
Affiliation: The University of Auckland

Getting started with GetDist on Python (and the GUI)

Post by Mason Ng » May 20 2017

Thanks a lot Antony! I had a follow-on problem after fixing chain paths, which I found out was because I did not have OpenMPI installed on my Mac. It is all done and working now!

I'm now trying to get this set-up on CosmoBox as well, which I believe has Python 2.7.11 installed (or 2.7.11+?). I had issues when I tried to use the Anaconda distribution, so after playing around on a few iterations on CosmoBox, I've got something satisfactory where I'm using virtual environments to (try and) overcome version clashes.

i.e. current configuration: using CosmoBox without the Anaconda distribution. I'm using Atom as a text editor and the Terminal to execute python scripts (ipython script.py or python script.py). However, I'm getting two problems:

1) [Related to GetDist]: I have GetDist installed in the (Python) virtual environment (via pip install; did the same thing for Healpy and it works). However, I get

Code: Select all

AttributeError&#58; 'module' object has no attribute 'getSubplotPlotter'
even though it is clearly installed as shown in 'pip list' in the virtual environment, or even looking at the list of packages in

Code: Select all

/local/lib/python2.7/site-packages
2) [Related to matplotlib - so that I can display the figures produced by Healpy]: This came with CosmoBox. I get the same problem as above, with the module 'figure'. I'm not too sure if this is the right avenue; I can forward this onto StackExchange; just thought someone might have encountered this before on CosmoBox.

Mason Ng
Posts: 26
Joined: May 17 2017
Affiliation: The University of Auckland

Getting started with GetDist on Python (and the GUI)

Post by Mason Ng » May 22 2017

Just managed to solve this problem - my issue was just how I was importing packages (oops!).

Post Reply