{ "cells": [ { "cell_type": "markdown", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "# Accessing Physical Quantities" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to compute the synthetic spectrum, TARDIS must either be told\n", "or must calculate many physical properties of the model. To understand and\n", "test the code it can be important to look at these values. One\n", "easy way to do this is to run TARDIS in an interactive mode and then\n", "inspect the model properties." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Runing in interactive Python session" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Download the atomic data\n", "from tardis.io.atom_data.util import download_atom_data\n", "download_atom_data('kurucz_cd23_chianti_H_He')\n", "\n", "# Download the example configuration file\n", "!curl -O https://raw.githubusercontent.com/tardis-sn/tardis/master/docs/tardis_example.yml" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tardis import run_tardis\n", "\n", "simulation = run_tardis('tardis_example.yml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If all goes well, the simulation should run as usual. Afterwards, the\n", "information from the simulation will all exist in `Simulation` and\n", "can be examined.\n", "Some examples for useful/interesting quantities are\n", "given below (but much more information is available: contact us via \n", "[tardis-sn-users](http://groups.google.com/forum/#!forum/tardis-sn-users) if you need\n", "further help)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Examples of finding physical quantities" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example, two of our important quantities are the parameters of the\n", "radiation field model, $T_{\\rm rad}$ and $W$. These exist as `numpy.ndarray`\n", "\n", "Thus `simulation.plasma.t_rad` will give you a list of the $T_{\\rm rad}$-values for the model zones in cgs units." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.t_rad" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly, the $W$-values can be accessed using `simulation.plasma.w`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.w" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Several important quantities that were setup when the model was defined by the configuration file are located in the `model` section of the simulation. For example, the inner and outer velocity boundaries of the zones in the model is given by `simulation.simulation_state.v_inner.cgs` and `simulation.simulation_state.v_outer.cgs` respectively. These exist as Astropy [Quantities](http://astropy.readthedocs.org/en/v0.2.1/_generated/astropy.units.quantity.Quantity.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.simulation_state.v_inner.cgs" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.simulation_state.v_outer.cgs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The average density in the zones is given by `simulation.simulation_state.density.cgs`. These also exist as Astropy [Quantities](http://astropy.readthedocs.org/en/v0.2.1/_generated/astropy.units.quantity.Quantity.html)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.simulation_state.density.cgs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Many other interesting quantities are stored in the `plasma`.\n", "For example the calculated ion populations and level populations is given by `simulation.plasma.ion_number_density` and `simulation.plasma.level_number_density` respectively." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.ion_number_density" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.level_number_density" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These are stored as Pandas `DataFrames`. An index can be supplied to obtain the population in a particular zone. E.g., for the ion populations of the innermost zone (index = 0), we will use \n", "`simulation.plasma.ion_number_density[0]`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.ion_number_density[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ion populations for a particular ionization stage of a particular element can be accessed by specifying an appropriate tuple (𝑍,𝐶), which identifies the element (via atomic number 𝑍 ) and the charge (via the ion charge 𝐶 ). Thus, `simulation.plasma.ion_number_density.loc[14,1]` will identify the ion popuations for Si II (𝑍=14,𝐶=1) in all the zones. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.ion_number_density.loc[14,1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The above examples can be combined to obtain e.g. the Si II population in the innermost zone\n", "can be obtained by\n", "`simulation.plasma.ion_number_density[0].loc[14,1]`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.ion_number_density[0].loc[14,1]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The level populations are stored (and can be accessed) in a similar way - a third label can be used to pick out a particular atomic level. E.g., to pull out the population of the ground state (index 0) of Si II we can use `simulation.plasma.level_number_density.loc[14,1,0]`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "simulation.plasma.level_number_density.loc[14,1,0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Notes\n", "- If you prefer to work in SI units, all the Astropy Quantities may instead by accessed with “xxx.si”.\n", "\n", "- Information that is not stored as Astropy Quantities (e.g. the ion and level populations used in the example above) are usually stored in cgs units (i.e. cm−3 for the populations)." ] } ], "metadata": { "celltoolbar": "Raw Cell Format", "kernelspec": { "display_name": "Python 3", "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.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }