You can interact with this notebook online: Launch interactive version
Running TARDIS Model Grids¶
This notebook demonstrates the capabilities of the TARDIS grid. The grid facilitates users running large numbers of TARDIS simulations.
[1]:
import pandas as pd
import numpy as np
from tardis.io.atom_data.util import download_atom_data
import tardis.grid as grid
/usr/share/miniconda3/envs/tardis/lib/python3.7/importlib/_bootstrap.py:219: QAWarning: pyne.data is not yet QA compliant.
return f(*args, **kwds)
/usr/share/miniconda3/envs/tardis/lib/python3.7/importlib/_bootstrap.py:219: QAWarning: pyne.material is not yet QA compliant.
return f(*args, **kwds)
Creating A Grid¶
There are 2 ways of creating a TARDIS grid: directly from a dataframe, or by defining a set of axes over which the grid should be defined. In both cases, a config.yml file is required. Note that for the dataframe, the column names are in the form of valid keys in a tardis Configuration dictionary. For the axes, the keys must similarly be valid tardis Configuration keys.
[2]:
# Load a DataFrame
df = pd.read_csv('example_grid.txt')
df
[2]:
model.abundances.H | model.abundances.He | model.structure.velocity.start | plasma.initial_t_inner | |
---|---|---|---|---|
0 | 1.0 | 0.0 | 10000 | 5000 |
1 | 0.4 | 0.6 | 12000 | 6000 |
2 | 0.7 | 0.3 | 15000 | 7000 |
[3]:
# Create a tardis grid directly from a dataframe.
grid.tardisGrid(configFile='example.yml', gridFrame=df)
[3]:
<tardis.grid.base.tardisGrid at 0x7f9955594450>
[4]:
# Create an axes dictionary
axesdict = {'model.structure.velocity.start':np.arange(10000,15000,1000),
'model.abundances.He':np.arange(0,1,0.1),
'model.abundances.H':np.arange(0,1,0.25)}
[5]:
#Create a tardis grid from an axes dict using the classmethod.
grid.tardisGrid.from_axes(configFile='example.yml', axesdict=axesdict)
[5]:
<tardis.grid.base.tardisGrid at 0x7f9955ae3210>
TARDIS Grid Attributes¶
The TARDIS grid only has 2 attributes. It creates a TARDIS Configuration object from the user specified config.yml file and saves this to the self.config
attribute. The grid also stores the parameters of every grid point in a Dataframe accessed by self.grid
[6]:
tg = grid.tardisGrid(configFile='example.yml', gridFrame=df)
[7]:
# The config generated from the user's yml file.
tg.config
[7]:
{'tardis_config_version': 'v1.0',
'supernova': {'luminosity_requested': <Quantity 5.679e+41 erg / s>,
'luminosity_wavelength_start': <Quantity 3481.82000178 Angstrom>,
'luminosity_wavelength_end': <Quantity 9947.78776065 Angstrom>,
'time_explosion': <Quantity 10. d>},
'atom_data': 'kurucz_cd23_chianti_H_He.h5',
'model': {'structure': {'type': 'specific',
'velocity': {'start': <Quantity 10000. km / s>,
'stop': <Quantity 20000. km / s>,
'num': 20},
'density': {'type': 'branch85_w7',
'w7_time_0': <Quantity 0.00023148 d>,
'w7_rho_0': <Quantity 3.e+29 g / cm3>,
'w7_v_0': <Quantity 1. km / s>}},
'abundances': {'type': 'uniform', 'He': 0.2, 'H': 0.8}},
'plasma': {'initial_t_inner': <Quantity 7000. K>,
'disable_electron_scattering': False,
'ionization': 'nebular',
'excitation': 'dilute-lte',
'radiative_rates_type': 'dilute-blackbody',
'line_interaction_type': 'macroatom',
'initial_t_rad': <Quantity -1. K>,
'disable_line_scattering': False,
'w_epsilon': 1e-10,
'nlte': {'species': [],
'coronal_approximation': False,
'classical_nebular': False},
'continuum_interaction': {'species': [],
'enable_adiabatic_cooling': False,
'enable_two_photon_decay': False},
'helium_treatment': 'none',
'heating_rate_data_file': 'none'},
'montecarlo': {'seed': 23111963,
'no_of_packets': 40000.0,
'iterations': 2,
'nthreads': 1,
'last_no_of_packets': 1000.0,
'no_of_virtual_packets': 3,
'convergence_strategy': {'type': 'damped',
'damping_constant': 0.5,
'threshold': 0.05,
'fraction': 0.8,
'hold_iterations': 3,
't_inner': {'damping_constant': 0.5, 'threshold': 0.05},
'stop_if_converged': False,
'lock_t_inner_cycles': 1,
't_inner_update_exponent': -0.5,
't_rad': {'damping_constant': 0.5, 'threshold': 0.05},
'w': {'damping_constant': 0.5, 'threshold': 0.05}},
'virtual_spectrum_spawn_range': {'start': <Quantity 1. Angstrom>,
'end': <Quantity inf Angstrom>},
'enable_reflective_inner_boundary': False,
'inner_boundary_albedo': 0.0,
'enable_full_relativity': False,
'tracking': {'track_rpacket': False, 'initial_array_length': 10},
'debug_packets': False,
'logger_buffer': 1,
'single_packet_seed': -1},
'spectrum': {'start': <Quantity 500. Angstrom>,
'stop': <Quantity 20000. Angstrom>,
'num': 10000,
'method': 'virtual',
'integrated': {'points': 1000, 'interpolate_shells': 0},
'virtual': {'tau_russian': 10.0,
'survival_probability': 0.0,
'enable_biasing': False,
'virtual_packet_logging': False}},
'config_dirname': ''}
[8]:
# The user specified grid.
tg.grid
[8]:
model.abundances.H | model.abundances.He | model.structure.velocity.start | plasma.initial_t_inner | |
---|---|---|---|---|
0 | 1.0 | 0.0 | 10000 | 5000 |
1 | 0.4 | 0.6 | 12000 | 6000 |
2 | 0.7 | 0.3 | 15000 | 7000 |
TARDIS Grid Functionality¶
The TARDIS Grid provides a variety of functions for using the grid to generate new Configurations, return new Radial1DModel objects, or directly run simulations using the parameters specified by the grid. This functionality is particularly useful for running large numbers of simulations and easily works with JobArrays where the row_index is the JobArray index.
[9]:
# Easily get a new TARDIS Configuration object
# which has the properties of the base self.config
# but with properties modified by a row of the grid.
new_grid = tg.grid_row_to_config(row_index=0);
print("tg.config is the original config:",tg.config.model.abundances)
print("The new config is modified: ",new_grid.model.abundances)
tg.config is the original config: {'type': 'uniform', 'He': 0.2, 'H': 0.8}
The new config is modified: {'type': 'uniform', 'He': 0.0, 'H': 1.0}
[10]:
# In case a user needs to make more complicated changes
# to the base TARDIS model (i.e. using parameters that
# are not valid TARDIS Configuration keys), the grid
# can return a Radial1DModel object for a given row.
model = tg.grid_row_to_model(row_index=0)
model
[10]:
<tardis.model.base.Radial1DModel at 0x7f9955552210>
[11]:
# We download the atomic data needed to run a TARDIS simulation
download_atom_data('kurucz_cd23_chianti_H_He')
# Users can easily run a full TARDIS simulation
# using the grid.
sim = tg.run_sim_from_grid(row_index=0)
Configuration File /home/runner/.astropy/config/tardis_internal_config.yml does not exist - creating new one from default
CRITICAL:root:
********************************************************************************
TARDIS will download different kinds of data (e.g. atomic) to its data directory /home/runner/Downloads/tardis-data
TARDIS DATA DIRECTORY not specified in /home/runner/.astropy/config/tardis_internal_config.yml:
ASSUMING DEFAULT DATA DIRECTORY /home/runner/Downloads/tardis-data
YOU CAN CHANGE THIS AT ANY TIME IN /home/runner/.astropy/config/tardis_internal_config.yml
********************************************************************************
[py.warnings ][WARNING] /usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/traitlets/traitlets.py:3050: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
FutureWarning,
(warnings.py:110)
WARNING:py.warnings:/usr/share/miniconda3/envs/tardis/lib/python3.7/site-packages/traitlets/traitlets.py:3050: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
FutureWarning,