mirror of
https://github.com/hoellin/selfisys_examples.git
synced 2025-06-07 00:01:10 +00:00
740 KiB
740 KiB
This notebook is part of the SelfiSys project and is licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later). See the accompanying LICENSE file or visit GNU GPL for details.
Tristan Hoellinger
Institut d'Astrophysique de Paris
tristan.hoellinger@iap.fr
Investigate the binning and interpolation strategy¶
Validate the interpolation strategy for representing power spectra.
Set up the environment and parameters¶
In [1]:
from selfisys.global_parameters import *
wd = Path(OUTPUT_PATH) / "expl_notebooks/interpolation/"
In [2]:
%load_ext autoreload
%autoreload 2
from pathlib import Path
import matplotlib.pyplot as plt
from selfisys.setup_model import *
from selfisys.utils.tools import get_k_max
from selfisys.utils.plot_params import *
from selfisys.utils.plot_examples import *
# Configure plotting aesthetics for consistent visualisation
setup_plotting()
modeldir = Path(wd) / "model"
modeldir.mkdir(parents=True, exist_ok=True)
(Path(wd) / "Figures").mkdir(parents=True, exist_ok=True)
In [3]:
size = 512
L = 3600
Pinit = 50
S = 64
Compute a power spectrum and plot it¶
In [4]:
k_max = get_k_max(L, size) # k_max in h/Mpc
print(f"k_max = {k_max}")
# Cosmo at the expansion point:
params_planck = params_planck_kmax_missing.copy()
params_planck["k_max"] = k_max
# Cosmo for BBKS spectrum with fiducial cosmology (for normalisation):
params_BBKS = params_BBKS_kmax_missing.copy()
params_BBKS["k_max"] = k_max
# Groundtruth cosmology:
params_cosmo_obs = params_cosmo_obs_kmax_missing.copy()
params_cosmo_obs["k_max"] = k_max
In [5]:
params = setup_model(
workdir=modeldir,
params_planck=params_planck,
params_P0=params_BBKS,
size=size,
L=L,
S=S,
Pinit=Pinit,
force=True,
)
(
size,
L,
P,
S,
G_sim_path,
G_ss_path,
Pbins_bnd,
Pbins,
k_s,
P_ss_obj_path,
P_0,
planck_Pk,
) = params
In [6]:
from pysbmy.power import PowerSpectrum, FourierGrid
true_P = PowerSpectrum(L, L, L, size, size, size, params_planck)
G_sim = FourierGrid.read(G_sim_path)
In [7]:
plot_power_spectrum(
G_sim,
true_P,
k_s,
planck_Pk,
Pbins,
Pbins_bnd,
size,
L,
wd,
"Power spectrum with Planck 2018 cosmological parameters",
)
In [8]:
relative_error_analysis(G_sim, true_P, k_s, planck_Pk, Pbins, Pbins_bnd, size, L, wd)