diff --git a/examples/Paper_v2.0/Figure_02_halo_miscentering_boost_theory.ipynb b/examples/Paper_v2.0/Figure_02_halo_miscentering_boost_theory.ipynb new file mode 100644 index 000000000..cf3b289c4 --- /dev/null +++ b/examples/Paper_v2.0/Figure_02_halo_miscentering_boost_theory.ipynb @@ -0,0 +1,167 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Figure to show the new 2-halo term and miscentering functionality" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from paper_formating import add_grid, prep_plot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imports specific to clmm " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import clmm\n", + "import clmm.utils as u\n", + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure we know which version we're using" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "clmm.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Define the galaxy cluster model. Here, we choose parameters that describe the galaxy cluster model, including the mass definition, concentration, and mass distribution. For the mass distribution, we choose a distribution that follows an NFW profile." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "moo = clmm.Modeling(massdef=\"mean\", delta_mdef=200, halo_profile_model=\"nfw\")\n", + "\n", + "mass_cl = 1.0e14\n", + "z_cl = 0.4\n", + "\n", + "conc_cl = 5.4 # Duffy08 value for this halo mass and redshift (see last commented cell)\n", + "halo_bias = 2.4 # Tkinker10 value for this halo mass and redshift (see last commented cell)\n", + "\n", + "moo.set_cosmo(cosmo)\n", + "moo.set_concentration(conc_cl)\n", + "moo.set_mass(mass_cl)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "r_proj = np.logspace(-2, 2, 100)\n", + "\n", + "DeltaSigma = moo.eval_excess_surface_density(r_proj, z_cl)\n", + "\n", + "# Miscentered DeltaSigma\n", + "DeltaSigma_mis = moo.eval_excess_surface_density(r_proj, z_cl, r_mis=0.2)\n", + "\n", + "# 2halo DeltaSigma\n", + "DeltaSigma_2h = moo.eval_excess_surface_density_2h(r_proj, z_cl, halobias=6)\n", + "\n", + "# boost model\n", + "r_scale = 0.3\n", + "nfw_boost = u.compute_nfw_boost(r_proj, r_scale, boost0=0.2)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plot the predicted profiles" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "\n", + "ax.loglog(r_proj, DeltaSigma, label=\"1-halo (reference)\", color=\"k\")\n", + "ax.loglog(r_proj, DeltaSigma_mis, ls=\"--\", label=r\"1-halo ($R_{\\rm mis} = 0.2$Mpc)\")\n", + "ax.loglog(r_proj, DeltaSigma / nfw_boost, ls=\":\", label=\"1-halo (boost correction)\")\n", + "ax.loglog(r_proj, DeltaSigma_2h, ls=\"dashdot\", label=\"2-halo\")\n", + "ax.legend(loc=1, fontsize=6.5)\n", + "\n", + "ax.set_xlabel(\"R [Mpc]\")\n", + "ax.set_ylabel(r\"$\\Delta\\Sigma$ [M$_\\odot$ Mpc$^{-2}$]\")\n", + "ax.set_ylim(8.0e10, 1e15)\n", + "ax.set_xlim(1e-2, 1e2)\n", + "\n", + "add_grid(ax)\n", + "\n", + "fig.tight_layout()\n", + "fig.savefig(\"2h_miscentering_boost.png\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/Paper_v2.0/Figure_03_magnification_bias.ipynb b/examples/Paper_v2.0/Figure_03_magnification_bias.ipynb new file mode 100644 index 000000000..00bab519c --- /dev/null +++ b/examples/Paper_v2.0/Figure_03_magnification_bias.ipynb @@ -0,0 +1,168 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Plot magnification bias" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imports specific to clmm " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import clmm\n", + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure we know which version we're using" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "clmm.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Define the galaxy cluster model. Here, we choose parameters that describe the galaxy cluster model, including the mass definition, concentration, and mass distribution. For the mass distribution, we choose a distribution that follows an NFW profile." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "moo = clmm.Modeling(massdef=\"mean\", delta_mdef=200, halo_profile_model=\"nfw\")\n", + "\n", + "moo.set_cosmo(cosmo)\n", + "moo.set_concentration(4)\n", + "moo.set_mass(1.0e15)\n", + "\n", + "z_cl = 1.0\n", + "\n", + "# source properties\n", + "z_src = 2.0 # all sources in the same plane\n", + "z_distrib_func = (\n", + " clmm.utils.redshift_distributions.chang2013\n", + ") # sources redshift following a distribution\n", + "alpha = [2, -0.5]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Compute quantity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "r3d = np.logspace(-2, 2, 100)\n", + "mu_bias = moo.eval_magnification_bias(r3d, z_cl, z_src, alpha)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Plot the predicted profiles" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from paper_formating import prep_plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "\n", + "ax.plot(r3d, mu_bias[0] - 1, label=\"$\\\\alpha$ =\" + str(alpha[0]))\n", + "ax.plot(r3d, mu_bias[1] - 1, label=\"$\\\\alpha$ =\" + str(alpha[1]))\n", + "\n", + "ax.set_ylabel(\"$\\delta_{\\mu}$\")\n", + "ax.set_xlabel(\"R [Mpc]\")\n", + "ax.legend() # fontsize=\"xx-large\")\n", + "ax.set_xscale(\"log\")\n", + "\n", + "ax.set_ylim(-1.1, 3)\n", + "ax.set_xlim(0.06, 1e1)\n", + "\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "\n", + "plt.tight_layout()\n", + "plt.savefig(\"delta_mu.png\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/Paper_v2.0/Figure_04_mass_conversion.ipynb b/examples/Paper_v2.0/Figure_04_mass_conversion.ipynb new file mode 100644 index 000000000..cff998b93 --- /dev/null +++ b/examples/Paper_v2.0/Figure_04_mass_conversion.ipynb @@ -0,0 +1,845 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Mass conversion between different mass definitions\n", + "## Mass conversion between spherical overdensity mass definitions\n", + "\n", + "In this notebook, we demonstrates how to convert the mass and concentration between various mass definitions (going from $200m$ to $500c$ in this example), and related functionalities, using both the object-oriented and functional interfaces of the code." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import clmm\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We define a cosmology first:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# first SOD definition\n", + "m1 = 1e14\n", + "c1 = 4\n", + "massdef1 = \"mean\"\n", + "delta_mdef1 = 200\n", + "halo_profile_model1 = \"nfw\"\n", + "# cluster redshift\n", + "z_cl = 0.4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# get a value for alpha\n", + "ein_def1 = clmm.Modeling(massdef=massdef1, delta_mdef=delta_mdef1, halo_profile_model=\"einasto\")\n", + "ein_def1.set_mass(m1)\n", + "ein_def1.set_concentration(c1)\n", + "\n", + "alpha = ein_def1.get_einasto_alpha(z_cl)\n", + "alpha" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "var_mod = {\n", + " \"delta_mdef2\": (150, 200, 500),\n", + " \"halo_profile_model2\": (\"nfw\", \"einasto\", \"hernquist\"),\n", + " \"massdef2\": (\"mean\", \"critical\"),\n", + "}\n", + "\n", + "\n", + "def loop_keys(keys_use, current_info, cfg_dict, list_cases):\n", + " if len(keys_use) == 0:\n", + " list_cases.append(\n", + " current_info\n", + " | {\n", + " \"data\": clmm.convert_profile_mass_concentration(\n", + " mdelta=m1,\n", + " cdelta=c1,\n", + " redshift=z_cl,\n", + " cosmo=cosmo,\n", + " massdef=massdef1,\n", + " delta_mdef=delta_mdef1,\n", + " halo_profile_model=halo_profile_model1,\n", + " alpha=alpha,\n", + " **current_info,\n", + " )\n", + " }\n", + " )\n", + " return\n", + "\n", + " new_keys = list(keys_use)\n", + " key = new_keys.pop(0)\n", + " for value in cfg_dict[key]:\n", + " new_info = current_info | {key: value}\n", + " loop_keys(new_keys, new_info, cfg_dict, list_cases)\n", + "\n", + "\n", + "new_defs3 = []\n", + "loop_keys(list(var_mod.keys()), {}, var_mod, new_defs3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from paper_formating import prep_plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "new_defs3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "_config = {\n", + " \"delta_mdef2\": {\n", + " 150: {\"c\": \"C0\", \"edgecolors\": \"C0\"},\n", + " 200: {\"c\": \"C1\", \"edgecolors\": \"C1\"},\n", + " 500: {\"c\": \"C2\", \"edgecolors\": \"C2\"},\n", + " },\n", + " \"halo_profile_model2\": {\n", + " \"nfw\": {\"marker\": \".\", \"lw\": 0.5, \"zorder\": 10},\n", + " \"einasto\": {\"marker\": \"^\", \"lw\": 0.5, \"zorder\": 2},\n", + " \"hernquist\": {\"marker\": \"v\", \"lw\": 0.5, \"zorder\": 2},\n", + " },\n", + " \"massdef2\": {\"mean\": {\"edgecolors\": \"1\"}, \"critical\": {\"c\": \"1\"}},\n", + "}\n", + "_leg = {\n", + " \"massdef2\": r\"$\\rho$: \",\n", + " \"delta_mdef2\": r\"$\\Delta$: \",\n", + " \"halo_profile_model2\": \"\",\n", + "}\n", + "_leg_val = {\n", + " \"nfw\": \"NFW\",\n", + " \"einasto\": \"Einasto\",\n", + " \"hernquist\": \"Hernquist\",\n", + "}\n", + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "for _case in new_defs3:\n", + " _kwargs = {\"s\": 200}\n", + " label = []\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " label.append(_leg[key] + f\"{_leg_val.get(value, value)}\")\n", + " label = \", \".join(label)\n", + " ax.scatter(*_case[\"data\"], **_kwargs, label=label)\n", + "\"\"\"\n", + "for i in range(0, len(new_defs3), 2):\n", + " ax.plot(\n", + " *np.transpose(\n", + " (new_defs3[i][\"data\"],\n", + " new_defs3[i+1][\"data\"])),\n", + " ls=\":\",\n", + " lw=.5,\n", + " c=f\"C{int(i/6)}\"\n", + " )\n", + "\"\"\"\n", + "ax.legend(ncols=3)\n", + "# ax.set_xscale(\"log\")\n", + "# \"\"\"\n", + "handles, labels = ax.get_legend_handles_labels()\n", + "\n", + "leg1 = ax.legend(\n", + " handles[:6:2],\n", + " [lab.split(\", \")[1] for lab in labels[:6:2]],\n", + " loc=(0.38, 0.73),\n", + " fontsize=8,\n", + " # borderpad=2,\n", + " labelspacing=1.1,\n", + ")\n", + "leg2 = ax.legend(\n", + " handles[::6],\n", + " [lab.split(\", \")[0] for lab in labels[::6]],\n", + " loc=(0.015, 0.6),\n", + " fontsize=8,\n", + ")\n", + "leg3 = ax.legend(\n", + " handles[:2],\n", + " [lab.split(\", \")[-1] for lab in labels[:2]],\n", + " loc=(0.015, 0.83),\n", + " fontsize=8,\n", + ")\n", + "ax.add_artist(leg1)\n", + "ax.add_artist(leg2)\n", + "# \"\"\"\n", + "ax.set_xlabel(\"$M$ [$M_\\odot$]\")\n", + "ax.set_ylabel(\"concentration\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.axvline(1e14, **fit_kwargs)\n", + "ax.axhline(4, **fit_kwargs)\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "new_defs3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "new_defs4 = [new_defs3[i] for i in [0, 2, 4, 6, 7, 8, 9, 10, 11, 12, 14, 16]]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "_config = {\n", + " \"delta_mdef2\": {\n", + " 150: {\"c\": \"C0\", \"edgecolors\": \"C0\"},\n", + " 200: {\"c\": \"C1\", \"edgecolors\": \"C1\"},\n", + " 500: {\"c\": \"C2\", \"edgecolors\": \"C2\"},\n", + " },\n", + " \"halo_profile_model2\": {\n", + " \"nfw\": {\"marker\": \".\", \"lw\": 0.5, \"zorder\": 10},\n", + " \"einasto\": {\"marker\": \"^\", \"lw\": 0.5, \"zorder\": 2},\n", + " \"hernquist\": {\"marker\": \"v\", \"lw\": 0.5, \"zorder\": 2},\n", + " },\n", + " \"massdef2\": {\"mean\": {\"edgecolors\": \"1\"}, \"critical\": {\"c\": \"1\"}},\n", + "}\n", + "_leg = {\n", + " \"massdef2\": r\"$\\rho$: \",\n", + " \"delta_mdef2\": r\"$\\Delta$: \",\n", + " \"halo_profile_model2\": \"\",\n", + "}\n", + "_leg_val = {\n", + " \"nfw\": \"NFW\",\n", + " \"einasto\": \"Einasto\",\n", + " \"hernquist\": \"Hernquist\",\n", + "}\n", + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "for _case in new_defs4:\n", + " _kwargs = {\"s\": 200}\n", + " label = []\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " label.append(_leg[key] + f\"{_leg_val.get(value, value)}\")\n", + " label = \", \".join(label)\n", + " ax.scatter(*_case[\"data\"], **_kwargs, label=label)\n", + "\n", + "ax.legend(ncols=3)\n", + "# ax.set_xscale(\"log\")\n", + "# \"\"\"\n", + "handles, labels = ax.get_legend_handles_labels()\n", + "\n", + "inds = [3, 5, 7]\n", + "leg1 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[1] for i in inds],\n", + " loc=(0.015, 0.77),\n", + " fontsize=7,\n", + " # borderpad=2,\n", + " labelspacing=1.1,\n", + ")\n", + "\n", + "\n", + "inds = [0, 3, 9]\n", + "leg2 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[0] for i in inds],\n", + " loc=(0.015, 0.59),\n", + " fontsize=7,\n", + ")\n", + "\n", + "\n", + "inds = [3, 4]\n", + "leg3 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[-1] for i in inds],\n", + " loc=(0.34, 0.86),\n", + " fontsize=7,\n", + ")\n", + "ax.add_artist(leg1)\n", + "ax.add_artist(leg2)\n", + "# \"\"\"\n", + "ax.set_xlabel(\"$M$ [$M_\\odot$]\")\n", + "ax.set_ylabel(\"concentration\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.axvline(1e14, **fit_kwargs)\n", + "ax.axhline(4, **fit_kwargs)\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion_simple.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "_config = {\n", + " \"delta_mdef2\": {\n", + " 150: {\"c\": \"C0\", \"edgecolors\": \"C0\"},\n", + " 200: {\"c\": \"C1\", \"edgecolors\": \"C1\"},\n", + " 500: {\"c\": \"C2\", \"edgecolors\": \"C2\"},\n", + " },\n", + " \"halo_profile_model2\": {\n", + " \"nfw\": {\"marker\": \".\", \"lw\": 0.5, \"zorder\": 10},\n", + " \"einasto\": {\"marker\": \"^\", \"lw\": 0.5, \"zorder\": 2},\n", + " \"hernquist\": {\"marker\": \"v\", \"lw\": 0.5, \"zorder\": 2},\n", + " },\n", + " \"massdef2\": {\"mean\": {\"edgecolors\": \"1\"}, \"critical\": {\"c\": \"1\"}},\n", + "}\n", + "_leg = {\n", + " \"massdef2\": r\"$\\rho$: \",\n", + " \"delta_mdef2\": r\"$\\Delta$: \",\n", + " \"halo_profile_model2\": \"\",\n", + "}\n", + "_leg_val = {\n", + " \"nfw\": \"NFW\",\n", + " \"einasto\": \"Einasto\",\n", + " \"hernquist\": \"Hernquist\",\n", + "}\n", + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "for _case in new_defs4:\n", + " _kwargs = {\"s\": 200}\n", + " label = []\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " label.append(_leg[key] + f\"{_leg_val.get(value, value)}\")\n", + " label = \", \".join(label)\n", + " ax.scatter(*_case[\"data\"], **_kwargs, label=label)\n", + "\n", + "ax.legend(ncols=3)\n", + "# ax.set_xscale(\"log\")\n", + "# \"\"\"\n", + "handles, labels = ax.get_legend_handles_labels()\n", + "\n", + "inds = [3, 5, 7]\n", + "leg1 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[1] for i in inds],\n", + " loc=(0.015, 0.77),\n", + " fontsize=7,\n", + " # borderpad=2,\n", + " labelspacing=1.1,\n", + ")\n", + "\n", + "\n", + "inds = [0, 3, 9]\n", + "leg2 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[0] for i in inds],\n", + " loc=(0.015, 0.59),\n", + " fontsize=7,\n", + ")\n", + "\n", + "\n", + "inds = [3, 4]\n", + "leg3 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[-1] for i in inds],\n", + " loc=(0.34, 0.86),\n", + " fontsize=7,\n", + ")\n", + "ax.add_artist(leg1)\n", + "ax.add_artist(leg2)\n", + "ax.set_yticks([1, 2, 3, 4])\n", + "# \"\"\"\n", + "ax.set_xlabel(\"$M$ [$M_\\odot$]\")\n", + "ax.set_ylabel(\"concentration\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.axvline(1e14, **fit_kwargs)\n", + "ax.axhline(4, **fit_kwargs)\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion_simple.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [], + "source": [ + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "\n", + "r_vals = np.logspace(np.log10(0.5), np.log10(2))\n", + "r_vals = np.logspace(-1, 1)\n", + "\n", + "for i0, inds in enumerate((range(3), [3, 5, 7], range(9, 12))):\n", + " for i, ls in zip(inds, [\"-\", \"--\", \":\"]):\n", + " plt.plot(\n", + " r_vals,\n", + " clmm.theory.compute_3d_density(\n", + " r_vals,\n", + " mdelta=new_defs4[i][\"data\"][0],\n", + " cdelta=new_defs4[i][\"data\"][1],\n", + " z_cl=0.4,\n", + " cosmo=cosmo,\n", + " massdef=new_defs4[i][\"massdef2\"],\n", + " delta_mdef=new_defs4[i][\"delta_mdef2\"],\n", + " halo_profile_model=new_defs4[i][\"halo_profile_model2\"],\n", + " ),\n", + " color=f\"C{i0}\",\n", + " lw=3 - i0,\n", + " ls=ls,\n", + " )\n", + "for _case in new_defs4:\n", + " _kwargs = {\"s\": 200}\n", + " label = []\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " label.append(_leg[key] + f\"{_leg_val.get(value, value)}\")\n", + " label = \", \".join(label)\n", + " _comp_kwargs = dict(\n", + " cosmo=cosmo,\n", + " massdef=_case[\"massdef2\"],\n", + " delta_mdef=_case[\"delta_mdef2\"],\n", + " mdelta=_case[\"data\"][0],\n", + " )\n", + " _r_val = clmm.theory.generic.compute_rdelta(**_comp_kwargs, redshift=0.4)\n", + " ax.scatter(\n", + " _r_val,\n", + " clmm.theory.compute_3d_density(\n", + " _r_val,\n", + " **_comp_kwargs,\n", + " cdelta=_case[\"data\"][1],\n", + " z_cl=0.4,\n", + " halo_profile_model=_case[\"halo_profile_model2\"],\n", + " ),\n", + " **_kwargs,\n", + " label=label,\n", + " )\n", + "\n", + "\n", + "ax.set_xscale(\"log\")\n", + "ax.set_yscale(\"log\")\n", + "ax.set_xlabel(\"$r$ [Mpc]\")\n", + "ax.set_ylabel(\"density\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion_profiles.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def _get_case_label(_case):\n", + " label = []\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " label.append(_leg[key] + f\"{_leg_val.get(value, value)}\")\n", + " label = \", \".join(label)\n", + " return label" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "\n", + "r_vals = np.logspace(np.log10(0.5), np.log10(2))\n", + "# r_vals = np.logspace(-1, 1)\n", + "\n", + "for i0, inds in enumerate((range(3), [3, 5, 7], range(9, 12))):\n", + " for i, ls in zip(inds, [\"-\", \"--\", \":\"]):\n", + " ax.plot(\n", + " r_vals,\n", + " clmm.theory.compute_3d_density(\n", + " r_vals,\n", + " mdelta=new_defs4[i][\"data\"][0],\n", + " cdelta=new_defs4[i][\"data\"][1],\n", + " z_cl=0.4,\n", + " cosmo=cosmo,\n", + " massdef=new_defs4[i][\"massdef2\"],\n", + " delta_mdef=new_defs4[i][\"delta_mdef2\"],\n", + " halo_profile_model=new_defs4[i][\"halo_profile_model2\"],\n", + " ),\n", + " color=f\"C{i0}\",\n", + " lw=1.2,\n", + " ls=ls,\n", + " label=_get_case_label(new_defs4[i]),\n", + " )\n", + "\n", + "\n", + "for _case in new_defs4:\n", + " _kwargs = {\"s\": 200}\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " _comp_kwargs = dict(\n", + " cosmo=cosmo,\n", + " massdef=_case[\"massdef2\"],\n", + " delta_mdef=_case[\"delta_mdef2\"],\n", + " mdelta=_case[\"data\"][0],\n", + " )\n", + " _r_val = clmm.theory.generic.compute_rdelta(**_comp_kwargs, redshift=0.4)\n", + " ax.scatter(\n", + " _r_val,\n", + " clmm.theory.compute_3d_density(\n", + " _r_val,\n", + " **_comp_kwargs,\n", + " cdelta=_case[\"data\"][1],\n", + " z_cl=0.4,\n", + " halo_profile_model=_case[\"halo_profile_model2\"],\n", + " ),\n", + " **_kwargs,\n", + " )\n", + "\n", + "ax.legend(fontsize=6)\n", + "handles, labels = ax.get_legend_handles_labels()\n", + "inds = [0, 1, 2]\n", + "leg1 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[1] for i in inds],\n", + " loc=(0.65, 0.77),\n", + " fontsize=7,\n", + " # borderpad=2,\n", + " labelspacing=1.1,\n", + ")\n", + "inds = [0, 3, 6]\n", + "leg2 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[0] for i in inds],\n", + " loc=(0.65, 0.58),\n", + " fontsize=7,\n", + ")\n", + "ax.add_artist(leg1)\n", + "\n", + "\n", + "ax.set_xlim(0.65, 1.25)\n", + "ax.set_ylim(2e12, 1.7e13)\n", + "# ax.set_xscale(\"log\")\n", + "# ax.set_yscale(\"log\")\n", + "ax.set_xlabel(\"$r$ [Mpc]\")\n", + "ax.set_ylabel(r\"$\\rho(r)$ [$M_\\odot Mpc^{-3}$]\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion_profiles.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "\n", + "r_vals = np.logspace(np.log10(0.5), np.log10(2))\n", + "# r_vals = np.logspace(-1, 1)\n", + "\n", + "\n", + "base = lambda r: clmm.theory.compute_3d_density(\n", + " r,\n", + " mdelta=new_defs4[3][\"data\"][0],\n", + " cdelta=new_defs4[3][\"data\"][1],\n", + " z_cl=0.4,\n", + " cosmo=cosmo,\n", + " massdef=new_defs4[3][\"massdef2\"],\n", + " delta_mdef=new_defs4[3][\"delta_mdef2\"],\n", + " halo_profile_model=new_defs4[3][\"halo_profile_model2\"],\n", + ")\n", + "\n", + "\n", + "for i0, inds in enumerate((range(3), [3, 5, 7], range(9, 12))):\n", + " for i, ls in zip(inds, [\"-\", \"--\", \":\"]):\n", + " ax.plot(\n", + " r_vals,\n", + " clmm.theory.compute_3d_density(\n", + " r_vals,\n", + " mdelta=new_defs4[i][\"data\"][0],\n", + " cdelta=new_defs4[i][\"data\"][1],\n", + " z_cl=0.4,\n", + " cosmo=cosmo,\n", + " massdef=new_defs4[i][\"massdef2\"],\n", + " delta_mdef=new_defs4[i][\"delta_mdef2\"],\n", + " halo_profile_model=new_defs4[i][\"halo_profile_model2\"],\n", + " )\n", + " / base(r_vals),\n", + " color=f\"C{i0}\",\n", + " lw=0.7,\n", + " ls=ls,\n", + " label=_get_case_label(new_defs4[i]),\n", + " )\n", + "\n", + "\n", + "for _case in new_defs4:\n", + " _kwargs = {\"s\": 50}\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " _comp_kwargs = dict(\n", + " cosmo=cosmo,\n", + " massdef=_case[\"massdef2\"],\n", + " delta_mdef=_case[\"delta_mdef2\"],\n", + " mdelta=_case[\"data\"][0],\n", + " )\n", + " _r_val = clmm.theory.generic.compute_rdelta(**_comp_kwargs, redshift=0.4)\n", + " ax.scatter(\n", + " _r_val,\n", + " clmm.theory.compute_3d_density(\n", + " _r_val,\n", + " **_comp_kwargs,\n", + " cdelta=_case[\"data\"][1],\n", + " z_cl=0.4,\n", + " halo_profile_model=_case[\"halo_profile_model2\"],\n", + " )\n", + " / base(_r_val),\n", + " **_kwargs,\n", + " )\n", + "\n", + "ax.legend(fontsize=6)\n", + "handles, labels = ax.get_legend_handles_labels()\n", + "inds = [0, 1, 2]\n", + "leg1 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[1] for i in inds],\n", + " loc=(0.65, 0.77),\n", + " fontsize=7,\n", + " # borderpad=2,\n", + " labelspacing=1.1,\n", + ")\n", + "inds = [0, 3, 6]\n", + "leg2 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[0] for i in inds],\n", + " loc=(0.65, 0.59),\n", + " fontsize=7,\n", + ")\n", + "ax.add_artist(leg1)\n", + "\n", + "\n", + "ax.set_xlim(0.6, 1.25)\n", + "# ax.set_ylim(2e12, 2.e13)\n", + "# ax.set_xscale(\"log\")\n", + "# ax.set_yscale(\"log\")\n", + "ax.set_xlabel(\"$r$ [Mpc]\")\n", + "ax.set_ylabel(r\"$\\rho(r)$ [$M_\\odot Mpc^{-3}$]\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion_profiles.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [], + "source": [ + "_config = {\n", + " \"delta_mdef2\": {\n", + " 150: {\"c\": \"C0\", \"edgecolors\": \"C0\"},\n", + " 200: {\"c\": \"C1\", \"edgecolors\": \"C1\"},\n", + " 500: {\"c\": \"C2\", \"edgecolors\": \"C2\"},\n", + " },\n", + " \"halo_profile_model2\": {\n", + " \"nfw\": {\"marker\": \".\", \"lw\": 0.5, \"zorder\": 10},\n", + " \"einasto\": {\"marker\": \"^\", \"lw\": 0.5, \"zorder\": 2},\n", + " \"hernquist\": {\"marker\": \"v\", \"lw\": 0.5, \"zorder\": 2},\n", + " },\n", + " \"massdef2\": {\"mean\": {\"edgecolors\": \"1\"}, \"critical\": {\"c\": \"1\"}},\n", + "}\n", + "_leg = {\n", + " \"massdef2\": r\"$\\rho$: \",\n", + " \"delta_mdef2\": r\"$\\Delta$: \",\n", + " \"halo_profile_model2\": \"\",\n", + "}\n", + "_leg_val = {\n", + " \"nfw\": \"NFW\",\n", + " \"einasto\": \"Einasto\",\n", + " \"hernquist\": \"Hernquist\",\n", + "}\n", + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "for _case in new_defs4:\n", + " _kwargs = {\"s\": 200}\n", + " label = []\n", + " for key, value in _case.items():\n", + " if key != \"data\":\n", + " _kwargs.update(_config[key][value])\n", + " label.append(_leg[key] + f\"{_leg_val.get(value, value)}\")\n", + " label = \", \".join(label)\n", + " ax.scatter(*_case[\"data\"], **_kwargs, label=label)\n", + "\n", + "for i, j in ((),):\n", + " ax.plot(\n", + " *np.transpose((new_defs4[i][\"data\"], new_defs4[j][\"data\"])),\n", + " ls=\":\",\n", + " lw=0.5,\n", + " c=f\"C{int(i/6)}\",\n", + " )\n", + "\n", + "ax.legend(ncols=3)\n", + "# ax.set_xscale(\"log\")\n", + "# \"\"\"\n", + "handles, labels = ax.get_legend_handles_labels()\n", + "\n", + "inds = [3, 5, 7]\n", + "leg1 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[1] for i in inds],\n", + " loc=(0.015, 0.77),\n", + " fontsize=7,\n", + " # borderpad=2,\n", + " labelspacing=1.1,\n", + ")\n", + "\n", + "\n", + "inds = [0, 3, 9]\n", + "leg2 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[0] for i in inds],\n", + " loc=(0.015, 0.59),\n", + " fontsize=7,\n", + ")\n", + "\n", + "\n", + "inds = [3, 4]\n", + "leg3 = ax.legend(\n", + " [handles[i] for i in inds],\n", + " [labels[i].split(\", \")[-1] for i in inds],\n", + " loc=(0.34, 0.86),\n", + " fontsize=7,\n", + ")\n", + "ax.add_artist(leg1)\n", + "ax.add_artist(leg2)\n", + "# \"\"\"\n", + "ax.set_xlabel(\"$M$ [$M_\\odot$]\")\n", + "ax.set_ylabel(\"concentration\")\n", + "fit_kwargs = {\"color\": \"r\", \"zorder\": 1, \"lw\": 1} # , \"ls\": \"--\"}\n", + "ax.axvline(1e14, **fit_kwargs)\n", + "ax.axhline(4, **fit_kwargs)\n", + "ax.grid(lw=0.5)\n", + "ax.minorticks_on()\n", + "ax.grid(which=\"minor\", lw=0.1)\n", + "ax.set_axisbelow(True)\n", + "plt.tight_layout()\n", + "plt.savefig(\"mass_conversion_simple_arrow.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "new_defs4" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/Paper_v2.0/Figure_05_6_theo_diff_z_types.ipynb b/examples/Paper_v2.0/Figure_05_6_theo_diff_z_types.ipynb new file mode 100644 index 000000000..5f06d93a5 --- /dev/null +++ b/examples/Paper_v2.0/Figure_05_6_theo_diff_z_types.ipynb @@ -0,0 +1,584 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Model WL Profiles (different redshift inputs)\n", + "## Model profiles using different type of source redshift information as input" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this example we model lensing profiles by giving as input either : \n", + "- discrete source redshifts, \n", + "- a redshift distribution function,\n", + "- the value of the mean beta parameters : \n", + "$\\langle \\beta_s \\rangle = \\left\\langle \\frac{D_{LS}}{D_S}\\frac{D_\\infty}{D_{L,\\infty}}\\right\\rangle$ ,\n", + "$\\langle \\beta_s^2 \\rangle = \\left\\langle \\left(\\frac{D_{LS}}{D_S}\\frac{D_\\infty}{D_{L,\\infty}}\\right)^2 \\right\\rangle$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "## Uncomment the following line if you want to use a specific modeling backend among 'ct' (cluster-toolkit), 'ccl' (CCL) or 'nc' (Numcosmo). Default is 'ccl'\n", + "# os.environ['CLMM_MODELING_BACKEND'] = 'nc'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import clmm\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from IPython.display import Math, display\n", + "\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from paper_formating import add_grid, prep_plot" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure we know which version we're using" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "clmm.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Import mock data module and setup the configuration " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from clmm.utils.redshift_distributions import *\n", + "from clmm.support import mock_data as mock\n", + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Mock data generation requires some cluster information" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# cluster properties from https://arxiv.org/pdf/1611.03866.pdf\n", + "cluster_id = \"SPT-CL J0000−5748\"\n", + "cluster_m = 4.56e14 # M500,c\n", + "cluster_z = 0.702\n", + "cluster_ra = 0.2499\n", + "cluster_dec = -57.8064\n", + "concentration = 5 # (arbitrary value, not from the paper)\n", + "\n", + "# source redshift distribution properties\n", + "cluster_beta_s_mean = 0.466\n", + "cluster_beta_s2_mean = 0.243\n", + "ngal_density = (\n", + " 26.0 * 100\n", + ") # density of source galaxies per arcmin^2 # (arbitrary value, not from the paper)\n", + "model_z_distrib_dict = {\"func\": desc_srd, \"name\": \"desc_srd\"}\n", + "delta_z_cut = 0.1\n", + "zsrc_min = cluster_z + delta_z_cut\n", + "zsrc_max = 3.0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Different inputs for the source redshifts" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Discrete redshifts" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Generate the mock source catalog\n", + "\n", + "The CLMM mock data generation will provide, among other things, a redshift value for each background galaxy that is draw from the redshift distribution given by `model_z_distrib_dict`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "np.random.seed(0)\n", + "source_catalog = mock.generate_galaxy_catalog(\n", + " cluster_m,\n", + " cluster_z,\n", + " concentration,\n", + " cosmo,\n", + " model_z_distrib_dict[\"name\"],\n", + " delta_so=500,\n", + " massdef=\"critical\",\n", + " zsrc_min=zsrc_min,\n", + " zsrc_max=zsrc_max,\n", + " ngal_density=ngal_density,\n", + " cluster_ra=cluster_ra,\n", + " cluster_dec=cluster_dec,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Beta parameters\n", + "From this udnerlying redshift distribution, one may directly compute the average $\\langle\\beta_s\\rangle$ and $\\langle\\beta_s^2\\rangle$ quantities" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "beta_label = lambda beta: rf\"\\langle\\beta_s\\rangle = {beta:.2f}\"\n", + "beta_sq_label = lambda beta_sq: rf\"\\langle\\beta_s^2\\rangle = {beta_sq:.2f}\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is also possible to compute $\\langle\\beta_s\\rangle$ and $\\langle\\beta_s^2\\rangle$ using galaxy shape weights:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "z_inf = 1000\n", + "\n", + "beta_s_mean = clmm.utils.compute_beta_s_mean_from_distribution(\n", + " cluster_z,\n", + " z_inf,\n", + " cosmo,\n", + " zmax=zsrc_max,\n", + " delta_z_cut=delta_z_cut,\n", + " zmin=None,\n", + " z_distrib_func=model_z_distrib_dict[\"func\"],\n", + ")\n", + "beta_s_square_mean = clmm.utils.compute_beta_s_square_mean_from_distribution(\n", + " cluster_z,\n", + " z_inf,\n", + " cosmo,\n", + " zmax=zsrc_max,\n", + " delta_z_cut=delta_z_cut,\n", + " zmin=None,\n", + " z_distrib_func=model_z_distrib_dict[\"func\"],\n", + ")\n", + "\n", + "display(Math(beta_label(beta_s_mean)))\n", + "display(Math(beta_sq_label(beta_s_square_mean)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Visualisation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "z = np.linspace(0, zsrc_max, 1000)\n", + "fig = prep_plot(figsize=(9, 9))\n", + "ax = plt.axes()\n", + "\n", + "ax.hist(source_catalog[\"z\"], bins=50, alpha=0.3, density=True, label=\"discrete values\")\n", + "ax.axvline(zsrc_min, color=\"red\")\n", + "# here we multiply by a constant for visualisation purposes\n", + "ax.plot(\n", + " z,\n", + " model_z_distrib_dict[\"func\"](z) * 25,\n", + " linestyle=\"dashed\",\n", + " label=\"distribution function\",\n", + ")\n", + "\n", + "ax.text(\n", + " 1.75,\n", + " 0.9,\n", + " f\"Resulting efficiency\\n${beta_label(beta_s_mean)}$\\n${beta_sq_label(beta_s_square_mean)}$\",\n", + " bbox={\"boxstyle\": \"round\", \"alpha\": 0.5, \"edgecolor\": \".7\", \"facecolor\": \"1\"},\n", + " fontsize=8,\n", + ")\n", + "ax.text(zsrc_min, 0.03, \"$z_{min}$\", color=\"r\", fontsize=8, rotation=30)\n", + "\n", + "\n", + "ax.set_xlim(0, 2.99)\n", + "ax.set_xlabel(\"redshift\")\n", + "ax.set_ylabel(\"distribution\")\n", + "ax.set_yticklabels([])\n", + "ax.legend(fontsize=8)\n", + "\n", + "add_grid(ax)\n", + "plt.tight_layout()\n", + "plt.savefig(\"theo_diff_z_types.png\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Profiles" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "prof_kwargs = dict(\n", + " r_proj=np.logspace(np.log10(0.2), np.log10(5), 10),\n", + " mdelta=cluster_m,\n", + " cdelta=concentration,\n", + " z_cluster=cluster_z,\n", + " cosmo=cosmo,\n", + " delta_mdef=500,\n", + " massdef=\"critical\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, + "source": [ + "### g_t" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "gt = {\n", + " key: clmm.theory.compute_reduced_tangential_shear(**prof_kwargs, **_kwargs)\n", + " for key, _kwargs in (\n", + " (\n", + " \"exact\",\n", + " dict(\n", + " z_src=model_z_distrib_dict[\"func\"],\n", + " z_src_info=\"distribution\",\n", + " approx=None,\n", + " ),\n", + " ),\n", + " (\n", + " \"order1\",\n", + " dict(\n", + " z_src=[beta_s_mean, beta_s_square_mean],\n", + " z_src_info=\"beta\",\n", + " approx=\"order1\",\n", + " ),\n", + " ),\n", + " (\n", + " \"order2\",\n", + " dict(\n", + " z_src=[beta_s_mean, beta_s_square_mean],\n", + " z_src_info=\"beta\",\n", + " approx=\"order2\",\n", + " ),\n", + " ),\n", + " )\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, + "source": [ + "### mu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "mu = {\n", + " key: clmm.theory.compute_magnification(**prof_kwargs, **_kwargs)\n", + " for key, _kwargs in (\n", + " (\n", + " \"exact\",\n", + " dict(\n", + " z_src=model_z_distrib_dict[\"func\"],\n", + " z_src_info=\"distribution\",\n", + " approx=None,\n", + " ),\n", + " ),\n", + " (\n", + " \"order1\",\n", + " dict(\n", + " z_src=[beta_s_mean, beta_s_square_mean],\n", + " z_src_info=\"beta\",\n", + " approx=\"order1\",\n", + " ),\n", + " ),\n", + " (\n", + " \"order2\",\n", + " dict(\n", + " z_src=[beta_s_mean, beta_s_square_mean],\n", + " z_src_info=\"beta\",\n", + " approx=\"order2\",\n", + " ),\n", + " ),\n", + " )\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "jp-MarkdownHeadingCollapsed": true + }, + "source": [ + "### delta_mu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "alpha = [2, -0.5]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "dmu = {\n", + " key: [\n", + " clmm.theory.compute_magnification_bias(**prof_kwargs, **_kwargs, alpha=_alpha)\n", + " for _alpha in alpha\n", + " ]\n", + " for key, _kwargs in (\n", + " (\n", + " \"exact\",\n", + " dict(\n", + " z_src=model_z_distrib_dict[\"func\"],\n", + " z_src_info=\"distribution\",\n", + " approx=None,\n", + " ),\n", + " ),\n", + " (\n", + " \"order1\",\n", + " dict(\n", + " z_src=[beta_s_mean, beta_s_square_mean],\n", + " z_src_info=\"beta\",\n", + " approx=\"order1\",\n", + " ),\n", + " ),\n", + " (\n", + " \"order2\",\n", + " dict(\n", + " z_src=[beta_s_mean, beta_s_square_mean],\n", + " z_src_info=\"beta\",\n", + " approx=\"order2\",\n", + " ),\n", + " ),\n", + " )\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def plot_cases(axes, radius, profiles):\n", + " axes[0].loglog(radius, profiles[0][0], **profiles[0][-1])\n", + " for case in profiles[1:]:\n", + " axes[0].loglog(radius, case[0], **case[-1])\n", + " axes[1].plot(radius, 100 * (case[0] / profiles[0][0] - 1), **case[-1])\n", + "\n", + " axes[1].set_xlabel(\"R [Mpc]\")\n", + " for ax in axes:\n", + " add_grid(ax)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib.ticker import NullFormatter" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig, axes = prep_plot(\n", + " figsize=(18, 7),\n", + " subplots=(2, 3),\n", + " subplots_kwargs=dict(sharex=True, height_ratios=[4, 1]),\n", + ")\n", + "plot_cases(\n", + " axes[:, 0],\n", + " prof_kwargs[\"r_proj\"],\n", + " [\n", + " (gt[\"exact\"], {\"label\": \"No Approx.\", \"color\": \"0\", \"lw\": 0.8}),\n", + " (gt[\"order1\"], {\"label\": \"Order 1\", \"color\": \"C0\"}),\n", + " (gt[\"order2\"], {\"label\": \"Order 2\", \"color\": \"C1\"}),\n", + " ],\n", + ")\n", + "plot_cases(\n", + " axes[:, 1],\n", + " prof_kwargs[\"r_proj\"],\n", + " [\n", + " (mu[\"exact\"], {\"label\": \"No Approx.\", \"color\": \"0\", \"lw\": 0.8}),\n", + " (mu[\"order1\"], {\"label\": \"Order 1\", \"color\": \"C0\"}),\n", + " (mu[\"order2\"], {\"label\": \"Order 2\", \"color\": \"C1\"}),\n", + " ],\n", + ")\n", + "plot_cases(\n", + " axes[:, 2],\n", + " prof_kwargs[\"r_proj\"],\n", + " [\n", + " (dmu[\"exact\"][0], {\"label\": \"No Approx.\", \"color\": \"0\", \"lw\": 0.8}),\n", + " (dmu[\"order1\"][0], {\"label\": \"Order 1\", \"color\": \"C0\"}),\n", + " (dmu[\"order2\"][0], {\"label\": \"Order 2\", \"color\": \"C1\"}),\n", + " ],\n", + ")\n", + "plot_cases(\n", + " axes[:, 2],\n", + " prof_kwargs[\"r_proj\"],\n", + " [\n", + " (dmu[\"exact\"][1], {\"label\": \"No Approx.\", \"color\": \"0\", \"ls\": \"--\", \"lw\": 0.6}),\n", + " (dmu[\"order1\"][1], {\"label\": \"Order 1\", \"color\": \"C0\", \"ls\": \"--\", \"lw\": 0.8}),\n", + " (dmu[\"order2\"][1], {\"label\": \"Order 2\", \"color\": \"C1\", \"ls\": \"--\", \"lw\": 0.8}),\n", + " ],\n", + ")\n", + "axes[0, 0].legend(fontsize=8)\n", + "axes[1, 0].set_ylabel(\"%\")\n", + "\n", + "for ax, label in zip(axes[0], (\"$\\gamma_t$\", \"$\\mu_t$\", \"$\\delta_{\\mu_t}$\")):\n", + " ax.set_title(label, fontsize=10)\n", + "\n", + "for ax in axes.flatten():\n", + " ax.tick_params(axis=\"both\", which=\"major\", labelsize=8)\n", + " # ax.tick_params(axis=\"both\", which=\"minor\", labelsize=8)\n", + " ax.yaxis.set_minor_formatter(NullFormatter())\n", + " ax.set_xlim(0.2, 5)\n", + "\n", + "handles, labels = axes[0, -1].get_legend_handles_labels()\n", + "axes[0, -1].legend(\n", + " handles[::3],\n", + " [rf\"$\\alpha={_alpha}$\" for _alpha in alpha],\n", + " # loc=(0.38, 0.8),\n", + " fontsize=8,\n", + ")\n", + "\n", + "\n", + "plt.tight_layout()\n", + "plt.subplots_adjust(hspace=0)\n", + "\n", + "plt.savefig(\"theo_diff_z_types_profiles.png\")" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/Paper_v2.0/Figure_07_triaxial_excess_surface_density_profiles.ipynb b/examples/Paper_v2.0/Figure_07_triaxial_excess_surface_density_profiles.ipynb new file mode 100644 index 000000000..7aaf8e498 --- /dev/null +++ b/examples/Paper_v2.0/Figure_07_triaxial_excess_surface_density_profiles.ipynb @@ -0,0 +1,296 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "7c213181-875a-408b-a95f-19dac19a324e", + "metadata": {}, + "source": [ + "# To make a plot that compares the contribution to excess surface density profiles for weak lensing when the lens is triaxial" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43f767fb-627e-4c15-aede-d7a7b051f9bb", + "metadata": {}, + "outputs": [], + "source": [ + "import clmm\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "# import seaborn as sns\n", + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "583e00e3-2f75-4a10-a773-ee816be0514a", + "metadata": {}, + "outputs": [], + "source": [ + "r = np.linspace(0.1, 5, 100)\n", + "\n", + "# A sample Mass, concentration for a halo:\n", + "mdelta_fit = 2.0e14 # in M_sun/h\n", + "cdelta_fit = 3.89\n", + "\n", + "# Ellipticities:\n", + "ell_1_0 = 0.0 # q = 1.0, ellipticity is (1-q)/(1+q)\n", + "ell_0_7 = 0.176 # q = 0.7, ellipticity is (1-q)/(1+q)\n", + "ell_0_3 = 0.497 # q = 0.3, ellipticity is (1-q)/(1+q)\n", + "\n", + "z_cl = 0.47\n", + "\n", + "mdef = \"critical\"\n", + "\n", + "\"\"\"\n", + "A Spherical Halo: (Axis ratio, q = 1.0 )\n", + "\"\"\"\n", + "ds_model_e_0 = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_1_0,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"mono\",\n", + ")\n", + "ds_const_model_e_0 = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_1_0,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"quad_const\",\n", + ")\n", + "ds_4theta_model_e_0 = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_1_0,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"quad_4theta\",\n", + ")\n", + "\n", + "\"\"\"\n", + "An Elliptical Halo: (Axis ratio, q = 0.7)\n", + "\"\"\"\n", + "ds_model = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_0_7,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"mono\",\n", + ")\n", + "ds_const_model = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_0_7,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"quad_const\",\n", + ")\n", + "ds_4theta_model = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_0_7,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"quad_4theta\",\n", + ")\n", + "\n", + "\n", + "\"\"\"\n", + "An Elliptical Halo: (Axis ratio, q = 0.3)\n", + "\"\"\"\n", + "ds_model_0_3 = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_0_3,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"mono\",\n", + ")\n", + "ds_const_model_0_3 = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_0_3,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"quad_const\",\n", + ")\n", + "ds_4theta_model_0_3 = clmm.compute_excess_surface_density_triaxial(\n", + " ell=ell_0_3,\n", + " r_proj=r,\n", + " mdelta=mdelta_fit,\n", + " cdelta=cdelta_fit,\n", + " z_cl=z_cl,\n", + " cosmo=cosmo,\n", + " halo_profile_model=\"nfw\",\n", + " delta_mdef=200,\n", + " massdef=mdef,\n", + " term=\"quad_4theta\",\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b87d23bd-7432-42cc-aee4-addbdd6f90c0", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots(1, 2, figsize=[10, 5])\n", + "\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_model_e_0 / 1e12,\n", + " ax=ax[0],\n", + " markers=True,\n", + " ms=20.0,\n", + " color=\"black\",\n", + " ls=\"dashdot\",\n", + " label=\"Spherical NFW\",\n", + ")\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_model / 1e12,\n", + " ax=ax[0],\n", + " color=\"darkorange\",\n", + " label=\"Elliptical NFW (q = 2/3)\",\n", + " ls=\"solid\",\n", + ")\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_model_0_3 / 1e12,\n", + " ax=ax[0],\n", + " color=\"darkorange\",\n", + " label=\"Elliptical NFW (q = 1/3)\",\n", + " ls=\"solid\",\n", + " alpha=0.4,\n", + ")\n", + "ax[0].set_yscale(\"log\")\n", + "ax[0].set_xscale(\"log\")\n", + "ax[0].set_xlabel(\"r [Mpc]\", fontsize=18)\n", + "ax[0].set_ylabel(r\"Monopole $\\Delta\\Sigma \\,[M_{\\odot} h/\\rm{pc}^{2}]$\", fontsize=18)\n", + "ax[0].tick_params(axis=\"both\", which=\"both\", labelsize=12)\n", + "ax[0].legend(fontsize=11)\n", + "plt.tight_layout()\n", + "axin1 = ax[0].inset_axes([0.18, 7, 1, 20], transform=ax[0].transData)\n", + "\n", + "sns.lineplot(x=r, y=(1 - ds_model / ds_model_e_0) * 100, ax=axin1, color=\"crimson\", label=\"q=2/3\")\n", + "sns.lineplot(\n", + " x=r,\n", + " y=(1 - ds_model_0_3 / ds_model_e_0) * 100,\n", + " ax=axin1,\n", + " color=\"crimson\",\n", + " alpha=0.4,\n", + " label=\"q=1/3\",\n", + ")\n", + "axin1.set_xscale(\"log\")\n", + "axin1.set_ylabel(\"Difference (%)\", fontsize=10)\n", + "axin1.legend()\n", + "# axin1.set_xlabel('r', fontsize=15)\n", + "\n", + "sns.lineplot(\n", + " x=r, y=ds_const_model_e_0 / 1e12, ax=ax[1], color=\"black\", ls=\"dashdot\", label=\"Spherical NFW\"\n", + ")\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_const_model / 1e12,\n", + " ax=ax[1],\n", + " color=\"crimson\",\n", + " label=r\"Elliptical NFW (q = 2/3) | $4\\theta$\",\n", + ")\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_4theta_model / 1e12,\n", + " ax=ax[1],\n", + " color=\"darkorange\",\n", + " label=\"Elliptical NFW (q = 2/3) | const\",\n", + " ls=\"dashed\",\n", + ")\n", + "\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_const_model_0_3 / 1e12,\n", + " ax=ax[1],\n", + " color=\"crimson\",\n", + " label=r\"Elliptical NFW (q = 1/3) | $4\\theta$\",\n", + " alpha=0.4,\n", + ")\n", + "sns.lineplot(\n", + " x=r,\n", + " y=ds_4theta_model_0_3 / 1e12,\n", + " ax=ax[1],\n", + " color=\"darkorange\",\n", + " label=\"Elliptical NFW (q = 1/3) | const\",\n", + " ls=\"dashed\",\n", + " alpha=0.4,\n", + ")\n", + "# ax[1].set_yscale('log')\n", + "ax[1].set_xscale(\"log\")\n", + "ax[1].set_xlabel(\"r [Mpc]\", fontsize=18)\n", + "ax[1].set_ylabel(r\"Quadrupole $\\Delta\\Sigma \\,[M_{\\odot} h/\\rm{pc}^{2}]$\", fontsize=18)\n", + "ax[1].tick_params(axis=\"both\", which=\"both\", labelsize=12)\n", + "ax[1].legend(fontsize=11)\n", + "plt.tight_layout()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/Paper_v2.0/Figure_08_Fit_Halo_mass_to_HSC_data_paper2.ipynb b/examples/Paper_v2.0/Figure_08_Fit_Halo_mass_to_HSC_data_paper2.ipynb new file mode 100644 index 000000000..0cb819092 --- /dev/null +++ b/examples/Paper_v2.0/Figure_08_Fit_Halo_mass_to_HSC_data_paper2.ipynb @@ -0,0 +1,832 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "74785dcc", + "metadata": { + "tags": [] + }, + "source": [ + "# Example 4: Using a real dataset (HSC)\n", + "## Fit halo mass to shear profile using HSC data\n", + "\n", + "_the LSST-DESC CLMM team_\n", + "\n", + "This notebook can be run on NERSC.\n", + "\n", + "Here we demonstrate how to run CLMM on real observational datasets. As an example, we use the data from the Hyper Suprime-Cam Subaru Strategic Program (HSC SSP) public releases (Aihara+2018ab, 2019; Mandelbaum+2018ab) (Credit: NAOJ / HSC Collaboration), which have similar observation conditions and data formats to the Rubin LSST.\n", + "\n", + "The steps in this notebook includes:\n", + "- [Setting things up](#Setup)\n", + "- [Selecting a cluster](#Selecting_a_cluster)\n", + "- [Downloading the published catalog at the cluster field](#Downloading_the_catalog)\n", + "- [Loading the catalog into CLMM](#Loading_the_catalog)\n", + "- [Running CLMM on the dataset](#Running_CLMM)\n", + "\n", + "Links:\n", + "\n", + "The data access of the HSC SSP Public Data Release: \n", + "https://hsc-release.mtk.nao.ac.jp/doc/index.php/data-access__pdr3/\n", + "\n", + "Shape catalog: \n", + "https://hsc-release.mtk.nao.ac.jp/doc/index.php/s16a-shape-catalog-pdr2/\n", + "\n", + "FAQ: \n", + "https://hsc-release.mtk.nao.ac.jp/doc/index.php/faq__pdr3/\n", + "\n", + "Photometric redshifts:\n", + "https://hsc-release.mtk.nao.ac.jp/doc/index.php/photometric-redshifts/\n", + "\n", + "Cluster catalog:\n", + "https://hsc-release.mtk.nao.ac.jp/doc/index.php/camira_pdr2/" + ] + }, + { + "cell_type": "markdown", + "id": "8b2a5bbe", + "metadata": {}, + "source": [ + "\n", + "## 1. Setup\n", + " \n", + "We import packages." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "89a38de9", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle as pkl\n", + "from pathlib import Path\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "# %matplotlib inline\n", + "from astropy.table import Table" + ] + }, + { + "cell_type": "markdown", + "id": "cf169f3c", + "metadata": {}, + "source": [ + "\n", + "## 2. Selecting a cluster\n", + "\n", + "We use the HSC SSP publications (https://hsc.mtk.nao.ac.jp/ssp/publications/) to select a list of reported massive galaxy clusters that have been measured by weak lensing. In the table below, the coordinates are for lensing peaks unless otherwise specified, and we assume h=0.7.\n", + "\n", + "Name | $$z_{cl}$$ | RA (deg) | DEC (deg) | WL Mass | Reference | Note\n", + "- | - | - | - | - | - | -\n", + "HWL16a-094 | 0.592 | 223.0801 | 0.1689 | 15.3, 7.8 | [Hamana+2020](https://ui.adsabs.harvard.edu/abs/2020PASJ...72...78H/abstract) | CAMIRA ID 1417; Miyazaki+2018 rank 34 \n", + "HWL16a-026 | 0.424 | 130.5895 | 1.6473 | 8.7, 4.7 | [Hamana+2020](https://ui.adsabs.harvard.edu/abs/2020PASJ...72...78H/abstract) | --\n", + "HWL16a-034 | 0.315 | 139.0387 | −0.3966 | 8.1, 5.6 | [Hamana+2020](https://ui.adsabs.harvard.edu/abs/2020PASJ...72...78H/abstract) | Abell 776; MACS J0916.1−0023; Miyazaki+2018 rank 8; see also Medezinski+2018 \n", + "Rank 9 | 0.312 | 37.3951 | −3.6099 | --, 5.9 | [Miyazaki+2018](https://ui.adsabs.harvard.edu/abs/2018PASJ...70S..27M/abstract) | --\n", + "Rank 48 | 0.529 | 220.7900 | 1.0509 | --, 10.4 | [Miyazaki+2018](https://ui.adsabs.harvard.edu/abs/2018PASJ...70S..27M/abstract) | --\n", + "Rank 62 | 0.592 | 216.6510 | 0.7982 | --, 10.2 | [Miyazaki+2018](https://ui.adsabs.harvard.edu/abs/2018PASJ...70S..27M/abstract) | --\n", + "MaxBCG J140.53188+03.76632 | 0.2701 | 140.54565 | 3.77820 | 44.3, 25.1 | [Medezinski+2018](https://ui.adsabs.harvard.edu/abs/2018PASJ...70S..28M%2F/abstract) | BCG center (close to the X-ray center); PSZ2 G228.50+34.95; double BCGs\n", + "XLSSC006 | 0.429 | 35.439 | −3.772 | 9.6, 5.6 | [Umetsu+2020](https://ui.adsabs.harvard.edu/abs/2020ApJ...890..148U/abstract) | X-ray center\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "71f2b585", + "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "tags": [] + }, + "source": [ + "\n", + "## 3. Downloading the catalog at the cluster field\n", + "\n", + "The 3 most massive cluster-candidates are MaxBCG.J140.53188+03.76632 (in the GAMA09H field), Miyazaki+2018 (M18 hearafter) rank 48 and 62 (in the GAMA15H field). We consider MaxBCG.J140.53188+03.76632 first.\n", + "The webpage for HSC SSP data access is here [link](https://hsc-release.mtk.nao.ac.jp/doc/index.php/data-access__pdr3/).\n", + "To download the catalogs, we need to first register for a user account ([link](https://hsc-release.mtk.nao.ac.jp/datasearch/new_user/new)).\n", + "Then we log into the system, query and download the catalogs at [CAS Search](https://hsc-release.mtk.nao.ac.jp/datasearch/helps/sql_search); we use `object_id` to cross match the shape catalog, photo-z catalog, and photometry catalog. \n", + "Since the clusters are at redshift about 0.4, a radius of 10 arcmin would be about 3 Mpc. However, we make a query for the whole field to save time.\n", + "The final catalog includes shape info, photo-z, and photometry. \n", + "Here is an example of the query SQL command (thank Calum Murray; [example command](https://hsc-release.mtk.nao.ac.jp/doc/index.php/s16a-shape-catalog-pdr2/); [schema](https://hsc-release.mtk.nao.ac.jp/schema/)); the query could take 1 hour and the size of the catalog could be 400 MB (.csv.gz). If you would like to test it, please copy from \"select\" to \"--LIMIT 5\". Also select \"PDR1\" or press \"Guess release from your SQL\" at the [CAS Search](https://hsc-release.mtk.nao.ac.jp/datasearch/helps/sql_search) webpage.\n", + "To unpress the file \".gz\", use \"gunzip\" or \"gzip -d\".\n", + "\n", + "```\n", + "select\n", + " b.*, \n", + " c.ira, c.idec, \n", + " a.ishape_hsm_regauss_e1, a.ishape_hsm_regauss_e2, \n", + " a.ishape_hsm_regauss_resolution, a.ishape_hsm_regauss_sigma, \n", + " d1.photoz_best as ephor_ab_photoz_best, d1.photoz_risk_best as ephor_ab_photoz_risk_best, \n", + " d2.photoz_best as frankenz_photoz_best, d2.photoz_risk_best as frankenz_photoz_risk_best, \n", + " d3.photoz_best as nnpz_photoz_best, d3.photoz_risk_best as nnpz_photoz_risk_best, \n", + " e.icmodel_mag, e.icmodel_mag_err, \n", + " e.detect_is_primary, \n", + " e.iclassification_extendedness, \n", + " e.icmodel_flux_flags, \n", + " e.icmodel_flux, e.icmodel_flux_err, \n", + " c.iblendedness_abs_flux\n", + "from\n", + " s16a_wide.meas2 a\n", + " inner join s16a_wide.weaklensing_hsm_regauss b using (object_id)\n", + " inner join s16a_wide.meas c using (object_id)\n", + " -- inner join s16a_wide.photoz_demp d using (object_id)\n", + " -- inner join s16a_wide.photoz_ephor d using (object_id)\n", + " inner join s16a_wide.photoz_ephor_ab d1 using (object_id)\n", + " inner join s16a_wide.photoz_frankenz d2 using (object_id)\n", + " -- inner join s16a_wide.photoz_mizuki d using (object_id)\n", + " -- inner join s16a_wide.photoz_mlz d using (object_id)\n", + " inner join s16a_wide.photoz_nnpz d3 using (object_id)\n", + " inner join s16a_wide.forced e using (object_id)\n", + "-- Uncomment the specific lines depending upon the field to be used\n", + " -- where s16a_wide.search_xmm(c.skymap_id)\n", + " -- where s16a_wide.search_wide01h(c.skymap_id)\n", + " -- where s16a_wide.search_vvds(c.skymap_id)\n", + " -- where s16a_wide.search_hectomap(c.skymap_id)\n", + " -- where s16a_wide.search_gama15h(c.skymap_id)\n", + " where s16a_wide.search_gama09h(c.skymap_id)\n", + " --AND e.detect_is_primary\n", + " --AND conesearch(c.icoord, 140.54565, 3.77820, 600) \n", + " --AND NOT e.icmodel_flux_flags\n", + " --AND e.iclassification_extendedness>0.5\n", + " --LIMIT 5\n", + "```\n" + ] + }, + { + "cell_type": "markdown", + "id": "eba97e69", + "metadata": {}, + "source": [ + "\n", + "## 4. Loading the catalog into CLMM\n", + "\n", + "Once we have the catalog, we read in the catalog, make cuts on the catalog, and adjust column names to prepare for the analysis in CLMM.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8dd8322-f639-4500-8624-7e973ab9294d", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "# Assume the downloaded catalog is at this path:\n", + "filename = \"/sps/lsst/groups/clusters/CLMM/HSC_data_example/197376_GAMMA09H.csv\"\n", + "data_0 = Table.read(filename, format=\"ascii.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03e1ca9a", + "metadata": {}, + "outputs": [], + "source": [ + "print(data_0.colnames)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8da2cdb", + "metadata": {}, + "outputs": [], + "source": [ + "# We select \"frankenz\" for the test, but there are other methods available.\n", + "photoz_type = \"frankenz\"\n", + "# photoz_type = \"nnpz\"\n", + "# photoz_type = \"ephor_ab\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bb7d297a", + "metadata": {}, + "outputs": [], + "source": [ + "# Cuts\n", + "def make_cuts(catalog_in):\n", + " # We consider some cuts in Mandelbaum et al. 2018 (HSC SSP Y1 shear catalog).\n", + " select = catalog_in[\"detect_is_primary\"] == \"True\"\n", + " select &= catalog_in[\"icmodel_flux_flags\"] == \"False\"\n", + " select &= catalog_in[\"iclassification_extendedness\"] > 0.5\n", + " select &= catalog_in[\"icmodel_mag_err\"] <= 2.5 / np.log(10.0) / 10.0\n", + " select &= (\n", + " catalog_in[\"ishape_hsm_regauss_e1\"] ** 2 + catalog_in[\"ishape_hsm_regauss_e2\"] ** 2 < 4.0\n", + " )\n", + " select &= catalog_in[\"icmodel_mag\"] <= 24.5\n", + " select &= catalog_in[\"iblendedness_abs_flux\"] < (10 ** (-0.375))\n", + " select &= catalog_in[\"ishape_hsm_regauss_resolution\"] >= 0.3 # similar to extendedness\n", + " select &= catalog_in[\"ishape_hsm_regauss_sigma\"] <= 0.4\n", + " # Note \"zbest\" minimizes the risk of the photo-z point estimate being far away from the true value.\n", + " # Details: https://hsc-release.mtk.nao.ac.jp/doc/wp-content/uploads/2017/02/pdr1_photoz_release_note.pdf\n", + " select &= catalog_in[\"%s_photoz_risk_best\" % photoz_type] < 0.5\n", + "\n", + " catalog_out = catalog_in[select]\n", + "\n", + " return catalog_out\n", + "\n", + "\n", + "data_1 = make_cuts(data_0)\n", + "print(len(data_0), len(data_1), len(data_1) * 1.0 / len(data_0))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bac2fc15", + "metadata": {}, + "outputs": [], + "source": [ + "# Reference: Mandelbaum et al. 2018 \"The first-year shear catalog of the Subaru Hyper Suprime-Cam Subaru Strategic Program Survey\".\n", + "# Section A.3.2: \"per-object galaxy shear estimate\".\n", + "def apply_shear_calibration(catalog_in):\n", + " e1_0 = catalog_in[\"ishape_hsm_regauss_e1\"]\n", + " e2_0 = -catalog_in[\"ishape_hsm_regauss_e2\"]\n", + " e_rms = catalog_in[\"ishape_hsm_regauss_derived_rms_e\"]\n", + " m = catalog_in[\"ishape_hsm_regauss_derived_shear_bias_m\"]\n", + " c1 = catalog_in[\"ishape_hsm_regauss_derived_shear_bias_c1\"]\n", + " c2 = catalog_in[\"ishape_hsm_regauss_derived_shear_bias_c2\"]\n", + " # Note: in the mass fit we have not implemented the weight yet.\n", + " weight = catalog_in[\"ishape_hsm_regauss_derived_shape_weight\"]\n", + "\n", + " R = 1.0 - np.sum(weight * e_rms**2.0) / np.sum(weight)\n", + " m_mean = np.sum(weight * m) / np.sum(weight)\n", + " c1_mean = np.sum(weight * c1) / np.sum(weight)\n", + " c2_mean = np.sum(weight * c2) / np.sum(weight)\n", + " print(\"R, m_mean, c1_mean, c2_mean: \", R, m_mean, c1_mean, c2_mean)\n", + "\n", + " g1 = (e1_0 / (2.0 * R) - c1) / (1.0 + m_mean)\n", + " g2 = (e2_0 / (2.0 * R) - c2) / (1.0 + m_mean)\n", + "\n", + " return g1, g2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cff6ac8e", + "metadata": {}, + "outputs": [], + "source": [ + "# Adjust column names.\n", + "def adjust_column_names(catalog_in):\n", + " # We consider a map between new and old column names.\n", + " # Note we have considered shear calibration here.\n", + " column_name_map = {\n", + " \"ra\": \"ira\",\n", + " \"dec\": \"idec\",\n", + " \"z\": \"%s_photoz_best\" % photoz_type,\n", + " \"id\": \"# object_id\",\n", + " }\n", + "\n", + " catalog_out = Table()\n", + " for i in column_name_map:\n", + " catalog_out[i] = catalog_in[column_name_map[i]]\n", + "\n", + " g1, g2 = apply_shear_calibration(catalog_in)\n", + " # CLMM uses \"epsilon shape\" rather than \"chi shape\".\n", + " catalog_out[\"e1\"] = g1\n", + " catalog_out[\"e2\"] = g2\n", + "\n", + " return catalog_out\n", + "\n", + "\n", + "data_2 = adjust_column_names(data_1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5315cfc", + "metadata": {}, + "outputs": [], + "source": [ + "# Make some figures for visualization.\n", + "def make_plots(catalog_in):\n", + " # Scatter plot\n", + " plt.figure()\n", + " plt.scatter(catalog_in[\"ra\"], catalog_in[\"dec\"], c=catalog_in[\"z\"], s=1.0, alpha=0.2)\n", + " plt.colorbar()\n", + " plt.xlabel(\"ra\")\n", + " plt.ylabel(\"dec\")\n", + " plt.title(\"z\")\n", + "\n", + " # Histogram\n", + " plt.figure()\n", + " plt.hist(catalog_in[\"z\"], bins=20)\n", + " plt.xlabel(\"z\")\n", + " plt.ylabel(\"count\")\n", + "\n", + " # Relation\n", + " plt.figure()\n", + " plt.plot(catalog_in[\"e1\"], catalog_in[\"e2\"], \",\")\n", + " plt.xlabel(\"e1\")\n", + " plt.ylabel(\"e2\")\n", + "\n", + "\n", + "# make_plots(data_2)" + ] + }, + { + "cell_type": "markdown", + "id": "5dc4163b", + "metadata": {}, + "source": [ + "\n", + "## 5. Running CLMM on the dataset\n", + "We use the functions similar to `examples/Paper_v1.0/gt_and_use_case.ipynb`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2ae7b3db-1246-493a-89af-61daf50d06d9", + "metadata": {}, + "outputs": [], + "source": [ + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5d455cf-9657-4154-ae4a-9983748522e8", + "metadata": {}, + "outputs": [], + "source": [ + "# Using the GalaxyCluster object.\n", + "\n", + "import clmm\n", + "import clmm.dataops as da\n", + "from clmm.utils import convert_units" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2474c36-4b0c-4bab-86a4-021b4a4ef54d", + "metadata": {}, + "outputs": [], + "source": [ + "def make_cluster_with_profile(\n", + " cluster_ra,\n", + " cluster_dec,\n", + " cluster_z,\n", + " galaxies,\n", + "):\n", + " obs_galaxies = galaxies[(galaxies[\"z\"] > (cluster_z + 0.1))]\n", + "\n", + " # Area cut: the query is made for the whole field and this can simplify the processing.\n", + " select = obs_galaxies[\"ra\"] < cluster_ra + 12.0 / 60.0 / np.cos(cluster_dec / 180.0 * np.pi)\n", + " select &= obs_galaxies[\"ra\"] > cluster_ra - 12.0 / 60.0 / np.cos(cluster_dec / 180.0 * np.pi)\n", + " select &= obs_galaxies[\"dec\"] < cluster_dec + 12.0 / 60.0\n", + " select &= obs_galaxies[\"dec\"] > cluster_dec - 12.0 / 60.0\n", + " obs_galaxies = obs_galaxies[select]\n", + "\n", + " obs_galaxies[\"id\"] = np.arange(len(obs_galaxies))\n", + "\n", + " # Put galaxy values on arrays.\n", + " gal_ra = obs_galaxies[\"ra\"] # Galaxies Ra in deg\n", + " gal_dec = obs_galaxies[\"dec\"] # Galaxies Dec in deg\n", + " gal_e1 = obs_galaxies[\"e1\"] # Galaxies elipticipy 1\n", + " gal_e2 = obs_galaxies[\"e2\"] # Galaxies elipticipy 2\n", + " gal_z = obs_galaxies[\"z\"] # Galaxies observed redshift\n", + " gal_id = obs_galaxies[\"id\"] # Galaxies ID\n", + "\n", + " # Create a GCData with the galaxies.\n", + " galaxies = clmm.GCData(\n", + " [gal_ra, gal_dec, gal_e1, gal_e2, gal_z, gal_id],\n", + " names=[\"ra\", \"dec\", \"e1\", \"e2\", \"z\", \"id\"],\n", + " )\n", + "\n", + " # Create a GalaxyCluster.\n", + " cluster = clmm.GalaxyCluster(\"Name of cluster\", cluster_ra, cluster_dec, cluster_z, galaxies)\n", + "\n", + " # Convert elipticities into shears for the members.\n", + " cluster.compute_tangential_and_cross_components()\n", + " print(cluster.galcat.colnames)\n", + "\n", + " # Measure profile and add profile table to the cluster.\n", + " seps = convert_units(cluster.galcat[\"theta\"], \"radians\", \"Mpc\", cluster.z, cosmo)\n", + "\n", + " cluster.make_radial_profile(\n", + " bins=da.make_bins(0.3, 3.0, 15, method=\"evenlog10width\"),\n", + " bin_units=\"Mpc\",\n", + " cosmo=cosmo,\n", + " include_empty_bins=False,\n", + " gal_ids_in_bins=True,\n", + " )\n", + " print(cluster.profile.colnames)\n", + " return cluster\n", + "\n", + "\n", + "# We consider MaxBCG J140.53188+03.76632\n", + "# cluster_z = 0.2701 # Cluster redshift\n", + "# cluster_ra = 140.54565\n", + "# cluster_dec = 3.77820\n", + "\n", + "clusters = {}\n", + "clusters[\"HWL16a-026\"] = make_cluster_with_profile(\n", + " cluster_z=0.424, cluster_ra=130.5895, cluster_dec=1.6473, galaxies=data_2\n", + ")\n", + "clusters[\"HWL16a-034\"] = make_cluster_with_profile(\n", + " cluster_z=0.315, cluster_ra=139.0387, cluster_dec=-0.3966, galaxies=data_2\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a806b0f1", + "metadata": {}, + "outputs": [], + "source": [ + "# Theoretical predictions\n", + "\n", + "# Model relying on the overall redshift distribution of the sources (WtG III Applegate et al. 2014).\n", + "# Note the concentration of MaxBCG J140.53188+03.76632 was not reported.\n", + "# The value from the stacked sample in the paper is ~7.\n", + "# For the mass scale, a typical c-M relation (e.g. Child et al. 2018) would give c~3 though.\n", + "# And we have not considered a c-M relation in the fitting.\n", + "z_inf = 1000\n", + "concentration = 4.0\n", + "\n", + "for cluster in clusters.values():\n", + "\n", + " bs_mean = np.mean(clmm.utils.compute_beta_s(cluster.galcat[\"z\"], cluster.z, z_inf, cosmo))\n", + " bs2_mean = np.mean(clmm.utils.compute_beta_s(cluster.galcat[\"z\"], cluster.z, z_inf, cosmo) ** 2)\n", + "\n", + " cluster.z_src_betas = (bs_mean, bs2_mean)\n", + "\n", + "\n", + "def predict_reduced_tangential_shear_redshift_distribution(cluster, logm):\n", + " gt = clmm.compute_reduced_tangential_shear(\n", + " r_proj=cluster.data_for_fit[\"radius\"], # Radial component of the profile\n", + " mdelta=10**logm, # Mass of the cluster [M_sun]\n", + " cdelta=concentration, # Concentration of the cluster\n", + " z_cluster=cluster.z, # Redshift of the cluster\n", + " z_src=cluster.z_src_betas, # tuple of (bs_mean, bs2_mean)\n", + " z_src_info=\"beta\",\n", + " approx=\"order1\",\n", + " cosmo=cosmo,\n", + " delta_mdef=200,\n", + " massdef=\"critical\",\n", + " halo_profile_model=\"nfw\",\n", + " )\n", + " return gt\n", + "\n", + "\n", + "# Model using individual redshift and radial information, to compute the averaged shear in each radial bin, based on the galaxies actually present in that bin.\n", + "\n", + "for cluster in clusters.values():\n", + " cluster.galcat[\"theta_mpc\"] = convert_units(\n", + " cluster.galcat[\"theta\"], \"radians\", \"mpc\", cluster.z, cosmo\n", + " )\n", + "\n", + "\n", + "def predict_reduced_tangential_shear_individual_redshift(cluster, logm):\n", + " return np.array(\n", + " [\n", + " np.mean(\n", + " clmm.compute_reduced_tangential_shear(\n", + " # Radial component of each source galaxy inside the radial bin\n", + " r_proj=cluster.galcat[radial_bin[\"gal_id\"]][\"theta_mpc\"],\n", + " mdelta=10**logm, # Mass of the cluster [M_sun]\n", + " cdelta=concentration, # Concentration of the cluster\n", + " z_cluster=cluster.z, # Redshift of the cluster\n", + " # Redshift value of each source galaxy inside the radial bin\n", + " z_src=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", + " cosmo=cosmo,\n", + " delta_mdef=200,\n", + " massdef=\"critical\",\n", + " halo_profile_model=\"nfw\",\n", + " )\n", + " )\n", + " for radial_bin in cluster.data_for_fit\n", + " ]\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "48dd5752", + "metadata": {}, + "outputs": [], + "source": [ + "# Mass fitting\n", + "\n", + "\n", + "from clmm.support.sampler import fitters\n", + "\n", + "\n", + "def fit_mass(predict_function, cluster):\n", + "\n", + " cluster.mask_for_fit = cluster.profile[\"n_src\"] > 2\n", + " cluster.data_for_fit = cluster.profile[cluster.mask_for_fit]\n", + "\n", + " popt, pcov = fitters[\"curve_fit\"](\n", + " predict_function,\n", + " cluster,\n", + " cluster.data_for_fit[\"gt\"],\n", + " cluster.data_for_fit[\"gt_err\"],\n", + " bounds=[10.0, 17.0],\n", + " )\n", + " logm, logm_err = popt[0], np.sqrt(pcov[0][0])\n", + " return {\n", + " \"logm\": logm,\n", + " \"logm_err\": logm_err,\n", + " \"m\": 10**logm,\n", + " \"m_err\": (10**logm) * logm_err * np.log(10),\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc3a7934", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "for cluster in clusters.values():\n", + " cluster.fit_redshift_distribution = fit_mass(\n", + " predict_reduced_tangential_shear_redshift_distribution, cluster\n", + " )\n", + " cluster.fit_individual_redshift = fit_mass(\n", + " predict_reduced_tangential_shear_individual_redshift, cluster\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73202bf8", + "metadata": {}, + "outputs": [], + "source": [ + "# Visualization of the results.\n", + "def get_predicted_shear(cluster, predict_function, fit_values):\n", + " gt_est = predict_function(cluster, fit_values[\"logm\"])\n", + " gt_est_err = [\n", + " predict_function(cluster, fit_values[\"logm\"] + i * fit_values[\"logm_err\"]) for i in (-3, 3)\n", + " ]\n", + " return gt_est, gt_est_err\n", + "\n", + "\n", + "for cluster in clusters.values():\n", + " cluster.gt_redshift_distribution, cluster.gt_err_redshift_distribution = get_predicted_shear(\n", + " cluster,\n", + " predict_reduced_tangential_shear_redshift_distribution,\n", + " cluster.fit_redshift_distribution,\n", + " )\n", + " cluster.gt_individual_redshift, cluster.gt_err_individual_redshift = get_predicted_shear(\n", + " cluster,\n", + " predict_reduced_tangential_shear_individual_redshift,\n", + " cluster.fit_individual_redshift,\n", + " )\n", + "# gt_paper1, gt_err_paper1 = get_predicted_shear(\n", + "# predict_reduced_tangential_shear_redshift_distribution, paper_value\n", + "# )\n", + "# gt_paper2, gt_err_paper2 = get_predicted_shear(\n", + "# predict_reduced_tangential_shear_individual_redshift, paper_value\n", + "# )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "60c39758-3f56-4eca-b6df-8fc9d67db42e", + "metadata": {}, + "outputs": [], + "source": [ + "from paper_formating import prep_plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5a7ca7d4", + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib.ticker import MultipleLocator\n", + "\n", + "\n", + "def make_paper_plot(cluster):\n", + " fig, axes = prep_plot(\n", + " subplots=3,\n", + " figsize=(9, 9),\n", + " subplots_kwargs=dict(sharex=True, height_ratios=[1, 3, 1]),\n", + " )\n", + "\n", + " gx_ax, gt_ax, res_ax = axes\n", + "\n", + " errorbar_kwargs = dict(linestyle=\"\", marker=\"o\", markersize=0.8, elinewidth=0.5, capthick=0.5)\n", + "\n", + " gx_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.data_for_fit[\"gx\"],\n", + " cluster.data_for_fit[\"gx_err\"],\n", + " c=\"k\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " # Points in grey have not been used for the fit.\n", + " gx_ax.errorbar(\n", + " cluster.profile[\"radius\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gx\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gx_err\"][~cluster.mask_for_fit],\n", + " c=\"grey\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " gt_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.data_for_fit[\"gt\"],\n", + " cluster.data_for_fit[\"gt_err\"],\n", + " c=\"k\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " # Points in grey have not been used for the fit.\n", + " gt_ax.errorbar(\n", + " cluster.profile[\"radius\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gt\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gt_err\"][~cluster.mask_for_fit],\n", + " c=\"grey\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " pow10 = 15\n", + " mlabel = lambda name, fits: (\n", + " rf\"$M_{{fit}}^{{{name}}} = \"\n", + " rf'{fits[\"m\"]/10**pow10:.2f}\\pm'\n", + " rf'{fits[\"m_err\"]/10**pow10:.2f}'\n", + " rf\"\\times 10^{{{pow10}}} M_\\odot$\"\n", + " )\n", + "\n", + " # The model for the 1st method.\n", + " gt_ax.loglog(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.gt_redshift_distribution,\n", + " \"-C1\",\n", + " label=mlabel(\"N(z)\", cluster.fit_redshift_distribution),\n", + " lw=0.5,\n", + " )\n", + " gt_ax.fill_between(\n", + " cluster.data_for_fit[\"radius\"],\n", + " *cluster.gt_err_redshift_distribution,\n", + " lw=0,\n", + " color=\"C1\",\n", + " alpha=0.2,\n", + " )\n", + "\n", + " # The model for the 2nd method.\n", + " gt_ax.loglog(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.gt_individual_redshift,\n", + " \"-C2\",\n", + " label=mlabel(\"z,R\", cluster.fit_individual_redshift),\n", + " lw=0.5,\n", + " )\n", + " gt_ax.fill_between(\n", + " cluster.data_for_fit[\"radius\"],\n", + " *cluster.gt_err_individual_redshift,\n", + " lw=0,\n", + " color=\"C2\",\n", + " alpha=0.2,\n", + " )\n", + "\n", + " errorbar_kwargs2 = {k: v for k, v in errorbar_kwargs.items() if \"marker\" not in k}\n", + " errorbar_kwargs2[\"markersize\"] = 1\n", + " errorbar_kwargs2[\"markeredgewidth\"] = 0.5\n", + " delta = (cluster.profile[\"radius\"][1] / cluster.profile[\"radius\"][0]) ** 0.25\n", + "\n", + " res_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.data_for_fit[\"gt\"] / cluster.gt_redshift_distribution - 1,\n", + " yerr=cluster.data_for_fit[\"gt_err\"] / cluster.gt_redshift_distribution,\n", + " marker=\"s\",\n", + " c=\"C1\",\n", + " **errorbar_kwargs2,\n", + " )\n", + " # errorbar_kwargs2[\"markersize\"] = 3\n", + " # errorbar_kwargs2[\"markeredgewidth\"] = 0.5\n", + "\n", + " res_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"] * delta,\n", + " cluster.data_for_fit[\"gt\"] / cluster.gt_individual_redshift - 1,\n", + " yerr=cluster.data_for_fit[\"gt_err\"] / cluster.gt_individual_redshift,\n", + " marker=\"*\",\n", + " c=\"C2\",\n", + " **errorbar_kwargs2,\n", + " )\n", + "\n", + " gx_ax.set_ylabel(r\"$g_x$\", fontsize=8)\n", + " gt_ax.set_ylabel(r\"$g_t$\", fontsize=8)\n", + " gt_ax.legend(fontsize=8)\n", + " res_ax.set_xlabel(r\"$R$ [Mpc]\", fontsize=8)\n", + "\n", + " res_ax.set_ylabel(\"$g_t$\\n [rel. diff]\", fontsize=8)\n", + " res_ax.set_xscale(\"log\")\n", + "\n", + " res_ax.set_ylim(-1.05, 1.05)\n", + " res_ax.yaxis.set_minor_locator(MultipleLocator(10))\n", + "\n", + " for ax in axes:\n", + " ax.tick_params(\"x\", labelsize=8)\n", + " ax.tick_params(\"y\", labelsize=8)\n", + "\n", + " for ax in axes:\n", + " ax.grid(lw=0.3, ls=\"-\")\n", + " ax.minorticks_on()\n", + " ax.grid(which=\"minor\", lw=0.1, ls=\":\")\n", + "\n", + " plt.tight_layout()\n", + " plt.subplots_adjust(hspace=0.0)\n", + " return fig, axes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1a0a57c4-a199-4d15-b21a-148e490977fc", + "metadata": {}, + "outputs": [], + "source": [ + "make_paper_plot(clusters[\"HWL16a-026\"])\n", + "plt.savefig(\"hsc_1_new.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f51f28e9-07cd-4624-b491-db6eb2c01f78", + "metadata": {}, + "outputs": [], + "source": [ + "fig, axes = make_paper_plot(clusters[\"HWL16a-034\"])\n", + "axes[1].set_ylim(1.01e-2, 0.25)\n", + "plt.savefig(\"hsc_2_new.png\")" + ] + }, + { + "cell_type": "markdown", + "id": "bc63da5c", + "metadata": {}, + "source": [ + "### Reference\n", + "\n", + "Aihara, H., Arimoto, N., Armstrong, R., et al. 2018, Publications of the Astronomical Society of Japan, 70, S4\n", + "\n", + "Aihara, H., Armstrong, R., Bickerton, S., et al. 2018, Publications of the Astronomical Society of Japan, 70, S8\n", + "\n", + "Aihara, H., AlSayyad, Y., Ando, M., et al. 2019, Publications of the Astronomical Society of Japan, 71\n", + "\n", + "Hamana, T., Shirasaki, M., Lin, Y.-T., 2020, Publications of the Astronomical Society of Japan, 72, 78\n", + "\n", + "Mandelbaum, R., Miyatake, H., Hamana, T., et al. 2018, Publications of the Astronomical Society of Japan, 70, S25\n", + "\n", + "Mandelbaum, R., Lanusse, F., Leauthaud, A., et al. 2018, Monthly Notices of the Royal Astronomical Society, 481, 3170\n", + "\n", + "Medezinski, E., Battaglia, N., Umetsu, K., et al., 2018, Publications of the Astronomical Society of Japan, 70, S28\n", + "\n", + "Miyazaki, S., Oguri, M., Hamana, T., et al., 2018, Publications of the Astronomical Society of Japan, 70, S27\n", + "\n", + "Umetsu, K., Sereno, M., Lieu, M., et al., 2020, Astrophysical Journal, 890, 148\n", + "\n", + "\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/Paper_v2.0/Figure_09_Fit_Halo_mass_to_DES_data_paper2.ipynb b/examples/Paper_v2.0/Figure_09_Fit_Halo_mass_to_DES_data_paper2.ipynb new file mode 100644 index 000000000..9473c6185 --- /dev/null +++ b/examples/Paper_v2.0/Figure_09_Fit_Halo_mass_to_DES_data_paper2.ipynb @@ -0,0 +1,751 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e320d2bf-dce6-4a5b-ab38-04b0c948155f", + "metadata": { + "tags": [] + }, + "source": [ + "# Example 5: Using a real datasets (DES)\n", + "## Fit halo mass to shear profile using DES data\n", + "\n", + "_the LSST-DESC CLMM team_\n", + "\n", + "This notebook can be run on NERSC.\n", + "\n", + "Here we demonstrate how to run CLMM on real observational datasets. As an example, we use the data from the Dark Energy Survey (DES) public releases. The catalogs can be accessed from the NOIRLab Astro Data Lab.\n", + "\n", + "The steps in this notebook includes:\n", + "- [Setting things up](#Setup)\n", + "- [Selecting a cluster](#Selecting_a_cluster)\n", + "- [Downloading the published catalog at the cluster field](#Downloading_the_catalog)\n", + "- [Loading the catalog into CLMM](#Loading_the_catalog)\n", + "- [Running CLMM on the dataset](#Running_CLMM)\n", + "\n", + "Acknowledgement\n", + "\n", + "DES data: https://des.ncsa.illinois.edu/thanks\n", + "\n", + "Astro Data Lab: https://datalab.noirlab.edu/acknowledgements.php\n" + ] + }, + { + "cell_type": "markdown", + "id": "4ef8f003-be65-44a3-8b0a-04749d1f7f13", + "metadata": {}, + "source": [ + "\n", + "## 1. Setup\n", + " \n", + "We import packages." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3503a1a-103f-48aa-b600-ef2d72de82a0", + "metadata": {}, + "outputs": [], + "source": [ + "import pickle as pkl\n", + "from pathlib import Path\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from astropy.table import Table" + ] + }, + { + "cell_type": "markdown", + "id": "5e228cf4-f5f3-4b55-97b7-f1e022a5b29c", + "metadata": {}, + "source": [ + "\n", + "## 2. Selecting a cluster\n", + "\n", + "We use the DES Y1 redMaPPer Catalogs (https://des.ncsa.illinois.edu/releases/y1a1/key-catalogs/key-redmapper) to select a list of high-richness (LAMBDA) galaxy clusters, which likely have high masses.\n", + "\n", + "Name | RA (deg) | DEC (deg) | Z_LAMBDA | LAMBDA | \n", + "- | - | - | - | - \n", + "RMJ025415.5 585710.7 | 43.564574 | -58.95297 | 0.429804 | 234.50368 \n", + "RMJ051637.4 543001.6 | 79.155704 | -54.500456 | 0.30416065 | 195.06956 \n", + "RMJ224851.8 443106.3 | 342.215897 | -44.518403 | 0.3514858 | 178.83827 \n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "c684515e-e176-4b92-9509-0217ade681a0", + "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "tags": [] + }, + "source": [ + "\n", + "## 3. Downloading the catalog at the cluster field\n", + "\n", + "We consider RMJ051637.4-543001.6 (ACO S520) as an example.\n", + "We can access the DES catalog from NOIRLab Data Lab (https://datalab.noirlab.edu/query.php?name=des_dr1.shape_metacal_riz_unblind). No registration is required.\n", + "We make the query and download the catalogs in \"Query Interface\". \n", + "We use `coadd_objects_id` to cross match the shape catalog and photo-z catalog (https://datalab.noirlab.edu/query.php?name=des_dr1.photo_z). \n", + "Since the cluster is at redshift about 0.3, a radius of 0.3 deg would be about a radial distance of 5 Mpc. \n", + "The final catalog includes shape info and photo-z. \n", + "Here is an example of the query SQL command. \n", + "The query could take a few minutes and the size of the catalog is about 1.4 MB (.csv). \n", + "\n", + "```\n", + "SELECT P.mean_z, \n", + "C.ra, C.dec, C.e1, C.e2, C.r11, C.r12, C.r21, C.r22 \n", + "FROM des_dr1.photo_z as P\n", + "INNER JOIN des_dr1.shape_metacal_riz_unblind as C\n", + "ON P.coadd_objects_id=C.coadd_objects_id\n", + "WHERE 't' = Q3C_RADIAL_QUERY(C.ra, C.dec,79.155704, -54.500456, 0.3) \n", + "AND P.minchi2<1\n", + "AND P.z_sigma<0.1\n", + "AND C.flags_select=0\n", + "\n", + "```\n" + ] + }, + { + "cell_type": "markdown", + "id": "9f4535f6-23b6-46e8-b9f8-7aeb899bfe7c", + "metadata": {}, + "source": [ + "\n", + "## 4. Loading the catalog into CLMM\n", + "\n", + "Once we have the catalog, we read in the catalog, make cuts on the catalog, and adjust column names to prepare for the analysis in CLMM.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42f0cb43-e6c8-4c1a-984e-8f0449a5e490", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "# Assume the downloaded catalog is at this path:\n", + "filename = \"/sps/lsst/groups/clusters/CLMM/DES_data_example/ID1+10.csv\"\n", + "data_0 = Table.read(filename, format=\"ascii.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "88e10ef1-f035-462b-98c6-ceac1d32a7e1", + "metadata": {}, + "outputs": [], + "source": [ + "print(data_0.colnames)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c5a40301-a3fd-4b29-a7c7-8bccf4c01c72", + "metadata": {}, + "outputs": [], + "source": [ + "from astropy.table import unique\n", + "\n", + "data_0 = unique(data_0, [\"ra\", \"dec\"])" + ] + }, + { + "cell_type": "markdown", + "id": "e66ea8ec-90f7-4df1-86a1-678a483da776", + "metadata": {}, + "source": [ + "### Shear response\n", + "Shears in the DES data have been measured using the `metacal` method and the catalog provides the shear response terms ($r11,r22, r12, r21$) required to calibrate the shear values. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5df10e3-771d-499e-b462-b72682902b98", + "metadata": {}, + "outputs": [], + "source": [ + "print(np.mean(data_0[\"r11\"]), np.mean(data_0[\"r22\"]))\n", + "print(np.mean(data_0[\"r12\"]), np.mean(data_0[\"r21\"]))\n", + "r_diag = np.mean([np.mean(data_0[\"r11\"]), np.mean(data_0[\"r22\"])])\n", + "r_off_diag = np.mean([np.mean(data_0[\"r12\"]), np.mean(data_0[\"r21\"])])\n", + "print(r_diag, r_off_diag, r_off_diag / r_diag)" + ] + }, + { + "cell_type": "markdown", + "id": "93c5d48a-3325-405e-b20a-e9e862d66975", + "metadata": {}, + "source": [ + "The diagonal terms are close to each other. The off-diagonal terms are much smaller (<1%).\n", + "We use the mean of the diagonal terms to reduce noise.\n", + "We also skip the selection bias since it is typically at percent level." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8a98993f-2261-452b-8515-a2c64d52c744", + "metadata": {}, + "outputs": [], + "source": [ + "# Adjust column names.\n", + "def adjust_column_names(catalog_in):\n", + " # We consider a map between new and old column names.\n", + " # Note we have considered shear calibration here.\n", + " column_name_map = {\n", + " \"ra\": \"ra\",\n", + " \"dec\": \"dec\",\n", + " \"z\": \"mean_z\",\n", + " \"e1\": \"e1\",\n", + " \"e2\": \"e2\",\n", + " }\n", + "\n", + " catalog_out = Table()\n", + " for i in column_name_map:\n", + " catalog_out[i] = catalog_in[column_name_map[i]]\n", + "\n", + " catalog_out[\"e1\"] /= r_diag\n", + " catalog_out[\"e2\"] /= r_diag\n", + "\n", + " return catalog_out\n", + "\n", + "\n", + "obs_galaxies = adjust_column_names(data_0)\n", + "\n", + "select = obs_galaxies[\"e1\"] ** 2 + obs_galaxies[\"e2\"] ** 2 <= 1.0\n", + "print(np.sum(~select))\n", + "obs_galaxies = obs_galaxies[select]" + ] + }, + { + "cell_type": "markdown", + "id": "09a7df70-8d40-4106-9137-9a9036fac7fc", + "metadata": {}, + "source": [ + "### Basic visualization" + ] + }, + { + "cell_type": "markdown", + "id": "e71d6d00-f18e-4e27-969b-f02f13032713", + "metadata": {}, + "source": [ + "\n", + "## 5. Running CLMM on the dataset\n", + "We use the functions similar to `examples/Paper_v1.0/gt_and_use_case.ipynb`." + ] + }, + { + "cell_type": "markdown", + "id": "4435913d-4d81-4d7c-b2a1-d828204cd889", + "metadata": {}, + "source": [ + "### Make a galaxy cluster object" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3514950f-eddf-4acc-8cbf-bd7adda54901", + "metadata": {}, + "outputs": [], + "source": [ + "import clmm\n", + "from cosmology_set import dc2_cosmo as cosmo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f9a8c215-c6d8-4544-a57f-973fd165e257", + "metadata": {}, + "outputs": [], + "source": [ + "import clmm.dataops as da\n", + "from clmm.utils import convert_units" + ] + }, + { + "cell_type": "markdown", + "id": "4d526e90-3c58-4f4e-ad9b-58c95464d72d", + "metadata": {}, + "source": [ + "### Measure the shear profile" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1591b322-3417-49d9-81db-7d868cee6f88", + "metadata": {}, + "outputs": [], + "source": [ + "def make_cluster_with_profile(\n", + " cluster_ra,\n", + " cluster_dec,\n", + " cluster_z,\n", + " galaxies,\n", + "):\n", + "\n", + " # Select background galaxies\n", + " obs_galaxies = galaxies[(galaxies[\"z\"] > (cluster_z + 0.1)) & (galaxies[\"z\"] < 1.5)]\n", + "\n", + " obs_galaxies[\"id\"] = np.arange(len(obs_galaxies))\n", + "\n", + " # Put galaxy values on arrays\n", + " gal_ra = obs_galaxies[\"ra\"] # Galaxies Ra in deg\n", + " gal_dec = obs_galaxies[\"dec\"] # Galaxies Dec in deg\n", + " gal_e1 = obs_galaxies[\"e1\"] # Galaxies elipticipy 1\n", + " gal_e2 = obs_galaxies[\"e2\"] # Galaxies elipticipy 2\n", + " gal_z = obs_galaxies[\"z\"] # Galaxies observed redshift\n", + " gal_id = obs_galaxies[\"id\"] # Galaxies ID\n", + "\n", + " # Create a GCData with the galaxies.\n", + " galaxies = clmm.GCData(\n", + " [gal_ra, gal_dec, gal_e1, gal_e2, gal_z, gal_id],\n", + " names=[\"ra\", \"dec\", \"e1\", \"e2\", \"z\", \"id\"],\n", + " )\n", + "\n", + " # Create a GalaxyCluster.\n", + " cluster = clmm.GalaxyCluster(\"Name of cluster\", cluster_ra, cluster_dec, cluster_z, galaxies)\n", + "\n", + " # Convert ellipticities into shears for the members.\n", + " cluster.compute_tangential_and_cross_components()\n", + " print(cluster.galcat.colnames)\n", + "\n", + " # Measure profile and add profile table to the cluster.\n", + " cluster.make_radial_profile(\n", + " bins=da.make_bins(0.2, 4.0, 6, method=\"evenlog10width\"),\n", + " bin_units=\"Mpc\",\n", + " cosmo=cosmo,\n", + " include_empty_bins=True,\n", + " gal_ids_in_bins=True,\n", + " )\n", + " print(cluster.profile.colnames)\n", + "\n", + " return cluster\n", + "\n", + "\n", + "# We consider RMJ051637.4-543001.6 (ACO S520)\n", + "# cluster_z = 0.30416065 # Cluster redshift\n", + "# cluster_ra = 79.155704 # Cluster Ra in deg\n", + "# cluster_dec = -54.500456 # Cluster Dec in deg\n", + "\n", + "clusters = {}\n", + "\n", + "clusters[\"ID1\"] = make_cluster_with_profile(\n", + " cluster_z=0.4298039972782135,\n", + " cluster_ra=43.564574,\n", + " cluster_dec=-58.95297,\n", + " galaxies=obs_galaxies,\n", + ")\n", + "clusters[\"ID10\"] = make_cluster_with_profile(\n", + " cluster_z=0.3264264166355133,\n", + " cluster_ra=323.800394,\n", + " cluster_dec=-1.04959,\n", + " galaxies=obs_galaxies,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "9cccdd77-3312-4780-a202-0b88c3aa9802", + "metadata": {}, + "source": [ + "### Theoretical predictions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "87e51a27-936a-48f5-abc7-120cff89b3ac", + "metadata": {}, + "outputs": [], + "source": [ + "# Theoretical predictions\n", + "\n", + "# Model relying on the overall redshift distribution of the sources (WtG III Applegate et al. 2014).\n", + "# Note the concentration of MaxBCG J140.53188+03.76632 was not reported.\n", + "# The value from the stacked sample in the paper is ~7.\n", + "# For the mass scale, a typical c-M relation (e.g. Child et al. 2018) would give c~3 though.\n", + "# And we have not considered a c-M relation in the fitting.\n", + "z_inf = 1000\n", + "concentration = 4.0\n", + "\n", + "for cluster in clusters.values():\n", + "\n", + " bs_mean = np.mean(clmm.utils.compute_beta_s(cluster.galcat[\"z\"], cluster.z, z_inf, cosmo))\n", + " bs2_mean = np.mean(clmm.utils.compute_beta_s(cluster.galcat[\"z\"], cluster.z, z_inf, cosmo) ** 2)\n", + "\n", + " cluster.z_src_betas = (bs_mean, bs2_mean)\n", + "\n", + "\n", + "def predict_reduced_tangential_shear_redshift_distribution(cluster, logm):\n", + " gt = clmm.compute_reduced_tangential_shear(\n", + " r_proj=cluster.data_for_fit[\"radius\"], # Radial component of the profile\n", + " mdelta=10**logm, # Mass of the cluster [M_sun]\n", + " cdelta=concentration, # Concentration of the cluster\n", + " z_cluster=cluster.z, # Redshift of the cluster\n", + " z_src=cluster.z_src_betas, # tuple of (bs_mean, bs2_mean)\n", + " z_src_info=\"beta\",\n", + " approx=\"order1\",\n", + " cosmo=cosmo,\n", + " delta_mdef=200,\n", + " massdef=\"critical\",\n", + " halo_profile_model=\"nfw\",\n", + " )\n", + " return gt\n", + "\n", + "\n", + "# Model using individual redshift and radial information, to compute the averaged shear in each radial bin, based on the galaxies actually present in that bin.\n", + "\n", + "for cluster in clusters.values():\n", + " cluster.galcat[\"theta_mpc\"] = convert_units(\n", + " cluster.galcat[\"theta\"], \"radians\", \"mpc\", cluster.z, cosmo\n", + " )\n", + "\n", + "\n", + "def predict_reduced_tangential_shear_individual_redshift(cluster, logm):\n", + " return np.array(\n", + " [\n", + " np.mean(\n", + " clmm.compute_reduced_tangential_shear(\n", + " # Radial component of each source galaxy inside the radial bin\n", + " r_proj=cluster.galcat[radial_bin[\"gal_id\"]][\"theta_mpc\"],\n", + " mdelta=10**logm, # Mass of the cluster [M_sun]\n", + " cdelta=concentration, # Concentration of the cluster\n", + " z_cluster=cluster.z, # Redshift of the cluster\n", + " # Redshift value of each source galaxy inside the radial bin\n", + " z_src=cluster.galcat[radial_bin[\"gal_id\"]][\"z\"],\n", + " cosmo=cosmo,\n", + " delta_mdef=200,\n", + " massdef=\"critical\",\n", + " halo_profile_model=\"nfw\",\n", + " )\n", + " )\n", + " for radial_bin in cluster.data_for_fit\n", + " ]\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "e2fd16d5-6d8b-4e9b-a0c3-5505af0291b8", + "metadata": {}, + "source": [ + "### Mass fitting" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c83799a1-5122-4e89-b67d-8f691ff9d541", + "metadata": {}, + "outputs": [], + "source": [ + "# Mass fitting\n", + "\n", + "\n", + "from clmm.support.sampler import fitters\n", + "\n", + "\n", + "def fit_mass(predict_function, cluster):\n", + "\n", + " cluster.mask_for_fit = cluster.profile[\"n_src\"] > 2\n", + " cluster.data_for_fit = cluster.profile[cluster.mask_for_fit]\n", + "\n", + " popt, pcov = fitters[\"curve_fit\"](\n", + " predict_function,\n", + " cluster,\n", + " cluster.data_for_fit[\"gt\"],\n", + " cluster.data_for_fit[\"gt_err\"],\n", + " bounds=[10.0, 17.0],\n", + " )\n", + " logm, logm_err = popt[0], np.sqrt(pcov[0][0])\n", + " return {\n", + " \"logm\": logm,\n", + " \"logm_err\": logm_err,\n", + " \"m\": 10**logm,\n", + " \"m_err\": (10**logm) * logm_err * np.log(10),\n", + " }" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dc59846f-a380-449d-a30b-5261085a34f2", + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "for cluster in clusters.values():\n", + " cluster.fit_redshift_distribution = fit_mass(\n", + " predict_reduced_tangential_shear_redshift_distribution, cluster\n", + " )\n", + " cluster.fit_individual_redshift = fit_mass(\n", + " predict_reduced_tangential_shear_individual_redshift, cluster\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "abd490e7-9404-4daa-8d79-f41a638d86da", + "metadata": {}, + "source": [ + "### Visualization of the results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84e71bf0-5aa8-4c48-8042-bd461430291a", + "metadata": {}, + "outputs": [], + "source": [ + "# Visualization of the results.\n", + "def get_predicted_shear(cluster, predict_function, fit_values):\n", + " gt_est = predict_function(cluster, fit_values[\"logm\"])\n", + " gt_est_err = [\n", + " predict_function(cluster, fit_values[\"logm\"] + i * fit_values[\"logm_err\"]) for i in (-3, 3)\n", + " ]\n", + " return gt_est, gt_est_err\n", + "\n", + "\n", + "for cluster in clusters.values():\n", + " cluster.gt_redshift_distribution, cluster.gt_err_redshift_distribution = get_predicted_shear(\n", + " cluster,\n", + " predict_reduced_tangential_shear_redshift_distribution,\n", + " cluster.fit_redshift_distribution,\n", + " )\n", + " cluster.gt_individual_redshift, cluster.gt_err_individual_redshift = get_predicted_shear(\n", + " cluster,\n", + " predict_reduced_tangential_shear_individual_redshift,\n", + " cluster.fit_individual_redshift,\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e8074a76-23ce-4244-a73d-483a91f5e450", + "metadata": {}, + "outputs": [], + "source": [ + "from paper_formating import prep_plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf89c28a-c19d-4022-83ce-32c113d2a615", + "metadata": {}, + "outputs": [], + "source": [ + "from matplotlib.ticker import MultipleLocator\n", + "\n", + "\n", + "def make_paper_plot(cluster):\n", + " fig, axes = prep_plot(\n", + " subplots=3,\n", + " figsize=(9, 9),\n", + " subplots_kwargs=dict(sharex=True, height_ratios=[1, 3, 1]),\n", + " )\n", + "\n", + " gx_ax, gt_ax, res_ax = axes\n", + "\n", + " errorbar_kwargs = dict(linestyle=\"\", marker=\"o\", markersize=0.8, elinewidth=0.5, capthick=0.5)\n", + "\n", + " gx_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.data_for_fit[\"gx\"],\n", + " cluster.data_for_fit[\"gx_err\"],\n", + " c=\"k\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " # Points in grey have not been used for the fit.\n", + " gx_ax.errorbar(\n", + " cluster.profile[\"radius\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gx\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gx_err\"][~cluster.mask_for_fit],\n", + " c=\"grey\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " gt_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.data_for_fit[\"gt\"],\n", + " cluster.data_for_fit[\"gt_err\"],\n", + " c=\"k\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " # Points in grey have not been used for the fit.\n", + " gt_ax.errorbar(\n", + " cluster.profile[\"radius\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gt\"][~cluster.mask_for_fit],\n", + " cluster.profile[\"gt_err\"][~cluster.mask_for_fit],\n", + " c=\"grey\",\n", + " **errorbar_kwargs,\n", + " )\n", + "\n", + " pow10 = 15\n", + " mlabel = lambda name, fits: (\n", + " rf\"$M_{{fit}}^{{{name}}} = \"\n", + " rf'{fits[\"m\"]/10**pow10:.2f}\\pm'\n", + " rf'{fits[\"m_err\"]/10**pow10:.2f}'\n", + " rf\"\\times 10^{{{pow10}}} M_\\odot$\"\n", + " )\n", + "\n", + " # The model for the 1st method.\n", + " gt_ax.loglog(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.gt_redshift_distribution,\n", + " \"-C1\",\n", + " label=mlabel(\"N(z)\", cluster.fit_redshift_distribution),\n", + " lw=0.5,\n", + " )\n", + " gt_ax.fill_between(\n", + " cluster.data_for_fit[\"radius\"],\n", + " *cluster.gt_err_redshift_distribution,\n", + " lw=0,\n", + " color=\"C1\",\n", + " alpha=0.2,\n", + " )\n", + "\n", + " # The model for the 2nd method.\n", + " gt_ax.loglog(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.gt_individual_redshift,\n", + " \"-C2\",\n", + " label=mlabel(\"z,R\", cluster.fit_individual_redshift),\n", + " lw=0.5,\n", + " )\n", + " gt_ax.fill_between(\n", + " cluster.data_for_fit[\"radius\"],\n", + " *cluster.gt_err_individual_redshift,\n", + " lw=0,\n", + " color=\"C2\",\n", + " alpha=0.2,\n", + " )\n", + "\n", + " errorbar_kwargs2 = {k: v for k, v in errorbar_kwargs.items() if \"marker\" not in k}\n", + " errorbar_kwargs2[\"markersize\"] = 1\n", + " errorbar_kwargs2[\"markeredgewidth\"] = 0.5\n", + " delta = (cluster.profile[\"radius\"][1] / cluster.profile[\"radius\"][0]) ** 0.25\n", + "\n", + " res_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"],\n", + " cluster.data_for_fit[\"gt\"] / cluster.gt_redshift_distribution - 1,\n", + " yerr=cluster.data_for_fit[\"gt_err\"] / cluster.gt_redshift_distribution,\n", + " marker=\"s\",\n", + " c=\"C1\",\n", + " **errorbar_kwargs2,\n", + " )\n", + " # errorbar_kwargs2[\"markersize\"] = 3\n", + " # errorbar_kwargs2[\"markeredgewidth\"] = 0.5\n", + "\n", + " res_ax.errorbar(\n", + " cluster.data_for_fit[\"radius\"] * delta,\n", + " cluster.data_for_fit[\"gt\"] / cluster.gt_individual_redshift - 1,\n", + " yerr=cluster.data_for_fit[\"gt_err\"] / cluster.gt_individual_redshift,\n", + " marker=\"*\",\n", + " c=\"C2\",\n", + " **errorbar_kwargs2,\n", + " )\n", + "\n", + " gx_ax.set_ylabel(r\"$g_x$\", fontsize=8)\n", + " gt_ax.set_ylabel(r\"$g_t$\", fontsize=8)\n", + " gt_ax.legend(fontsize=8)\n", + " res_ax.set_xlabel(r\"$R$ [Mpc]\", fontsize=8)\n", + "\n", + " res_ax.set_ylabel(\"$g_t$\\n [rel. diff]\", fontsize=8)\n", + " res_ax.set_xscale(\"log\")\n", + "\n", + " res_ax.set_ylim(-1.05, 1.05)\n", + " res_ax.yaxis.set_minor_locator(MultipleLocator(10))\n", + "\n", + " for ax in axes:\n", + " ax.tick_params(\"x\", labelsize=8)\n", + " ax.tick_params(\"y\", labelsize=8)\n", + "\n", + " for ax in axes:\n", + " ax.grid(lw=0.3, ls=\"-\")\n", + " ax.minorticks_on()\n", + " ax.grid(which=\"minor\", lw=0.1, ls=\":\")\n", + "\n", + " plt.tight_layout()\n", + " plt.subplots_adjust(hspace=0.0)\n", + " return fig, axes" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "64838792-6fb1-4c4e-8547-1c0cdda0c7aa", + "metadata": {}, + "outputs": [], + "source": [ + "make_paper_plot(clusters[\"ID1\"])\n", + "plt.savefig(\"des_ID1_new.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6fbbdeea-fc25-465a-a0a7-852a93b8a7a7", + "metadata": {}, + "outputs": [], + "source": [ + "make_paper_plot(clusters[\"ID10\"])\n", + "plt.savefig(\"des_ID10_new.png\")" + ] + }, + { + "cell_type": "markdown", + "id": "4e50e37a-5c53-4420-9453-310aed730df0", + "metadata": {}, + "source": [ + "## References\n", + "\n", + "Zuntz J., Sheldon E., Samuroff S., Troxel M. A., Jarvis M., MacCrann N., Gruen D., et al., 2018, MNRAS, 481, 1149. [doi:10.1093/mnras/sty2219](\n", + "http://adsabs.harvard.edu/cgi-bin/bib_query?arXiv:1708.01533)\n", + "\n", + "Hoyle B., Gruen D., Bernstein G. M., Rau M. M., De Vicente J., Hartley W. G., Gaztanaga E., et al., 2018, MNRAS, 478, 592. [doi:10.1093/mnras/sty957](http://adsabs.harvard.edu/abs/2018MNRAS.478..592H)\n", + "\n", + "McClintock T., Varga T. N., Gruen D., Rozo E., Rykoff E. S., Shin T., Melchior P., et al., 2019, MNRAS, 482, 1352. [doi:10.1093/mnras/sty2711](https://ui.adsabs.harvard.edu/abs/2019MNRAS.482.1352M/abstract)\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/Paper_v2.0/Figure_10_DC2_redMaPPer_clusterensemble_object.ipynb b/examples/Paper_v2.0/Figure_10_DC2_redMaPPer_clusterensemble_object.ipynb new file mode 100644 index 000000000..6e84e9c2d --- /dev/null +++ b/examples/Paper_v2.0/Figure_10_DC2_redMaPPer_clusterensemble_object.ipynb @@ -0,0 +1,567 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "4d6efa8a-7255-40b8-9787-c9731bf78172", + "metadata": {}, + "source": [ + "## Compute stacked excess surface density profile arround redMaPPer clusters from the extragalactic cosmoDC2 catalog\n", + "\n", + "This notebook can be run at NERSC or CC-IN2P3 where the DESC DC2 products are stored. You need to be a DESC member to be able to access those. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a2ce472-8077-48ce-8e7c-8d5fe2338978", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from astropy.table import Table, hstack, vstack\n", + "import random\n", + "import pickle\n", + "from clmm import GalaxyCluster, ClusterEnsemble, GCData\n", + "import healpy, glob\n", + "import clmm\n", + "import matplotlib.pyplot as plt\n", + "\n", + "\n", + "def load(filename, **kwargs):\n", + " with open(filename, \"rb\") as fin:\n", + " return pickle.load(fin, **kwargs)\n", + "\n", + "\n", + "np.random.seed(1)" + ] + }, + { + "cell_type": "markdown", + "id": "059d0d80-3a32-4709-bacf-a10ec2eb070e", + "metadata": {}, + "source": [ + "### 1. Extract the catalog of redMaPPer clusters detected in the cosmoDC2 extragalactig catalog\n", + "- `python extract_cluster_catalog_redMaPPer.py` extract the catalog of redMaPPer-detected clusters\n", + "- The output catalog in saved at\n", + "-- `/global/cfs/projectdirs/lsst/groups/CL/CLMM/DC2_data/cosmoDC2_v1.1.4_redmapper_v0.8.1_catalog.pkl` (if you use NERSC).\n", + "-- `/sps/lsst/groups/clusters/CLMM/DC2_data/cosmoDC2_v1.1.4_redmapper_v0.8.1_catalog.pkl` (if you use NERSC)\n", + "- THe figure below displays the redMaPPer catalog" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1a027780-fdf9-4203-b187-f54b8736891c", + "metadata": {}, + "outputs": [], + "source": [ + "path_DC2_data_ccin2p3 = \"/sps/lsst/groups/clusters/CLMM/DC2_data/\"\n", + "path_DC2_data_nersc = \"/global/cfs/projectdirs/lsst/groups/CL/CLMM/DC2_data/\"\n", + "path_DC2_data = path_DC2_data_ccin2p3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53a53ba9-1451-42a3-90b4-3635b655dc61", + "metadata": {}, + "outputs": [], + "source": [ + "redmapper_cat = load(path_DC2_data + \"cosmoDC2_v1.1.4_redmapper_v0.8.1_catalog.pkl\")\n", + "plt.hist2d(\n", + " redmapper_cat[\"redshift\"],\n", + " redmapper_cat[\"richness\"],\n", + " cmin=1,\n", + " bins=[10, np.logspace(np.log10(10), np.log10(300), 50)],\n", + " cmap=\"gist_rainbow\",\n", + ")\n", + "plt.colorbar(label=\"count\")\n", + "plt.yscale(\"log\")\n", + "plt.xlabel(\"redshift\", fontsize=15)\n", + "plt.ylabel(r\"$\\lambda$\", fontsize=15)\n", + "plt.tick_params(axis=\"both\", which=\"major\", labelsize=15)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "cfa567d0-9c1b-4aad-a26a-d2fd6666f5a2", + "metadata": {}, + "source": [ + "### 2. Extract background galaxy sources for a sub-sample of the redMaPPer clusters and estimate individual lensing profiles\n", + "- We extract background source catalog for each redMaPPer-detected cluster. We consider a sub-sample of the redMaPPer cluster catalog, wiht richness $20 < \\lambda < 40$ and redshift $0.2 < z < 0.4$. This sub-sample consists in $n_{\\rm clusters}\\sim 450$ clusters. \n", + "- We consider the source selection mag-$i < 24.25$ and mag-$r < 28$, to reach a galaxy density $n_{\\rm gal} = 26$ gal/arcmin$^2$. \n", + "- The background galaxies are selected using the simple cut on the true redshift of the source galaxy $z_{s}$, such as $z_{s} > z_{\\rm cl}+0.2$. \n", + "- Then, we estimate the lensing profile for each cluster in 15 logarithm equally-spaced radial bins between $0.5$ Mpc and $30$ Mpc. " + ] + }, + { + "cell_type": "markdown", + "id": "eb82124c-6709-4490-ab4e-06ac41474902", + "metadata": {}, + "source": [ + "#### Extraction of galaxy catalogs from cosmoDC2\n", + "\n", + "- To speed up the extraction of cosmoDC2 source galaxies and lensing profile estimation, we subdivide the cluster sample in 20 independant splits. We then run the extraction for each independent split (containing $\\sim 25$ clusters).\n", + "- `python extract_sources_and_compute_ind_profile_cosmoDC2_per_split.py --which_split 0 --number_of_splits 30` is an example, which extracts background source catalogs and lensing profiles for clusters in the split with index `0`.\n", + "-- The extraction of cosmoDC2 data can be done using GCRCatalogs. Here, we use Qserv available at CC-IN2P3, that provides a fast interface to extract cosmoDC2 quantities (only available at CC-IN2P3). Qserv has design optimized for astronomical queries (parallel distributed SQL database).\n", + "-- Some useful functions to deal with cosmoDC2 data are stored in `_utils_cosmoDC2.py`.\n", + "- We then sublmit 20 parrallel jobs for each idependant split. `python jobs_extract_sources_cosmoDC2.py` writes and runs 20 parrallel jobs at CC-IN2P3.\n", + "- The individual profiles (stored by split from 0 to 19) are saved in the directory `./DC2_data/individual_redMaPPer_cluster_lensing_profiles/`.\n", + "- We group the individual lensing profiles in a single file." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "76d586a5-0990-472e-afff-d6fedfb1b6b2", + "metadata": {}, + "outputs": [], + "source": [ + "path_to_splits = path_DC2_data + \"individual_redMaPPer_cluster_lensing_profiles/\"\n", + "list_files = glob.glob(path_to_splits + \"individual_profiles_split*\")\n", + "for i, name_file in enumerate(list_files):\n", + " file = load(\n", + " name_file,\n", + " )\n", + " if i == 0:\n", + " file_stack = file\n", + " continue\n", + " else:\n", + " file_stack = vstack([file_stack, file])" + ] + }, + { + "cell_type": "markdown", + "id": "2453672d-5fb0-41b6-9760-053fd8b29fd4", + "metadata": {}, + "source": [ + "### 3. Creating `ClusterEnsemble object`\n", + "- We add the individual lensing profiles to the `ClusterEnsemble object`\n", + "- We create three ensemble object, respectively with:\n", + "-- clusters within the full range $20 < \\lambda < 40$ and $0.2 < z < 0.4$ (450 objects)\n", + "-- 100 randomly selected clusters within $20 < \\lambda < 40$ and $0.2 < z < 0.4$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5df85992-e7e1-444d-9f4f-633b73f862c6", + "metadata": {}, + "outputs": [], + "source": [ + "from astropy import units as u" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "246ea896-ca6e-42a7-b906-0b53d8705833", + "metadata": {}, + "outputs": [], + "source": [ + "# ClusterEnsemble object for the full sample\n", + "cluster_ensemble = ClusterEnsemble(\"stack full sample\")\n", + "dat = clmm.GCData(\n", + " [\n", + " file_stack[\"cluster_id\"],\n", + " file_stack[\"cluster_ra\"],\n", + " file_stack[\"cluster_dec\"],\n", + " file_stack[\"cluster_redshift\"],\n", + " file_stack[\"radius\"],\n", + " file_stack[\"binned_DS_t\"],\n", + " file_stack[\"binned_DS_x\"],\n", + " file_stack[\"W_l\"],\n", + " ],\n", + " names=(\"cluster_id\", \"ra\", \"dec\", \"z\", \"radius\", \"DS_t\", \"DS_x\", \"W_l\"),\n", + " masked=True,\n", + " meta={\"bin_units\": \"mpc\", \"radius_min\": file_stack[\"radius_min\"][0]*u.mpc, \"radius_max\": file_stack[\"radius_max\"][0]*u.mpc}\n", + ")\n", + "cluster_ensemble.data = dat" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3953a669-75b1-4983-b16a-7cb63e66fdf8", + "metadata": {}, + "outputs": [], + "source": [ + "index_cluster_full = np.arange(len(file_stack))\n", + "index_cluster_small = np.random.choice(index_cluster_full, 100, replace=False)\n", + "file_stack_small = file_stack[index_cluster_small]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0c0ed7e9-5504-4fb6-8383-7da6aa4c3d29", + "metadata": {}, + "outputs": [], + "source": [ + "# ClusterEnsemble object for the small sample\n", + "cluster_ensemble_small = ClusterEnsemble(\"stack reduced sample (low-lambda)\")\n", + "dat = clmm.GCData(\n", + " [\n", + " file_stack_small[\"cluster_id\"],\n", + " file_stack_small[\"cluster_ra\"],\n", + " file_stack_small[\"cluster_dec\"],\n", + " file_stack_small[\"cluster_redshift\"],\n", + " file_stack_small[\"radius\"],\n", + " file_stack_small[\"binned_DS_t\"],\n", + " file_stack_small[\"binned_DS_x\"],\n", + " file_stack_small[\"W_l\"],\n", + " ],\n", + " names=(\"cluster_id\", \"ra\", \"dec\", \"z\", \"radius\", \"DS_t\", \"DS_x\", \"W_l\"),\n", + " masked=True,\n", + " meta={\"bin_units\": \"mpc\", \"radius_min\": file_stack_small[\"radius_min\"][0]*u.mpc, \"radius_max\": file_stack_small[\"radius_max\"][0]*u.mpc}\n", + ")\n", + "cluster_ensemble_small.data = dat" + ] + }, + { + "cell_type": "markdown", + "id": "29ebfcd7-6419-4582-a4e3-07c558ca96dd", + "metadata": {}, + "source": [ + "### 4. Estimating the stacked profile and the covariance matrices\n", + "- We compute the stacked lensing profiles for the considered cluster sample. \n", + "- We estimate the stacked profile covariance matrix using three different data-based methods, namely the Sample, the Bootstrap and the Jackknife approaches as detailled in the [example notebook](https://github.com/LSSTDESC/CLMM/blob/main/examples/demo_mock_ensemble.ipynb) of the `ClusterEnsemble object`. Here, we use $N_{\\rm side}=16$ and $N_{\\rm bootstrap} = 500$." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f970031e-e9b2-49ff-9197-51f67002f4b5", + "metadata": {}, + "outputs": [], + "source": [ + "# stacked profile\n", + "cluster_ensemble.make_stacked_radial_profile(tan_component=\"DS_t\", cross_component=\"DS_x\")\n", + "r_stack, gt_stack, gx_stack = (cluster_ensemble.stacked_data[c] for c in (\"radius\", \"DS_t\", \"DS_x\"))\n", + "\n", + "cluster_ensemble_small.make_stacked_radial_profile(tan_component=\"DS_t\", cross_component=\"DS_x\")\n", + "r_stack_small, gt_stack_small, gx_stack_small = (\n", + " cluster_ensemble_small.stacked_data[c] for c in (\"radius\", \"DS_t\", \"DS_x\")\n", + ")\n", + "\n", + "# covariance matrices\n", + "cluster_ensemble.compute_sample_covariance(tan_component=\"DS_t\", cross_component=\"DS_x\")\n", + "cluster_ensemble.compute_bootstrap_covariance(\n", + " tan_component=\"DS_t\", cross_component=\"DS_x\", n_bootstrap=500\n", + ")\n", + "cluster_ensemble.compute_jackknife_covariance(\n", + " n_side=16, tan_component=\"DS_t\", cross_component=\"DS_x\"\n", + ")\n", + "\n", + "cluster_ensemble_small.compute_sample_covariance(tan_component=\"DS_t\", cross_component=\"DS_x\")\n", + "cluster_ensemble_small.compute_bootstrap_covariance(\n", + " tan_component=\"DS_t\", cross_component=\"DS_x\", n_bootstrap=500\n", + ")\n", + "cluster_ensemble_small.compute_jackknife_covariance(\n", + " n_side=16, tan_component=\"DS_t\", cross_component=\"DS_x\"\n", + ")\n", + "\n", + "\n", + "err_gt = cluster_ensemble.cov[\"tan_sc\"].diagonal() ** 0.5 / 1e13\n", + "err_gx = cluster_ensemble.cov[\"cross_sc\"].diagonal() ** 0.5 / 1e13\n", + "\n", + "err_gt_small = cluster_ensemble_small.cov[\"tan_sc\"].diagonal() ** 0.5 / 1e13\n", + "err_gx_small = cluster_ensemble_small.cov[\"cross_sc\"].diagonal() ** 0.5 / 1e13" + ] + }, + { + "cell_type": "markdown", + "id": "095d6eda-75c9-4651-b67b-ab76111a2e3a", + "metadata": {}, + "source": [ + "In the Figure below, we plot:\n", + "- Upper panel: \n", + "-- the stacked excess surface density profile for the full sample in black, with error-bars coming from the Bootstrap covariance matrix\n", + "-- the stacked excess surface density profiles for the small cluster sample\n", + "- Lower panel:\n", + "-- the same as the upper plot, but considering the cross component of the source galaxy ellipticities." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33eed8bc-831e-446d-bcfa-ec903714c08d", + "metadata": {}, + "outputs": [], + "source": [ + "fig, axs = plt.subplots(2, 1, figsize=(6, 6), gridspec_kw={\"height_ratios\": [2, 1]})\n", + "\n", + "axs[0].fill_between(\n", + " r_stack,\n", + " gt_stack / 1e13 - err_gt,\n", + " gt_stack / 1e13 + err_gt,\n", + " color=\"C0\",\n", + " zorder=100,\n", + " alpha=0.7,\n", + " label=r\"Stacked profile (full sample)\",\n", + ")\n", + "axs[0].plot(\n", + " r_stack,\n", + " gt_stack / 1e13,\n", + " color=\"C0\",\n", + " zorder=100,\n", + " alpha=0.5,\n", + ")\n", + "\n", + "axs[0].fill_between(\n", + " r_stack,\n", + " gt_stack_small / 1e13 - err_gt_small,\n", + " gt_stack_small / 1e13 + err_gt_small,\n", + " color=\"C1\",\n", + " zorder=100,\n", + " alpha=0.5,\n", + " label=r\"Stacked profile (small sample)\",\n", + ")\n", + "axs[0].plot(\n", + " r_stack_small,\n", + " gt_stack_small / 1e13,\n", + " color=\"C1\",\n", + " zorder=100,\n", + " alpha=0.5,\n", + ")\n", + "\n", + "# for i in range(400):\n", + "# axs[0].plot(\n", + "# cluster_ensemble.data[\"radius\"][i],\n", + "# cluster_ensemble.data[\"DS_t\"][i] / 1e13,\n", + "# \"C1\",\n", + "# alpha=.1,\n", + "# linewidth=1,)\n", + "# axs[1].plot(\n", + "# cluster_ensemble.data[\"radius\"][i],\n", + "# cluster_ensemble.data[\"DS_x\"][i] / 1e13,\n", + "# \"C1\",\n", + "# alpha=.1,\n", + "# linewidth=1,)\n", + "\n", + "axs[0].loglog(\n", + " [],\n", + " [],\n", + ")\n", + "\n", + "axs[1].fill_between(\n", + " r_stack,\n", + " gx_stack / 1e13 - err_gx,\n", + " gx_stack / 1e13 + err_gx,\n", + " color=\"C0\",\n", + " zorder=100,\n", + " alpha=0.7,\n", + " label=r\"Stacked profile (full sample)\",\n", + ")\n", + "axs[1].plot(\n", + " r_stack,\n", + " gx_stack / 1e13,\n", + " color=\"C0\",\n", + " zorder=100,\n", + " alpha=0.5,\n", + ")\n", + "\n", + "axs[1].fill_between(\n", + " r_stack,\n", + " gx_stack_small / 1e13 - err_gx_small,\n", + " gx_stack_small / 1e13 + err_gx_small,\n", + " color=\"C1\",\n", + " zorder=100,\n", + " alpha=0.5,\n", + " label=r\"Stacked profile (small sample)\",\n", + ")\n", + "axs[1].plot(\n", + " r_stack_small,\n", + " gx_stack_small / 1e13,\n", + " color=\"C1\",\n", + " zorder=100,\n", + " alpha=0.5,\n", + ")\n", + "x = np.linspace(-10, 50, 100)\n", + "axs[1].plot(x, 0 * x, \"--\")\n", + "axs[1].set_xscale(\"log\")\n", + "axs[0].set_xscale(\"log\")\n", + "axs[1].set_xlabel(\"R [Mpc]\", fontsize=15)\n", + "axs[0].tick_params(axis=\"both\", which=\"major\", labelsize=15)\n", + "axs[1].tick_params(axis=\"both\", which=\"major\", labelsize=15)\n", + "axs[0].set_ylabel(r\"$\\Delta\\Sigma_+$ $[\\times 10^{13} M_\\odot /Mpc^2])$\", fontsize=15)\n", + "axs[1].set_ylabel(r\"$\\Delta\\Sigma_\\times \\times 10^{13}$ \", fontsize=15)\n", + "axs[0].grid(True, which=\"both\")\n", + "axs[1].grid(True, which=\"both\")\n", + "axs[0].set_ylim(0.03, 10)\n", + "axs[1].set_ylim(-0.7, 0.7)\n", + "axs[0].set_xlim(0.5, 30)\n", + "axs[1].set_xlim(0.5, 30)\n", + "axs[0].legend()\n", + "plt.savefig(f\"redmapper_clusters_lensing_stacked_profile_DC2.png\", bbox_inches=\"tight\", dpi=200)" + ] + }, + { + "cell_type": "markdown", + "id": "086dcc79-4438-44cf-b1b2-0ee020cf7618", + "metadata": {}, + "source": [ + "In the Figure below, we plot the diagonal elements of the three covariance matrices, estimated respectively using the sample, bootstrap and Jackknife approach." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d92eb003-7678-4815-87b3-a19ded959a8c", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure(figsize=(7, 6))\n", + "plt.plot(\n", + " cluster_ensemble.data[\"radius\"][0],\n", + " (cluster_ensemble.cov[\"tan_jk\"].diagonal() ** 0.5) / 1e13,\n", + " \"-s\",\n", + " label=\"Jackknife\",\n", + " color=\"g\",\n", + " linewidth=2,\n", + ")\n", + "\n", + "plt.plot(\n", + " cluster_ensemble.data[\"radius\"][0],\n", + " (cluster_ensemble.cov[\"tan_bs\"].diagonal() ** 0.5) / 1e13,\n", + " \"-\",\n", + " color=\"r\",\n", + " label=\"Bootstrap\",\n", + " linewidth=1.5,\n", + " markersize=4,\n", + ")\n", + "plt.plot(\n", + " cluster_ensemble.data[\"radius\"][0],\n", + " (cluster_ensemble.cov[\"tan_sc\"].diagonal() ** 0.5) / 1e13,\n", + " \"--\",\n", + " color=\"C0\",\n", + " label=\"Sample\",\n", + " linewidth=2,\n", + ")\n", + "plt.loglog(\n", + " cluster_ensemble_small.data[\"radius\"][0],\n", + " (cluster_ensemble_small.cov[\"tan_bs\"].diagonal() ** 0.5) / 1e13,\n", + " \"--\",\n", + " c=\"r\",\n", + " label=\"Bootstrap (small sample)\",\n", + " linewidth=1.5,\n", + " markersize=4,\n", + ")\n", + "plt.xlabel(\"R [Mpc]\", fontsize=20)\n", + "plt.ylabel(r\"$C_{ii}^{1/2}$ $[\\times 10^{13} M_\\odot /Mpc^2])$\", fontsize=15)\n", + "plt.tick_params(axis=\"both\", which=\"major\", labelsize=15)\n", + "plt.legend(frameon=True, fontsize=12)\n", + "plt.minorticks_on()\n", + "plt.grid(lw=0.5)\n", + "plt.ylim(0.01, 1)\n", + "plt.grid(\n", + " which=\"both\",\n", + ")\n", + "plt.xscale(\"log\")\n", + "plt.savefig(\n", + " f\"redmapper_clusters_lensing_stacked_profile_DC2_variance.png\", bbox_inches=\"tight\", dpi=200\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "4a7c79c8-b14d-42c5-ad49-9b0d5da98e0e", + "metadata": {}, + "source": [ + "Similarly, we show the associated correlation matrices." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "73641494-017a-4a6b-a110-d156e1ac9181", + "metadata": {}, + "outputs": [], + "source": [ + "fig, axes = plt.subplots(1, 3, figsize=(20, 5))\n", + "fig.subplots_adjust(wspace=0.15, hspace=0)\n", + "\n", + "maximum = cluster_ensemble.cov[\"tan_sc\"].max()\n", + "for ax, cov, label in zip(\n", + " axes,\n", + " [\n", + " cluster_ensemble.cov[\"tan_sc\"],\n", + " cluster_ensemble.cov[\"tan_bs\"],\n", + " cluster_ensemble.cov[\"tan_jk\"],\n", + " ],\n", + " [\"Stack : Sample\", \"Stack : Bootstrap\", \"Stack : Jackknife\"],\n", + "):\n", + " ax.set_title(label, fontsize=20)\n", + " ax.set_xlabel(\"radial bin index\", fontsize=18)\n", + " ax.set_ylabel(\"radial bin index\", fontsize=18)\n", + " ax.tick_params(axis=\"both\", which=\"major\", labelsize=12)\n", + " im = ax.imshow(np.corrcoef(cov), cmap=\"coolwarm\", vmin=-1, vmax=1, origin=\"lower\")\n", + " plt.colorbar(im, ax=ax)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "0a102c0e-48af-4a2c-afe4-04f142c4baa9", + "metadata": {}, + "source": [ + "(to save just one figure)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e10dd16d-9dc9-4d03-af4b-f37a1f61708d", + "metadata": {}, + "outputs": [], + "source": [ + "plt.xlabel(\"R [Mpc]\", fontsize=18)\n", + "plt.ylabel(\"R [Mpc]\", fontsize=18)\n", + "plt.tick_params(axis=\"both\", which=\"major\", labelsize=12)\n", + "im = plt.imshow(\n", + " np.corrcoef(cluster_ensemble.cov[\"tan_bs\"]), cmap=\"coolwarm\", vmin=-1, vmax=1, origin=\"lower\"\n", + ")\n", + "ticks = np.array([0, 2, 4, 6, 8, 10, 12, 14])\n", + "labels = [f\"{r_stack[t]:.1f}\" for t in ticks]\n", + "plt.xticks(\n", + " labels=labels,\n", + " ticks=ticks,\n", + ")\n", + "plt.yticks(\n", + " labels=labels,\n", + " ticks=ticks,\n", + ")\n", + "\n", + "plt.colorbar()\n", + "plt.savefig(\n", + " f\"redmapper_clusters_lensing_stacked_profile_DC2_correlation_matrix.png\",\n", + " bbox_inches=\"tight\",\n", + " dpi=200,\n", + ")\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "clmm", + "language": "python", + "name": "clmm" + }, + "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.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/Paper_v2.0/cosmology_set.py b/examples/Paper_v2.0/cosmology_set.py new file mode 100644 index 000000000..c5aad404b --- /dev/null +++ b/examples/Paper_v2.0/cosmology_set.py @@ -0,0 +1,3 @@ +from clmm import Cosmology + +dc2_cosmo = Cosmology(H0=70.0, Omega_dm0=0.27 - 0.045, Omega_b0=0.045, Omega_k0=0.0) diff --git a/examples/Paper_v2.0/paper_formating.py b/examples/Paper_v2.0/paper_formating.py new file mode 100644 index 000000000..b95f31ef0 --- /dev/null +++ b/examples/Paper_v2.0/paper_formating.py @@ -0,0 +1,434 @@ +import matplotlib as mpl +import pylab as plt + + +def prep_plot( + figsize=(9, 9), + adjust=None, # {'left':0.2, 'right':0.95, 'top':0.94, 'bottom':0.2}, + subplots=False, + subplots_kwargs=None, +): + main_parameters = { + "figure.dpi": 300.0, + "legend.fontsize": 10, + "axes.labelsize": 12, + "axes.titlesize": 12, + "xtick.labelsize": 12, + "ytick.labelsize": 12, + "axes.linewidth": 0.8, + "xtick.major.width": 0.8, + "ytick.major.width": 0.8, + "errorbar.capsize": 0.8, + #'errorbar.capthick': 0.4, + #'errorbar.elinewidth': 0.4, + } + other_parameters = { + "legend": { + "fontsize": 10, + }, + "xlabel": {}, # {'fontsize': 2,}, + "ylabel": {}, # {'fontsize': 20,}, + "xtick": {"labelsize": 10}, + "ytick": {"labelsize": 10}, + } + plt.clf() + _figsize = list(x / 2.54 for x in figsize) + print(_figsize) + if subplots: + if subplots_kwargs is None: + subplots_kwargs = {} + try: + fig, axes = plt.subplots(*subplots, figsize=_figsize, **subplots_kwargs) + except: + fig, axes = plt.subplots(subplots, figsize=_figsize, **subplots_kwargs) + else: + fig = plt.figure(figsize=_figsize) + if adjust is not None: + plt.subplots_adjust(**adjust) + mpl.rcParams.update(main_parameters) + # mpl.rc('xtick', **other_parameters['xtick']) + # mpl.rc('ytick', **other_parameters['ytick']) + + if subplots: + return fig, axes + return fig + + +def add_grid(ax, lw_major=0.5, lw_minor=0.1): + + ax.minorticks_on() + ax.grid(lw=lw_major) + ax.grid(which="minor", lw=lw_minor) + ax.set_axisbelow(True) + + +default = { + "_internal.classic_mode": False, + "agg.path.chunksize": 0, + "animation.avconv_args": [], + "animation.avconv_path": "avconv", + "animation.bitrate": -1, + "animation.codec": "h264", + "animation.convert_args": [], + "animation.convert_path": "convert", + "animation.embed_limit": 20.0, + "animation.ffmpeg_args": [], + "animation.ffmpeg_path": "ffmpeg", + "animation.frame_format": "png", + "animation.html": "none", + "animation.html_args": [], + "animation.writer": "ffmpeg", + "axes.autolimit_mode": "data", + "axes.axisbelow": "line", + "axes.edgecolor": "black", + "axes.facecolor": "white", + "axes.formatter.limits": [-7, 7], + "axes.formatter.min_exponent": 0, + "axes.formatter.offset_threshold": 4, + "axes.formatter.use_locale": False, + "axes.formatter.use_mathtext": False, + "axes.formatter.useoffset": True, + "axes.grid": False, + "axes.grid.axis": "both", + "axes.grid.which": "major", + "axes.labelcolor": "black", + "axes.labelpad": 4.0, + "axes.labelsize": 20.0, + "axes.labelweight": "normal", + "axes.linewidth": 0.8, + "axes.prop_cycle": mpl.cycler( + "color", + [ + "#1f77b4", + "#ff7f0e", + "#2ca02c", + "#d62728", + "#9467bd", + "#8c564b", + "#e377c2", + "#7f7f7f", + "#bcbd22", + "#17becf", + ], + ), + "axes.spines.bottom": True, + "axes.spines.left": True, + "axes.spines.right": True, + "axes.spines.top": True, + "axes.titlepad": 6.0, + "axes.titlesize": 20.0, + "axes.titleweight": "normal", + "axes.unicode_minus": True, + "axes.xmargin": 0.05, + "axes.ymargin": 0.05, + "axes3d.grid": True, + "backend": "module://ipykernel.pylab.backend_inline", + "backend.qt4": None, + "backend.qt5": None, + "backend_fallback": True, + "boxplot.bootstrap": None, + "boxplot.boxprops.color": "black", + "boxplot.boxprops.linestyle": "-", + "boxplot.boxprops.linewidth": 1.0, + "boxplot.capprops.color": "black", + "boxplot.capprops.linestyle": "-", + "boxplot.capprops.linewidth": 1.0, + "boxplot.flierprops.color": "black", + "boxplot.flierprops.linestyle": "none", + "boxplot.flierprops.linewidth": 1.0, + "boxplot.flierprops.marker": "o", + "boxplot.flierprops.markeredgecolor": "black", + "boxplot.flierprops.markerfacecolor": "none", + "boxplot.flierprops.markersize": 6.0, + "boxplot.meanline": False, + "boxplot.meanprops.color": "C2", + "boxplot.meanprops.linestyle": "--", + "boxplot.meanprops.linewidth": 1.0, + "boxplot.meanprops.marker": "^", + "boxplot.meanprops.markeredgecolor": "C2", + "boxplot.meanprops.markerfacecolor": "C2", + "boxplot.meanprops.markersize": 6.0, + "boxplot.medianprops.color": "C1", + "boxplot.medianprops.linestyle": "-", + "boxplot.medianprops.linewidth": 1.0, + "boxplot.notch": False, + "boxplot.patchartist": False, + "boxplot.showbox": True, + "boxplot.showcaps": True, + "boxplot.showfliers": True, + "boxplot.showmeans": False, + "boxplot.vertical": True, + "boxplot.whiskerprops.color": "black", + "boxplot.whiskerprops.linestyle": "-", + "boxplot.whiskerprops.linewidth": 1.0, + "boxplot.whiskers": 1.5, + "contour.corner_mask": True, + "contour.negative_linestyle": "dashed", + "datapath": "/opt/conda/lib/python3.6/site-packages/matplotlib/mpl-data", + "date.autoformatter.day": "%Y-%m-%d", + "date.autoformatter.hour": "%m-%d %H", + "date.autoformatter.microsecond": "%M:%S.%f", + "date.autoformatter.minute": "%d %H:%M", + "date.autoformatter.month": "%Y-%m", + "date.autoformatter.second": "%H:%M:%S", + "date.autoformatter.year": "%Y", + "docstring.hardcopy": False, + "errorbar.capsize": 0.0, + "examples.directory": "", + "figure.autolayout": False, + "figure.constrained_layout.h_pad": 0.04167, + "figure.constrained_layout.hspace": 0.02, + "figure.constrained_layout.use": False, + "figure.constrained_layout.w_pad": 0.04167, + "figure.constrained_layout.wspace": 0.02, + "figure.dpi": 100.0, + "figure.edgecolor": "white", + "figure.facecolor": "white", + "figure.figsize": [6.4, 4.8], + "figure.frameon": True, + "figure.max_open_warning": 20, + "figure.subplot.bottom": 0.11, + "figure.subplot.hspace": 0.2, + "figure.subplot.left": 0.125, + "figure.subplot.right": 0.9, + "figure.subplot.top": 0.88, + "figure.subplot.wspace": 0.2, + "figure.titlesize": "large", + "figure.titleweight": "normal", + "font.cursive": [ + "Apple Chancery", + "Textile", + "Zapf Chancery", + "Sand", + "Script MT", + "Felipa", + "cursive", + ], + "font.family": ["sans-serif"], + "font.fantasy": [ + "Comic Sans MS", + "Chicago", + "Charcoal", + "Impact", + "Western", + "Humor Sans", + "xkcd", + "fantasy", + ], + "font.monospace": [ + "DejaVu Sans Mono", + "Bitstream Vera Sans Mono", + "Computer Modern Typewriter", + "Andale Mono", + "Nimbus Mono L", + "Courier New", + "Courier", + "Fixed", + "Terminal", + "monospace", + ], + "font.sans-serif": [ + "DejaVu Sans", + "Bitstream Vera Sans", + "Computer Modern Sans Serif", + "Lucida Grande", + "Verdana", + "Geneva", + "Lucid", + "Arial", + "Helvetica", + "Avant Garde", + "sans-serif", + ], + "font.serif": [ + "DejaVu Serif", + "Bitstream Vera Serif", + "Computer Modern Roman", + "New Century Schoolbook", + "Century Schoolbook L", + "Utopia", + "ITC Bookman", + "Bookman", + "Nimbus Roman No9 L", + "Times New Roman", + "Times", + "Palatino", + "Charter", + "serif", + ], + "font.size": 10.0, + "font.stretch": "normal", + "font.style": "normal", + "font.variant": "normal", + "font.weight": "normal", + "grid.alpha": 1.0, + "grid.color": "#b0b0b0", + "grid.linestyle": "-", + "grid.linewidth": 0.8, + "hatch.color": "black", + "hatch.linewidth": 1.0, + "hist.bins": 10, + "image.aspect": "equal", + "image.cmap": "viridis", + "image.composite_image": True, + "image.interpolation": "nearest", + "image.lut": 256, + "image.origin": "upper", + "image.resample": True, + "interactive": True, + "keymap.all_axes": ["a"], + "keymap.back": ["left", "c", "backspace"], + "keymap.copy": ["ctrl+c", "cmd+c"], + "keymap.forward": ["right", "v"], + "keymap.fullscreen": ["f", "ctrl+f"], + "keymap.grid": ["g"], + "keymap.grid_minor": ["G"], + "keymap.help": ["f1"], + "keymap.home": ["h", "r", "home"], + "keymap.pan": ["p"], + "keymap.quit": ["ctrl+w", "cmd+w", "q"], + "keymap.quit_all": ["W", "cmd+W", "Q"], + "keymap.save": ["s", "ctrl+s"], + "keymap.xscale": ["k", "L"], + "keymap.yscale": ["l"], + "keymap.zoom": ["o"], + "legend.borderaxespad": 0.5, + "legend.borderpad": 0.4, + "legend.columnspacing": 2.0, + "legend.edgecolor": "0.8", + "legend.facecolor": "inherit", + "legend.fancybox": True, + "legend.fontsize": 20.0, + "legend.framealpha": 0.8, + "legend.frameon": True, + "legend.handleheight": 0.7, + "legend.handlelength": 2.0, + "legend.handletextpad": 0.8, + "legend.labelspacing": 0.5, + "legend.loc": "best", + "legend.markerscale": 1.0, + "legend.numpoints": 1, + "legend.scatterpoints": 1, + "legend.shadow": False, + "legend.title_fontsize": None, + "lines.antialiased": True, + "lines.color": "C0", + "lines.dash_capstyle": "butt", + "lines.dash_joinstyle": "round", + "lines.dashdot_pattern": [6.4, 1.6, 1.0, 1.6], + "lines.dashed_pattern": [3.7, 1.6], + "lines.dotted_pattern": [1.0, 1.65], + "lines.linestyle": "-", + "lines.linewidth": 1.5, + "lines.marker": "None", + "lines.markeredgecolor": "auto", + "lines.markeredgewidth": 1.0, + "lines.markerfacecolor": "auto", + "lines.markersize": 6.0, + "lines.scale_dashes": True, + "lines.solid_capstyle": "projecting", + "lines.solid_joinstyle": "round", + "markers.fillstyle": "full", + "mathtext.bf": "sans:bold", + "mathtext.cal": "cursive", + "mathtext.default": "it", + "mathtext.fallback_to_cm": True, + "mathtext.fontset": "dejavusans", + "mathtext.it": "sans:italic", + "mathtext.rm": "sans", + "mathtext.sf": "sans", + "mathtext.tt": "monospace", + "patch.antialiased": True, + "patch.edgecolor": "black", + "patch.facecolor": "C0", + "patch.force_edgecolor": False, + "patch.linewidth": 1.0, + "path.effects": [], + "path.simplify": True, + "path.simplify_threshold": 0.1111111111111111, + "path.sketch": None, + "path.snap": True, + "pdf.compression": 6, + "pdf.fonttype": 3, + "pdf.inheritcolor": False, + "pdf.use14corefonts": False, + "pgf.preamble": [], + "pgf.rcfonts": True, + "pgf.texsystem": "xelatex", + "polaraxes.grid": True, + "ps.distiller.res": 6000, + "ps.fonttype": 3, + "ps.papersize": "letter", + "ps.useafm": False, + "ps.usedistiller": False, + "savefig.bbox": None, + "savefig.directory": "~", + "savefig.dpi": "figure", + "savefig.edgecolor": "white", + "savefig.facecolor": "white", + "savefig.format": "png", + "savefig.frameon": True, + "savefig.jpeg_quality": 95, + "savefig.orientation": "portrait", + "savefig.pad_inches": 0.1, + "savefig.transparent": False, + "scatter.marker": "o", + "svg.fonttype": "path", + "svg.hashsalt": None, + "svg.image_inline": True, + "text.antialiased": True, + "text.color": "black", + "text.hinting": "auto", + "text.hinting_factor": 8, + "text.latex.preamble": [], + "text.latex.preview": False, + "text.latex.unicode": True, + "text.usetex": False, + "timezone": "UTC", + "tk.window_focus": False, + "toolbar": "toolbar2", + "verbose.fileo": "sys.stdout", + "verbose.level": "silent", + "webagg.address": "127.0.0.1", + "webagg.open_in_browser": True, + "webagg.port": 8988, + "webagg.port_retries": 50, + "xtick.alignment": "center", + "xtick.bottom": True, + "xtick.color": "black", + "xtick.direction": "out", + "xtick.labelbottom": True, + "xtick.labelsize": 18.0, + "xtick.labeltop": False, + "xtick.major.bottom": True, + "xtick.major.pad": 3.5, + "xtick.major.size": 3.5, + "xtick.major.top": True, + "xtick.major.width": 0.8, + "xtick.minor.bottom": True, + "xtick.minor.pad": 3.4, + "xtick.minor.size": 2.0, + "xtick.minor.top": True, + "xtick.minor.visible": False, + "xtick.minor.width": 0.6, + "xtick.top": False, + "ytick.alignment": "center_baseline", + "ytick.color": "black", + "ytick.direction": "out", + "ytick.labelleft": True, + "ytick.labelright": False, + "ytick.labelsize": 18.0, + "ytick.left": True, + "ytick.major.left": True, + "ytick.major.pad": 3.5, + "ytick.major.right": True, + "ytick.major.size": 3.5, + "ytick.major.width": 0.8, + "ytick.minor.left": True, + "ytick.minor.pad": 3.4, + "ytick.minor.right": True, + "ytick.minor.size": 2.0, + "ytick.minor.visible": False, + "ytick.minor.width": 0.6, + "ytick.right": False, +}