Skip to content

Commit

Permalink
Changes for Planck 2018 defaults and accuracy tweaks
Browse files Browse the repository at this point in the history
- default halofit version now mead (HMCode), as Planck 2018
- update BBN default model to 2018 Parthenope table
- Calculate all L<=15 (small change in EE polarization at 10<L<15)
- Updated C_L template file
- doc updates
  • Loading branch information
cmbant committed Jan 18, 2019
1 parent fa9bcd2 commit 22c019b
Show file tree
Hide file tree
Showing 26 changed files with 8,333 additions and 8,245 deletions.
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ matrix:
- CHANNEL="conda-forge"
python: "3.6"


#before_install:
# - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
# - sudo apt-get update -qq
# - sudo apt-get install -qq gfortran-6
# - sudo update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-6 90

install:
- mkdir -p gfortran-symlinks
- ln -s /usr/bin/gfortran-$GCC_VERSION gfortran-symlinks/gfortran
Expand All @@ -67,7 +60,7 @@ install:
script: fortran/tests/run_tests.sh

after_failure:
- test $TRAVIS_PULL_REQUEST == "false" && test $CHANNEL == "defaults" && test $TRAVIS_REPO_SLUG == "cmbant/CAMB" && [ -d testfiles ] && bash fortran/tests/upload_tests.sh
- test $TRAVIS_PULL_REQUEST == "false" && test $CHANNEL == "defaults" && test $TRAVIS_REPO_SLUG == "cmbant/CAMB" && [ -d fortran/testfiles ] && bash fortran/tests/upload_tests.sh

before_deploy:
- pushd fortran; make clean delete; popd
Expand Down
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
include *.rst *.txt
recursive-include camb *.py
recursive-include camb_tests *.py
recursive-include fortran Makefile* *.dat *.?90
recursive-include forutils Makefile* *.?90
include camb/cambdll.dll
exclude camb/camblib.so
include camb/PArthENoPE_880.2_marcucci.dat
include camb/PArthENoPE_880.2_standard.dat
include camb/PRIMAT_Yp_DH_Error.dat
exclude camb/HighLExtrapTemplate_lenspotentialCls.dat
exclude fortran/sigma8.f90
exclude fortran/writefits.f90
include docs/README_pypi.rst

42 changes: 27 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,40 @@ Description and installation

CAMB is a cosmology code for calculating cosmlogical observables, including
CMB, lensing, source count and 21cm angular power spectra, matter power spectra, transfer functions
and background evolution. The code is in Python and modern Fortran.
and background evolution. The code is in Python, with numerical code implemented in fast modern Fortran.

To install the CAMB python package on your computer run::
See the `CAMB python example notebook <https://camb.readthedocs.org/en/latest/CAMBdemo.html>`_ for a
quick introduction to how to use the CAMB Python package.

pip install camb
For a standard non-editable installation use::

or from the source
pip install camb [--user]

python setup.py install
The --user is optional and only required if you don't have write permission to your main python installation.
To install from source, clone from github using::

You will need gfortran 6 or higher installed to compile. Binary library builds for python on
Windows are also provided, so these are used instead if no gfortran installation
is found on Windows machines.
git clone --recursive https://github.com/cmbant/CAMB

See the `CAMB python example notebook <https://camb.readthedocs.org/en/latest/CAMBdemo.html>`_ for a
quick introduction to how to use the CAMB Python package.
Then in the project source root directory use::

python setup.py install [--user]

If you want to work on the code, you can also just install in place without copying anything using::

python setup.py make
pip install -e . [--user]

You will need gfortran 6 or higher installed to compile. Binary files for Windows are also provided, so these are used instead if no
gfortran installation is found on Windows machines. If you have gfortran installed, "python setup.py make" will build
the Fortran library on all systems (including Windows without directly using a Makefile).

The python wrapper provides a module called "camb" documented in the `Python CAMB documentation <https://camb.readthedocs.io/en/latest/>`_.

.. image:: https://readthedocs.org/projects/camb/badge/?version=latest
:target: https://camb.readthedocs.org/en/latest
After installation you can also run CAMB from the command line reading parameters from a .ini file, e.g.::

camb inifiles/planck_2018.ini

To compile the Fortran command-line code run "Make" in the fortran directory. For full details
To compile the Fortran command-line code run "make camb" in the fortran directory. For full details
see the `ReadMe <https://camb.info/readme.html>`_.

Branches
Expand All @@ -57,8 +68,9 @@ Reference results and test outputs are stored in the `test outputs repository <h

To reproduce legacy results, see these branches:

CAMB_sources is the old public `CAMB Sources <http://camb.info/sources/>`_ code.
CAMB_v1 is the old Fortran-oriented (gfortran 4.8-compatible) version as used by the Planck 2018 analysis.
- *CAMB_sources* is the old public `CAMB Sources <http://camb.info/sources/>`_ code.
- *CAMB_v1* is the old Fortran-oriented (gfortran 4.8-compatible) version as used by the Planck 2018 analysis.
- *rayleigh* includes frequency-dependent Rayleigh scattering

=============

Expand Down
5 changes: 3 additions & 2 deletions camb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Python command line CAMB reading parameters from a .ini file
# an alternative to fortran binary compiled into fortran/camb using "make camb".
# To use .ini files from a python script use camb.run_ini or camb.read_ini
# If you have installed the camb package, you can just use "camb params.ini" without using this script.

from camb._command_line import _run_command_line
from camb._command_line import run_command_line

_run_command_line()
run_command_line()
8 changes: 5 additions & 3 deletions camb/_command_line.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import os
import sys

Expand All @@ -9,10 +10,11 @@
import ctypes
import six

def _run_command_line():

def run_command_line():
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter,
description='Python command line CAMB reading parameters from a .ini file.' +
'\n\n Example usage:\n\n python camb.py inifiles/planck_2018.ini')
'\n\nSample .ini files are provided in the source distribution, e.g. see inifiles/planck_2018.ini')
parser.add_argument('ini_file', help='text .ini file with parameter settings')
parser.add_argument('--validate', action='store_true',
help='Just validate the .ini file, don''t actually run anything')
Expand All @@ -33,4 +35,4 @@ def _run_command_line():


if __name__ == "__main__":
_run_command_line()
run_command_line()
17 changes: 10 additions & 7 deletions camb/baseconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def __getitem__(self, name_or_ordinal):
else:

if not osp.isfile(CAMBL):
sys.exit(
'Library file %s does not exist.\nMake sure you have installed or built the camb package (or remove any old installation and install again).' % (
CAMBL))
sys.exit('Library file %s does not exist.\nMake sure you have installed or built the camb package '
'(e.g. using "python setup.py make"); or remove any old conflicting installation and install again.' % (
CAMBL))

camblib = ctypes.LibraryLoader(ifort_gfortran_loader).LoadLibrary(CAMBL)

Expand Down Expand Up @@ -86,19 +86,22 @@ def lib_import(module_name, class_name, func_name, restype=None):
return func


def set_filelocs():
HighLExtrapTemplate = osp.join(BASEDIR, "HighLExtrapTemplate_lenspotentialCls.dat")
def set_cl_template_file(cl_template_file=None):
if cl_template_file and not osp.exists(cl_template_file):
raise ValueError('File not found : %s' % cl_template_file)

HighLExtrapTemplate = cl_template_file or osp.join(BASEDIR, "HighLExtrapTemplate_lenspotentialCls.dat")
if not osp.exists(HighLExtrapTemplate):
HighLExtrapTemplate = osp.abspath(
osp.join(BASEDIR, "../../fortran", "HighLExtrapTemplate_lenspotentialCls.dat"))
osp.join(BASEDIR, "..", "..", "fortran", "HighLExtrapTemplate_lenspotentialCls.dat"))
HighLExtrapTemplate = six.b(HighLExtrapTemplate)
func = camblib.__handles_MOD_set_cls_template
func.argtypes = [ctypes.c_char_p, ctypes.c_long]
s = ctypes.create_string_buffer(HighLExtrapTemplate)
func(s, ctypes.c_long(len(HighLExtrapTemplate)))


set_filelocs()
set_cl_template_file()


def _get_fortran_sizes():
Expand Down
23 changes: 12 additions & 11 deletions camb/bbn.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ def Y_He(self, ombh2, delta_neff=0.):

class BBN_table_interpolator(BBNPredictor):
"""
BBN predictor based on interpolation on a table calculated from BBN code
BBN predictor based on interpolation from a numerical table calculated by a BBN code.
Tables are supplied for `Parthenope <http://parthenope.na.infn.it/>`_ 2017 (PArthENoPE_880.2_standard.dat, default),
similar but with Marucci rates (PArthENoPE_880.2_marcucci.dat), and `PRIMAT <http://www2.iap.fr/users/pitrou/primat.htm>`_ (PRIMAT_Yp_DH_Error.dat).
:param interpolation_table: filename of interpolation table to use.
:param function_of: two variables that determine the interpolation grid (x,y) in the table, matching top column label comment.
By default ombh2, DeltaN, and function argument names reflect that, but can also be used more generally.
"""

def __init__(self, interpolation_table='PArthENoPE_880.2_standard.dat', function_of=['ombh2', 'DeltaN']):
"""
Load table file and initialize interpolation
:param interpolation_table: filename of interpolation table to use.
:param function_of: two variables that determine the interpolation grid (x,y) in the table, matching top column label comment.
By default ombh2, DeltaN, and function argument names reflect that, but can also be used more generally.
"""

if os.sep not in interpolation_table and '/' not in interpolation_table:
interpolation_table = os.path.normpath(os.path.join(os.path.dirname(__file__), interpolation_table))
Expand Down Expand Up @@ -149,7 +150,7 @@ def get(self, name, ombh2, delta_neff=0., grid=False):

class BBN_fitting_parthenope(BBNPredictor):
"""
BBN predictions for Helium abundance using fitting formulae based on Parthenope (pre 2015)
Old BBN predictions for Helium abundance using fitting formulae based on Parthenope (pre 2015).
"""

def __init__(self, tau_neutron=None):
Expand Down Expand Up @@ -191,11 +192,11 @@ def DH(self, ombh2, delta_neff, tau_neutron=None):

def get_default_predictor():
"""
Get instance of default BBNPredictor class. Currently fitting formula to match Planck 2015 analysis.
Get instance of default BBNPredictor class. Currently numerical table interpolation as Planck 2018 analysis.
"""
global _default_predictor
if _default_predictor is None:
_default_predictor = BBN_fitting_parthenope()
_default_predictor = BBN_table_interpolator()
return _default_predictor


Expand Down
Binary file modified camb/cambdll.dll
Binary file not shown.
19 changes: 10 additions & 9 deletions camb/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AccuracyParams(CAMB_Structure):
_fields_ = [
("AccuracyBoost", c_double,
"general accuracy setting effecting everything related to step sizes etc. (including separate settings below except the next two)"),
("lSampleBoost", c_double, "accuracy for sampling in ell for interpolation for the C_l"),
("lSampleBoost", c_double, "accuracy for sampling in ell for interpolation for the C_l (if >=50, all ell are calculated)"),
("lAccuracyBoost", c_double, "Boosts number of multipoles integrated in Boltzman heirarchy"),
("AccuratePolarization", c_bool, "Do you care about the accuracy of the polarization Cls?"),
("AccurateBB", c_bool, "Do you care about BB accuracy (e.g. in lensing)"),
Expand Down Expand Up @@ -160,7 +160,7 @@ class in model.py to add the new parameter in the corresponding location of the
You could also modify the wrapper functions to set the field value less directly.
You can view the set of underlying parameters used by the Fortran code by printing the CAMBparams instance.
In python, to set cosmology parameters it is usually best to use :meth:`.model.CAMBparams.set_cosmology` and
In python, to set cosmology parameters it is usually best to use :meth:`set_cosmology` and
equivalent methods for most other parameters. Alternatively the convenience function :func:`.camb.set_params` can construct
a complete instance from a dictionary of relevant parameters.
Expand Down Expand Up @@ -227,7 +227,8 @@ class in model.py to add the new parameter in the corresponding location of the
("Do21cm", c_bool, "21cm is not yet implemented via the python wrapper"),
("transfer_21cm_cl", c_bool, "Get 21cm C_L at a given fixed redshift"),
("Log_lvalues", c_bool, "Use log spacing for sampling in L"),
("use_cl_spline_template", c_bool, "When interpolating use a fiducial spectrum shape to define ratio to spline"),
(
"use_cl_spline_template", c_bool, "When interpolating use a fiducial spectrum shape to define ratio to spline"),

("SourceWindows", AllocatableObjectArray(SourceWindow)),
("CustomSources", CustomSources)
Expand Down Expand Up @@ -586,11 +587,11 @@ def get_zre(self):
def get_Y_p(self, ombh2=None, delta_neff=None):
r"""
Get BBN helium nucleon fraction (NOT the same as the mass fraction Y_He) by intepolation using the
:class:`.bbn.BBNPredictor` instance passed to :meth:`.model.CAMBparams.set_cosmology`
:class:`.bbn.BBNPredictor` instance passed to :meth:`set_cosmology`
(or the default one, if `Y_He` has not been set).
:param ombh2: :math:`\Omega_b h^2` (default: value passed to :meth:`.model.CAMBparams.set_cosmology`)
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.046) (default: from values passed to :meth:`.model.CAMBparams.set_cosmology`)
:param ombh2: :math:`\Omega_b h^2` (default: value passed to :meth:`set_cosmology`)
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.046) (default: from values passed to :meth:`set_cosmology`)
:return: :math:`Y_p^{\rm BBN}` helium nucleon fraction predicted by BBN.
"""
try:
Expand All @@ -603,11 +604,11 @@ def get_Y_p(self, ombh2=None, delta_neff=None):
def get_DH(self, ombh2=None, delta_neff=None):
r"""
Get deuterium ration D/H by intepolation using the
:class:`.bbn.BBNPredictor` instance passed to :meth:`.model.CAMBparams.set_cosmology`
:class:`.bbn.BBNPredictor` instance passed to :meth:`set_cosmology`
(or the default one, if `Y_He` has not been set).
:param ombh2: :math:`\Omega_b h^2` (default: value passed to :meth:`.model.CAMBparams.set_cosmology`)
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.046) (default: from values passed to :meth:`.model.CAMBparams.set_cosmology`)
:param ombh2: :math:`\Omega_b h^2` (default: value passed to :meth:`set_cosmology`)
:param delta_neff: additional :math:`N_{\rm eff}` relative to standard value (of 3.046) (default: from values passed to :meth:`set_cosmology`)
:return: BBN helium nucleon fraction D/H
"""
try:
Expand Down
2 changes: 1 addition & 1 deletion camb/nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NonLinearModel(F2003Class):
halofit_casarini = 'casarini'
halofit_mead2015 = 'mead2015'

halofit_default = halofit_takahashi
halofit_default = halofit_mead

halofit_version_names = [halofit_original, halofit_bird, halofit_peacock, halofit_takahashi, halofit_mead,
halofit_halomodel, halofit_casarini, halofit_mead2015]
Expand Down
Loading

0 comments on commit 22c019b

Please sign in to comment.