Page 1 of 1

Saving Cls and mpk from cobaya

Posted: April 09 2025
by Tristan L Smith
I am interested in running cobaya with a specific set of cosmological parameters and having it save the Cls and matter power spectrum. Is there a quick way to do this?

Re: Saving Cls and mpk from cobaya

Posted: April 09 2025
by Tristan L Smith
After poking around a bit, I found a way to do this:

Code: Select all

import cobaya
import numpy as np
from cobaya.yaml import yaml_load
from cobaya.model import get_model

yaml_file='./XXX.yaml' #your yaml file

info = yaml_load(yaml_file)
model = get_model(info)

point = dict(zip(model.parameterization.sampled_params(),model.prior.sample(ignore_external=True)[0]))

logposterior = model.logposterior(point, as_dict=True)

Cls = model.provider.get_Cl(ell_factor=True)

np.savez('Cls.npz',  Cls)

Re: Saving Cls and mpk from cobaya

Posted: April 09 2025
by Tristan L Smith
and I forgot to add that I put

Code: Select all

sampler:
  evaluate:
in my yaml file.