CosmoCoffee Forum Index CosmoCoffee

 
 FAQFAQ   SearchSearch  MemberlistSmartFeed   MemberlistMemberlist    RegisterRegister 
   ProfileProfile   Log inLog in 
Arxiv New Filter | Bookmarks & clubs | Arxiv ref/author:

Getting started with GetDist on Python (and the GUI)
 
Post new topic   Reply to topic    CosmoCoffee Forum Index -> Computers and software
View previous topic :: View next topic  
Author Message
Mason Ng



Joined: 17 May 2017
Posts: 18
Affiliation: The University of Auckland

PostPosted: May 17 2017  Reply with quote

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/Planck/release_2/ancillary-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:
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:
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('/Users/masonng/.spyder/temp.py', wdir='/Users/masonng/.spyder')

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
    builtins.execfile(filename, *where)

  File "/Users/masonng/.spyder/temp.py", line 11, in <module>
    g.triangle_plot(roots, params, plot_3d_with_param=param_3d, filled_compare=True, shaded=True)

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 1784, in triangle_plot
    params = self.get_param_array(roots[0], params)

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

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

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 576, in paramsForRoot
    samples = self.samplesForRoot(root)

  File "/Users/masonng/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 462, in samplesForRoot
    raise GetDistPlotError('chain not found: ' + root)

[b]GetDistPlotError: chain not found: plikHM_TT_lowTEB[/b]


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:
ImportError: dlopen(/Users/masonng/anaconda2/lib/python2.7/site-packages/PySide/QtCore.so, 2): Library not loaded: /usr/local/lib/QtCore.framework/Versions/4/QtCore
  Referenced from: /Users/masonng/anaconda2/lib/python2.7/site-packages/PySide/QtCore.so
  Reason: image not found


Tried this too: https://forum.qt.io/topic/8814/solved-pyside-new-mac-os-install-can-t-load-qtcore-so

It turns out that I did not have Qt4/PyQt4 in my system, but conda can’t find this even though
Code:
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!
Back to top
View user's profile  
Sunny Vagnozzi



Joined: 15 Aug 2016
Posts: 34
Affiliation: Oskar Klein Centre, Stockholm University

PostPosted: May 17 2017  Reply with quote

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:
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:
./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:
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.
Back to top
View user's profile  
Antony Lewis



Joined: 23 Sep 2004
Posts: 1257
Affiliation: University of Sussex

PostPosted: May 17 2017  Reply with quote

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.

There is no need to run getdist to make plots from downloaded chains (and the fortran ./getdist is now superceded by the python version).
Back to top
View user's profile [ Hidden ] Visit poster's website
Mason Ng



Joined: 17 May 2017
Posts: 18
Affiliation: The University of Auckland

PostPosted: May 18 2017  Reply with quote

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:
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:
./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:
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.

Quote:
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:

roots = ['base_nnu_mnu_plikHM_TT_lowTEB']
roots = ['base_nnu_mnu_plikHM_TT_lowTEB_1']
roots = ['base_nnu_mnu/plikHM_TT_lowTEB/plikHM_TT_lowTEB_1'] #(making sure)
roots = ['base_nnu_mnu/plikHM_TT_lowTEB/plikHM_TT_lowTEB']


and also tried adding '.txt' at the end, to no avail. I think I have not properly set some settings somewhere?
Back to top
View user's profile  
Antony Lewis



Joined: 23 Sep 2004
Posts: 1257
Affiliation: University of Sussex

PostPosted: May 18 2017  Reply with quote

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.
Back to top
View user's profile [ Hidden ] Visit poster's website
Mason Ng



Joined: 17 May 2017
Posts: 18
Affiliation: The University of Auckland

PostPosted: May 20 2017  Reply with quote

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:
AttributeError: '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:
/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.
Back to top
View user's profile  
Mason Ng



Joined: 17 May 2017
Posts: 18
Affiliation: The University of Auckland

PostPosted: May 22 2017  Reply with quote

Just managed to solve this problem - my issue was just how I was importing packages (oops!).
Back to top
View user's profile  
Display posts from previous:   
Post new topic   Reply to topic    CosmoCoffee Forum Index -> Computers and software All times are GMT + 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group. Sponsored by WordWeb online dictionary and dictionary software.