{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Halo Occupation Distribution from extragalactic catalogs\n", "\n", "> Notebook owner: Yao-Yuan Mao [@yymao](https://github.com/LSSTDESC/DC2-analysis/issues/new?body=@yymao). Last run: Nov 30, 2018\n", "\n", "In this notebook we demostrate how to plot the halo occupation distribution of the protoDC2/cosmoDC2 galaxy catalog.\n", "\n", "## Learning objectives\n", "- Use `GCRCatalogs` to access the protoDC2 or cosmoDC2 catalogs. \n", "- Access cosmology in the extragalactic catalogs.\n", "- Use `CCL` to predict Halo Mass Function." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import GCRCatalogs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pyccl as ccl" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gc = GCRCatalogs.load_catalog('cosmoDC2_v1.1.4_small')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "zmax = 0.25\n", "mass_bins = np.logspace(10, 15, 21)\n", "mass_center = np.sqrt(mass_bins[1:] * mass_bins[:-1])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data = gc.get_quantities(['halo_mass', 'Mag_true_r_lsst_z0', 'redshift'], filters=['redshift < {}'.format(zmax)])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cosmo = ccl.Cosmology(\n", " Omega_c=gc.cosmology.Om0-gc.cosmology.Ob0, \n", " Omega_b=gc.cosmology.Ob0, \n", " h=gc.cosmology.h, \n", " sigma8=gc.cosmology.sigma8, \n", " n_s=gc.cosmology.n_s, \n", " transfer_function='bbks',\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# approximate hmf using mean redshift\n", "mean_scale_factor = 1.0/(1.0+data['redshift'].mean())\n", "hmf_dn_dlogm = ccl.massfunc(cosmo, mass_center, mean_scale_factor)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "d = gc.cosmology.comoving_distance(zmax).to('Mpc').value\n", "volume = np.deg2rad(np.deg2rad(gc.sky_area)) * d**3 / 3.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dlogm = np.ediff1d(np.log10(mass_bins))\n", "nhalo_expected = hmf_dn_dlogm * volume * dlogm" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for Mr_thres, color in zip((-21.5, -21, -20.5, -20), plt.cm.tab20c.colors):\n", " plt.loglog(\n", " mass_center, \n", " np.histogram(data['halo_mass'][data['Mag_true_r_lsst_z0'] < Mr_thres], mass_bins)[0] / nhalo_expected,\n", " label=r'$M_r < {}$'.format(Mr_thres),\n", " c=color,\n", " );\n", "\n", "plt.xlabel(r'${\\rm M}_h \\,/\\, {\\rm M}_\\odot$');\n", "plt.ylabel(r'$\\langle N_{\\rm gal} \\,|\\, {\\rm M}_h \\rangle$');\n", "plt.title(r'HOD $(z < 0.25)$');\n", "plt.ylim(0.01, None)\n", "plt.axhline(1, lw=0.5, c='k');\n", "plt.legend();" ] } ], "metadata": { "kernelspec": { "display_name": "desc-python", "language": "python", "name": "desc-python" }, "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }