{ "cells": [ { "cell_type": "markdown", "id": "fa8d2452", "metadata": {}, "source": [ "# Composite Stellar Population (CSP) tutorial" ] }, { "cell_type": "code", "execution_count": null, "id": "80fd97c3", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from galapy.analysis.plot import plt, format_axes_ticks" ] }, { "cell_type": "markdown", "id": "35fedc0f", "metadata": {}, "source": [ "The `galapy.CompositeStellarPopulation` module defines classes and functions for reading and operating on Simple Stellar Population, properly formatted, tables.\n", "These tables can be combined into composite populations (CSP), driving the kernel emission processes from galaxies.\n", "\n", "It can be imported via:" ] }, { "cell_type": "code", "execution_count": null, "id": "9b8e43fe", "metadata": {}, "outputs": [], "source": [ "import galapy.CompositeStellarPopulation as gpcsp " ] }, { "cell_type": "markdown", "id": "a0a8c8d7", "metadata": {}, "source": [ "Or called from the global namespace of the library:\n", "\n", "```python\n", ">>> import galapy as gp\n", ">>> gp.CompositeStellarPopulation\n", "\n", "```" ] }, { "cell_type": "markdown", "id": "ce7f0525", "metadata": {}, "source": [ "The module provides access to already formatted SSP tables, a list of which can be print on screen with the dedicated function:" ] }, { "cell_type": "code", "execution_count": null, "id": "1dfd1ea4", "metadata": {}, "outputs": [], "source": [ "gpcsp.print_ssp_libs()" ] }, { "cell_type": "markdown", "id": "37e2cb28", "metadata": {}, "source": [ "In order to build an object of type CSP the user has to select among these tables, the default being `'bc03.basel.chab.extend'`:" ] }, { "cell_type": "code", "execution_count": null, "id": "02279822", "metadata": {}, "outputs": [], "source": [ "csp = gpcsp.CSP( ssp_lib = 'bc03.basel.chab' )" ] }, { "cell_type": "markdown", "id": "3e92d29c", "metadata": {}, "source": [ "The above command has loaded the full table encoded in the provided binary file, splitting it into the three arrays\n", "* `csp.l`: wavelength grid \n", "* `csp.t`: time grid\n", "* `csp.Z`: metallicity grid\n", "\n", "and an array `csp.L` of size `len(csp.l)*len(csp.t)*len(csp.Z)` containing the actual luminosity table.\n", "\n", "This latter array can be indexed in three dimensions:\n", "* `il`: index in the wavelength grid\n", "* `it`: index in the time grid\n", "* `iz`: index in the metallicity grid\n", "\n", "through the function `csp.SSP(il,it,iz)`, that is equivalent of indexing a re-shaped version of the array:\n", "```python\n", "SSP_table = csp.L.reshape( len(csp.l), len(csp.t), len(csp.Z) )\n", "SSP_table[il,it,iz]\n", "```\n", "\n", "This operations on the SSP table allow to extract the emission of single SSPs:" ] }, { "cell_type": "code", "execution_count": null, "id": "5e6c0eff", "metadata": {}, "outputs": [], "source": [ "itv, stv = [ 10, 100, 220 ], [ 'r', 'g', 'b' ]\n", "izv, szv = [ 0, 3, 6 ], [ '-', '--', ':' ]\n", "fig = plt.figure(figsize=(6,4))\n", "for it, st in zip( itv, stv ) :\n", " for iz, sz in zip( izv, szv ) :\n", " plt.plot( np.ma.log10( csp.l ), np.ma.log10( [ csp.SSP( il, it, iz ) for il in range( csp.l.shape[0] ) ] ), \n", " color=st, linestyle=sz )\n", "format_axes_ticks(fig)" ] }, { "cell_type": "markdown", "id": "cff6a9cb", "metadata": {}, "source": [ "## Computing the CSP by assuming a SFH\n", "\n", "As mentioned, SSPs can be combined into a Composite Stellar Population (CSP), operation which obviously requires to assume a Star Formation History (SFH). This can be done by building an object of type SFH, implemented in the dedicated module of the library:" ] }, { "cell_type": "code", "execution_count": null, "id": "97a2cf99", "metadata": {}, "outputs": [], "source": [ "from galapy.StarFormationHistory import SFH\n", "sfh = SFH()" ] }, { "cell_type": "markdown", "id": "04105e17", "metadata": {}, "source": [ "We can than compute the resulting emission at different CSP-ages by calling the function `csp.emission`.\n", "This function takes two positional arguments, the age of the population and the assumed SFH:" ] }, { "cell_type": "code", "execution_count": null, "id": "bfb76582", "metadata": {}, "outputs": [], "source": [ "ages = [ 1.e+7, 1.e+8, 1.e+9 ]\n", "Lcsp = [ csp.emission( age, sfh ) for age in ages ]" ] }, { "cell_type": "code", "execution_count": null, "id": "ac556f9c", "metadata": {}, "outputs": [], "source": [ "fig = plt.figure(figsize=(6,4))\n", "for LL, age in zip( Lcsp, ages ) :\n", " plt.plot( np.ma.log10( csp.l ), np.ma.log10( LL ), label = f'$\\\\tau = 10^{{{np.log10(age):.1f}}} $' )\n", "plt.legend(fontsize=14)\n", "format_axes_ticks(fig)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "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.12" } }, "nbformat": 4, "nbformat_minor": 5 }