CAMB CMB power spectra at high L

Use of Healpix, camb, CLASS, cosmomc, compilers, etc.
Post Reply
Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 19 2019

Hello everyone, Dr. Lewis,

I am getting a warning stating that

Code: Select all

WARNING:root:getting CMB power spectra to higher L than calculated, may be innacurate/zeroed.
when attempting to get CMB spectra for T and E up to [math] = 8000.

I'm aware that those are very small scales. I'm trying to make Fisher matrix forecasts for the Simons Observatory and they'll have non-zero SNR at those scales, so I prefer not to throw them away.

I set an [math] for CAMB using camb.model.CAMBparams.set_for_lmax and I also specify the same [math] when calling camb.CAMBdata.get_cmb_power_spectra.

I don't understand why I'm getting this warning, when I supposedly have set the desired [math] already.

I appreciate any assistance.
Felipe Maldonado

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

Re: CAMB CMB power spectra at high L

Post by Antony Lewis » January 19 2019

It was because of the extra truncation when avoiding convolution tails in the lensed spectra.

I've just pushed a change to the github master branch (as of today, based on major upgrade to version 1.0) that should ensure that the lensed spectra go up to at least the requested lmax even when lmax>5000.

Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

Re: CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 20 2019

Thank you for your reply Dr. Lewis.

I updated to version 1.0.1 and tried again, and unfortunately, the warning persists.

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

Re: CAMB CMB power spectra at high L

Post by Antony Lewis » January 20 2019

From github? Check your ran "python setup.py make" (or build/install) to update the library file. If you still get it please paste the exact code you are using to reproduce the error.

Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

Re: CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 21 2019

I installed the newest version with PIP when I realized that it was there. I then installed it again from source and tried again. The warning persists.

I made this minimal example that produces the warning.

Code: Select all

import camb
print "Using CAMB version", camb.__version__

lmax = 8000

pars = camb.CAMBparams()
pars.set_cosmology(H0=67.5, ombh2=0.022, omch2=0.122, mnu=0.06, omk=0, tau=0.06)
pars.set_nonlinear_lensing(True)
pars.set_for_lmax(lmax, lens_potential_accuracy=1)

cambresults = camb.get_results( pars )

powers = cambresults.get_cmb_power_spectra\
(pars, lmax=lmax, spectra=['total', 'unlensed_scalar'], CMB_unit='muK', raw_cl=True)
The output it produces is

Code: Select all

Using CAMB version 1.0.1
WARNING:root:getting CMB power spectra to higher L than calculated, may be innacurate/zeroed.
WARNING:root:getting CMB power spectra to higher L than calculated, may be innacurate/zeroed.

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

Re: CAMB CMB power spectra at high L

Post by Antony Lewis » January 21 2019

Thanks for the code, though that works OK for me: check "camb.__file__" gives the path of the github version (e.g. perhaps you have previous pip installation being loaded from your path instead?)

Using

Code: Select all

pip uninstall camb
pip install -e /path/to/git/camb
is probably the way to go.

Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

Re: CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 22 2019

Hello Dr. Lewis,

I uninstalled CAMB with pip and then reinstalled it from source, now the version is 1.0.2 and the example above doesn't produce the warning anymore.

However, my code still produces the warning (and is also running on the same version 1.0.2).

I'll find what is different and post another example where the warning is happening again.

Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

Re: CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 23 2019

Hello Dr. Lewis.

I reproduced the warning once more, it seems that it's tied to changing of cosmological parameters, which is necessary for me because I need to take derivatives in order to compute Fisher matrices.

The example below won't run as is without two more modules, and I apologize for that but I feared the example would get too convoluted to be understandable. I attempted to attach the files to this post, but it says the files are invalid. I can share them over email if it would help.

Code: Select all

import camb
print "Using CAMB version", camb.__version__
print "Located at", camb.__file__


import copy

#this is just a dictionary with values of the Planck 2018 cosmological parameters
from planck2018 import cosmology as fiducial_cosmology

#this modifies the dictionary to change the cosmology slightly
import cosmology_modifier

#cosmological_parameters = ['w_b', 'w_DM', 'tau', 'n', 'ln10As', 'mnu', 'nnu', 'omega_lambda_0']


lmax = 8000


def getCAMBpars( cosmology, lmax ):
    '''
    Given a cosmology, sets parameters for CAMB and returns a CAMBdata instance.
    '''

    pars = camb.CAMBparams()

    #set cosmology
    pars.set_cosmology(H0=cosmology['h']*100.0, ombh2=cosmology['w_b'], omch2=cosmology['w_DM']\
                       , omk=cosmology['omega_k_0'], num_massive_neutrinos=cosmology['num_massive_neutrinos'],\
                       mnu=cosmology['mnu'], nnu=cosmology['nnu'], meffsterile=cosmology['meffsterile'],\
                       standard_neutrino_neff=cosmology['standard_neutrino_neff'], tau=cosmology['tau']\
                       , TCMB = cosmology['Tcmb']/(1.0E6) )

    pars.InitPower.set_params(As=cosmology['As'], ns=cosmology['n'])
    
    pars.set_nonlinear_lensing(True)
    
    pars.set_for_lmax(lmax, lens_potential_accuracy=1);
    
    return pars


def get_TP_Cl( cambresults, cosmology, lmax ):

    #give CAMB the cosmology, which might be slightly different from the cosmology the results were built from
    cambpars = getCAMBpars( cosmology, lmax )
    
    #get the power spectrum you want, without recalculating cambresults
    powers = cambresults.\
    get_cmb_power_spectra(cambpars, lmax=lmax, spectra=['total', 'unlensed_scalar'], CMB_unit='muK', raw_cl=True)
    
    return powers


fiducial_cambpars = getCAMBpars( fiducial_cosmology, lmax )
cambresults = camb.get_results( fiducial_cambpars )

#get CMB T and E spectra for fiducial cosmology
cl = get_TP_Cl( cambresults, fiducial_cosmology, lmax )


#return to fiducial cosmology
perturbed_cosmology = copy.deepcopy( fiducial_cosmology )

#modify dimensionless baryon density in Hubble units
cosmology_modifier.modify_cosmology\
( perturbed_cosmology, fiducial_cosmology, 'w_b', cosmology_modifier.POSITIVE_STEP, keep_flatness = False)

#get CMB T and E spectra for slightly modified cosmology
cl = get_TP_Cl( cambresults, perturbed_cosmology, lmax )


#return to fiducial cosmology
perturbed_cosmology = copy.deepcopy( fiducial_cosmology )

#modify amplitude of primordial fluctuations
cosmology_modifier.modify_cosmology\
( perturbed_cosmology, fiducial_cosmology, 'ln10As', cosmology_modifier.POSITIVE_STEP, keep_flatness = False)

#get CMB T and E spectra for slightly modified cosmology
cl = get_TP_Cl( cambresults, perturbed_cosmology, lmax )


#return to fiducial cosmology
perturbed_cosmology = copy.deepcopy( fiducial_cosmology )

#modify optical depth to reionization
cosmology_modifier.modify_cosmology\
( perturbed_cosmology, fiducial_cosmology, 'tau', cosmology_modifier.POSITIVE_STEP, keep_flatness = False)

#get CMB T and E spectra for slightly modified cosmology
cl = get_TP_Cl( cambresults, perturbed_cosmology, lmax )


#return to fiducial cosmology
perturbed_cosmology = copy.deepcopy( fiducial_cosmology )

#modify dimensionless dark matter density in Hubble units
cosmology_modifier.modify_cosmology\
( perturbed_cosmology, fiducial_cosmology, 'w_DM', cosmology_modifier.POSITIVE_STEP, keep_flatness = False)

#get CMB T and E spectra for slightly modified cosmology
cl = get_TP_Cl( cambresults, perturbed_cosmology, lmax )
In short, what I'm doing is giving CAMB the cosmological parameter values from the best fit cosmology of Planck 2018. I then calculate CMB T and E power spectra for this fiducial cosmology. (no warnings up to this point)

Then I increase [math] by 0.1% and recalculate the power spectra. I use a camb.results instance so not everything has to be recalculated, but I do inform CAMB of the modified cosmology. The warnings appear here.

I then return to the fiducial cosmology and now modify [math], and I get no warnings. I also don't get any warnings in the next step when I modify [math] but the warnings appear again when I change [math].

I'm afraid I don't understand this behavior.
I appreciate your assistance.
Felipe Maldonado

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

Re: CAMB CMB power spectra at high L

Post by Antony Lewis » January 23 2019

Looks like it is because you are are looking at a non-flat model. The change I made only works for flat (I wouldn't at all count on the non-flat result being accurate out to L~8000 - it's not something I have tested). I just pushed a change to master branch that may make it also work for non-flat.

Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

Re: CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 23 2019

I updated to the latest version and tried again, and the warnings persist.

I understand if it's not reliable out to such high $\ell$, but why would it only raise the warning for the density parameters and not for the other two, nor for the fiducial cosmology?

What is the maximum $\ell$ at which the power spectrum is still accurate?

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

Re: CAMB CMB power spectra at high L

Post by Antony Lewis » January 23 2019

Changing As and tau doesn't change the background so it remains flat.
Check you have this (I think I forgot to push it until a few hours ago).

I don't know where non-flat models are accurate up to, but should be fine at L<3000. Probably you don't really want non-flat anyway? (keeping thetastar and omega_k fixed is usually what people really want when varying other parameters for doing Fisher-like things).

Felipe Maldonado
Posts: 19
Joined: November 10 2016
Affiliation: FSU

Re: CAMB CMB power spectra at high L

Post by Felipe Maldonado » January 25 2019

Just in case I performed another clean installation of CAMB because I wasn't able to verify that the change you just mentioned was present in the version I had. The warnings disappeared completely both in the example code and in the real code.

Up to this point I had made the decision to allow curvature, since Planck and other analysis teams allow it, plus it's a more conservative choice (there's less information in total if it has to leak into $\Omega_{K}$). But I will try turning flatness off in the future.

Thank you for your assistance, Dr. Lewis.

Post Reply