csiborgtools/notebooks/flow/reconstruction_comparison.ipynb

521 lines
18 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
2024-07-05 12:28:06 +02:00
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Copyright (C) 2024 Richard Stiskalek\n",
"# This program is free software; you can redistribute it and/or modify it\n",
"# under the terms of the GNU General Public License as published by the\n",
"# Free Software Foundation; either version 3 of the License, or (at your\n",
"# option) any later version.\n",
"#\n",
"# This program is distributed in the hope that it will be useful, but\n",
"# WITHOUT ANY WARRANTY; without even the implied warranty of\n",
"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General\n",
"# Public License for more details.\n",
"#\n",
"# You should have received a copy of the GNU General Public License along\n",
"# with this program; if not, write to the Free Software Foundation, Inc.,\n",
"# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from corner import corner\n",
"from getdist import plots\n",
"\n",
"\n",
"from reconstruction_comparison import *\n",
"\n",
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"\n",
"paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### $\\log Z$ and BIC for simulations/catalogues"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2024-07-05 12:28:06 +02:00
"sims = [\"Carrick2015\", \"Lilow2024\", \"CF4\", \"CF4gp\", \"csiborg2_main\", \"csiborg2X\"]\n",
"catalogues = [\"LOSS\", \"Foundation\", \"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
"\n",
"for catalogue in catalogues:\n",
" y_BIC = np.asarray([get_gof(\"BIC\", sim, catalogue) for sim in sims])\n",
" y_BIC -= y_BIC.min()\n",
2024-07-05 12:28:06 +02:00
" y_lnZ = np.full_like(y_BIC, np.nan)\n",
" # y_lnZ = np.asarray([get_gof(\"lnZ\", sim, catalogue) for sim in sims])\n",
" # y_lnZ -= y_lnZ.min()\n",
"\n",
" fig, ax_left = plt.subplots()\n",
" fig.suptitle(f\"{catalogue}\")\n",
" ax_right = ax_left.twinx()\n",
"\n",
"\n",
" ax_left.plot(np.arange(len(sims)), y_lnZ, 'bo')\n",
" ax_right.plot(np.arange(len(sims)), y_BIC, 'rx')\n",
"\n",
" # y-ticks\n",
2024-07-05 12:28:06 +02:00
" ax_left.set_ylabel(r\"$-\\Delta \\log \\mathcal{Z}$\", color=\"blue\")\n",
" ax_left.tick_params(axis='y', labelcolor=\"blue\")\n",
" ax_right.set_ylabel(r\"$\\Delta \\mathrm{BIC}$\", color=\"red\")\n",
" ax_right.tick_params(axis='y', labelcolor=\"red\")\n",
"\n",
" ax_left.set_xticks(np.arange(len(sims)), simname_to_pretty(sims), rotation=35)\n",
" fig.tight_layout()\n",
" fig.savefig(f\"../../plots/GOF_{catalogue}.png\", dpi=450)\n",
" fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setting $\\beta = 1$?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sims = [\"Lilow2024\", \"CF4\", \"CF4gp\", \"csiborg1\", \"csiborg2_main\", \"csiborg2X\"]\n",
"catalogues = [\"LOSS\", \"Foundation\", \"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
"\n",
"for catalogue in catalogues:\n",
" y_lnZ = [get_gof(\"lnZ\", sim, catalogue, sample_beta=True) - get_gof(\"lnZ\", sim, catalogue, sample_beta=False) for sim in sims]\n",
" y_BIC = [get_gof(\"BIC\", sim, catalogue, sample_beta=True) - get_gof(\"BIC\", sim, catalogue, sample_beta=False) for sim in sims]\n",
"\n",
" fig, ax_left = plt.subplots()\n",
" fig.suptitle(rf\"{catalogue} (higher signifies preference for $\\beta = 1$)\")\n",
" ax_right = ax_left.twinx()\n",
"\n",
" ax_left.plot(np.arange(len(sims)), y_lnZ, 'bo')\n",
" ax_right.plot(np.arange(len(sims)), y_BIC, 'rx')\n",
"\n",
" # y-ticks\n",
" ax_left.set_ylabel(r\"$\\log \\mathcal{Z}_{\\beta} - \\log \\mathcal{Z}_{\\beta = 1}$\", color=\"blue\")\n",
" ax_left.tick_params(axis='y', labelcolor=\"blue\")\n",
" ax_right.set_ylabel(r\"$\\mathrm{BIC}_{\\beta} - \\mathrm{BIC}_{\\beta = 1}$\", color=\"red\")\n",
" ax_right.tick_params(axis='y', labelcolor=\"red\")\n",
"\n",
" ax_left.set_xticks(np.arange(len(sims)), simname_to_pretty(sims), rotation=35)\n",
" ax_left.axhline(0, color=\"black\", linestyle=\"--\", linewidth=1)\n",
" fig.tight_layout()\n",
" fig.savefig(f\"../../plots/GOF_beta_{catalogue}.png\", dpi=450)\n",
" fig.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### What $\\beta$ is preferred by the data? "
]
},
{
"cell_type": "code",
2024-07-03 10:50:21 +02:00
"execution_count": null,
"metadata": {},
2024-07-03 10:50:21 +02:00
"outputs": [],
"source": [
"# sims = [\"Lilow2024\", \"CF4\", \"CF4gp\", \"csiborg1\", \"csiborg2_main\", \"csiborg2X\"]\n",
2024-07-05 12:28:06 +02:00
"sims = [\"csiborg2_main\", \"csiborg2X\"]\n",
"catalogues = [\"LOSS\", \"Foundation\", \"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
"key = \"beta\"\n",
"\n",
"for sim in sims:\n",
" plt.figure()\n",
" plt.title(simname_to_pretty(sim))\n",
"\n",
" for catalogue in catalogues:\n",
" beta = get_samples(sim, catalogue)[key]\n",
" plt.hist(beta, bins=\"auto\", histtype=\"step\", label=catalogue, density=1)\n",
"\n",
"\n",
" plt.xlabel(names_to_latex([key], True)[0])\n",
" plt.ylabel(\"Normalized PDF\")\n",
" # plt.xlim(0., 1.5)\n",
" plt.legend()\n",
2024-07-05 12:28:06 +02:00
" plt.savefig(f\"../../plots/what_beta_{sim}.png\", dpi=450)\n",
"\n",
" plt.tight_layout()\n",
" plt.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Flow | catalogue"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"catalogues = [\"LOSS\", \"Foundation\", \"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
"sims = [\"Carrick2015\", \"csiborg2_main\", \"csiborg2X\"]\n",
"params = [\"Vmag\", \"beta\", \"sigma_v\"]\n",
"\n",
"for catalogue in catalogues:\n",
" X = [samples_to_getdist(get_samples(sim, catalogue), sim)\n",
" for sim in sims]\n",
"\n",
" g = plots.get_subplot_plotter()\n",
" g.settings.figure_legend_frame = False\n",
" g.settings.alpha_filled_add = 0.75\n",
"\n",
" g.triangle_plot(X, params=params, filled=True, legend_loc='upper right')\n",
" plt.gcf().suptitle(f'{catalogue}', y=1.025)\n",
" plt.gcf().tight_layout()\n",
2024-07-05 12:28:06 +02:00
" plt.gcf().savefig(f\"../../plots/calibration_{catalogue}.png\", dpi=500, bbox_inches='tight')\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Flow | simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"catalogues = [\"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
"sims = [\"Carrick2015\", \"csiborg2_main\", \"csiborg2X\"]\n",
2024-07-05 12:28:06 +02:00
"params = [\"Vmag\", \"l\", \"b\", \"beta\", \"sigma_v\"]\n",
"\n",
"for sim in sims:\n",
" X = [samples_to_getdist(get_samples(sim, catalogue), sim, catalogue)\n",
" for catalogue in catalogues]\n",
"\n",
" g = plots.get_subplot_plotter()\n",
" g.settings.figure_legend_frame = False\n",
" g.settings.alpha_filled_add = 0.75\n",
"\n",
" g.triangle_plot(X, params=params, filled=True, legend_loc='upper right')\n",
" plt.gcf().suptitle(f'{sim}', y=1.025)\n",
" plt.gcf().tight_layout()\n",
" plt.gcf().savefig(f\"../../plots/calibration_{sim}.png\", dpi=500, bbox_inches='tight')\n",
" plt.gcf().show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Stacking vs marginalising CB boxes\n",
"\n",
"#### $V_{\\rm ext}$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sim = \"csiborg2X\"\n",
"catalogue = \"2MTF\"\n",
"key = \"Vext\"\n",
"\n",
"X = [get_samples(sim, catalogue, nsim=nsim, convert_Vext_to_galactic=False)[key] for nsim in range(20)]\n",
"Xmarg = get_samples(sim, catalogue, convert_Vext_to_galactic=False)[key]\n",
"\n",
"\n",
"fig, axs = plt.subplots(1, 3, figsize=(15, 5), sharey=True)\n",
"fig.suptitle(f\"{simname_to_pretty(sim)}, {catalogue}\")\n",
"fig.subplots_adjust(wspace=0.0, hspace=0)\n",
"\n",
"for i in range(3):\n",
" for n in range(20):\n",
" axs[i].hist(X[n][:, i], bins=\"auto\", alpha=0.25, histtype='step',\n",
" color='black', linewidth=0.5, density=1, zorder=0,\n",
" label=\"Individual box\" if (n == 0 and i == 0) else None)\n",
"\n",
"axs[i].hist(np.hstack([X[n][:, i] for n in range(20)]), bins=\"auto\",\n",
" histtype='step', color='blue', density=1,\n",
" label=\"Stacked individual boxes\" if i == 0 else None)\n",
"axs[i].hist(Xmarg[:, i], bins=\"auto\", histtype='step', color='red',\n",
" density=1, label=\"Marginalised boxes\" if i == 0 else None)\n",
" \n",
"axs[0].legend(fontsize=\"small\", loc='upper left', frameon=False)\n",
"\n",
"axs[0].set_xlabel(r\"$V_{\\mathrm{ext}, x} ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
"axs[1].set_xlabel(r\"$V_{\\mathrm{ext}, y} ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
"axs[2].set_xlabel(r\"$V_{\\mathrm{ext}, z} ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
"axs[0].set_ylabel(\"Normalized PDF\")\n",
"fig.tight_layout()\n",
"fig.savefig(f\"../../plots/consistency_{sim}_{catalogue}_{key}.png\", dpi=450)\n",
"fig.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### $\\beta$ and others"
]
},
{
"cell_type": "code",
2024-07-03 10:50:21 +02:00
"execution_count": null,
"metadata": {},
2024-07-03 10:50:21 +02:00
"outputs": [],
"source": [
"sim = \"csiborg2_main\"\n",
"catalogue = \"Pantheon+\"\n",
2024-07-05 12:28:06 +02:00
"key = \"alpha\"\n",
"\n",
"X = [get_samples(sim, catalogue, nsim=nsim, convert_Vext_to_galactic=False)[key] for nsim in range(20)]\n",
"Xmarg = get_samples(sim, catalogue, convert_Vext_to_galactic=False)[key]\n",
"\n",
"\n",
"plt.figure()\n",
"plt.title(f\"{simname_to_pretty(sim)}, {catalogue}\")\n",
"for n in range(20):\n",
" plt.hist(X[n], bins=\"auto\", alpha=0.25, histtype='step',\n",
" color='black', linewidth=0.5, density=1, zorder=0,\n",
" label=\"Individual box\" if n == 0 else None)\n",
"\n",
"plt.hist(np.hstack([X[n] for n in range(20)]), bins=\"auto\",\n",
" histtype='step', color='blue', density=1,\n",
" label=\"Stacked individual boxes\")\n",
"plt.hist(Xmarg, bins=\"auto\", histtype='step', color='red',\n",
" density=1, label=\"Marginalised boxes\")\n",
"\n",
"plt.legend(fontsize=\"small\", frameon=False, loc='upper left', ncols=3)\n",
"plt.xlabel(names_to_latex([key], True)[0])\n",
"plt.ylabel(\"Normalized PDF\")\n",
"\n",
"plt.tight_layout()\n",
"plt.savefig(f\"../../plots/consistency_{sim}_{catalogue}_{key}.png\", dpi=450)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### SN/TFR Calibration consistency"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# catalogues = [\"LOSS\", \"Foundation\", \"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
"catalogues = [\"Pantheon+\"]\n",
"sims = [\"Carrick2015\", \"csiborg2_main\", \"csiborg2X\"]\n",
"\n",
"for catalogue in catalogues:\n",
" X = [samples_to_getdist(get_samples(sim, catalogue), sim)\n",
" for sim in sims]\n",
"\n",
" if \"Pantheon+\" in catalogue or catalogue in [\"Foundation\", \"LOSS\"]:\n",
" params = [\"alpha_cal\", \"beta_cal\", \"mag_cal\", \"e_mu\"]\n",
" else:\n",
" params = [\"aTF\", \"bTF\", \"e_mu\"]\n",
"\n",
" g = plots.get_subplot_plotter()\n",
" g.settings.figure_legend_frame = False\n",
" g.settings.alpha_filled_add = 0.75\n",
"\n",
" g.triangle_plot(X, params=params, filled=True, legend_loc='upper right')\n",
" plt.gcf().suptitle(f'{catalogue}', y=1.025)\n",
" plt.gcf().tight_layout()\n",
" # plt.gcf().savefig(f\"../../plots/calibration_{catalogue}.png\", dpi=500, bbox_inches='tight')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2024-07-03 10:50:21 +02:00
"### $V_{\\rm ext}$ comparison"
]
},
2024-07-03 10:50:21 +02:00
{
"cell_type": "code",
2024-07-05 12:28:06 +02:00
"execution_count": null,
2024-07-03 10:50:21 +02:00
"metadata": {},
2024-07-05 12:28:06 +02:00
"outputs": [],
2024-07-03 10:50:21 +02:00
"source": [
"catalogues = [\"LOSS\"]\n",
"# sims = [\"Carrick2015\", \"csiborg2_main\", \"csiborg2X\"]\n",
"sims = [\"Carrick2015\"]\n",
"params = [\"Vmag\", \"l\", \"b\"]\n",
"\n",
"for sim in sims:\n",
" X = [samples_to_getdist(get_samples(sim, catalogue), sim, catalogue)\n",
" for catalogue in catalogues]\n",
"\n",
" g = plots.get_subplot_plotter()\n",
" g.settings.figure_legend_frame = False\n",
" g.settings.alpha_filled_add = 0.75\n",
"\n",
" g.triangle_plot(X, params=params, filled=True, legend_loc='upper right')\n",
" plt.gcf().suptitle(f'{simname_to_pretty(sim)}', y=1.025)\n",
" plt.gcf().tight_layout()\n",
" # plt.gcf().savefig(f\"../../plots/calibration_{sim}.png\", dpi=500, bbox_inches='tight')\n",
" plt.gcf().show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bulk flow in the simulation rest frame"
]
},
{
"cell_type": "code",
2024-07-05 12:28:06 +02:00
"execution_count": null,
2024-07-03 10:50:21 +02:00
"metadata": {},
2024-07-05 12:28:06 +02:00
"outputs": [],
2024-07-03 10:50:21 +02:00
"source": [
"sims = [\"Carrick2015\", \"csiborg1\", \"csiborg2_main\", \"csiborg2X\"]\n",
"convert_to_galactic = False\n",
"\n",
"fig, axs = plt.subplots(1, 3, figsize=(15, 5))\n",
"cols = plt.rcParams['axes.prop_cycle'].by_key()['color']\n",
"\n",
"for i, sim in enumerate(sims):\n",
" r, B = get_bulkflow_simulation(sim, convert_to_galactic=convert_to_galactic)\n",
" if sim == \"Carrick2015\":\n",
" if convert_to_galactic:\n",
" B[..., 0] *= 0.43\n",
" else:\n",
" B *= 0.43\n",
"\n",
" for n in range(3):\n",
" ylow, ymed, yhigh = np.percentile(B[..., n], [16, 50, 84], axis=0)\n",
" axs[n].fill_between(r, ylow, yhigh, color=cols[i], alpha=0.5, label=simname_to_pretty(sim) if n == 0 else None)\n",
"\n",
2024-07-03 10:50:21 +02:00
"axs[0].legend()\n",
"if convert_to_galactic:\n",
" axs[0].set_ylabel(r\"$B ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
" axs[1].set_ylabel(r\"$\\ell_B ~ [\\degree]$\")\n",
" axs[2].set_ylabel(r\"$b_B ~ [\\degree]$\")\n",
"else:\n",
" axs[0].set_ylabel(r\"$B_{x} ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
" axs[1].set_ylabel(r\"$B_{y} ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
" axs[2].set_ylabel(r\"$B_{z} ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
"\n",
"for n in range(3):\n",
" axs[n].set_xlabel(r\"$R ~ [\\mathrm{Mpc}]$\")\n",
"\n",
"\n",
"fig.tight_layout()\n",
2024-07-05 12:28:06 +02:00
"fig.savefig(\"../../plots/bulkflow_simulations_restframe.png\", dpi=450)\n",
2024-07-03 10:50:21 +02:00
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Bulk flow in the CMB rest frame"
]
},
{
"cell_type": "code",
2024-07-05 12:28:06 +02:00
"execution_count": null,
"metadata": {},
2024-07-05 12:28:06 +02:00
"outputs": [],
"source": [
2024-07-05 12:28:06 +02:00
"sim = \"csiborg2_main\"\n",
"catalogues = [\"Pantheon+\", \"2MTF\", \"SFI_gals\"]\n",
2024-07-03 10:50:21 +02:00
"\n",
"\n",
"fig, axs = plt.subplots(1, 3, figsize=(15, 5), sharex=True)\n",
"cols = plt.rcParams['axes.prop_cycle'].by_key()['color']\n",
2024-07-03 10:50:21 +02:00
"# fig.suptitle(f\"Calibrated against {catalogue}\")\n",
"\n",
2024-07-03 10:50:21 +02:00
"for i, catalogue in enumerate(catalogues):\n",
2024-07-05 12:28:06 +02:00
" r, B = get_bulkflow(sim, catalogue, sample_beta=True, convert_to_galactic=True,\n",
" weight_simulations=True, downsample=3)\n",
2024-07-03 10:50:21 +02:00
" c = cols[i]\n",
" for n in range(3):\n",
" ylow, ymed, yhigh = np.percentile(B[..., n], [16, 50, 84], axis=-1)\n",
" axs[n].plot(r, ymed, color=c)\n",
" axs[n].fill_between(r, ylow, yhigh, alpha=0.5, color=c, label=catalogue)\n",
"\n",
"\n",
"# CMB-LG velocity\n",
2024-07-03 10:50:21 +02:00
"axs[0].fill_between([r.min(), 10.], [627 - 22, 627 - 22], [627 + 22, 627 + 22], color='black', alpha=0.5, zorder=0.5, label=\"CMB-LG\", hatch=\"x\")\n",
"axs[1].fill_between([r.min(), 10.], [276 - 3, 276 - 3], [276 + 3, 276 + 3], color='black', alpha=0.5, zorder=0.5, hatch=\"x\")\n",
"axs[2].fill_between([r.min(), 10.], [30 - 3, 30 - 3], [30 + 3, 30 + 3], color='black', alpha=0.5, zorder=0.5, hatch=\"x\")\n",
"\n",
"# LCDM expectation\n",
"Rs,mean,std,mode,p05,p16,p84,p95 = np.load(\"/mnt/users/rstiskalek/csiborgtools/data/BulkFlowPlot.npy\")\n",
"m = Rs < 175\n",
"axs[0].plot(Rs[m], mode[m], color=\"violet\", zorder=0)\n",
"axs[0].fill_between(Rs[m], p16[m], p84[m], alpha=0.25, color=\"violet\",\n",
" zorder=0, hatch='//', label=r\"$\\Lambda\\mathrm{CDM}$\")\n",
"\n",
"for n in range(3):\n",
" axs[n].set_xlabel(r\"$r ~ [\\mathrm{Mpc} / h]$\")\n",
"\n",
"axs[0].legend()\n",
"axs[0].set_ylabel(r\"$B ~ [\\mathrm{km} / \\mathrm{s}]$\")\n",
"axs[1].set_ylabel(r\"$\\ell_B ~ [\\mathrm{deg}]$\")\n",
"axs[2].set_ylabel(r\"$b_B ~ [\\mathrm{deg}]$\")\n",
"\n",
"axs[0].set_xlim(r.min(), r.max())\n",
"\n",
"fig.tight_layout()\n",
"fig.savefig(f\"../../plots/bulkflow_{sim}_{catalogue}.png\", dpi=450)\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
2024-07-03 10:51:00 +02:00
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv_csiborg",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2024-07-05 12:28:06 +02:00
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}