{ "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: Mar 8, 2024 by @patricialarsen\n", "\n", "In this notebook we demostrate how to plot the halo occupation distribution of the cosmoDC2/skysim/roman_rubin galaxy catalogs.\n", "\n", "## Learning objectives\n", "- Use `GCRCatalogs` to access the cosmoDC2, skysim or roman_rubin catalogs. \n", "- Access cosmology in the extragalactic catalogs.\n", "- Use `CCL` to predict Halo Mass Function." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import GCRCatalogs" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import pyccl as ccl" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Catalog selection\n", "Uncomment the line corresponding to the catalog you want to inspect" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "#gc = GCRCatalogs.load_catalog('cosmoDC2_v1.1.4_small')\n", "gc = GCRCatalogs.load_catalog('skysim5000_v1.1.2_small')\n", "#gc = GCRCatalogs.load_catalog('roman_rubin_2023_v1.1.3_elais')\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "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": "markdown", "metadata": {}, "source": [ "### Get the data\n", "Retrieve the data given the maximum redshift value determined above\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "data = gc.get_quantities(['halo_mass', 'Mag_true_r_lsst_z0', 'redshift','halo_id'], filters=['redshift < {}'.format(zmax)])" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Cosmology\n", "Retrieve the cosmological parameters and use them to create a ccl cosmology object" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "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": "markdown", "metadata": {}, "source": [ "### Get expected halo mass function from CCL\n", "We approximate the hmf by using the mean redshift, create a mass definition and decide which mass function to use" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# approximate hmf using mean redshift\n", "mean_scale_factor = 1.0/(1.0+data['redshift'].mean())\n", "\n", "hmd_fof = ccl.halos.MassDefFof\n", "mf = ccl.halos.MassFuncSheth99(mass_def=hmd_fof)\n", "hmf_dn_dlogm = mf(cosmo, mass_center, mean_scale_factor)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Determine expected number of halos\n", "\n", "Use the halo mass function and the volume (given by 4/3 pi * fsky * r^3) to get the total number of halos expected in the volume. We also select on halo ids to get the true number of halos in the volume. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "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": { "tags": [] }, "outputs": [], "source": [ "dlogm = np.ediff1d(np.log10(mass_bins))\n", "nhalo_expected = hmf_dn_dlogm * volume * dlogm\n", "\n", "hid,idx,count=np.unique(data['halo_id'],return_index=True,return_counts=True)" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Plot halo occupation distribution" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "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'$CCL:\\ M_r < {}$'.format(Mr_thres),\n", " c=color,\n", " );\n", " plt.loglog(\n", " mass_center, \n", " np.histogram(data['halo_mass'][data['Mag_true_r_lsst_z0'] < Mr_thres], mass_bins)[0]/np.histogram(data['halo_mass'][idx], mass_bins)[0],\n", " label=r'$M_r < {}$'.format(Mr_thres),\n", " c=color,\n", " linestyle='--'\n", " );\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();" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.10.13" } }, "nbformat": 4, "nbformat_minor": 4 }