Skip to content

Commit

Permalink
changing yaml file path convention + small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiardie committed Sep 19, 2024
1 parent 449fcfe commit 785cacc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions mflike/Foreground.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ top_hat_band:
# or be read from a file (either from external file with name "rootname" or from sacc)
# - if Gaussian_beam = False/empty and beam_from_file = False/empty, it will be read from the sacc file (currently not working)
# - if Gaussian_beam = False/empty and beam_from_file is specified, it will be read from this file
# the file name has to be its absolute path without the yaml extension
# the file name has to be its absolute path, with the yaml extension
# it has to be a yaml with keys = experiments and items = array((freqs, ells))
# i.e. numpy arrays of beam profiles for each frequency in the passband of that array
# - If we want to compute Gaussian beams, fill the Gaussian_beam entry with dictionaries
# containing the parametrization for FWHM for each experiment/array in T and pol
# - If bandpass shifts are != 0 and you want to propagate them to the beams, you have to fill
# the Bandpass_shifted_beams key with the name of the file containing the dictionary
# with beam profiles for different values of Delta nu. As before, the file should be a yaml,
# and you should provide its absolute path without the ".yaml" extension.
# and you should provide its absolute path with the ".yaml" extension.
# The dictionary should contain a key for each experiment/array, and for each of these keys
# there should be a "nu_0", "alpha" and "beams" keys. The "beams" item would be a
# dictionary {"nu_0 + Delta nu": b_ell, "nu_0 + 2Delta nu": b'_ell,...}
Expand Down
22 changes: 6 additions & 16 deletions mflike/foreground.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
* reading the beams from the sacc file (``Gaussian_beam: False/null``, ``beam_from_file: False/null``).
The beams have to be stored in the ``sacc.tracers[exp].beam`` tracer
(this is not working so far, since the sacc beam tracer doesn't like an array(freq, ell))
* reading the beams from an external yaml file (``Gaussian_beam: False/null``, ``beam_from_file: filename``). ``filename`` has to be the absolute path for the file, without the ``.yaml`` extension,
* reading the beams from an external yaml file (``Gaussian_beam: False/null``, ``beam_from_file: filename``). ``filename`` has to be the absolute path for the file, with the ``.yaml/.yml`` extension,
which is automatically added by the code. The yaml file has to be a dictionary
``{"{exp}_s0": {"nu": nu, "beams": array(freqs, ells+2)}, "{exp}_s2": {"nu": nu, "beams": array(freqs, ells+2)},...}``
* computing the beams as Gaussian beams (``Gaussian_beam: dict``, ``beam_from_file: ...``). When
Expand Down Expand Up @@ -142,7 +142,7 @@
alpha: ...
...
``bandpass_shifted_beams`` has to be an absolute path, without the ``.yaml`` extension, which is added by the code.
``bandpass_shifted_beams`` has to be an absolute path, with the ``.yaml/.yml`` extension, which is added by the code.
It is important the keys of ``beam_profile["Bandpass_shifted_beams"]["{exp}_s0/2"]["beams"]`` are strings of floats representing the value of :math:`\Delta \nu` (if they are strings of int the code to read the associated beams would not work).
"""
Expand All @@ -151,10 +151,10 @@
import numpy as np
from cobaya.log import LoggedError
from cobaya.theory import Theory
from cobaya.yaml import yaml_load
from cobaya.yaml import yaml_load, yaml_load_file
from cobaya.typing import empty_dict
from typing import Optional
from scipy import constants
from itertools import product

try:
from numpy import trapezoid
Expand Down Expand Up @@ -533,7 +533,7 @@ def init_bandpowers(self):

self.bandsh_beams_path = self.beam_profile.get("Bandpass_shifted_beams")
if self.bandsh_beams_path:
self.bandpass_shifted_beams = self._read_yaml_file(self.bandsh_beams_path)
self.bandpass_shifted_beams = yaml_load_file(file_name = self.bandsh_beams_path)

self._bandint_shift_params = [f"bandint_shift_{f}" for f in self.experiments]
# default bandpass when shift is 0
Expand Down Expand Up @@ -725,14 +725,6 @@ def _bandpass_construction(self, _initialize=False, **params):
## the correction expected for a Gaussian beam in case of bandpass shift
## that should be applied to any beam profile
###########################################################################
def _read_yaml_file(self, file_path):

from cobaya.yaml import yaml_load_file

filename = "%s.yaml" % file_path
file = yaml_load_file(file_name = filename)

return file

def _init_beam_from_file(self):
"""
Expand All @@ -747,10 +739,9 @@ def _init_beam_from_file(self):
if not bool(self.beams):
raise ValueError("Beams not stored in sacc files!")
else:
self.beams = self._read_yaml_file(self.beam_file)
self.beams = yaml_load_file(file_name = self.beam_file)

#checking that the freq array is compatible with the bandpass one
from itertools import product
for exp, spin in product(self.experiments, ["s0", "s2"]):
key = f"{exp}_{spin}"
# checking nu is the same as the bandpass one
Expand All @@ -767,7 +758,6 @@ def _init_gauss_beams(self):
Computes the dictionary of beams for each frequency of self.experiments
"""
self.beams = {}
from itertools import product
for exp, spin in product(self.experiments, ["s0", "s2"]):
key = f"{exp}_{spin}"
gauss_pars = self.gaussian_params[key]
Expand Down
2 changes: 1 addition & 1 deletion mflike/tests/test_mflike.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def compute_FWHM(nu):
"mflike.BandpowerForeground":{
"beam_profile": {"Gaussian_beam": beam_params,
"Bandpass_shifted_beams": packages_path +
"/data/MFLike/v0.8/LAT_beam_bandshift"},
"/data/MFLike/v0.8/LAT_beam_bandshift.yaml"},
},
},
"params": cosmo_params | params,
Expand Down

0 comments on commit 785cacc

Please sign in to comment.