{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using a calibrated flow model to predict $z_{\\rm cosmo}$" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] } ], "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 h5py import File\n", "from tqdm import tqdm\n", "\n", "import csiborgtools\n", "\n", "%load_ext autoreload\n", "%autoreload 2\n", "%matplotlib inline\n", "\n", "paths = csiborgtools.read.Paths(**csiborgtools.paths_glamdring)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def load_calibration(catalogue, simname, nsim, ksmooth):\n", " fname = f\"/mnt/extraspace/rstiskalek/csiborg_postprocessing/peculiar_velocity/flow_samples_{catalogue}_{simname}_smooth_{ksmooth}.hdf5\" # noqa\n", " keys = [\"Vext_x\", \"Vext_y\", \"Vext_z\", \"alpha\", \"beta\", \"sigma_v\"]\n", "\n", " # SN_keys = ['mag_cal', 'alpha_cal', 'beta_cal']\n", " # SN_keys = []\n", " calibration_samples = {}\n", " with File(fname, 'r') as f:\n", " for key in keys:\n", " calibration_samples[key] = f[f\"sim_{nsim}/{key}\"][:][::10]\n", "\n", " # for key in SN_keys:\n", " # calibration_samples[key] = f[f\"sim_{nsim}/{key}\"][:]\n", "\n", " return calibration_samples" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Test running a model" ] }, { "cell_type": "code", "execution_count": 135, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " 0%| | 0/19 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.figure()\n", "\n", "# for i in range(len(nsims)):\n", " # mask = pzcosmo[i] > 1e-5\n", " # plt.plot(zcosmo[mask], pzcosmo[i][mask], color=\"black\", alpha=0.1)\n", "\n", "# mu = np.nanmean(pzcosmo, axis=0)\n", "mask = pzcosmo > 1e-5\n", "plt.plot(zcosmo[mask], pzcosmo[mask], color=\"black\", label=r\"$p(z_{\\rm cosmo})$\")\n", "\n", "plt.ylim(0)\n", "plt.axvline(zcosmo_mean[n], color=\"green\", label=r\"$z_{\\rm cosmo}$\")\n", "plt.axvline(zobs[n], color=\"red\", label=r\"$z_{\\rm CMB}$\")\n", "\n", "plt.xlabel(r\"$z$\")\n", "plt.ylabel(r\"$p(z)$\")\n", "plt.legend()\n", "plt.tight_layout()\n", "# plt.savefig(\"../plots/zcosmo_posterior_mock_example_B.png\", dpi=450)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "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", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }