Skip to content

Commit 727ecae

Browse files
committed
doc updates and hmcode tidies (thanks Alex Mead, Minh Nguyen)
1 parent ad4464f commit 727ecae

File tree

7 files changed

+44
-70
lines changed

7 files changed

+44
-70
lines changed

.travis.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,27 @@ branches:
1313

1414
jobs:
1515
include:
16-
- name: "GCC6 + Python 3.7"
17-
addons:
18-
apt:
19-
packages:
20-
- gfortran-6
21-
env:
22-
- GCC_VERSION="6"
23-
- CHANNEL="defaults"
24-
- PYDIST="ANACONDA"
25-
- FORTRAN="test"
26-
python: "3.7"
27-
- name: "GCC9 + Python 3.9 (anaconda)"
28-
addons:
29-
apt:
30-
sources:
31-
- sourceline: "ppa:ubuntu-toolchain-r/test"
32-
packages:
33-
- gfortran-9
34-
env:
35-
- GCC_VERSION="9"
36-
- PYDIST="ANACONDA"
37-
- CHANNEL="defaults"
38-
- FORTRAN="test"
39-
python: "3.9"
40-
- name: "Ubuntu 20.04 + Python 3.8"
16+
- name: "Ubuntu 20.04 + Python 3.7"
4117
dist: focal
4218
addons:
4319
apt:
4420
packages:
4521
- gfortran
46-
python: "3.10"
22+
python: "3.7"
4723
env:
4824
- PYPI_DIST="true"
49-
- name: "GCC10 + Python 3.9 (conda-forge)"
25+
- name: "GCC10 + Python 3.10 anaconda"
5026
dist: focal
5127
addons:
5228
apt:
5329
packages:
5430
- gfortran-10
5531
env:
5632
- GCC_VERSION="10"
57-
- FORTRAN="test"
58-
- CHANNEL="conda-forge"
33+
- CHANNEL="defaults"
5934
- PYDIST="ANACONDA"
60-
python: "3.9"
35+
- FORTRAN="test"
36+
python: "3.10"
6137
- name: "GCC trunk cosmobox"
6238
language: shell
6339
services:

README.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ To install from source, clone from github using::
3535

3636
git clone --recursive https://github.com/cmbant/CAMB
3737

38-
Then in the project source root directory use::
38+
Then install using::
3939

40-
python setup.py install [--user]
41-
42-
If you want to work on the code, you can also just install in place without copying anything using::
43-
44-
pip install -e . [--user]
40+
pip install -e ./CAMB [--user]
4541

4642
You will need gfortran 6 or higher installed to compile. Binary files for Windows are also provided, so these are used instead if no
4743
gfortran installation is found on Windows machines. If you have gfortran installed, "python setup.py make"

camb/cambdll.dll

0 Bytes
Binary file not shown.

docs/source/fortran_compilers.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you do not have a suitable Fortran compiler, you can get one as follows:
1717
:Mac:
1818
Download the `binary installation <https://gcc.gnu.org/wiki/GFortranBinaries>`_
1919
:Windows:
20-
Download gfortran as part of `MinGW-w64 <https://sourceforge.net/projects/mingw-w64/>`_ (select x86_64 option in the installation program)
20+
Download gfortran as part of `MinGW-w64 <https://sourceforge.net/projects/mingw-w64/files>`_ (select x86_64 option in the installation program)
2121
:Linux:
2222
To install from the standard repository use:
2323

@@ -74,4 +74,3 @@ If you want to automamatically rebuild the library from Jupyter you can do somet
7474

7575
except subprocess.CalledProcessError as E:
7676
print(E.output.decode())
77-

docs/source/index.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,36 @@ For a standard non-editable installation use::
1717
The --user is optional and only required if you don't have write permission to your main python installation.
1818
If you want to work on the code from `GitHub <https://github.com/cmbant/camb>`_, you can also just install in place without copying anything using::
1919

20-
pip install -e /path/to/CAMB [--user]
20+
git clone --recursive https://github.com/cmbant/CAMB.git
21+
pip install -e ./CAMB [--user]
2122

2223
You will need ifort or gfortran 6 or higher installed (and on your path) to compile; see :ref:`fortran-compilers` for
2324
compiler installation details if needed. A compiled library for Windows is also provided, and is used if no
24-
gfortran installation is found on Windows machines. If you have gfortrand installed, "python setup.py make" will build
25+
gfortran installation is found on Windows machines. If you have gfortran installed, "python setup.py make" will build
2526
the Fortran library on all systems (including Windows without directly using a Makefile), and can be used to update
2627
a source installation after changes or pulling an updated version.
2728

28-
Anaconda users can also install from conda-forge using::
29+
Anaconda users can also install from conda-forge, best making a new clean environment using::
2930

30-
conda install -c conda-forge camb
31+
conda create -n camb -c conda-forge python=3.9 camb
32+
activate camb
3133

3234
with no need for a Fortran compiler (unless you want to use custom sources/symbolic compilation features).
33-
Check that conda installs the latest version, if not try installing in a new clean conda environment.
35+
Check that conda installs the latest version, if not try installing
36+
in a new clean conda environment as above.
3437

3538
After installation the camb python module can be loaded from your scripts using "import camb".
39+
3640
You can also run CAMB from the command line reading parameters from a .ini file, e.g.::
3741

3842
camb inifiles/planck_2018.ini
3943

40-
You may need to check your python scripts directory is in your path for this to work.
41-
Alternatively from the source package root directory (after make but without installation) use::
44+
You may need to check your python scripts directory is in your path for this to work. Alternatively from the source package root directory (after make but without installation) use::
4245

4346
python camb.py inifiles/planck_2018.ini
4447

48+
Sample .ini files can be obtained from the `repository <https://github.com/cmbant/CAMB/tree/master/inifiles>`_. You can load parameters programmatically from an .ini file or URL using :func:`.camb.read_ini`.
49+
4550
Main high-level modules:
4651

4752
.. toctree::

fortran/halofit.f90

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ SUBROUTINE HMcode(this,State,CAMB_Pk)
617617
DO i=1,nk
618618
k=exp(CAMB_Pk%log_kh(i))
619619
plin=p_lin(k,z,0,cosi)
620-
CALL this%halomod(k,z,p1h,p2h,pfull,plin,lut,cosi)
620+
CALL this%halomod(k,p1h,p2h,pfull,plin,lut,cosi)
621621
IF(this%imead==3) THEN
622622
CAMB_Pk%nonlin_ratio(i,j)=sqrt(pfull/plin)
623623
ELSE IF(this%imead==4) THEN
@@ -641,7 +641,7 @@ SUBROUTINE HMcode(this,State,CAMB_Pk)
641641
DO i=1,nk
642642
k=exp(CAMB_Pk%log_kh(i))
643643
plin=p_lin(k,z,0,cosi)
644-
CALL this%halomod(k,z,p1h,p2h,pfull,plin,lut,cosi)
644+
CALL this%halomod(k,p1h,p2h,pfull,plin,lut,cosi)
645645
CAMB_Pk%nonlin_ratio(i,j)=sqrt(pfull/plin)
646646
END DO
647647
!$OMP END PARALLEL DO
@@ -844,11 +844,11 @@ FUNCTION r_nl(lut)
844844

845845
END FUNCTION r_nl
846846

847-
SUBROUTINE halomod(this,k,z,p1h,p2h,pfull,plin,lut,cosm)
847+
SUBROUTINE halomod(this,k,p1h,p2h,pfull,plin,lut,cosm)
848848
class(THalofit) :: this
849849
!Calcuates 1-halo and 2-halo terms and combines them to form the full halomodel power
850850
REAL(dl), INTENT(OUT) :: p1h, p2h, pfull
851-
REAL(dl), INTENT(IN) :: plin, k, z
851+
REAL(dl), INTENT(IN) :: plin, k
852852
REAL(dl) :: a
853853
TYPE(HM_cosmology), INTENT(IN) :: cosm
854854
TYPE(HM_tables), INTENT(IN) :: lut
@@ -859,7 +859,7 @@ SUBROUTINE halomod(this,k,z,p1h,p2h,pfull,plin,lut,cosm)
859859
p1h=0.
860860
p2h=0.
861861
ELSE
862-
p1h=this%p_1h(k,z,lut,cosm)
862+
p1h=this%p_1h(k,lut,cosm)
863863
p2h=this%p_2h(k,plin,lut,cosm)
864864
END IF
865865

@@ -1705,22 +1705,22 @@ FUNCTION p_2h(this,k,plin,lut,cosm)
17051705
kdamp=0.05699*lut%sig8z_cold**(-1.089)
17061706
ndamp=2.85
17071707
x=(k/kdamp)**ndamp
1708-
p_2h=p_dewiggle(k, lut%z, lut%sigv, cosm)*(1.-frac*x/(1.+x))
1708+
p_2h=p_dewiggle(k, lut%z, plin, lut%sigv, cosm)*(1.-frac*x/(1.+x))
17091709
END IF
17101710

17111711
!For some strange cosmologies frac>1. so this must be added to prevent p_2h<0.
17121712
IF(p_2h<0.) p_2h=0.
17131713

17141714
END FUNCTION p_2h
17151715

1716-
FUNCTION p_1h(this,k,z,lut,cosm)
1716+
FUNCTION p_1h(this,k,lut,cosm)
17171717
class(THalofit) :: this
17181718
!Calculates the 1-halo term
17191719
REAL(dl) :: p_1h
1720-
REAL(dl), INTENT(IN) :: k, z
1720+
REAL(dl), INTENT(IN) :: k
17211721
TYPE(HM_tables), INTENT(IN) :: lut
17221722
TYPE(HM_cosmology), INTENT(IN) :: cosm
1723-
REAL(dl) :: Dv, g, fac, et, ks, wk, x, m
1723+
REAL(dl) :: g, fac, et, ks, wk, x, m
17241724
REAL(dl) :: integrand(lut%n)
17251725
REAL(dl) :: sum
17261726
INTEGER :: i
@@ -1767,35 +1767,30 @@ FUNCTION p_1h(this,k,z,lut,cosm)
17671767

17681768
END FUNCTION p_1h
17691769

1770-
REAL FUNCTION p_dewiggle(k, z, sigv, cosm)
1770+
REAL FUNCTION p_dewiggle(k, z, p_linear, sigv, cosm)
17711771
! Call the dewiggled power spectrum, which is linear but with damped wiggles
1772-
REAL(dl), INTENT(IN) :: k
1773-
REAL(dl), INTENT(IN) :: z
1774-
REAL(dl), INTENT(IN) :: sigv
1772+
REAL(dl), INTENT(IN) :: k, z, p_linear, sigv
17751773
TYPE(HM_cosmology), INTENT(IN) :: cosm
1776-
REAL(dl) :: p_wiggle, f, p_linear, logk
1777-
INTEGER, PARAMETER :: itype = 0 ! Matter power here
1774+
REAL(dl) :: p_wiggle, f, logk
17781775
INTEGER, PARAMETER :: iorder = iorder_wiggle
17791776
INTEGER, PARAMETER :: ifind = ifind_wiggle
17801777
INTEGER, PARAMETER :: imeth = imeth_wiggle
17811778

1782-
p_linear = p_lin(k, z, itype, cosm)
17831779
logk = log(k)
17841780
IF (logk < cosm%log_k_wiggle(1) .OR. logk > cosm%log_k_wiggle(nk_wiggle)) THEN
1785-
p_wiggle = 0.
1781+
p_wiggle = 0
17861782
ELSE
1787-
p_wiggle = find(log(k), cosm%log_k_wiggle, cosm%pk_wiggle, nk_wiggle, iorder, ifind, imeth)
1783+
p_wiggle = find(logk, cosm%log_k_wiggle, cosm%pk_wiggle, nk_wiggle, iorder, ifind, imeth)
17881784
END IF
17891785
f = exp(-(k*sigv)**2)
1790-
p_dewiggle = p_linear+(f-1.)*p_wiggle*grow(z, cosm)**2
1786+
p_dewiggle = p_linear+(f-1)*p_wiggle*grow(z, cosm)**2
17911787

17921788
END FUNCTION p_dewiggle
17931789

17941790
SUBROUTINE init_wiggle(cosm)
17951791
! Isolate the power spectrum wiggle
17961792
TYPE(HM_cosmology), INTENT(INOUT) :: cosm
17971793
REAL(dl), ALLOCATABLE :: k(:), Pk(:)
1798-
REAL(dl), ALLOCATABLE :: logk(:), logPk(:)
17991794
REAL(dl), ALLOCATABLE :: Pk_smooth(:), Pk_wiggle(:)
18001795
INTEGER :: i
18011796
REAL(dl), PARAMETER :: kmin = kmin_wiggle
@@ -1857,7 +1852,6 @@ SUBROUTINE calculate_psmooth(k, z, Pk, Pk_smt, cosm)
18571852
REAL(dl), ALLOCATABLE, INTENT(OUT) :: Pk_smt(:)
18581853
REAL(dl), ALLOCATABLE :: Pk_nw(:)
18591854
TYPE(HM_cosmology), INTENT(IN) :: cosm
1860-
INTEGER :: ia, na
18611855
REAL(dl), PARAMETER :: sig = wiggle_sigma
18621856

18631857
! Reduce dynamic range
@@ -1880,7 +1874,7 @@ SUBROUTINE calculate_nowiggle(k, z, Pk, Pk_nw, cosm)
18801874
REAL(dl), INTENT(IN) :: Pk(:)
18811875
REAL(dl), ALLOCATABLE, INTENT(OUT) :: Pk_nw(:)
18821876
TYPE(HM_cosmology), INTENT(IN) :: cosm
1883-
INTEGER :: ik, ia, nk
1877+
INTEGER :: ik, nk
18841878
REAL(dl) :: Pk_norm, Pk_nw_norm
18851879
REAL(dl), PARAMETER :: knorm = knorm_nowiggle
18861880
INTEGER, PARAMETER :: type = 0 ! Matter here
@@ -3329,7 +3323,7 @@ REAL(dl) FUNCTION dc_Mead(z, cosm)
33293323
IMPLICIT NONE
33303324
REAL(dl), INTENT(IN) :: z
33313325
TYPE(HM_cosmology), INTENT(IN) :: cosm
3332-
REAL(dl) :: lg, bG, Om_m, ai, a
3326+
REAL(dl) :: lg, bG, Om_m, a
33333327

33343328
! See Appendix A of Mead (2017) for naming convention
33353329
REAL(dl), PARAMETER :: p10 = -0.0069

setup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def make_library(cluster=False):
122122
if not ok:
123123
print('WARNING: gfortran %s or higher not in path (if you just installed '
124124
'you may need to log off and on again).' % _compile.gfortran_min)
125-
print(' You can get a Windows gfortran build from https://sourceforge.net/projects/mingw-w64/')
126-
print(' - go to Files, and download MinGW-W64 Online Installer.')
125+
print(' You can get a Windows gfortran build from https://sourceforge.net/projects/mingw-w64/files/')
126+
print(' - go to Files, and download MinGW-W64 Online Installer.')
127127
if _compile.is_32_bit:
128128
raise IOError('No 32bit Windows DLL provided, you need to build or use 64 bit python')
129129
else:
@@ -192,6 +192,9 @@ def make_library(cluster=False):
192192
else:
193193
print('DLL up to date.')
194194
else:
195+
if not _compile.call_command('make -v'):
196+
raise IOError('Build failed - you must have "make" installed. '
197+
'E.g. on ubuntu install with "sudo apt install make" (or use build-essential package).')
195198
get_forutils()
196199
print("Compiling source...")
197200
subprocess.call("make python PYCAMB_OUTPUT_DIR=%s/camb/ CLUSTER_SAFE=%d" %
@@ -303,6 +306,7 @@ def run(self):
303306
'Programming Language :: Python :: 3.7',
304307
'Programming Language :: Python :: 3.8',
305308
'Programming Language :: Python :: 3.9'
309+
'Programming Language :: Python :: 3.10'
306310
],
307311
keywords=['cosmology', 'CAMB', 'CMB'],
308312
install_requires=['scipy>=1.0', 'sympy>=1.0'],

0 commit comments

Comments
 (0)