Skip to content

Commit

Permalink
Merge pull request #86 from simonsobs/restructure
Browse files Browse the repository at this point in the history
Refactor for SoLikeT
  • Loading branch information
cmbant authored Sep 4, 2024
2 parents 660e0fa + 37e1022 commit 37048c1
Show file tree
Hide file tree
Showing 32 changed files with 1,606 additions and 1,411 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
if: matrix.os == 'macos-latest'
run: |
set -x
sudo ln -s /opt/homebrew/bin/gfortran-11 /usr/local/bin/gfortran
sudo ln -s /opt/homebrew/bin/gfortran-12 /usr/local/bin/gfortran
gfortran --version
- name: Install dependencies via pip
Expand Down
21 changes: 21 additions & 0 deletions docs/source/foreground.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
``foreground`` – Application of foregrounds with bandpass
=========================================================

.. automodule:: mflike.foreground

``Foreground`` class content
-----------------------------

.. autoclass:: mflike.Foreground
:exclude-members: initialize
:members:
:show-inheritance:
:private-members:
:member-order: bysource

.. autoclass:: mflike.BandpowerForeground
:exclude-members: initialize
:members:
:show-inheritance:
:private-members:
:member-order: bysource
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
:caption: API

mflike.rst
theoryforge.rst
foreground.rst
236 changes: 37 additions & 199 deletions docs/source/notebooks/tutorial_fisher.ipynb

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions docs/source/notebooks/tutorial_foregrounds.ipynb

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions docs/source/notebooks/tutorial_loading.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"mflike_input_file = dict(\n",
" input_file=\"LAT_simu_sacc_00044.fits\", cov_Bbl_file=\"data_sacc_w_covar_and_Bbl.fits\"\n",
")\n",
"mflike_config = {\"mflike.MFLike\": mflike_input_file}"
"mflike_config = {\"mflike.TTTEEE\": mflike_input_file}"
]
},
{
Expand Down Expand Up @@ -306,7 +306,8 @@
"tags": []
},
"source": [
"We finally put everything into a dictionary to push it into `cobaya` configuration system. Here for the purpose of this tutorial, we use `camb` as Boltzmann solver with minimal settings. Another configuration `high_accuracy_settings` is also provided and you can switch within the `info` object"
"We finally put everything into a dictionary to push it into `cobaya` configuration system. Here for the purpose of this tutorial, we use `camb` as Boltzmann solver with minimal settings. Another configuration `high_accuracy_settings` is also provided and you can switch within the `info` object. \n",
"The likelihood also depends on the foreground model, the default model for which can also be obtained from mflike.BandpowerForeground."
]
},
{
Expand Down Expand Up @@ -339,7 +340,8 @@
"info = {\n",
" \"params\": cosmo_params | fg_params | nuisance_params,\n",
" \"likelihood\": mflike_config,\n",
" \"theory\": {\"camb\": {\"extra_args\": minimal_settings}},\n",
" \"theory\": {\"camb\": {\"extra_args\": minimal_settings},\n",
" \"mflike.BandpowerForeground\": None},\n",
" \"packages_path\": packages_path,\n",
"}"
]
Expand Down Expand Up @@ -416,7 +418,7 @@
},
"outputs": [],
"source": [
"mflike = model.likelihood[\"mflike.MFLike\"]"
"mflike = model.likelihood[\"mflike.TTTEEE\"]"
]
},
{
Expand Down Expand Up @@ -450,7 +452,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.5"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
54 changes: 30 additions & 24 deletions docs/source/notebooks/tutorial_logp_value.ipynb

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions docs/source/notebooks/tutorial_residuals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"tags": []
},
"source": [
"To take into account the systematics, we call the `mflike.ThFo.get_modified_theory` function. In this function, we need to use the same $\\ell$ range set by the data through the variable `l_bpws`, that is why we generated the theory spectra using the `mflike.l_bpws` ell range. (Notice that `dls` has a multipole range of `2, mflike.l_bpws[-1]`)."
"To take into account the systematics, we call the `mflike.get_modified_theory` function. In this function, we need to use the same $\\ell$ range set by the data through the variable `l_bpws`, that is why we generated the theory spectra using the `mflike.l_bpws` ell range. (Notice that `dls` has a multipole range of `2, mflike.l_bpws[-1]`)."
]
},
{
Expand All @@ -171,7 +171,9 @@
"source": [
"ell = mflike.l_bpws\n",
"dls_cmb = {mode: dls[mode][ell] for mode in [\"tt\", \"te\", \"ee\", \"bb\"]}\n",
"dl_obs = mflike.ThFo.get_modified_theory(dls_cmb, **fg_params, **nuisance_params)"
"foreground_model = model.theory[\"mflike.BandpowerForeground\"]\n",
"fg_totals = foreground_model.get_fg_totals()\n",
"dl_obs = mflike.get_modified_theory(dls_cmb, fg_totals, **nuisance_params)"
]
},
{
Expand Down Expand Up @@ -201,7 +203,7 @@
"source": [
"## Simulated data *vs.* data model\n",
"\n",
"We start by plotting unbinned theory + foreground model with the total power spectrum modified by the systematics for a bunch of simulated files. Let's first start by retrieving the foreground model"
"We start by plotting unbinned theory + foreground model with the total power spectrum modified by the systematics for a bunch of simulated files. Let's first start by retrieving the foreground model as a dictionary"
]
},
{
Expand All @@ -217,7 +219,7 @@
},
"outputs": [],
"source": [
"fg_models = mflike.ThFo._get_foreground_model(ell=ell, **fg_params)"
"fg_models = foreground_model.get_foreground_model(ell=ell, **fg_params)"
]
},
{
Expand All @@ -231,7 +233,7 @@
"tags": []
},
"source": [
"To load `MFLike` for different simulated data file, we will use the external way as described in the last part of this [tutorial](tutorial_logp_value.ipynb). Altough the `spec_meta` attribute holds the different spectra, there is no easy way to extract a specific cross and/or mode. Here we will built a dictionnary indexed on spectrum mode and cross experiments to be latter used by the plotting function (the `contextmanager` is just to catch and flush the `logging` messages when initializing `MFLike` likelihood)"
"To load `MFLike` for different simulated data file, we will use the external way as described in the last part of this [tutorial](tutorial_logp_value.ipynb). Altough the `spec_meta` attribute holds the different spectra, there is no easy way to extract a specific cross and/or mode. Here we will built a dictionary indexed on spectrum mode and cross experiments to be latter used by the plotting function (the `contextmanager` is just to catch and flush the `logging` messages when initializing `MFLike` likelihood)"
]
},
{
Expand Down Expand Up @@ -265,7 +267,7 @@
"import logging\n",
"from contextlib import contextmanager\n",
"\n",
"from mflike import MFLike\n",
"from mflike import TTTEEE\n",
"from tqdm.auto import tqdm\n",
"\n",
"\n",
Expand All @@ -284,7 +286,7 @@
"for isim in tqdm(range(nsims)):\n",
" input_file = dict(input_file=f\"LAT_simu_sacc_{isim:05d}.fits\")\n",
" with disable_logging():\n",
" ext_mflike = MFLike(mflike_input_file | input_file, packages_path=packages_path)\n",
" ext_mflike = TTTEEE(mflike_input_file | input_file, packages_path=packages_path)\n",
" for data in ext_mflike.spec_meta:\n",
" lb, db = data.get(\"leff\"), data.get(\"cl_data\")\n",
" cross = (data.get(\"t1\"), data.get(\"t2\"))\n",
Expand Down Expand Up @@ -493,7 +495,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.11.5"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
Expand Down
14 changes: 0 additions & 14 deletions docs/source/theoryforge.rst

This file was deleted.

29 changes: 15 additions & 14 deletions examples/mflike_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ likelihood:
input_file: LAT_simu_sacc_00044.fits
cov_Bbl_file: data_sacc_w_covar_and_Bbl.fits

theory:
camb:
stop_at_error: False
extra_args:
kmax: 10
k_per_logint: 130
nonlinear: True
lens_potential_accuracy: 8
lens_margin: 2050
AccuracyBoost: 2.0
lSampleBoost: 2.0
lAccuracyBoost: 2.0
DoLateRadTruncation: False
mflike.BandpowerForeground:

params:
# Sampled
cosmomc_theta:
Expand Down Expand Up @@ -66,20 +81,6 @@ params:
value: 9.60
latex: T_d

theory:
camb:
stop_at_error: False
extra_args:
kmax: 10
k_per_logint: 130
nonlinear: True
lens_potential_accuracy: 8
lens_margin: 2050
AccuracyBoost: 2.0
lSampleBoost: 2.0
lAccuracyBoost: 2.0
DoLateRadTruncation: False


sampler:
mcmc:
Expand Down
11 changes: 11 additions & 0 deletions mflike/EE.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Specify default set of spectra and scale cuts
# to be used
requested_cls: [ "ee" ]
defaults:
# Which spectra?
polarizations: [ EE ]
# Scale cuts (in ell) for each spectrum
scales:
EE: [ 30, 9000 ]

params: !defaults [ mflike_common, calib_E ]
63 changes: 63 additions & 0 deletions mflike/Foreground.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
requested_cls: [ "tt", "te", "ee" ]
lmin: 2
lmax: 6001
# ells set automatically from above if not set directly
ells:
experiments: [ "LAT_93", "LAT_145", "LAT_225" ]
bandint_freqs: [ 93.0, 145.0, 225.0 ]
# Parameters to build a top-hat band:
# - nsteps sets the number of frequencies used in the band integration
# - bandwidth sets the relative width of the band wrt the central frequency
# the central frequency of each band is set from the bands stored in the sacc file
# - with nstep: 1, bandwidth must be 0
# Dirac delta bandpass, no band integration
# useful if you don't want to do band integration
# when the bandpasses in the sacc file are multifrequency
# the freq used is the effective frequency from the bandpass
# - if nstep > 1, bandwidth must be > 1
# bandwidth can be a list if you want a different width for each band
# e.g. bandwidth: [0.3,0.2,0.3] for 3 bands
# when top_hat_band is a null dict: no top-hat band is built and
# bandpasses read from sacc file. Band integration is performed accordingly
# (if bandpass in sacc is a single freq, no band integration)
# the default is to read bandpasses from file, to build top-hat uncomment the
# parameters of the block!
# Bandpass has to be divided by nu^2 if measured with respect to a RJ source
# the nu^2 factor is set back again in the _bandpass_construction function
top_hat_band:
# nsteps: 1
# bandwidth: 0

normalisation:
nu_0: 150.0
ell_0: 3000
T_CMB: 2.725

components:
tt:
- kSZ
- tSZ_and_CIB
- cibp
- dust
- radio
te:
- radio
- dust
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}
Loading

0 comments on commit 37048c1

Please sign in to comment.