Skip to content

Commit

Permalink
tidy with cobaya 3.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed Aug 15, 2024
1 parent 3c58c01 commit a3cdc7f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
15 changes: 15 additions & 0 deletions mflike/Foreground.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ components:
ee:
- radio
- dust

# parameters that are always used
params:
beta_s: #beta radio
value: -2.5
latex: \beta_s
alpha_s: #alpha radio
value: 1.0
latex: \alpha_s
T_effd: #effective galactic dust temperature
value: 19.6
latex: T_{\mathrm{dust},\mathrm{eff}}
beta_d: #beta galactic dust
value: 1.5
latex: \beta_\mathrm{dust}
12 changes: 0 additions & 12 deletions mflike/fg_common.yaml

This file was deleted.

34 changes: 14 additions & 20 deletions mflike/foreground.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from cobaya.log import LoggedError
from cobaya.theory import Theory
from cobaya.yaml import yaml_load
from cobaya.typing import empty_dict
from scipy import constants

try:
Expand Down Expand Up @@ -75,24 +76,7 @@ def _cmb2bb(nu):
return np.exp(x) * (nu * x / np.expm1(x)) ** 2


class ForegroundParamsTheory(Theory):
# TODO: this class can be abolished once Cobaya allows class options and yaml for the same class

@classmethod
def get_class_options(cls, input_options={}):

options = super().get_class_options().copy()
if cls is ForegroundParamsTheory and (
param_requested_cls := input_options.get('requested_cls', ['tt', 'te', 'ee'])) \
or ('requested_cls' not in input_options and (param_requested_cls := options.get('requested_cls'))):
params = yaml_load(cls.get_text_file_content('fg_common.yaml'))
for spec in param_requested_cls:
params |= yaml_load(cls.get_text_file_content('fg_%s.yaml' % spec.upper()))
options["params"] = params
return options


class Foreground(ForegroundParamsTheory):
class Foreground(Theory):
normalisation: dict
components: dict
experiments: list[str]
Expand All @@ -102,6 +86,16 @@ class Foreground(ForegroundParamsTheory):
bandint_freqs: list
ells: np.ndarray

@classmethod
def get_modified_defaults(cls, defaults, input_options=empty_dict):
"""
Adds the appropriate foreground parameters based on the requested_cls
"""
requested_cls = input_options.get('requested_cls') or defaults.get('requested_cls', ['tt', 'te', 'ee'])
for spec in requested_cls:
defaults['params'] |= yaml_load(cls.get_text_file_content('fg_%s.yaml' % spec.upper()))
return defaults

# Initializes the foreground model. It sets the SED and reads the templates
def initialize(self):
"""
Expand Down Expand Up @@ -288,7 +282,7 @@ def get_foreground_model(self, ell=None, freqs_order=None, **fg_params):
used to compute the foreground components. Useful when
this class is called outside of mflike, used in place of
``self.experiments``
:param **fg_params: parameters of the foreground components
:param fg_params: parameters of the foreground components
:return: the foreground dictionary
"""
Expand Down Expand Up @@ -325,7 +319,7 @@ def calculate(self, state, want_derived=False, **params_values_dict):
:param state: ``state`` dictionary to be filled with computed foreground
spectra
:param want_derived: if derived wanted (none here)
:param **params_values_dict: dictionary of parameters from the sampler
:param params_values_dict: dictionary of parameters from the sampler
"""

state["fg_totals"] = self.get_foreground_model_totals(**params_values_dict)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ requires-python = ">=3.9.0"
dependencies = [
"fgspectra>=1.2.1",
"syslibrary>=0.2.0",
"cobaya>=3.5.2",
"cobaya>=3.5.4",
"sacc>=0.9.0",
]

Expand Down

0 comments on commit a3cdc7f

Please sign in to comment.