You can interact with this notebook online: Launch notebook

Reading a ConfigurationΒΆ

This notebook demonstrates how TARDIS reads a configuration file or a configuration dictionary and creates an instance of the Configuration class.

[1]:
from tardis.io.configuration.config_reader import Configuration

The configuration can be read this way. It will be validated by the json-schema schemas (including filling out default configuration options that had not been specified).

[2]:
conf = Configuration.from_yaml('tardis_example.yml')

Despite the very simple nature of tardis_example.yml, the output does contain all the default values

[3]:
conf
[3]:
{'tardis_config_version': 'v1.0',
 'supernova': {'luminosity_requested': <Quantity 1.05927636e+43 erg / s>,
  'time_explosion': <Quantity 13. d>,
  'luminosity_wavelength_start': <Quantity 0. Angstrom>,
  'luminosity_wavelength_end': <Quantity inf Angstrom>},
 'atom_data': 'kurucz_cd23_chianti_H_He.h5',
 'model': {'structure': {'type': 'specific',
   'velocity': {'start': <Quantity 11000. 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',
   'O': 0.19,
   'Mg': 0.03,
   'Si': 0.52,
   'S': 0.19,
   'Ar': 0.04,
   'Ca': 0.03,
   'model_isotope_time_0': <Quantity 0. s>}},
 'plasma': {'disable_electron_scattering': False,
  'ionization': 'lte',
  'excitation': 'lte',
  'radiative_rates_type': 'dilute-blackbody',
  'line_interaction_type': 'macroatom',
  'initial_t_inner': <Quantity -1. K>,
  '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',
  'link_t_rad_t_electron': 0.9,
  'nlte_ionization_species': [],
  'nlte_excitation_species': [],
  'nlte_solver': 'root'},
 'montecarlo': {'seed': 23111963,
  'no_of_packets': 40000.0,
  'iterations': 20,
  'nthreads': 1,
  'last_no_of_packets': 100000.0,
  'no_of_virtual_packets': 10,
  'convergence_strategy': {'type': 'damped',
   'damping_constant': 1.0,
   'threshold': 0.05,
   'fraction': 0.8,
   'hold_iterations': 3,
   't_inner': {'damping_constant': 0.5, 'type': 'damped', 'threshold': 0.05},
   'stop_if_converged': False,
   'lock_t_inner_cycles': 1,
   't_inner_update_exponent': -0.5,
   't_rad': {'damping_constant': 1.0, 'threshold': 0.05, 'type': 'damped'},
   'w': {'damping_constant': 1.0, 'threshold': 0.05, 'type': 'damped'},
   'v_inner_boundary': {'damping_constant': 1.0,
    'threshold': 0.05,
    'type': 'damped'}},
  'virtual_spectrum_spawn_range': {'start': <Quantity 1. Angstrom>,
   'end': <Quantity inf Angstrom>},
  'enable_full_relativity': False,
  'enable_nonhomologous_expansion': False,
  'tracking': {'track_rpacket': False, 'initial_array_length': 10},
  'debug_packets': False,
  'logger_buffer': 1},
 'spectrum': {'start': <Quantity 500. Angstrom>,
  'stop': <Quantity 20000. Angstrom>,
  'num': 10000,
  'method': 'virtual',
  'integrated': {'points': 1000, 'interpolate_shells': 0, 'compute': 'CPU'},
  'virtual': {'tau_russian': 10.0,
   'survival_probability': 0.0,
   'enable_biasing': False,
   'virtual_packet_logging': False}},
 'config_dirname': ''}

Values can either be accessed using .:

[4]:
conf.model.structure.velocity.start
[4]:
$11000 \; \mathrm{\frac{km}{s}}$

or by treating the configuration as a dictionary:

[5]:
conf['montecarlo']['convergence_strategy']['damping_constant']
[5]:
1.0

Similarly to how they are accessed, entries in the configuration can be edited. For example,

[6]:
conf['montecarlo']['convergence_strategy']['damping_constant'] = 0.3

sets that entry of the configuration to 0.3:

[7]:
conf['montecarlo']['convergence_strategy']['damping_constant']
[7]:
0.3

This can be done using . as well.

You can also read a configuration from a dictionary. For example:

[8]:
from astropy import units as u

conf_dict = {'tardis_config_version': 'v1.0',
 'supernova': {'luminosity_requested': 1.05e+43 * u.erg / u.s,
  'time_explosion': 13 * u.day},
 'atom_data': 'kurucz_cd23_chianti_H_He.h5',
 'model': {'structure': {'type': 'specific',
   'velocity': {'start': 11000. * u.km / u.s,
    'stop': 20000. * u.km / u.s,
    'num': 20},
   'density': {'type': 'branch85_w7'}},
  'abundances': {'type': 'uniform',
   'O': 0.19,
   'Mg': 0.03,
   'Si': 0.52,
   'S': 0.19,
   'Ar': 0.04,
   'Ca': 0.03}},
 'plasma': {'ionization': 'lte',
  'excitation': 'lte',
  'radiative_rates_type': 'dilute-blackbody',
  'line_interaction_type': 'macroatom',},
 'montecarlo': {'seed': 23111963,
  'no_of_packets': 40000.0,
  'iterations': 20,
  'last_no_of_packets': 100000.0,
  'no_of_virtual_packets': 10,},
 'spectrum': {'start': 500. * u.Angstrom,
  'stop': 20000. * u.Angstrom,
  'num': 10000,}}
[9]:
conf2 = Configuration.from_config_dict(conf_dict)
conf2
[9]:
{'tardis_config_version': 'v1.0',
 'supernova': {'luminosity_requested': <Quantity 1.05e+43 erg / s>,
  'time_explosion': <Quantity 13. d>,
  'luminosity_wavelength_start': <Quantity 0. Angstrom>,
  'luminosity_wavelength_end': <Quantity inf Angstrom>},
 'atom_data': 'kurucz_cd23_chianti_H_He.h5',
 'model': {'structure': {'type': 'specific',
   'velocity': {'start': <Quantity 11000. 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',
   'O': 0.19,
   'Mg': 0.03,
   'Si': 0.52,
   'S': 0.19,
   'Ar': 0.04,
   'Ca': 0.03,
   'model_isotope_time_0': <Quantity 0. s>}},
 'plasma': {'ionization': 'lte',
  'excitation': 'lte',
  'radiative_rates_type': 'dilute-blackbody',
  'line_interaction_type': 'macroatom',
  'initial_t_inner': <Quantity -1. K>,
  'initial_t_rad': <Quantity -1. K>,
  'disable_electron_scattering': False,
  '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',
  'link_t_rad_t_electron': 0.9,
  'nlte_ionization_species': [],
  'nlte_excitation_species': [],
  'nlte_solver': 'root'},
 'montecarlo': {'seed': 23111963,
  'no_of_packets': 40000.0,
  'iterations': 20,
  'last_no_of_packets': 100000.0,
  'no_of_virtual_packets': 10,
  'nthreads': 1,
  'virtual_spectrum_spawn_range': {'start': <Quantity 1. Angstrom>,
   'end': <Quantity inf Angstrom>},
  'convergence_strategy': {'type': 'damped',
   'stop_if_converged': False,
   'fraction': 0.8,
   'hold_iterations': 3,
   'damping_constant': 1.0,
   'threshold': 0.05,
   'lock_t_inner_cycles': 1,
   't_inner_update_exponent': -0.5,
   't_inner': {'damping_constant': 1.0, 'threshold': 0.05, 'type': 'damped'},
   't_rad': {'damping_constant': 1.0, 'threshold': 0.05, 'type': 'damped'},
   'w': {'damping_constant': 1.0, 'threshold': 0.05, 'type': 'damped'},
   'v_inner_boundary': {'damping_constant': 1.0,
    'threshold': 0.05,
    'type': 'damped'}},
  'enable_full_relativity': False,
  'enable_nonhomologous_expansion': False,
  'tracking': {'track_rpacket': False, 'initial_array_length': 10},
  'debug_packets': False,
  'logger_buffer': 1},
 'spectrum': {'start': <Quantity 500. Angstrom>,
  'stop': <Quantity 20000. Angstrom>,
  'num': 10000,
  'method': 'virtual',
  'integrated': {'points': 1000, 'interpolate_shells': 0, 'compute': 'CPU'},
  'virtual': {'tau_russian': 10.0,
   'survival_probability': 0.0,
   'enable_biasing': False,
   'virtual_packet_logging': False}},
 'config_dirname': ''}

Notice that the Configuration object once again has all the default values filled in.

Note

In most cases, we strongly recommend using a configuration file as opposed to a configuration dictionary.