From cbf2938555f300cb289d2815836d6fd4f5613a21 Mon Sep 17 00:00:00 2001 From: Robert Izzard <r.izzard@surrey.ac.uk> Date: Wed, 8 Sep 2021 16:52:58 +0200 Subject: [PATCH] fix typos in the luminosity notebook --- .../source/notebook_luminosity_function.ipynb | 76 ++++++++++++------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/docs/source/notebook_luminosity_function.ipynb b/docs/source/notebook_luminosity_function.ipynb index 7c6163c1a..c55933bc1 100644 --- a/docs/source/notebook_luminosity_function.ipynb +++ b/docs/source/notebook_luminosity_function.ipynb @@ -7,7 +7,7 @@ "tags": [] }, "source": [ - "# Stellar luminosity function\n", + "# Zero-age stellar luminosity function\n", "\n", "In this notebook we compute the luminosity function of the zero-age main-sequence by running a population of single stars using binary_c. \n", "\n", @@ -25,7 +25,7 @@ "import math\n", "from binarycpython.utils.grid import Population\n", "\n", - "# help(Population) # Uncomment to see the public functions of this object" + "# help(Population) # Uncomment this line to see the public functions of this object" ] }, { @@ -34,7 +34,7 @@ "metadata": {}, "source": [ "## Setting up the Population object\n", - "To set up and configure the population object we need to make an object instance of the `Population` object, and add configuration via the `.set()` function.\n", + "To set up and configure the population object we need to make a new instance of the `Population` object and configure it with the `.set()` function.\n", "\n", "In our case, we only need to set the maximum evolution time to something short, because we care only about zero-age main sequence stars which have, by definition, age zero." ] @@ -82,14 +82,9 @@ "## Adding grid variables\n", "The main purpose of the Population object is to handle the population synthesis side of running a set of stars. The main method to do this with binarycpython, as is the case with Perl binarygrid, is to use grid variables. These are loops over a predefined range of values, where a probability will be assigned to the systems based on the chosen probability distributions.\n", "\n", - "Usually we use either 1 mass grid variable, or a trio of mass, mass ratio and period (See below for full examples of all of these). We can, however, also add grid sampling for e.g. eccentricity, metallicity or other parameters. \n", + "Usually we use either 1 mass grid variable, or a trio of mass, mass ratio and period (other notebooks cover these examples). We can, however, also add grid sampling for e.g. eccentricity, metallicity or other parameters. \n", "\n", - "In some cases it could be easier to set up a for loop that sets that parameter and calls the evolve function several times, e.g. when you want to vary a prescription (usually a discrete, unweighted parameter) \n", - "\n", - "\n", - "A notable special type of grid variable is that of the Moe & di Stefano 2017 dataset (see further down in the notebook).\n", - "\n", - "To add a grid variable to the population object we use `population.add_grid_variable` (see next cell)" + "To add a grid variable to the population object we use `population.add_grid_variable`" ] }, { @@ -124,12 +119,40 @@ "# help(binarycpython.utils.distribution_functions)" ] }, + { + "cell_type": "markdown", + "id": "2a9104fc-4136-4e53-8604-f24ad52fbe56", + "metadata": {}, + "source": [ + "First let us set up some global variables that will be useful throughout. \n", + "* The resolution is the number of stars we simulate in our model population.\n", + "* The massrange is a list of the min and max masses\n", + "* The total_probability is the theoretical integral of a probability density function, i.e. 1.0.\n", + "* The binwidth sets the resolution of the final distribution. If set to 0.5, the bins in log*L* are 0.5dex wide." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aba3fe4e-18f2-4bb9-8e5c-4c6007ab038b", + "metadata": {}, + "outputs": [], + "source": [ + "# Set resolution and mass range that we simulate\n", + "resolution = {\"M_1\": 40} # start with resolution = 10, and increase later if you want \"more accurate\" data\n", + "massrange = (0.07, 100.0) # we work with stars of mass 0.07 to 100 Msun\n", + "total_probability = 1.0 # theoretical integral of the mass probability density function over all masses \n", + "# distribution binwidths : \n", + "# (log10) luminosity distribution\n", + "binwidth = { 'luminosity' : 0.5 }" + ] + }, { "cell_type": "markdown", "id": "1b3a007b-5c17-42a7-a981-7e268e6f545c", "metadata": {}, "source": [ - "The next cell contains an example of adding the mass grid variable, but sampling in log mass. The commented grid variables are examples of the mass ratio sampling and the period sampling." + "The next cell contains an example of adding the mass grid variable, sampling the phase space in linear mass *M*_1." ] }, { @@ -139,11 +162,6 @@ "metadata": {}, "outputs": [], "source": [ - "# Add grid variables\n", - "resolution = {\"M_1\": 40} # start with resolution = 10, and increase later if you want \"more accurate\" data\n", - "massrange = [0.07, 100.0] # we work with stars of mass 0.07 to 100 Msun\n", - "total_probability = 1.0\n", - "\n", "# Mass\n", "population = Population()\n", "population.add_grid_variable(\n", @@ -156,7 +174,7 @@ " dphasevol=\"dM_1\",\n", " parameter_name=\"M_1\",\n", " condition=\"\", # Impose a condition on this grid variable. Mostly for a check for yourself\n", - ")\n" + ")" ] }, { @@ -165,21 +183,28 @@ "metadata": {}, "source": [ "## Setting logging and handling the output\n", - "On default, binary_c will not output anything (except for 'SINGLE STAR LIFETIME'). It is up to us to determine what will be printed. We can either do that by hardcoding the print statements into `binary_c` (see documentation binary_c). Or, we can use the custom logging functionality of binarycpython (see notebook `notebook_custom_logging.ipynb`), which is faster to set up and requires no recompilation of binary_c, but is somewhat more limited in its functionality. \n", + "By default, binary_c will not output anything (except for 'SINGLE STAR LIFETIME'). It is up to us to determine what will be printed. We can either do that by hardcoding the print statements into `binary_c` (see documentation binary_c) or we can use the custom logging functionality of binarycpython (see notebook `notebook_custom_logging.ipynb`), which is faster to set up and requires no recompilation of binary_c, but is somewhat more limited in its functionality. For our current purposes, it works perfectly well.\n", "\n", "After configuring what will be printed, we need to make a function to parse the output. This can be done by setting the parse_function parameter in the population object (see also notebook `notebook_individual_systems.ipynb`). \n", "\n", - "In the code below we will set up both the custom logging, and a parse function to handle that output" + "In the code below we will set up both the custom logging and a parse function to handle that output." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 18, "id": "0c986215-93b1-4e30-ad79-f7c397e9ff7d", "metadata": {}, "outputs": [], "source": [ - "# Create custom logging statement: in this case we will log when the star turns into a compact object, and then terminate the evolution.\n", + "# Create custom logging statement\n", + "#\n", + "# we check that the model number is zero, i.e. we're on the first timestep (stars are born on the ZAMS)\n", + "# we make sure that the stellar type is <= MAIN_SEQUENCE, i.e. the star is a main-sequence star\n", + "# we also check that the time is 0.0 (this is not strictly required, but good to show how it is done)\n", + "#\n", + "# The Printf statement does the outputting: note that the header string is ZERO_AGE_MAIN_SEQUENCE_STAR\n", + "\n", "custom_logging_statement = \"\"\"\n", "if(stardata->model.model_number == 0 &&\n", " stardata->star[0].stellar_type <= MAIN_SEQUENCE &&\n", @@ -217,12 +242,8 @@ "outputs": [], "source": [ "# import the bin_data function so we can construct finite-resolution probability distributions\n", + "# import the datalinedict to make a dictionary from each line of data from binary_c\n", "from binarycpython.utils.functions import bin_data,datalinedict\n", - " \n", - "# distribution binwidths : \n", - "# (log10) luminosity distribution\n", - "binwidth = { 'luminosity' : 0.5 }\n", - "\n", "\n", "def parse_function(self, output):\n", " \"\"\"\n", @@ -387,8 +408,7 @@ "p = sns.lineplot(data=plot_data)\n", "p.set_xlabel(\"$\\log_{10}$ ($L_\\mathrm{ZAMS}$ / L$_{☉}$)\")\n", "p.set_ylabel(\"Number of stars\")\n", - "p.set(yscale=\"log\")\n", - "\n" + "p.set(yscale=\"log\")" ] }, { -- GitLab