{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to Read ARTIS Models with TARDIS\n", "\n", "This notebook demonstrates how to read in density and abundance data from ARTIS-based files using TARDIS.\n", "\n", "We assume you've already installed TARDIS (including the `tardis.io.model.artis` module)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "import tardis\n", "from tardis.io.model.artis.readers import (\n", " read_artis_density,\n", " read_artis_mass_fractions,\n", " read_artis_model,\n", ")\n", "\n", "# We use the example files provided within the TARDIS test suite.\n", "tardis_dir = Path(tardis.__file__).parent\n", "artis_data_dir = tardis_dir / \"io\" / \"model\" / \"artis\" / \"tests\" / \"data\"\n", "\n", "density_filename = artis_data_dir / \"artis_model.dat\"\n", "abundance_filename = artis_data_dir / \"artis_abundances.dat\"\n", "\n", "# Option 1: Read separately (use legacy_return=False to get isotope mass fractions as well)\n", "time_of_model, velocity, mean_density, isotope_mass_fractions = read_artis_density(\n", " density_filename, legacy_return=False\n", ")\n", "mass_fractions_df = read_artis_mass_fractions(abundance_filename)\n", "\n", "print('Time of model:', time_of_model)\n", "print('Velocity shape:', velocity.shape)\n", "print('Mean density shape:', mean_density.shape)\n", "print('\\nIsotope mass fractions (from artis_model.dat):')\n", "print(isotope_mass_fractions.head())\n", "\n", "print('\\nElemental mass fractions (from artis_abundances.dat):')\n", "print(mass_fractions_df.head())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Option 2: Use the combined read_artis_model\n", "model_data = read_artis_model(density_filename, abundance_filename)\n", "\n", "print(\"ArtisData instance:\")\n", "print(model_data)\n", "\n", "# Example of converting model_data to a homologous geometry\n", "geometry = model_data.to_geometry()\n", "print(\"\\nHomologousRadial1DGeometry from model_data:\")\n", "print(\"v_inner =\", geometry.v_inner)\n", "print(\"v_outer =\", geometry.v_outer)\n", "print(\"time_explosion =\", geometry.time_explosion)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After running these cells, you'll have an instance of the `ArtisData` dataclass that contains: \n", " - `time_of_model`: The model's valid time as an astropy Quantity (in seconds)\n", " - `velocity`: An array of velocity values (converted to cm/s by default)\n", " - `mean_density`: The mean density values (in g/cm^3)\n", " - `mass_fractions`: A DataFrame holding mass fractions across each shell \n", "You can directly integrate this object into TARDIS for simulation or leverage its properties for further data analysis and visualization." ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "tardis-devel", "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.13.3" } }, "nbformat": 4, "nbformat_minor": 2 }