# Download the atomic data
from tardis.io.atom_data.util import download_atom_data
download_atom_data('kurucz_cd23_chianti_H_He')

# Download the example configuration file
!curl -O https://raw.githubusercontent.com/tardis-sn/tardis/master/docs/models/examples/tardis_example.yml

from tardis import run_tardis

simulation = run_tardis('tardis_example.yml')

"""
Explanation: Accessing Physical Quantities
In order to compute the synthetic spectrum, TARDIS must either be told
or must calculate many physical properties of the model. To understand and
test the code it can be important to look at these values. One
easy way to do this is to run TARDIS in an interactive mode and then
inspect the model properties.
Runing in interactive Python session
End of explanation
"""


simulation.plasma.t_rad

"""
Explanation: If all goes well, the simulation should run as usual. Afterwards, the
information from the simulation will all exist in Simulation and
can be examined.
Some examples for useful/interesting quantities are
given below (but much more information is available: contact us via 
tardis-sn-users if you need
further help).
Examples of finding physical quantities
For example, two of our important quantities are the parameters of the
radiation field model, $T_{\rm rad}$ and $W$. These exist as numpy.ndarray
Thus simulation.plasma.t_rad will give you a list of the $T_{\rm rad}$-values for the model zones in cgs units.
End of explanation
"""


simulation.plasma.w

"""
Explanation: Similarly, the $W$-values can be accessed using simulation.plasma.w
End of explanation
"""


simulation.model.v_inner.cgs

simulation.model.v_outer.cgs

"""
Explanation: 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.model.v_inner.cgs and simulation.model.v_outer.cgs respectively. These exist as Astropy Quantities.
End of explanation
"""


simulation.model.density.cgs

"""
Explanation: The average density in the zones is given by simulation.model.density.cgs. These also exist as Astropy Quantities.
End of explanation
"""


simulation.plasma.ion_number_density

simulation.plasma.level_number_density

"""
Explanation: Many other interesting quantities are stored in the plasma.
For example the calculated ion populations and level populations is given by simulation.plasma.ion_number_density and simulation.plasma.level_number_density respectively.
End of explanation
"""


simulation.plasma.ion_number_density[0]

"""
Explanation: 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 
simulation.plasma.ion_number_density[0]
End of explanation
"""


simulation.plasma.ion_number_density.loc[14,1]

"""
Explanation: 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.
End of explanation
"""


simulation.plasma.ion_number_density[0].loc[14,1]

"""
Explanation: The above examples can be combined to obtain e.g. the Si II population in the innermost zone
can be obtained by
simulation.plasma.ion_number_density[0].loc[14,1]
End of explanation
"""


simulation.plasma.level_number_density.loc[14,1,0]

"""
Explanation: 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]
End of explanation
"""


