{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# $P(k, H_0)$\n",
    "\n",
    "Quick notebook to see how the power spectrum depends on $H_0$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import camb\n",
    "from camb import model\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_pk(h):\n",
    "    pars = camb.CAMBparams()\n",
    "\n",
    "    pars.set_cosmology(H0=h*100, ombh2=0.04825 * h**2, omch2=(0.307 - 0.04825) * h**2)\n",
    "    pars.InitPower.set_params(ns=0.9611)\n",
    "    pars.set_matter_power(redshifts=[0.], kmax=40)\n",
    "\n",
    "    #Non-Linear spectra (Halofit)\n",
    "    pars.NonLinear = model.NonLinear_both\n",
    "    results = camb.get_results(pars)\n",
    "    results.calc_power_spectra(pars)\n",
    "    kh_nonlin, z_nonlin, pk_nonlin = results.get_matter_power_spectrum(minkh=1e-3, maxkh=50, npoints = 200)\n",
    "\n",
    "    return kh_nonlin, pk_nonlin[0]\n",
    "\n",
    "kh_nonlin, pk_nonlin_reference = get_pk(0.705)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 53852 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure()\n",
    "\n",
    "for h in [0.65, 0.70, 0.75]:\n",
    "    __, pk = get_pk(h)\n",
    "    plt.plot(kh_nonlnie, pk / pk_nonlin_reference, label=r\"$h = {}$\".format(h))\n",
    "\n",
    "plt.legend()\n",
    "plt.xscale(\"log\")\n",
    "plt.xlabel(r\"$k ~ [h / \\mathrm{Mpc}]$\")\n",
    "plt.ylabel(r\"$P(k, h) / P(k, h=0.705)$\")\n",
    "\n",
    "plt.tight_layout()\n",
    "plt.savefig(\"../plots/pk_h0_dependence.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
}
