{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Likelihood Fitting of Tracer Luminosity Function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this tutorial, we show how you can perform simple likelihood fitting to the tracer luminosity function (LF) using the ``lumfunc_likelihood`` module." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load luminosity function measurements" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get hold of the demo data (a parameter file for the LF model), we use the ``get_test_data_loc`` function from the ``utils`` module." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from horizonground.utils import get_test_data_loc\n", "\n", "demo_measurements_file = get_test_data_loc(\"eBOSS_QSO_LF_measurements.txt\")\n", "demo_uncertainties_file = get_test_data_loc(\"eBOSS_QSO_LF_uncertainties.txt\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's have a preview of the files' first few rows. Note the table headers format the column names as ``Phi_z__``." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
lg_Phi_z_0.68_1.06,lg_Phi_z_1.06_1.44,lg_Phi_z_1.44_1.82,lg_Phi_z_1.82_2.20,lg_Phi_z_2.20_2.60,lg_Phi_z_2.60_3.00,lg_Phi_z_3.00_3.50,lg_Phi_z_3.50_4.00
magnitude,
-28.8NaNNaNNaNNaNNaNNaNNaN-8.34
-28.4NaNNaNNaNNaN-7.98-7.42-7.89-8.35
-28.0NaNNaNNaN-7.63-7.49-7.10-7.33-8.36
-27.6NaNNaN-7.32-6.91-6.88-6.99-7.33NaN
\n", "
" ], "text/plain": [ " lg_Phi_z_0.68_1.06, lg_Phi_z_1.06_1.44, lg_Phi_z_1.44_1.82, \\\n", " magnitude, \n", "-28.8 NaN NaN NaN \n", "-28.4 NaN NaN NaN \n", "-28.0 NaN NaN NaN \n", "-27.6 NaN NaN -7.32 \n", "\n", " lg_Phi_z_1.82_2.20, lg_Phi_z_2.20_2.60, lg_Phi_z_2.60_3.00, \\\n", " magnitude, \n", "-28.8 NaN NaN NaN \n", "-28.4 NaN -7.98 -7.42 \n", "-28.0 -7.63 -7.49 -7.10 \n", "-27.6 -6.91 -6.88 -6.99 \n", "\n", " lg_Phi_z_3.00_3.50, lg_Phi_z_3.50_4.00 \n", " magnitude, \n", "-28.8 NaN -8.34 \n", "-28.4 -7.89 -8.35 \n", "-28.0 -7.33 -8.36 \n", "-27.6 -7.33 NaN " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
d_lg_Phi_z_0.68_1.06,d_lg_Phi_z_1.06_1.44,d_lg_Phi_z_1.44_1.82,d_lg_Phi_z_1.82_2.20,d_lg_Phi_z_2.20_2.60,d_lg_Phi_z_2.60_3.00,d_lg_Phi_z_3.00_3.50,d_lg_Phi_z_3.50_4.00
magnitude,
-28.8NaNNaNNaNNaNNaNNaNNaN0.44
-28.4NaNNaNNaNNaN0.310.170.260.44
-28.0NaNNaNNaN0.220.180.120.140.44
-27.6NaNNaN0.160.110.100.110.14NaN
\n", "
" ], "text/plain": [ " d_lg_Phi_z_0.68_1.06, d_lg_Phi_z_1.06_1.44, \\\n", " magnitude, \n", "-28.8 NaN NaN \n", "-28.4 NaN NaN \n", "-28.0 NaN NaN \n", "-27.6 NaN NaN \n", "\n", " d_lg_Phi_z_1.44_1.82, d_lg_Phi_z_1.82_2.20, \\\n", " magnitude, \n", "-28.8 NaN NaN \n", "-28.4 NaN NaN \n", "-28.0 NaN 0.22 \n", "-27.6 0.16 0.11 \n", "\n", " d_lg_Phi_z_2.20_2.60, d_lg_Phi_z_2.60_3.00, \\\n", " magnitude, \n", "-28.8 NaN NaN \n", "-28.4 0.31 0.17 \n", "-28.0 0.18 0.12 \n", "-27.6 0.10 0.11 \n", "\n", " d_lg_Phi_z_3.00_3.50, d_lg_Phi_z_3.50_4.00 \n", " magnitude, \n", "-28.8 NaN 0.44 \n", "-28.4 0.26 0.44 \n", "-28.0 0.14 0.44 \n", "-27.6 0.14 NaN " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "from IPython.display import display\n", "\n", "display(pd.read_csv(demo_measurements_file, sep='\\s+', index_col=0, nrows=4, escapechar='#'))\n", "display(pd.read_csv(demo_uncertainties_file, sep='\\s+', index_col=0, nrows=4, escapechar='#'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``LumFuncMeasurements`` class helps organise the data tables into luminosity and redshift bins. The ``base10_log`` boolean keyword parameter, if ``True``, means the LF values will be converted to base 10 logarithms unless ``'lg_'`` is detected in the table column names (i.e. the raw data are already logarithmic). Please note that *naming your table columns as shown above* helps ``LumFuncMeasurements`` process the data labels *and* values." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'Luminosity bins': array([-28.8, -28.4, -28. , -27.6, -27.2, -26.8, -26.4, -26. , -25.6,\n", " -25.2, -24.8, -24.4, -24. , -23.6, -23.2, -22.8, -22.4, -22. ,\n", " -21.6, -21.2, -20.8]),\n", " 'Redshift bin centres': array([0.87, 1.25, 1.63, 2.01, 2.4 , 2.8 , 3.25, 3.75]),\n", " 'Redshift bin labels': ['$0.68