Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,43 @@

# Import SOLikeT (for autodoc)
import sys

sys.path.insert(0, "..")

# Create some mock imports
from unittest import mock

MOCK_MODULES = ["cosmopower", "tensorflow", "pyccl", "camb"]
for module in MOCK_MODULES:
sys.modules[module] = mock.Mock()

import soliket

__all__ = ['soliket']
__all__ = ["soliket"]

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'SOLikeT'
copyright = '2023, The SO Collaboration'
author = 'The SO Collaboration'
project = "SOLikeT"
copyright = "2023, The SO Collaboration"
author = "The SO Collaboration"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc", # Generate doc pages from source docstrings
"sphinx.ext.viewcode", # Generate links to source code
"sphinx.ext.mathjax", # Mathematical symbols
"sphinx_rtd_theme", # readthedocs theme
"sphinx.ext.autodoc", # Generate doc pages from source docstrings
"sphinx.ext.viewcode", # Generate links to source code
"sphinx.ext.mathjax", # Mathematical symbols
"sphinx_rtd_theme", # readthedocs theme
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
124 changes: 124 additions & 0 deletions examples/example_2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
debug: False

# Choose a sampler.
# Running the evaluate sampler will compute the likelihood
# only at a single value of parameters
sampler:
evaluate: null

# Specify the output location and file prefix
output: output/example_2

# Specify which Likelihoods we would like to use
# Any options for the Likelihood will use their default values unless specified here
# In this case the options and defaults are specified in soliket/mflike/MFLike.yaml
# Note that MFLike is a Cobaya `installable likelihood`.
# When running this yaml file, or calling `cobaya-install example_1.yaml` the required
# installable components will automatically be downloaded and installed.
# Note that for the soliket MFLike likelihood we are required to calculate:
# - CMB theory power spectra (from CAMB theory below)
# - Multi-frequency bandpass calibrations (from soliket.BandPass theory below)
# - Multi-frequency foregrounds (from soliket.Foreground theory below)
# - The combination of the above components (from soliket.TheoryForge_MFLike theory below)
likelihood:
soliket.MFLike:
data_folder: MFLike/v0.8
input_file: LAT_simu_sacc_00000.fits
cov_Bbl_file: data_sacc_w_covar_and_Bbl.fits
lmax_theory: 1500
defaults:
polarizations: ['TT', 'TE', 'ET', 'EE']
scales:
TT: [30, 1500]
TE: [30, 1500]
ET: [30, 1500]
EE: [30, 1500]
symmetrize: False
lcuts: 1500

# Specify the Theory codes which will compute observables to be compared with the data
# in the Likelihood.
# Here we specify the CAMB Einstein-Boltzmann code, with a number of choices made on
# precision and neutrino model.
theory:
soliket.CosmoPower:
network_path: soliket/cosmopower/data/CP_paper
network_settings:
tt:
type: NN
log: True
filename: cmb_TT_NN
has_ell_factor: False
ee:
type: NN
log: True
filename: cmb_EE_NN
has_ell_factor: False
te:
type: PCAplusNN
log: False
filename: cmb_TE_PCAplusNN
has_ell_factor: False

soliket.BandPass:
stop_at_error: True

soliket.Foreground:
stop_at_error: True
spectra:
polarizations: ["tt", "te", "ee"]
lmin: 2
lmax: 1500
exp_ch: ["LAT_150"]
eff_freqs: [150.]

soliket.TheoryForge_MFLike:
spectra:
polarizations: ['tt', 'te', 'ee']
lmin: 2
lmax: 1500
stop_at_error: True

# Specify the parameter values at which to compute the likelihood
params:
H0:
latex: H_0
derived: 'lambda h: h * 100.'
h:
latex: h_0
value: 0.677
logA:
# Dropped parameters are sampled but not passed to Likelihood/Theory codes
# Here it is As (specified below) which is passed to the Likelihood/Theory code.
# drop: true
latex: \log(10^{10} A_\mathrm{s})
value: 3.05
As:
value: 'lambda logA: 1e-10*np.exp(logA)'
ombh2:
latex: \Omega_\mathrm{b} h^2
value: 0.0224
omch2:
latex: \Omega_c h^2
value: 0.1202
ns:
latex: n_s
value: 0.9649
Alens:
latex: A_lens
value: 1.0
tau:
latex: \tau_\mathrm{reio}
value: 0.0554
mnu1:
value: 0.0
drop: True
mnu2:
value: 'lambda: np.sqrt(7.5e-5)'
drop: True
mnu3:
value: 'lambda: np.sqrt(2.5e-3)'
drop: True
mnu:
value: 'lambda mnu1, mnu2 ,mnu3: mnu1 + mnu2 + mnu3'
latex: \sum m_\nu
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
https://soliket.readthedocs.io/en/latest/developers.html#checking-code-in-development
"""

if 'test' in sys.argv:
if "test" in sys.argv:
print(TEST_HELP)
sys.exit(1)

Expand All @@ -44,7 +44,7 @@
https://soliket.readthedocs.io/en/latest/developers.html#documentation
"""

if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv:
if "build_docs" in sys.argv or "build_sphinx" in sys.argv:
print(DOCS_HELP)
sys.exit(1)

Expand All @@ -59,5 +59,9 @@
version = '{version}'
""".lstrip()

setup(use_scm_version={'write_to': os.path.join('soliket', 'version.py'),
'write_to_template': VERSION_TEMPLATE})
setup(
use_scm_version={
"write_to": os.path.join("soliket", "version.py"),
"write_to_template": VERSION_TEMPLATE,
}
)
8 changes: 6 additions & 2 deletions soliket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
from .ccl import CCL
from .clusters import ClusterLikelihood
from .cosmopower import CosmoPower, CosmoPowerDerived
from .cross_correlation import (CrossCorrelationLikelihood,
GalaxyKappaLikelihood, ShearKappaLikelihood)
from .cross_correlation import (
CrossCorrelationLikelihood,
GalaxyKappaLikelihood,
ShearKappaLikelihood,
)
from .foreground import Foreground
from .gaussian import GaussianLikelihood, MultiGaussianLikelihood
from .lensing import LensingLikelihood, LensingLiteLikelihood
from .mflike import MFLike, TheoryForge_MFLike

# from .studentst import StudentstLikelihood
from .ps import BinnedPSLikelihood, PSLikelihood
from .xcorr import XcorrLikelihood
Expand Down
72 changes: 45 additions & 27 deletions soliket/bandpass/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ class BandPass(Theory):
external_bandpass: dict

def initialize(self):

self.expected_params_bp = ["bandint_shift_LAT_93",
"bandint_shift_LAT_145",
"bandint_shift_LAT_225"]
self.expected_params_bp = [
"bandint_shift_LAT_93",
"bandint_shift_LAT_145",
"bandint_shift_LAT_225",
]

self.exp_ch = None
# self.eff_freqs = None
Expand All @@ -148,37 +149,46 @@ def initialize(self):

self.bandint_external_bandpass = bool(self.external_bandpass)
if self.bandint_external_bandpass:
path = os.path.normpath(os.path.join(self.data_folder,
self.external_bandpass["path"]))
path = os.path.normpath(
os.path.join(self.data_folder, self.external_bandpass["path"])
)
arrays = os.listdir(path)
self._init_external_bandpass_construction(path, arrays)

if (not self.read_from_sacc and not self.use_top_hat_band
and not self.bandint_external_bandpass):
if (
not self.read_from_sacc
and not self.use_top_hat_band
and not self.bandint_external_bandpass
):
raise LoggedError(
self.log, "fill the dictionaries in the yaml file for"
"either reading the passband from sacc file (mflike default)"
"or an external passband or building a top-hat one!"
self.log,
"fill the dictionaries in the yaml file for"
"either reading the passband from sacc file (mflike default)"
"or an external passband or building a top-hat one!",
)

def initialize_with_params(self):
# Check that the parameters are the right ones
differences = are_different_params_lists(
self.input_params, self.expected_params_bp,
name_A="given", name_B="expected")
self.input_params,
self.expected_params_bp,
name_A="given",
name_B="expected",
)
if differences:
raise LoggedError(
self.log, "Configuration error in parameters: %r.",
differences)
self.log, "Configuration error in parameters: %r.", differences
)

def must_provide(self, **requirements):
# bandint_freqs is required by Foreground
# and requires some params to be computed
# Assign those from Foreground
if "bandint_freqs" in requirements:
self.bands = requirements["bandint_freqs"]["bands"]
self.exp_ch = [k.replace("_s0", "") for k in self.bands.keys()
if "_s0" in k]
self.exp_ch = [
k.replace("_s0", "") for k in self.bands.keys() if "_s0" in k
]

def calculate(self, state, want_derived=False, **params_values_dict):
r"""
Expand Down Expand Up @@ -231,7 +241,7 @@ def _bandpass_construction(self, **params):
data_are_monofreq = False
bandint_freqs = []
for ifr, fr in enumerate(self.exp_ch):
bandpar = 'bandint_shift_' + str(fr)
bandpar = "bandint_shift_" + str(fr)
bands = self.bands[f"{fr}_s0"]
nu_ghz, bp = np.asarray(bands["nu"]), np.asarray(bands["bandpass"])
if self.use_top_hat_band:
Expand All @@ -240,19 +250,25 @@ def _bandpass_construction(self, **params):
self.bandint_width = np.full_like(
self.exp_ch, self.bandint_width, dtype=float
)
if self.bandint_nsteps > 1 and np.any(np.array(self.bandint_width) == 0):
if self.bandint_nsteps > 1 and np.any(
np.array(self.bandint_width) == 0
):
raise LoggedError(
self.log, "One band has width = 0, \
set a positive width and run again"
self.log,
"One band has width = 0, \
set a positive width and run again",
)
# Compute central frequency given bandpass
fr = nu_ghz @ bp / bp.sum()
if self.bandint_nsteps > 1:
bandlow = fr * (1 - self.bandint_width[ifr] * .5)
bandhigh = fr * (1 + self.bandint_width[ifr] * .5)
nub = np.linspace(bandlow + params[bandpar],
bandhigh + params[bandpar],
self.bandint_nsteps, dtype=float)
bandlow = fr * (1 - self.bandint_width[ifr] * 0.5)
bandhigh = fr * (1 + self.bandint_width[ifr] * 0.5)
nub = np.linspace(
bandlow + params[bandpar],
bandhigh + params[bandpar],
self.bandint_nsteps,
dtype=float,
)
tranb = _cmb2bb(nub)
tranb_norm = np.trapz(_cmb2bb(nub), nub)
bandint_freqs.append([nub, tranb / tranb_norm])
Expand Down Expand Up @@ -313,7 +329,9 @@ def _external_bandpass_construction(self, **params):
if not hasattr(bp, "__len__"):
bandint_freqs.append(nub)
bandint_freqs = np.asarray(bandint_freqs)
self.log.info("bandpass is delta function, no band integration performed")
self.log.info(
"bandpass is delta function, no band integration performed"
)
else:
trans_norm = np.trapz(bp * _cmb2bb(nub), nub)
trans = bp / trans_norm * _cmb2bb(nub)
Expand Down
Loading