<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction to SYGMA
Prepared by Christian Ritter
How to use the notebook
Step1:  1.) Runnig the simulation
In the following the evolution of a single stellar population (SSP, one starburst) with an initial metallicty of $Z=0.0001$ is calculated. The SSP has a total mass of $10^{11}M_{\odot}$.  When reaching $1.3*10^{10}$ years the code stops. Start the simulation by creating an instance s1 of the class $sygma$
Step2:  Here we use the default values of many input parameter such as the Salpeter IMF and the mass range betwen $1M_{\odot}$ and $30M_{\odot}$.
2) Visualization
Attached to SYGMA is an analysis test suite of various functions.
Total mass evolution
SYGMA provides plotting functions which have the form plot_*. Check out the
<a href="http
Step3:  SYGMA traces the (accumulated!) amount of mass ejected by stars which increases over time because more and more stars eject their matter. The value of $10^{11}M_{\odot}$ chosen as the initial gas mass of the cloud will never be reached because a lot of matter is forever locked away inside the stellar remnants.
Gas mass from different sources
From where is the ejected mass coming from? You can distinguish between three main stellar sources
Step4:  First the massive stars eject their matter due to their short lifetime. Later AGB stars and SNIa start to contribute.
After about $3*10^8$ years AGB stars have ejected the most matter.
Analysis of the composition
One can also analyze the contribution of specific isotopes and elements.
Let us look a the element carbon.
Step5:  Spectroscopic notation
You can plot the evolution of isotopes and elements in spectroscopic notation, such as [Fe/H]
Step6:  Single star sources
To analyse which stars are relevant for the element production you can plot the contribution
of stars of different intial mass. Here you see the total mass contribution for C from each initial mass interval.
Step7:  The low-mass AGB stars produce the most C while for massive and S-AGB stars the contribution drops.
3) Data extraction
To extract how much of elements and isotopes are ejected you can extract tables.
In the following example the elements H, He and C are extracted and are saved
in the evol_tables directory. 
(If you use this notebook in the WENDI web interface you cannot access the table directly.)
Step8:  The amount of H, He and C is normalized to the total amount of the gas mass specified initially ($10^{11}M_{\odot}$ in our case.)
4) Demonstration of basic capabilities
In the following we show basic capabilities of SYGMA which include changing the IMF, adaptiong the IMF range and changing the delay-time distribution of SNIa.
Step9:  For each run you could add here plots introduced in 2) by using the instances s2, s3 and s4.
5) Modifying the yield input
All yield input is provided as tables which can be easily modified. Or you can provide your own yield tables.
As default SYGMA uses NuGrid's yield tables for AGB and massive stars (<a href="http
<ASSISTANT_TASK:>
Python Code:
from NuPyCEE import sygma as s
%matplotlib nbagg
Explanation: Introduction to SYGMA
Prepared by Christian Ritter
How to use the notebook:
$\odot$ Execute cell: select cell and shift+enter
$\odot$ To start again and remove all output:  Cell > All output > Clear
$\odot$ The circle in the menu bar in the upper right corner indicates if the program is busy.
Abstract
The purpose of this notebook is to demonstrate and explain the basic capabilities of SYGMA.
You can run all the commmands below in the interactive python session on your computer.
Accessing SYGMA
Import of the module. You have to tell the code where to find the root directory by pointing
the bash variable SYGMADIR to the root directory of NuPyCEE. One execption is if you execute SYGMA
from within the root directory. You find the SYGMADIR defined in this bash script start_notebook_server.sh.
End of explanation
s1=s.sygma(iniZ=0.0001,tend=1.0e10,mgal=1.3e10)
Explanation: 1.) Runnig the simulation
In the following the evolution of a single stellar population (SSP, one starburst) with an initial metallicty of $Z=0.0001$ is calculated. The SSP has a total mass of $10^{11}M_{\odot}$.  When reaching $1.3*10^{10}$ years the code stops. Start the simulation by creating an instance s1 of the class $sygma$:
End of explanation
s1.plot_totmasses(fig=1,source='all')
Explanation: Here we use the default values of many input parameter such as the Salpeter IMF and the mass range betwen $1M_{\odot}$ and $30M_{\odot}$.
2) Visualization
Attached to SYGMA is an analysis test suite of various functions.
Total mass evolution
SYGMA provides plotting functions which have the form plot_*. Check out the
<a href="http://nugrid.github.io/NuPyCEE/SPHINX/build/html/sygma.html">SPHINX documentation</a> for
more input parameter and their definition.
Now let us plot the evolution of the total (ejected) gas mass.
End of explanation
s1.plot_totmasses(fig=2,source='agb')
s1.plot_totmasses(fig=2,source='massive')
s1.plot_totmasses(fig=2,source='sn1a')
Explanation: SYGMA traces the (accumulated!) amount of mass ejected by stars which increases over time because more and more stars eject their matter. The value of $10^{11}M_{\odot}$ chosen as the initial gas mass of the cloud will never be reached because a lot of matter is forever locked away inside the stellar remnants.
Gas mass from different sources
From where is the ejected mass coming from? You can distinguish between three main stellar sources: AGB, masive and SN1a. For that we use other parameter of the plotting function as explained in the online documentation.
End of explanation
s1.plot_mass(fig=3,specie='C', source='all')
Explanation: First the massive stars eject their matter due to their short lifetime. Later AGB stars and SNIa start to contribute.
After about $3*10^8$ years AGB stars have ejected the most matter.
Analysis of the composition
One can also analyze the contribution of specific isotopes and elements.
Let us look a the element carbon.
End of explanation
s1.plot_spectro(fig=4,xaxis='age',yaxis='[O/Fe]', source='all')
Explanation: Spectroscopic notation
You can plot the evolution of isotopes and elements in spectroscopic notation, such as [Fe/H]:
End of explanation
s1.plot_mass_range_contributions(fig=5,specie='C')
Explanation: Single star sources
To analyse which stars are relevant for the element production you can plot the contribution
of stars of different intial mass. Here you see the total mass contribution for C from each initial mass interval.
End of explanation
s1.write_evol_table(elements=['H','He','C'])
Explanation: The low-mass AGB stars produce the most C while for massive and S-AGB stars the contribution drops.
3) Data extraction
To extract how much of elements and isotopes are ejected you can extract tables.
In the following example the elements H, He and C are extracted and are saved
in the evol_tables directory. 
(If you use this notebook in the WENDI web interface you cannot access the table directly.)
End of explanation
#default type 'salpeter', change to chabrier IMF
s2=s.sygma(iniZ=0.0001,tend=1.0e10,mgal=1.3e10,imf_type='chabrier') 
#default from 1 to 30Msun, changed to 2 to 15Msun
s3=s.sygma(iniZ=0.0001,tend=1.0e10,mgal=1.3e10,imf_bdys=[2,15]) 
#turning SNIa  off
s4=s.sygma(iniZ=0.0001,tend=1.0e10,mgal=1.3e10,sn1a_on=False) 
Explanation: The amount of H, He and C is normalized to the total amount of the gas mass specified initially ($10^{11}M_{\odot}$ in our case.)
4) Demonstration of basic capabilities
In the following we show basic capabilities of SYGMA which include changing the IMF, adaptiong the IMF range and changing the delay-time distribution of SNIa.
End of explanation
s_other_yields=s.sygma(iniZ=0.0001,tend=1.0e10,mgal=1.3e10,
             table='yield_tables/agb_and_massive_stars_h1.txt',
             iniabu_table='yield_tables/iniabu/iniab_h1.ppn')
s_other_yields.plot_totmasses(fig=6,source='all')
Explanation: For each run you could add here plots introduced in 2) by using the instances s2, s3 and s4.
5) Modifying the yield input
All yield input is provided as tables which can be easily modified. Or you can provide your own yield tables.
As default SYGMA uses NuGrid's yield tables for AGB and massive stars (<a href="http://adsabs.harvard.edu/abs/2016ApJS..225...24P">Pignatari et al. 2016</a>). Other defaults include the
choice of SNIa yields from <a href="http://adsabs.harvard.edu/abs/1986A%26A...158...17T">Thielemann 1986</a>
and PopIII stars from <a href="http://adsabs.harvard.edu/abs/2010ApJ...724..341H">Heger 2010</a>.
Using your own yield is not possible within the WENDI web interface.
To use own yields for AGB stars and massive stars it is necessary to specify the input variable table = 'yourtablename'. The table needs to have the NuGrid yield table format which is found as the default yield table file (specified with $table='yield_tables/isotope_yield_table.txt'$). All NuPyCEE yield table files are available in the $yield_tables$ directory. 
Note that yield tables and initial abundance files must include the same isotopes. Hence it is necessary to specify a initial abundance file via the input variable $iniabu_table$ which must be placed in the $iniabu$ directory
within $yield_tables$. 
In the following we show a example with artificial yields with only the species H-1.
End of explanation
<END_TASK>