<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>omega &mdash; SYGMA DOC v1.0 documentation</title>
    
    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     'v1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="SYGMA DOC v1.0 documentation" href="../index.html" />
    <link rel="up" title="Module code" href="index.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SYGMA DOC v1.0 documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for omega</h1><div class="highlight"><pre>
<span></span><span class="sd">&#39;&#39;&#39;</span>

<span class="sd">GCE OMEGA (One-zone Model for the Evolution of Galaxies) module</span>


<span class="sd">Functionality</span>
<span class="sd">=============</span>

<span class="sd">This tool allows one to simulate the chemical evolution of single-zone galaxies.</span>
<span class="sd">Having the star formation history as one of the input parameters, OMEGA can</span>
<span class="sd">target local galaxies by using observational data found in the literature.</span>


<span class="sd">Made by</span>
<span class="sd">=======</span>

<span class="sd">FEB2015: C. Ritter, B. Cote</span>

<span class="sd">MAY2015: B. Cote</span>

<span class="sd">The code inherits the chem_evol class, which contains common functions shared by</span>
<span class="sd">SYGMA and OMEGA.  The code in chem_evol has been developed by :</span>

<span class="sd">v0.1 NOV2013: C. Fryer, C. Ritter</span>

<span class="sd">v0.2 JAN2014: C. Ritter</span>

<span class="sd">v0.3 APR2014: C. Ritter, J. F. Navarro, F. Herwig, C. Fryer, E. Starkenburg,</span>
<span class="sd">              M. Pignatari, S. Jones, K. Venn1, P. A. Denissenkov &amp; </span>
<span class="sd">              the NuGrid collaboration</span>

<span class="sd">v0.4 FEB2015: C. Ritter, B. Cote</span>

<span class="sd">v0.5 MAR2015: B. Cote</span>

<span class="sd">v0.6 OCT2016: B. Cote</span>


<span class="sd">Usage</span>
<span class="sd">=====</span>

<span class="sd">Import the module:</span>

<span class="sd">&gt;&gt;&gt; import omega as o</span>

<span class="sd">Get help:</span>

<span class="sd">&gt;&gt;&gt; help o</span>

<span class="sd">Get more information:</span>

<span class="sd">&gt;&gt;&gt; o.omega?</span>

<span class="sd">Create a custom galaxy (closed box):</span>

<span class="sd">&gt;&gt;&gt; o1 = o.omega(cte_sfr=1.0, mgal=1.5e10)</span>

<span class="sd">Simulate a known galaxy (open box):</span>

<span class="sd">&gt;&gt;&gt; o2 = o.omega(galaxy=&#39;sculptor&#39;, in_out_control=True, mgal=1e6, mass_loading=8, in_out_ratio=1.5)</span>

<span class="sd">Analysis functions: See the Sphinx documentation</span>

<span class="sd">&#39;&#39;&#39;</span>

<span class="c1">#standard packages</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">random</span>

<span class="c1"># Import the class inherited by SYGMA</span>
<span class="kn">import</span> <span class="nn">sygma</span>
<span class="kn">from</span> <span class="nn">chem_evol</span> <span class="kn">import</span> <span class="o">*</span>


<div class="viewcode-block" id="omega"><a class="viewcode-back" href="../omega.html#omega.omega">[docs]</a><span class="k">class</span> <span class="nc">omega</span><span class="p">(</span> <span class="n">chem_evol</span> <span class="p">):</span>

    <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Input parameters (OMEGA)</span>
<span class="sd">    ================</span>

<span class="sd">    Important : By default, a closed box model is always assumed.</span>

<span class="sd">    galaxy : string</span>
<span class="sd">        Name of the target galaxy.  By using a known galaxy, the code</span>
<span class="sd">        automatically selects the corresponding star formation history, stellar</span>
<span class="sd">        mass, and total mass (when available).  By using &#39;none&#39;, the user has</span>
<span class="sd">        perfect control of these three last parameters.</span>

<span class="sd">        Choices : &#39;milky_way&#39;, &#39;milky_way_cte&#39;, &#39;sculptor&#39;, &#39;carina&#39;, &#39;fornax&#39;,</span>
<span class="sd">        &#39;none&#39;</span>

<span class="sd">        Default value : &#39;none&#39; </span>

<span class="sd">        Special note : The &#39;milky_way_cte&#39; option uses the Milky Way&#39;s</span>
<span class="sd">        characteristics, but with a constant star formation history.</span>

<span class="sd">    cte_sfr : float</span>
<span class="sd">        Constant star formation history in [Mo/yr].</span>

<span class="sd">        Default value : 1.0</span>

<span class="sd">    rand_sfh : float</span>
<span class="sd">        Maximum possible ratio between the maximum and the minimum values of a star</span>
<span class="sd">        formation history that is randomly generated.</span>

<span class="sd">        Default value : 0.0 (deactivated)</span>

<span class="sd">        Special note : A value greater than zero automatically generates a random</span>
<span class="sd">        star formation history, which pypasses the use of the cte_sfr parameter.</span>

<span class="sd">    sfh_file : string</span>
<span class="sd">        Path to a file containing an input star formation history.  The first and</span>
<span class="sd">        second columns must be the age of the galaxy in [yr] and the star</span>
<span class="sd">        formation rate in [Mo/yr].</span>

<span class="sd">        Default value : &#39;none&#39; (deactivated)</span>

<span class="sd">        Special note : When a path is specified, it by passes the cte_sfr and the</span>
<span class="sd">        and_sfh parameters.</span>

<span class="sd">    stellar_mass_0 : float</span>
<span class="sd">        Current stellar mass of the galaxy, in [Mo], at the end of the simulation.</span>
<span class="sd">        </span>
<span class="sd">        Default value : -1.0 (you need to specify a value with unknown galaxies)</span>

<span class="sd">    in_out_control : boolean</span>
<span class="sd">        The in_out_control implementation enables control of the outflow and</span>
<span class="sd">        the inflow rates independently by using constant values (see outflow_rate</span>
<span class="sd">        and inflow_rate) or by using a mass-loading factor that connects the</span>
<span class="sd">        rates to the star formation history (see mass_loading and in_out_ratio).</span>

<span class="sd">        Default value : False (deactivated)</span>

<span class="sd">    mass_loading : float</span>
<span class="sd">        Ratio between the outflow rate and the star formation rate.</span>

<span class="sd">        Default value : 1.0</span>

<span class="sd">    outflow_rate : float</span>
<span class="sd">        Constant outflow rate in [Mo/yr].</span>

<span class="sd">        Default value : -1.0 (deactivated)</span>

<span class="sd">        Special note : A value greater or equal to zero activates the constant</span>
<span class="sd">        utflow mode, which bypasses the use of the mass_loading parameter.</span>

<span class="sd">    in_out_ratio : float</span>
<span class="sd">        Used in : in_out_control mode</span>

<span class="sd">        Ratio between the inflow rate and the outflow rate.  This parameter is</span>
<span class="sd">        used to calculate the inflow rate, not the outflow rate.</span>

<span class="sd">        Default value : 1.0</span>

<span class="sd">    inflow_rate : float</span>
<span class="sd">        Used in : in_out_control mode</span>
<span class="sd">        Constant inflow rate in [Mo/yr].</span>

<span class="sd">        Default value : -1.0 (deactivated)</span>

<span class="sd">        Special note : A value greater or equal to zero activates the constant</span>
<span class="sd">        inflow mode, which bypasses the use of the in_out_ratio parameter.</span>

<span class="sd">    SF_law : boolean</span>
<span class="sd">        The SF_law inplementation assumes a Kennicutt-Schmidt star formation law</span>
<span class="sd">        and combines it to the known input star formation history in order to</span>
<span class="sd">        derive the mass of the gas reservoir at every timestep.</span>

<span class="sd">        Default value : False (deactivated)</span>

<span class="sd">    sfe : float</span>
<span class="sd">        Used in : SF_law and DM_evolution modes</span>

<span class="sd">        Star formation efficiency present in the Kennicutt-Schmidt law.</span>

<span class="sd">        Default value : 0.1</span>

<span class="sd">    f_dyn : float</span>
<span class="sd">        Used in : SF_law and DM_evolution modes</span>
<span class="sd">        Scaling factor used to calculate the star formation timescale present in</span>
<span class="sd">        the Kennicutt-Schmidt law.  We assume that this timescale is equal to a</span>
<span class="sd">        fraction of the dynamical timescale of the virialized system (dark and</span>
<span class="sd">        baryonic matter), t_star = f_dyn * t_dyn.</span>

<span class="sd">        Default value : 0.1</span>

<span class="sd">    m_DM_0 : float</span>
<span class="sd">        Used in : SF_law and DM_evolution modes</span>
<span class="sd">        Current dark matter halo mass of the galaxy, in [Mo], at the end of the</span>
<span class="sd">        simulations.</span>

<span class="sd">        Default value : 1.0e+11 </span>

<span class="sd">    t_star : float</span>
<span class="sd">        Used in : SF_law and DM_evolution modes</span>
<span class="sd">        Star formation timescale, in [yr], used in the Kennicutt-Schmidt law.</span>
<span class="sd">        Default value = -1.0 (deactivated)</span>

<span class="sd">        Special note : A positive value activates the use of this parameter, </span>
<span class="sd">        which bypasses the f_dyn parameter.</span>

<span class="sd">    DM_evolution : boolean</span>
<span class="sd">        The DM_evolution implementation is an extension of the SF_law option.</span>
<span class="sd">        In addition to using a Kennicutt-Schmidt star formation law, it assumes</span>
<span class="sd">        an evolution in the total mass of the galaxy as function of time.  With</span>
<span class="sd">        this prescription, the mass-loading factor has a mass dependency.  The</span>
<span class="sd">        mass_loading parameter then only represents the final value at the end</span>
<span class="sd">        of the simulation. </span>

<span class="sd">        Default value : False (deactivated)</span>

<span class="sd">    exp_ml : float</span>
<span class="sd">        Used in : DM_evolution mode</span>

<span class="sd">        Exponent of the mass dependency of the mass-loading factor.  This last</span>
<span class="sd">        factor is proportional to M_vir**(-exp_ml/3), where M_vir is the sum of</span>
<span class="sd">        dark and baryonic matter.</span>

<span class="sd">        Default value : 2.0    </span>

<span class="sd">    ================</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="c1">#Combine docstrings from chem_evol with sygma docstring</span>
    <span class="n">__doc__</span> <span class="o">=</span> <span class="n">__doc__</span><span class="o">+</span><span class="n">chem_evol</span><span class="o">.</span><span class="n">__doc__</span>


    <span class="c1">##############################################</span>
    <span class="c1">##               Constructor                ##</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">galaxy</span><span class="o">=</span><span class="s1">&#39;none&#39;</span><span class="p">,</span> <span class="n">in_out_control</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">SF_law</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> \
                 <span class="n">DM_evolution</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">Z_trans</span><span class="o">=</span><span class="mf">1e-20</span><span class="p">,</span> <span class="n">f_dyn</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">sfe</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> \
                 <span class="n">outflow_rate</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">inflow_rate</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">rand_sfh</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">cte_sfr</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> \
                 <span class="n">m_DM_0</span><span class="o">=</span><span class="mf">1.0e11</span><span class="p">,</span> <span class="n">mass_loading</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">t_star</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">sfh_file</span><span class="o">=</span><span class="s1">&#39;none&#39;</span><span class="p">,</span> \
                 <span class="n">in_out_ratio</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">stellar_mass_0</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> \
                 <span class="n">z_dependent</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">exp_ml</span><span class="o">=</span><span class="mf">2.0</span><span class="p">,</span><span class="n">nsmerger_bdys</span><span class="o">=</span><span class="p">[</span><span class="mi">8</span><span class="p">,</span> <span class="mi">100</span><span class="p">],</span> \
                 <span class="n">imf_type</span><span class="o">=</span><span class="s1">&#39;kroupa&#39;</span><span class="p">,</span> <span class="n">alphaimf</span><span class="o">=</span><span class="mf">2.35</span><span class="p">,</span> <span class="n">imf_bdys</span><span class="o">=</span><span class="p">[</span><span class="mf">0.1</span><span class="p">,</span><span class="mi">100</span><span class="p">],</span> \
                 <span class="n">sn1a_rate</span><span class="o">=</span><span class="s1">&#39;power_law&#39;</span><span class="p">,</span> <span class="n">iniZ</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">dt</span><span class="o">=</span><span class="mf">1e6</span><span class="p">,</span> <span class="n">special_timesteps</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> \
                 <span class="n">tend</span><span class="o">=</span><span class="mf">13e9</span><span class="p">,</span> <span class="n">mgal</span><span class="o">=</span><span class="mf">1.0e10</span><span class="p">,</span> <span class="n">transitionmass</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">iolevel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> \
                 <span class="n">ini_alpha</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">nb_nsm_per_m</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">t_nsm_coal</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span>\
                 <span class="n">table</span><span class="o">=</span><span class="s1">&#39;yield_tables/isotope_yield_table_MESA_only_fryer12_delay.txt&#39;</span><span class="p">,</span> \
                 <span class="n">hardsetZ</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">sn1a_on</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">nsm_dtd_power</span><span class="o">=</span><span class="p">[],</span>\
                 <span class="n">sn1a_table</span><span class="o">=</span><span class="s1">&#39;yield_tables/sn1a_t86.txt&#39;</span><span class="p">,</span>\
                 <span class="n">ns_merger_on</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">f_binary</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">f_merger</span><span class="o">=</span><span class="mf">0.0008</span><span class="p">,</span>\
                 <span class="n">t_merger_max</span><span class="o">=</span><span class="mf">1.0e10</span><span class="p">,</span> <span class="n">m_ej_nsm</span> <span class="o">=</span> <span class="mf">2.5e-02</span><span class="p">,</span> \
                 <span class="n">nsmerger_table</span> <span class="o">=</span> <span class="s1">&#39;yield_tables/r_process_rosswog_2014.txt&#39;</span><span class="p">,</span> \
                 <span class="n">bhns_merger_on</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">m_ej_bhnsm</span><span class="o">=</span><span class="mf">2.5e-02</span><span class="p">,</span> \
                 <span class="n">bhnsmerger_table</span> <span class="o">=</span> <span class="s1">&#39;yield_tables/r_process_rosswog_2014.txt&#39;</span><span class="p">,</span> \
                 <span class="n">iniabu_table</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">extra_source_on</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> \
                 <span class="n">extra_source_table</span><span class="o">=</span><span class="s1">&#39;yield_tables/extra_source.txt&#39;</span><span class="p">,</span> \
 		 <span class="n">f_extra_source</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> \
                 <span class="n">pop3_table</span><span class="o">=</span><span class="s1">&#39;yield_tables/popIII_heger10.txt&#39;</span><span class="p">,</span> \
                 <span class="n">imf_bdys_pop3</span><span class="o">=</span><span class="p">[</span><span class="mf">0.1</span><span class="p">,</span><span class="mi">100</span><span class="p">],</span> <span class="n">imf_yields_range_pop3</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">30</span><span class="p">],</span> \
                 <span class="n">starbursts</span><span class="o">=</span><span class="p">[],</span> <span class="n">beta_pow</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">gauss_dtd</span><span class="o">=</span><span class="p">[</span><span class="mf">1e9</span><span class="p">,</span><span class="mf">6.6e8</span><span class="p">],</span><span class="n">exp_dtd</span><span class="o">=</span><span class="mf">2e9</span><span class="p">,</span>\
                 <span class="n">nb_1a_per_m</span><span class="o">=</span><span class="mf">1.0e-3</span><span class="p">,</span> <span class="n">f_arfo</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">t_merge</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span>\
                 <span class="n">imf_yields_range</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">30</span><span class="p">],</span><span class="n">exclude_masses</span><span class="o">=</span><span class="p">[],</span> \
		 <span class="n">netyields_on</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">wiersmamod</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">skip_zero</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">redshift_f</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span><span class="n">print_off</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">long_range_ref</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">f_s_enhance</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span><span class="n">m_gas_f</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">cl_SF_law</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">external_control</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">calc_SSP_ej</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">tau_ferrini</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">input_yields</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">popIII_on</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">t_sf_z_dep</span> <span class="o">=</span> <span class="mf">1.0</span><span class="p">,</span>\
                 <span class="n">m_crit_on</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">norm_crit_m</span><span class="o">=</span><span class="mf">8.0e+09</span><span class="p">,</span> <span class="n">mass_frac_SSP</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span>\
                 <span class="n">sfh_array_norm</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">imf_rnd_sampling</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">out_follows_E_rate</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">r_gas_star</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">cte_m_gas</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">t_dtd_poly_split</span><span class="o">=-</span><span class="mf">1.0</span><span class="p">,</span>\
		 <span class="n">stellar_param_on</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
                 <span class="n">bhnsmerger_dtd_array</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> \
                 <span class="n">DM_array</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">nsmerger_dtd_array</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">sfh_array</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span><span class="n">ism_ini</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">mdot_ini</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">mdot_ini_t</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">ytables_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">zm_lifetime_grid_nugrid_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">isotopes_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">ytables_pop3_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">zm_lifetime_grid_pop3_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">ytables_1a_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
		 <span class="n">ytables_nsmerger_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> \
                 <span class="n">dt_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">dt_split_info</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">ej_massive</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">ej_agb</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">ej_sn1a</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">ej_massive_coef</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">ej_agb_coef</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">ej_sn1a_coef</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">dt_ssp</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span><span class="n">yield_interp</span><span class="o">=</span><span class="s1">&#39;lin&#39;</span><span class="p">,</span>\
                 <span class="n">mass_sampled</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">scale_cor</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">mass_sampled_ssp</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">scale_cor_ssp</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">poly_fit_dtd_5th</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">poly_fit_range</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span>\
                 <span class="n">m_tot_ISM_t_in</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])):</span>

        <span class="c1"># Announce the beginning of the simulation </span>
        <span class="k">print</span> <span class="s1">&#39;OMEGA run in progress..&#39;</span>
        <span class="n">start_time</span> <span class="o">=</span> <span class="n">t_module</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
	<span class="bp">self</span><span class="o">.</span><span class="n">start_time</span> <span class="o">=</span> <span class="n">start_time</span>

        <span class="c1"># Call the init function of the class inherited by SYGMA</span>
        <span class="n">chem_evol</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">imf_type</span><span class="o">=</span><span class="n">imf_type</span><span class="p">,</span> <span class="n">alphaimf</span><span class="o">=</span><span class="n">alphaimf</span><span class="p">,</span> \
                 <span class="n">imf_bdys</span><span class="o">=</span><span class="n">imf_bdys</span><span class="p">,</span> <span class="n">sn1a_rate</span><span class="o">=</span><span class="n">sn1a_rate</span><span class="p">,</span> <span class="n">iniZ</span><span class="o">=</span><span class="n">iniZ</span><span class="p">,</span> <span class="n">dt</span><span class="o">=</span><span class="n">dt</span><span class="p">,</span> \
                 <span class="n">special_timesteps</span><span class="o">=</span><span class="n">special_timesteps</span><span class="p">,</span> <span class="n">tend</span><span class="o">=</span><span class="n">tend</span><span class="p">,</span> <span class="n">mgal</span><span class="o">=</span><span class="n">mgal</span><span class="p">,</span> \
                 <span class="n">transitionmass</span><span class="o">=</span><span class="n">transitionmass</span><span class="p">,</span> <span class="n">iolevel</span><span class="o">=</span><span class="n">iolevel</span><span class="p">,</span> \
                 <span class="n">ini_alpha</span><span class="o">=</span><span class="n">ini_alpha</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">hardsetZ</span><span class="o">=</span><span class="n">hardsetZ</span><span class="p">,</span> \
                 <span class="n">sn1a_on</span><span class="o">=</span><span class="n">sn1a_on</span><span class="p">,</span> <span class="n">sn1a_table</span><span class="o">=</span><span class="n">sn1a_table</span><span class="p">,</span> <span class="n">nsm_dtd_power</span><span class="o">=</span><span class="n">nsm_dtd_power</span><span class="p">,</span>\
		 <span class="n">ns_merger_on</span><span class="o">=</span><span class="n">ns_merger_on</span><span class="p">,</span> <span class="n">f_binary</span><span class="o">=</span><span class="n">f_binary</span><span class="p">,</span> <span class="n">f_merger</span><span class="o">=</span><span class="n">f_merger</span><span class="p">,</span>\
                 <span class="n">nsmerger_table</span><span class="o">=</span><span class="n">nsmerger_table</span><span class="p">,</span> <span class="n">t_merger_max</span><span class="o">=</span><span class="n">t_merger_max</span><span class="p">,</span>\
                 <span class="n">m_ej_nsm</span> <span class="o">=</span> <span class="n">m_ej_nsm</span><span class="p">,</span> <span class="n">nb_nsm_per_m</span><span class="o">=</span><span class="n">nb_nsm_per_m</span><span class="p">,</span> <span class="n">t_nsm_coal</span><span class="o">=</span><span class="n">t_nsm_coal</span><span class="p">,</span> \
                 <span class="n">bhns_merger_on</span><span class="o">=</span><span class="n">bhns_merger_on</span><span class="p">,</span> <span class="n">m_ej_bhnsm</span><span class="o">=</span><span class="n">m_ej_bhnsm</span><span class="p">,</span> \
                 <span class="n">bhnsmerger_table</span><span class="o">=</span><span class="n">bhnsmerger_table</span><span class="p">,</span> \
                 <span class="n">iniabu_table</span><span class="o">=</span><span class="n">iniabu_table</span><span class="p">,</span> <span class="n">extra_source_on</span><span class="o">=</span><span class="n">extra_source_on</span><span class="p">,</span> \
                 <span class="n">extra_source_table</span><span class="o">=</span><span class="n">extra_source_table</span><span class="p">,</span><span class="n">f_extra_source</span><span class="o">=</span><span class="n">f_extra_source</span><span class="p">,</span> \
 		 <span class="n">pop3_table</span><span class="o">=</span><span class="n">pop3_table</span><span class="p">,</span> \
                 <span class="n">imf_bdys_pop3</span><span class="o">=</span><span class="n">imf_bdys_pop3</span><span class="p">,</span> \
                 <span class="n">imf_yields_range_pop3</span><span class="o">=</span><span class="n">imf_yields_range_pop3</span><span class="p">,</span> \
                 <span class="n">starbursts</span><span class="o">=</span><span class="n">starbursts</span><span class="p">,</span> <span class="n">beta_pow</span><span class="o">=</span><span class="n">beta_pow</span><span class="p">,</span> \
                 <span class="n">gauss_dtd</span> <span class="o">=</span> <span class="n">gauss_dtd</span><span class="p">,</span> <span class="n">exp_dtd</span> <span class="o">=</span> <span class="n">exp_dtd</span><span class="p">,</span> \
                 <span class="n">nb_1a_per_m</span><span class="o">=</span><span class="n">nb_1a_per_m</span><span class="p">,</span> <span class="n">Z_trans</span><span class="o">=</span><span class="n">Z_trans</span><span class="p">,</span> <span class="n">f_arfo</span><span class="o">=</span><span class="n">f_arfo</span><span class="p">,</span> \
                 <span class="n">imf_yields_range</span><span class="o">=</span><span class="n">imf_yields_range</span><span class="p">,</span><span class="n">exclude_masses</span><span class="o">=</span><span class="n">exclude_masses</span><span class="p">,</span> \
                 <span class="n">netyields_on</span><span class="o">=</span><span class="n">netyields_on</span><span class="p">,</span><span class="n">wiersmamod</span><span class="o">=</span><span class="n">wiersmamod</span><span class="p">,</span> \
                 <span class="n">input_yields</span><span class="o">=</span><span class="n">input_yields</span><span class="p">,</span>\
                 <span class="n">tau_ferrini</span><span class="o">=</span><span class="n">tau_ferrini</span><span class="p">,</span> <span class="n">t_dtd_poly_split</span><span class="o">=</span><span class="n">t_dtd_poly_split</span><span class="p">,</span> \
                 <span class="n">t_merge</span><span class="o">=</span><span class="n">t_merge</span><span class="p">,</span><span class="n">popIII_on</span><span class="o">=</span><span class="n">popIII_on</span><span class="p">,</span>\
                 <span class="n">out_follows_E_rate</span><span class="o">=</span><span class="n">out_follows_E_rate</span><span class="p">,</span>\
		 <span class="n">stellar_param_on</span><span class="o">=</span><span class="n">stellar_param_on</span><span class="p">,</span>\
                 <span class="n">ism_ini</span><span class="o">=</span><span class="n">ism_ini</span><span class="p">,</span><span class="n">ytables_in</span><span class="o">=</span><span class="n">ytables_in</span><span class="p">,</span>\
                 <span class="n">zm_lifetime_grid_nugrid_in</span><span class="o">=</span><span class="n">zm_lifetime_grid_nugrid_in</span><span class="p">,</span>\
                 <span class="n">isotopes_in</span><span class="o">=</span><span class="n">isotopes_in</span><span class="p">,</span><span class="n">ytables_pop3_in</span><span class="o">=</span><span class="n">ytables_pop3_in</span><span class="p">,</span>\
                 <span class="n">zm_lifetime_grid_pop3_in</span><span class="o">=</span><span class="n">zm_lifetime_grid_pop3_in</span><span class="p">,</span>\
                 <span class="n">ytables_1a_in</span><span class="o">=</span><span class="n">ytables_1a_in</span><span class="p">,</span> \
                 <span class="n">nsmerger_dtd_array</span><span class="o">=</span><span class="n">nsmerger_dtd_array</span><span class="p">,</span>\
                 <span class="n">bhnsmerger_dtd_array</span><span class="o">=</span><span class="n">bhnsmerger_dtd_array</span><span class="p">,</span> \
		 <span class="n">ytables_nsmerger_in</span><span class="o">=</span><span class="n">ytables_nsmerger_in</span><span class="p">,</span> <span class="n">dt_in</span><span class="o">=</span><span class="n">dt_in</span><span class="p">,</span>\
                 <span class="n">dt_split_info</span><span class="o">=</span><span class="n">dt_split_info</span><span class="p">,</span><span class="n">ej_massive</span><span class="o">=</span><span class="n">ej_massive</span><span class="p">,</span>\
                 <span class="n">ej_agb</span><span class="o">=</span><span class="n">ej_agb</span><span class="p">,</span><span class="n">ej_sn1a</span><span class="o">=</span><span class="n">ej_sn1a</span><span class="p">,</span>\
                 <span class="n">ej_massive_coef</span><span class="o">=</span><span class="n">ej_massive_coef</span><span class="p">,</span><span class="n">ej_agb_coef</span><span class="o">=</span><span class="n">ej_agb_coef</span><span class="p">,</span>\
                 <span class="n">ej_sn1a_coef</span><span class="o">=</span><span class="n">ej_sn1a_coef</span><span class="p">,</span><span class="n">dt_ssp</span><span class="o">=</span><span class="n">dt_ssp</span><span class="p">,</span>\
		 <span class="n">yield_interp</span><span class="o">=</span><span class="n">yield_interp</span><span class="p">,</span>\
                 <span class="n">poly_fit_dtd_5th</span><span class="o">=</span><span class="n">poly_fit_dtd_5th</span><span class="p">,</span><span class="n">poly_fit_range</span><span class="o">=</span><span class="n">poly_fit_range</span><span class="p">)</span>

        <span class="c1"># Quit if something bad happened in chem_evol ..</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">need_to_quit</span><span class="p">:</span>
            <span class="k">return</span>

        <span class="c1"># Calculate the number of CC SNe per Msun formed</span>
        <span class="k">if</span> <span class="n">out_follows_E_rate</span><span class="p">:</span>
            <span class="n">A_pop3</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">_imf</span><span class="p">(</span><span class="n">imf_bdys_pop3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">imf_bdys_pop3</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nb_ccsne_per_m_pop3</span> <span class="o">=</span> \
                <span class="n">A_pop3</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_imf</span><span class="p">(</span><span class="n">imf_yields_range_pop3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> \
                              <span class="n">imf_yields_range_pop3</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">1</span><span class="p">)</span>
            <span class="n">A</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">_imf</span><span class="p">(</span><span class="n">imf_bdys</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">imf_bdys</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">2</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nb_ccsne_per_m</span> <span class="o">=</span> \
                <span class="n">A</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">_imf</span><span class="p">(</span><span class="n">transitionmass</span><span class="p">,</span><span class="n">imf_yields_range</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="mi">1</span><span class="p">)</span>

        <span class="c1"># Attribute the input parameters to the current OMEGA object</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">=</span> <span class="n">galaxy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span> <span class="o">=</span> <span class="n">in_out_control</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="o">=</span> <span class="n">SF_law</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span> <span class="o">=</span> <span class="n">DM_evolution</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">f_dyn</span> <span class="o">=</span> <span class="n">f_dyn</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfe</span> <span class="o">=</span> <span class="n">sfe</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outflow_rate</span> <span class="o">=</span> <span class="n">outflow_rate</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">inflow_rate</span> <span class="o">=</span> <span class="n">inflow_rate</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">rand_sfh</span> <span class="o">=</span> <span class="n">rand_sfh</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cte_sfr</span> <span class="o">=</span> <span class="n">cte_sfr</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">=</span> <span class="n">m_DM_0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mass_loading</span> <span class="o">=</span> <span class="n">mass_loading</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_star</span> <span class="o">=</span> <span class="n">t_star</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfh_file</span> <span class="o">=</span> <span class="n">sfh_file</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">in_out_ratio</span> <span class="o">=</span> <span class="n">in_out_ratio</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="n">stellar_mass_0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">z_dependent</span> <span class="o">=</span> <span class="n">z_dependent</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">exp_ml</span> <span class="o">=</span> <span class="n">exp_ml</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">DM_too_low</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">skip_zero</span> <span class="o">=</span> <span class="n">skip_zero</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redshift_f</span> <span class="o">=</span> <span class="n">redshift_f</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">print_off</span> <span class="o">=</span> <span class="n">print_off</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">long_range_ref</span> <span class="o">=</span> <span class="n">long_range_ref</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_on</span> <span class="o">=</span> <span class="n">m_crit_on</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">norm_crit_m</span> <span class="o">=</span> <span class="n">norm_crit_m</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array_norm</span> <span class="o">=</span> <span class="n">sfh_array_norm</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span> <span class="o">=</span> <span class="n">DM_array</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span> <span class="o">=</span> <span class="n">sfh_array</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini</span> <span class="o">=</span> <span class="n">mdot_ini</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini_t</span> <span class="o">=</span> <span class="n">mdot_ini_t</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">r_gas_star</span> <span class="o">=</span> <span class="n">r_gas_star</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">=</span> <span class="n">m_gas_f</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cl_SF_law</span> <span class="o">=</span> <span class="n">cl_SF_law</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">external_control</span> <span class="o">=</span> <span class="n">external_control</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mass_sampled</span> <span class="o">=</span> <span class="n">mass_sampled</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">scale_cor</span> <span class="o">=</span> <span class="n">scale_cor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">imf_rnd_sampling</span> <span class="o">=</span> <span class="n">imf_rnd_sampling</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cte_m_gas</span> <span class="o">=</span> <span class="n">cte_m_gas</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_sf_z_dep</span> <span class="o">=</span> <span class="n">t_sf_z_dep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">out_follows_E_rate</span> <span class="o">=</span> <span class="n">out_follows_E_rate</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span> <span class="o">=</span> <span class="n">m_tot_ISM_t_in</span>

        <span class="c1"># If the IMF will randomly be sampled ...</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_rnd_sampling</span><span class="p">:</span>

            <span class="c1"># Print info about the IMF samplint</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_pop_max</span> <span class="o">=</span> <span class="mf">1.0e4</span>
            <span class="k">print</span> <span class="s1">&#39;IMF random sampling for SSP with M &lt; &#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">m_pop_max</span>

            <span class="c1"># Calculate the stellar mass associated with the</span>
            <span class="c1"># highest IMF value (needed for Monte Carlo)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">imf_norm_sampled</span> <span class="o">=</span> <span class="mf">10.0</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">imfnorm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_norm_sampled</span>
            <span class="n">imf_temp</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">m_temp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_bdys</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">dm</span> <span class="o">=</span> <span class="mf">0.02</span>
            <span class="k">while</span> <span class="n">m_temp</span> <span class="o">&lt;=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">imf_bdys</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
                <span class="n">imf_temp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_imf</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span><span class="mf">2.0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">mass</span><span class="o">=</span><span class="n">m_temp</span><span class="p">))</span>
                <span class="n">m_temp</span> <span class="o">+=</span> <span class="n">dm</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">imf_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">imf_temp</span><span class="p">)</span>

        <span class="c1"># Set cosmological parameters - Dunkley et al. (2009)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">omega_0</span>   <span class="o">=</span> <span class="mf">0.257</span>   <span class="c1"># Current mass density parameter</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">omega_b_0</span> <span class="o">=</span> <span class="mf">0.044</span>   <span class="c1"># Current baryonic mass density parameter</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lambda_0</span>  <span class="o">=</span> <span class="mf">0.742</span>   <span class="c1"># Current dark energy density parameter</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">H_0</span>       <span class="o">=</span> <span class="mf">71.9</span>    <span class="c1"># Hubble constant [km s^-1 Mpc^-1]</span>

        <span class="c1"># Look for errors in the input parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__check_inputs_omega</span><span class="p">()</span>

        <span class="c1"># Define whether the open box scenario is used or not</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span> <span class="o">=</span> <span class="bp">False</span>

        <span class="c1"># Check if the timesteps need to be refined</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_redshift_t</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_t_SF_t</span><span class="p">()</span>
            <span class="n">need_t_raf</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">for</span> <span class="n">i_raf</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_raf</span><span class="p">]</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_raf</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe</span><span class="p">:</span>
                    <span class="n">need_t_raf</span> <span class="o">=</span> <span class="bp">True</span>
                    <span class="k">break</span>
            <span class="k">if</span> <span class="n">need_t_raf</span><span class="p">:</span>
              <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">long_range_ref</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__rafine_steps_lr</span><span class="p">()</span>
              <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__rafine_steps</span><span class="p">()</span>

            <span class="c1"># Re-Create entries for the mass-loss rate of massive stars</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">massive_ej_rate</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sn1a_ej_rate</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">massive_ej_rate</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sn1a_ej_rate</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>

        <span class="c1"># Declare arrays used to follow the evolution of the galaxy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__declare_evol_arrays</span><span class="p">()</span>

        <span class="c1"># If the mass fraction ejected by SSPs needs to be calculated ...</span>
        <span class="c1"># Need to be before self.__initialize_gal_prop()!!</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.0</span>
        <span class="k">if</span> <span class="n">calc_SSP_ej</span><span class="p">:</span>

            <span class="c1"># Run SYGMA with five different metallicities</span>
            <span class="n">Z</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.02</span><span class="p">,</span> <span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.006</span><span class="p">,</span> <span class="mf">0.001</span><span class="p">,</span> <span class="mf">0.0001</span><span class="p">]</span>
            <span class="n">s_inst</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="k">for</span> <span class="n">i_Z_SSP</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">Z</span><span class="p">)):</span>
                <span class="n">s_inst</span> <span class="o">=</span> <span class="n">sygma</span><span class="o">.</span><span class="n">sygma</span><span class="p">(</span><span class="n">imf_type</span><span class="o">=</span><span class="n">imf_type</span><span class="p">,</span> <span class="n">alphaimf</span><span class="o">=</span><span class="n">alphaimf</span><span class="p">,</span>\
                 <span class="n">imf_bdys</span><span class="o">=</span><span class="n">imf_bdys</span><span class="p">,</span> <span class="n">sn1a_rate</span><span class="o">=</span><span class="n">sn1a_rate</span><span class="p">,</span> <span class="n">iniZ</span><span class="o">=</span><span class="n">Z</span><span class="p">[</span><span class="n">i_Z_SSP</span><span class="p">],</span> <span class="n">dt</span><span class="o">=</span><span class="n">dt</span><span class="p">,</span> \
                 <span class="n">special_timesteps</span><span class="o">=</span><span class="n">special_timesteps</span><span class="p">,</span> <span class="n">tend</span><span class="o">=</span><span class="n">tend</span><span class="p">,</span> <span class="n">mgal</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> \
                 <span class="n">transitionmass</span><span class="o">=</span><span class="n">transitionmass</span><span class="p">,</span> <span class="n">iolevel</span><span class="o">=</span><span class="n">iolevel</span><span class="p">,</span> \
                 <span class="n">ini_alpha</span><span class="o">=</span><span class="n">ini_alpha</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="n">table</span><span class="p">,</span> <span class="n">hardsetZ</span><span class="o">=</span><span class="n">hardsetZ</span><span class="p">,</span> \
                 <span class="n">sn1a_on</span><span class="o">=</span><span class="n">sn1a_on</span><span class="p">,</span> <span class="n">sn1a_table</span><span class="o">=</span><span class="n">sn1a_table</span><span class="p">,</span> \
                 <span class="n">iniabu_table</span><span class="o">=</span><span class="n">iniabu_table</span><span class="p">,</span> <span class="n">extra_source_on</span><span class="o">=</span><span class="n">extra_source_on</span><span class="p">,</span> \
                 <span class="n">extra_source_table</span><span class="o">=</span><span class="n">extra_source_table</span><span class="p">,</span> <span class="n">pop3_table</span><span class="o">=</span><span class="n">pop3_table</span><span class="p">,</span> \
                 <span class="n">imf_bdys_pop3</span><span class="o">=</span><span class="n">imf_bdys_pop3</span><span class="p">,</span> \
                 <span class="n">imf_yields_range_pop3</span><span class="o">=</span><span class="n">imf_yields_range_pop3</span><span class="p">,</span> \
                 <span class="n">starbursts</span><span class="o">=</span><span class="n">starbursts</span><span class="p">,</span> <span class="n">beta_pow</span><span class="o">=</span><span class="n">beta_pow</span><span class="p">,</span> \
                 <span class="n">gauss_dtd</span> <span class="o">=</span> <span class="n">gauss_dtd</span><span class="p">,</span> <span class="n">exp_dtd</span> <span class="o">=</span> <span class="n">exp_dtd</span><span class="p">,</span> \
                 <span class="n">nb_1a_per_m</span><span class="o">=</span><span class="n">nb_1a_per_m</span><span class="p">,</span> <span class="n">Z_trans</span><span class="o">=</span><span class="n">Z_trans</span><span class="p">,</span> <span class="n">f_arfo</span><span class="o">=</span><span class="n">f_arfo</span><span class="p">,</span> \
                 <span class="n">imf_yields_range</span><span class="o">=</span><span class="n">imf_yields_range</span><span class="p">,</span><span class="n">exclude_masses</span><span class="o">=</span><span class="n">exclude_masses</span><span class="p">,</span>\
                 <span class="n">netyields_on</span><span class="o">=</span><span class="n">netyields_on</span><span class="p">,</span><span class="n">wiersmamod</span><span class="o">=</span><span class="n">wiersmamod</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">+=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">s_inst</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

            <span class="c1"># Calculate the average mass fraction returned</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">Z</span><span class="p">)</span>
            <span class="k">print</span> <span class="s1">&#39;Average SSP mass fraction returned = &#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">=</span> <span class="n">mass_frac_SSP</span>

        <span class="c1"># Set the general properties of the selected galaxy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__initialize_gal_prop</span><span class="p">()</span>

        <span class="c1"># Fill arrays used to follow the evolution</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__fill_evol_arrays</span><span class="p">()</span>

        <span class="c1"># Read the primordial composition of the inflow gas</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>
            <span class="n">prim_comp_table</span> <span class="o">=</span> <span class="s1">&#39;yield_tables/bb_walker91.txt&#39;</span>
	    <span class="bp">self</span><span class="o">.</span><span class="n">prim_comp</span> <span class="o">=</span> <span class="n">ry</span><span class="o">.</span><span class="n">read_yield_sn1a_tables</span><span class="p">(</span><span class="n">global_path</span> <span class="o">+</span> \
                <span class="n">prim_comp_table</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">)</span>

        <span class="c1"># In construction .. need to avoid altering default setups ..</span>
        <span class="c1"># Assume the baryonic ratio for the initial gas reservoir, if needed</span>
<span class="c1">#        if len(self.ism_ini) == 0 and not self.SF_law and not self.DM_evolution:</span>
<span class="c1">#          if self.bar_ratio and not self.cl_SF_law:</span>
<span class="c1">#            scale_m_tot = self.m_DM_0 * self.omega_b_0 / \</span>
<span class="c1">#            (self.omega_0*sum(self.ymgal[0]))</span>
<span class="c1">#            for k_cm in range(len(self.ymgal[0])):</span>
<span class="c1">#                self.ymgal[0][k_cm] = self.ymgal[0][k_cm] * scale_m_tot</span>

        <span class="c1"># Add the stellar ejecta coming from external galaxies that just merged</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__add_ext_mdot</span><span class="p">()</span>

        <span class="c1"># Initialisation of the composition of the gas reservoir</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ism_ini</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i_ini</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">len_ymgal</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">i_ini</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ism_ini</span><span class="p">[</span><span class="n">i_ini</span><span class="p">]</span>

        <span class="c1"># Copy the outflow-vs-SFR array and re-initialize for delayed outflow</span>
        <span class="k">if</span> <span class="n">out_follows_E_rate</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">outflow_test</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t_vs_SFR</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i_ofer</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i_ofer</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="c1"># If the timestep are not control by an external program ...</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">external_control</span><span class="p">:</span>

            <span class="c1"># Run the simulation</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__run_simulation</span><span class="p">(</span><span class="n">mass_sampled</span><span class="p">,</span> <span class="n">scale_cor</span><span class="p">)</span>


    <span class="c1">##############################################</span>
    <span class="c1">#             Check Inputs OMEGA             #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__check_inputs_omega</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function checks for incompatible input entries, and stops</span>
<span class="sd">        the simulation if needed.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Input galaxy</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;none&#39;</span><span class="p">,</span> <span class="s1">&#39;milky_way&#39;</span><span class="p">,</span> <span class="s1">&#39;milky_way_cte&#39;</span><span class="p">,</span> \
                               <span class="s1">&#39;sculptor&#39;</span><span class="p">,</span> <span class="s1">&#39;fornax&#39;</span><span class="p">,</span> <span class="s1">&#39;carina&#39;</span><span class="p">]:</span>
            <span class="k">print</span> <span class="s1">&#39;Error - Selected galaxy not available.&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Random SFH</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">rand_sfh</span> <span class="o">&gt;</span> <span class="mf">0.0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">&lt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Error - You need to choose a current stellar mass.&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Inflow control when non-available</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span> <span class="ow">and</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">):</span>
            <span class="k">print</span> <span class="s1">&#39;Error - Cannot control inflows and outflows when SF_law or&#39;</span>\
                  <span class="s1">&#39;DM_evolution is equal to True.&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Defined initial dark matter halo mass when non-available</span>
        <span class="c1">#if self.m_DM_ini &gt; 0.0 and not self.DM_evolution:</span>
        <span class="c1">#    print &#39;Warning - Can\&#39;t control m_DM_ini when the mass of&#39;, \</span>
        <span class="c1">#          &#39;the dark matter halo is not evolving.&#39;</span>

        <span class="c1"># Inflow and outflow control when the dark matter mass if evolving</span>
        <span class="k">if</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">outflow_rate</span> <span class="o">&gt;=</span> <span class="mf">0.0</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">inflow_rate</span> <span class="o">&gt;=</span> <span class="mf">0.0</span><span class="p">)</span> <span class="ow">and</span> \
            <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Error - Cannot fix inflow and outflow rates when the mass&#39;</span>\
                  <span class="s1">&#39;of the dark matter halo is evolving.&#39;</span>
            <span class="k">return</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                Refine Steps                #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__rafine_steps</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function increases the number of timesteps if the star formation</span>
<span class="sd">        will eventually consume all the gas, which occurs when dt &gt; (t_star/sfe).</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Declaration of the new timestep array</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">print_off</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;..Time refinement..&#39;</span>
        <span class="n">new_dt</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># For every timestep ...</span>
        <span class="k">for</span> <span class="n">i_rs</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)):</span>

            <span class="c1"># Calculate the critical time delay</span>
            <span class="n">t_raf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe</span>

            <span class="c1"># If the step needs to be refined ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">t_raf</span><span class="p">:</span>

                <span class="c1"># Calculate the split factor</span>
                <span class="n">nb_split</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span> <span class="o">/</span> <span class="n">t_raf</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>

                <span class="c1"># Split the step</span>
                <span class="k">for</span> <span class="n">i_sp_st</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">nb_split</span><span class="p">):</span>
                    <span class="n">new_dt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span><span class="o">/</span><span class="n">nb_split</span><span class="p">)</span>

            <span class="c1"># If ok, don&#39;t change anything</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">new_dt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">])</span>

        <span class="c1"># Update the timestep information</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">new_dt</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span> <span class="o">=</span> <span class="n">new_dt</span>

        <span class="c1"># If a timestep needs to be added to be synchronized with</span>
        <span class="c1"># the external program managing merger trees ...</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_merge</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># Find the interval where the step needs to be added</span>
            <span class="n">i_temp</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">t_temp</span> <span class="o">=</span> <span class="n">new_dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">while</span> <span class="n">t_temp</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_merge</span> <span class="o">&lt;</span> <span class="mf">0.9999999</span><span class="p">:</span>
                <span class="n">i_temp</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">t_temp</span> <span class="o">+=</span> <span class="n">new_dt</span><span class="p">[</span><span class="n">i_temp</span><span class="p">]</span>

            <span class="c1"># Keep the t_merger index in memory</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">i_t_merger</span> <span class="o">=</span> <span class="n">i_temp</span>

        <span class="c1"># Update/redeclare all the arrays</span>
        <span class="n">ymgal</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_iniabu</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">len_ymgal</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">ymgal</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mdot</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_massive</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_agb</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_1a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_nsm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_bhnsm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_massive</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">mdot_agb</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_1a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_nsm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_bhnsm</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">sn1a_numbers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sn2_numbers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nsm_numbers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bhnsm_numbers</span><span class="p">,</span>\
 	<span class="bp">self</span><span class="o">.</span><span class="n">imf_mass_ranges</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">imf_mass_ranges_contribution</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_mass_ranges_mtot</span> <span class="o">=</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">_get_storing_arrays</span><span class="p">(</span><span class="n">ymgal</span><span class="p">)</span>

        <span class="c1"># Recalculate the simulation time (used in chem_evol)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">i_init</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span><span class="p">[</span><span class="n">i_init</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_init</span><span class="p">])</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Rafine Steps LR               #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__rafine_steps_lr</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function increases the number of timesteps if the star formation</span>
<span class="sd">        will eventually consume all the gas, which occurs when dt &gt; (t_star/sfe).</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Declaration of the new timestep array</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">print_off</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;..Time refinement (long range)..&#39;</span>
        <span class="n">new_dt</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># For every timestep ...</span>
        <span class="k">for</span> <span class="n">i_rs</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)):</span>

            <span class="c1"># Calculate the critical time delay</span>
            <span class="n">t_raf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe</span>

            <span class="c1"># If the step needs to be refined ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">t_raf</span><span class="p">:</span>

                <span class="c1"># Calculate the number of remaining steps</span>
                <span class="n">nb_step_rem</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)</span> <span class="o">-</span> <span class="n">i_rs</span>
                <span class="n">t_rem</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">for</span> <span class="n">i_rs</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)):</span>
                    <span class="n">t_rem</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">]</span>

                <span class="c1"># Calculate the split factor</span>
                <span class="n">nb_split</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">t_rem</span> <span class="o">/</span> <span class="n">t_raf</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>

                <span class="c1"># Split the step</span>
                <span class="k">for</span> <span class="n">i_sp_st</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">nb_split</span><span class="p">):</span>
                    <span class="n">new_dt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t_rem</span><span class="o">/</span><span class="n">nb_split</span><span class="p">)</span>

                <span class="c1"># Quit the for loop</span>
                <span class="k">break</span>

            <span class="c1"># If ok, don&#39;t change anything</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">new_dt</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_rs</span><span class="p">])</span>

        <span class="c1"># Update the timestep information</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">new_dt</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span> <span class="o">=</span> <span class="n">new_dt</span>

        <span class="c1"># If a timestep needs to be added to be synchronized with</span>
        <span class="c1"># the external program managing merger trees ...</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_merge</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># Find the interval where the step needs to be added</span>
            <span class="n">i_temp</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">t_temp</span> <span class="o">=</span> <span class="n">new_dt</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">while</span> <span class="n">t_temp</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_merge</span> <span class="o">&lt;</span> <span class="mf">0.9999999</span><span class="p">:</span>
                <span class="n">i_temp</span> <span class="o">+=</span> <span class="mi">1</span>
                <span class="n">t_temp</span> <span class="o">+=</span> <span class="n">new_dt</span><span class="p">[</span><span class="n">i_temp</span><span class="p">]</span>

            <span class="c1"># Keep the t_merger index in memory</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">i_t_merger</span> <span class="o">=</span> <span class="n">i_temp</span>

        <span class="c1"># Update/redeclare all the arrays</span>
        <span class="n">ymgal</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_iniabu</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">len_ymgal</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">ymgal</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mdot</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_massive</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_agb</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_1a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_nsm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_bhnsm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_massive</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">mdot_agb</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_1a</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_nsm</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_bhnsm</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">sn1a_numbers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sn2_numbers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nsm_numbers</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bhnsm_numbers</span><span class="p">,</span>\
 	<span class="bp">self</span><span class="o">.</span><span class="n">imf_mass_ranges</span><span class="p">,</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">imf_mass_ranges_contribution</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_mass_ranges_mtot</span> <span class="o">=</span> \
        <span class="bp">self</span><span class="o">.</span><span class="n">_get_storing_arrays</span><span class="p">(</span><span class="n">ymgal</span><span class="p">)</span>

        <span class="c1"># Recalculate the simulation time (used in chem_evol)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">i_init</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">t_ce</span><span class="p">[</span><span class="n">i_init</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_init</span><span class="p">])</span>


    <span class="c1">##############################################</span>
    <span class="c1">#            Declare Evol Arrays             #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__declare_evol_arrays</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function declares the arrays used to follow the evolution of the</span>
<span class="sd">        galaxy regarding its growth and the exchange of gas with its surrounding.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Arrays with specific values at every timestep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span> <span class="o">=</span> <span class="p">[]</span>     <span class="c1"># Star formation rate [Mo yr^-1]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span> <span class="o">=</span> <span class="p">[]</span>        <span class="c1"># Mass of the dark matter halo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">r_vir_DM_t</span><span class="o">=</span><span class="p">[]</span>      <span class="c1"># Virial radius of the dark matter halo</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">v_vir_DM_t</span><span class="o">=</span><span class="p">[]</span>      <span class="c1"># Virial velocity of the dark matter &quot;particle&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span> <span class="o">=</span> <span class="p">[]</span>   <span class="c1"># Mass of the ISM in gas at every timestep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span> <span class="o">=</span> <span class="p">[]</span>   <span class="c1"># Mass of the outflow at every timestep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># Mass-loading factor == M_outflow / SFR</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span> <span class="o">=</span> <span class="p">[]</span>        <span class="c1"># Star formation timescale at every timestep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span> <span class="o">=</span> <span class="p">[]</span>      <span class="c1"># Critital ISM mass below which no SFR</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span> <span class="o">=</span> <span class="p">[]</span>    <span class="c1"># Redshift associated to every timestep</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_inflow_t</span> <span class="o">=</span> <span class="p">[]</span>    <span class="c1"># Mass of the inflow at every timestep</span>

        <span class="c1"># Extends the arrays to cover all timestep</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">r_vir_DM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">v_vir_DM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_inflow_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>

        <span class="c1"># Add one additional slot for t = tend when needed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">r_vir_DM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">v_vir_DM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>


    <span class="c1">##############################################</span>
    <span class="c1">#            Initialize Gal Prop             #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__initialize_gal_prop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function sets the properties of the selected galaxy, such as its</span>
<span class="sd">        SFH, its total mass, and its stellar mass.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># No specific galaxy - Use input parameters</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;none&#39;</span><span class="p">:</span>

            <span class="c1">#If an array is used for the SFH ..</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_array</span><span class="p">()</span>

            <span class="c1"># If an input file is used for the SFH ...</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_file</span> <span class="o">==</span> <span class="s1">&#39;none&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_input</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfh_file</span><span class="p">)</span>

            <span class="c1"># If a star formation law is used in a closed box ...</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">cl_SF_law</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_sfe_cl</span><span class="p">()</span>

            <span class="c1"># If a random SFH is chosen ...</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">rand_sfh</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__generate_rand_sfh</span><span class="p">()</span>

            <span class="c1"># If the SFH is constant ...</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i_cte_sfr</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_cte_sfr</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cte_sfr</span>

        <span class="c1"># Milky Way galaxy ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;milky_way&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;milky_way_cte&#39;</span><span class="p">:</span>

            <span class="c1"># Set the current dark and stellar masses (corrected for mass loss)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">=</span> <span class="mf">1.0e12</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="mf">5.0e10</span> 

            <span class="c1"># Read Chiappini et al. (2001) SFH</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;milky_way&#39;</span><span class="p">:</span> 
                <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_input</span><span class="p">(</span><span class="s1">&#39;milky_way_data/sfh_mw_cmr01.txt&#39;</span><span class="p">)</span>

            <span class="c1"># Read constant SFH</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_input</span><span class="p">(</span><span class="s1">&#39;milky_way_data/sfh_cte.txt&#39;</span><span class="p">)</span>

        <span class="c1"># Sculptor dwarf galaxy ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;sculptor&#39;</span><span class="p">:</span>

            <span class="c1"># Set the current dark and stellar masses (corrected for mass loss)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">=</span> <span class="mf">1.5e9</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="mf">7.8e6</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span><span class="p">)</span>

            <span class="c1"># Read deBoer et al. (2012) SFH</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_input</span><span class="p">(</span><span class="s1">&#39;sculptor_data/sfh_deBoer12.txt&#39;</span><span class="p">)</span>

        <span class="c1"># Fornax dwarf galaxy ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;fornax&#39;</span><span class="p">:</span>

            <span class="c1"># Set the current dark and stellar masses (corrected for mass loss)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">=</span> <span class="mf">7.08e8</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="mf">4.3e7</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span><span class="p">)</span>

            <span class="c1"># Read deBoer et al. (2012) SFH</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_input</span><span class="p">(</span><span class="s1">&#39;fornax_data/sfh_fornax_deboer_et_al_2012.txt&#39;</span><span class="p">)</span>

        <span class="c1"># Carina dwarf galaxy ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;carina&#39;</span><span class="p">:</span>

            <span class="c1"># Set the current dark and stellar masses (corrected for mass loss)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">=</span> <span class="mf">3.4e6</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="mf">1.07e6</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span><span class="p">)</span>

            <span class="c1"># Read deBoer et al. (2014) SFH</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__copy_sfr_input</span><span class="p">(</span><span class="s1">&#39;carina_data/sfh_deBoer14.txt&#39;</span><span class="p">)</span>

        <span class="c1"># Interpolate the last timestep</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>  
            <span class="n">aa</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">])</span><span class="o">/</span>\
                 <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">bb</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span><span class="o">*</span><span class="n">aa</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">aa</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span> <span class="o">+</span> <span class="n">bb</span>

        <span class="c1"># Keep the SFH in memory</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span>


    <span class="c1">##############################################</span>
    <span class="c1">##             Copy SFR Array               ##</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__copy_sfr_array</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        See copy_sfr_input() for more info.</span>

<span class="sd">        &#39;&#39;&#39;</span>
   
        <span class="c1"># Variable to keep track of the OMEGA&#39;s timestep</span>
        <span class="n">i_dt_csa</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">t_csa</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="n">nb_dt_csa</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">+</span> <span class="mi">1</span>

        <span class="c1"># Variable to keep track of the total stellar mass from the input SFH</span>
        <span class="n">m_stel_sfr_in</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="c1"># For every timestep given in the array (starting at the second step)</span>
        <span class="k">for</span> <span class="n">i_csa</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">)):</span>

            <span class="c1"># Calculate the SFR interpolation coefficient</span>
            <span class="n">a_sfr</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">b_sfr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">a_sfr</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>

            <span class="c1"># While we stay in the same time bin ...</span>
            <span class="k">while</span> <span class="n">t_csa</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>

                <span class="c1"># Interpolate the SFR</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="n">a_sfr</span> <span class="o">*</span> <span class="n">t_csa</span> <span class="o">+</span> <span class="n">b_sfr</span>

                <span class="c1"># Cumulate the stellar mass formed</span>
                <span class="n">m_stel_sfr_in</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span>

                <span class="c1"># Exit the loop if the array is full</span>
                <span class="k">if</span> <span class="n">i_dt_csa</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
                    <span class="k">break</span>

                <span class="c1"># Calculate the new time</span>
                <span class="n">t_csa</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span>
                <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="c1"># Exit the loop if the array is full</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">i_dt_csa</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
                <span class="k">break</span>

        <span class="c1"># If the array has been read completely, but the sfr_input array is</span>
        <span class="c1"># not full, fil the rest of the array with the last read value</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="n">sfr_temp</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sfr_temp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">while</span> <span class="n">i_dt_csa</span> <span class="o">&lt;</span> <span class="n">nb_dt_csa</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="n">sfr_temp</span>
            <span class="n">m_stel_sfr_in</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">*</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span>
            <span class="n">t_csa</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span>
            <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># Normalise the SFR in order to be consistent with the integrated</span>
        <span class="c1"># input star formation array (no mass loss considered!)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array_norm</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="n">norm_sfr_in</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfh_array_norm</span> <span class="o">/</span> <span class="n">m_stel_sfr_in</span>
            <span class="k">for</span> <span class="n">i_csa</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">nb_dt_csa</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csa</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csa</span><span class="p">]</span> <span class="o">*</span> <span class="n">norm_sfr_in</span>

        <span class="c1"># Fill the missing last entry (extention of the last timestep, for tend)</span>
        <span class="c1"># Since we don&#39;t know dt starting at tend, it is not part of m_stel_sfr_in</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>


    <span class="c1">##############################################</span>
    <span class="c1">##             Calculate SFE Cl.            ##</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_sfe_cl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        Calculate the star formation efficiency and the initial mass of gas</span>
<span class="sd">        for a closed box model, given the final gas mass and the current</span>
<span class="sd">        stellar mass.</span>

<span class="sd">        &#39;&#39;&#39;</span>
   
        <span class="c1"># Get the average return gas fraction of SSPs</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span> <span class="o">==</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">:</span>
            <span class="n">f_ej</span> <span class="o">=</span> <span class="mf">0.35</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">f_ej</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span>

        <span class="c1"># If the gas-to-stellar mass ratio is the selected input ...</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">r_gas_star</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># Calculate the final mass of gas</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">r_gas_star</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span>

            <span class="c1"># Calculate the initial mass of gas</span>
            <span class="n">m_gas_ini</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span>

        <span class="c1"># If the final mass of gas is the selected input ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># Calculate the initial mass of gas</span>
            <span class="n">m_gas_ini</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span>

        <span class="c1"># If the initial mass of gas is the selected input ...</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="c1"># Use the input value for the initial mass of gas</span>
            <span class="n">m_gas_ini</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mgal</span>

            <span class="c1"># Calculate the final mass of gas</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">=</span> <span class="n">m_gas_ini</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span>

        <span class="c1"># Verify if the final mass of gas is negative</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span> <span class="o">&lt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">not_enough_gas</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">sfe_gcs</span> <span class="o">=</span> <span class="mf">1.0e-10</span>
            <span class="k">print</span> <span class="s1">&#39;!!Error - Try to have a negative final gas mass!!&#39;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">not_enough_gas</span><span class="p">:</span>

          <span class="c1"># Scale the initial mass of all isotopes</span>
          <span class="n">scale_m_tot</span> <span class="o">=</span> <span class="n">m_gas_ini</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
          <span class="k">for</span> <span class="n">k_cm</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">])):</span>
              <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">k_cm</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">k_cm</span><span class="p">]</span> <span class="o">*</span> <span class="n">scale_m_tot</span>

          <span class="c1"># Initialization for finding the right SFE</span>
          <span class="n">sfe_gcs</span> <span class="o">=</span> <span class="mf">1.8e-10</span>
          <span class="n">sfe_max</span> <span class="o">=</span> <span class="mf">1.0</span>
          <span class="n">sfe_min</span> <span class="o">=</span> <span class="mf">0.0</span>
          <span class="n">m_gas_f_try</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_m_gas_f</span><span class="p">(</span><span class="n">m_gas_ini</span><span class="p">,</span> <span class="n">sfe_gcs</span><span class="p">,</span> <span class="n">f_ej</span><span class="p">)</span>

          <span class="c1"># While the SFE is not the right one ...</span>
          <span class="k">while</span> <span class="nb">abs</span><span class="p">(</span><span class="n">m_gas_f_try</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">0.01</span><span class="p">:</span>

            <span class="c1"># If the SFE needs to be increased ...</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">m_gas_f_try</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_gas_f</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>

              <span class="c1"># Set the lower limit of the SFE interval</span>
              <span class="n">sfe_min</span> <span class="o">=</span> <span class="n">sfe_gcs</span>

              <span class="c1"># If an upper limit is already defined ...</span>
              <span class="k">if</span> <span class="n">sfe_max</span> <span class="o">&lt;</span> <span class="mf">1.0</span><span class="p">:</span>

                <span class="c1"># Set the SFE to the middle point of the interval</span>
                <span class="n">sfe_gcs</span> <span class="o">=</span> <span class="p">(</span><span class="n">sfe_max</span> <span class="o">+</span> <span class="n">sfe_gcs</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span>

              <span class="c1"># If an upper limit is not already defined ...</span>
              <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Try a factor of 2</span>
                <span class="n">sfe_gcs</span> <span class="o">=</span> <span class="n">sfe_gcs</span> <span class="o">*</span> <span class="mf">2.0</span>

            <span class="c1"># If the SFE needs to be decreased ...</span>
            <span class="k">else</span><span class="p">:</span>

              <span class="c1"># Set the upper limit of the SFE interval</span>
              <span class="n">sfe_max</span> <span class="o">=</span> <span class="n">sfe_gcs</span>

              <span class="c1"># If a lower limit is already defined ...</span>
              <span class="k">if</span> <span class="n">sfe_min</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

                <span class="c1"># Set the SFE to the middle point of the interval</span>
                <span class="n">sfe_gcs</span> <span class="o">=</span> <span class="p">(</span><span class="n">sfe_min</span> <span class="o">+</span> <span class="n">sfe_gcs</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.5</span>

              <span class="c1"># If a lower limit is not already defined ...</span>
              <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Try a factor of 2</span>
                <span class="n">sfe_gcs</span> <span class="o">=</span> <span class="n">sfe_gcs</span> <span class="o">*</span> <span class="mf">0.5</span>

            <span class="c1"># Get the approximated final mass of gas</span>
            <span class="n">m_gas_f_try</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_m_gas_f</span><span class="p">(</span><span class="n">m_gas_ini</span><span class="p">,</span> <span class="n">sfe_gcs</span><span class="p">,</span> <span class="n">f_ej</span><span class="p">)</span>

        <span class="c1"># Keep the SFE in memory</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfe_gcs</span> <span class="o">=</span> <span class="n">sfe_gcs</span>


    <span class="c1">##############################################</span>
    <span class="c1">##               Get M_gas_f                ##</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__get_m_gas_f</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m_gas_ini</span><span class="p">,</span> <span class="n">sfe_gcs</span><span class="p">,</span> <span class="n">f_ej</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        Return the final mass of gas, given the initial mass of the gas</span>
<span class="sd">        reservoir and the star formation efficiency.  The function uses</span>
<span class="sd">        a simple star formation law in the form of SFR(t) = sfe * M_gas(t)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Initialisation of the integration</span>
        <span class="n">m_gas_loop</span> <span class="o">=</span> <span class="n">m_gas_ini</span>
        <span class="n">t_gmgf</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="c1"># For every timestep ...</span>
        <span class="k">for</span> <span class="n">i_gmgf</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>

            <span class="c1"># Calculate the new mass of gass</span>
            <span class="n">t_gmgf</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_gmgf</span><span class="p">]</span>

            <span class="c1">#self.sfr_input[i_gmgf] = sfe_gcs * m_gas_loop</span>
            <span class="n">m_gas_loop</span> <span class="o">-=</span> <span class="n">sfe_gcs</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span><span class="o">-</span><span class="n">f_ej</span><span class="p">)</span> <span class="o">*</span> <span class="n">m_gas_loop</span> <span class="o">*</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_gmgf</span><span class="p">]</span>

        <span class="c1"># Return the final mass of gas</span>
        <span class="k">return</span> <span class="n">m_gas_loop</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Copy SFR Input                #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__copy_sfr_input</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path_sfh_in</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function reads a SFH input file and interpolates its values so it</span>
<span class="sd">        can be inserted in the array &quot;sfr_input&quot;, which contains the SFR for each</span>
<span class="sd">        OMEGA timestep.</span>

<span class="sd">        Note</span>
<span class="sd">        ====</span>

<span class="sd">          The input file does not need to have constant time step lengths, and </span>
<span class="sd">          does not need to have the same number of timesteps as the number of </span>
<span class="sd">          OMEGA timesteps.</span>

<span class="sd">        Important</span>
<span class="sd">        =========</span>

<span class="sd">          In OMEGA and SYGMA, t += timestep[i] is the first thing done in the main</span>
<span class="sd">          loop.  The loop calculates what happened between the previous t and the </span>
<span class="sd">          new t.  This means the mass of stars formed must be SFR(previous t) *</span>
<span class="sd">          timestep[i].  Therefore, sfr_input[i] IS NOT the SFR at time t += </span>
<span class="sd">          timestep[i], but rather the SFR at previous time which is used for the </span>
<span class="sd">          current step i.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          path_sfh_in : Path of the input SFH file.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Variable to keep track of the OMEGA timestep</span>
        <span class="n">nb_dt_csi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">+</span> <span class="mi">1</span>
        <span class="n">i_dt_csi</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">t_csi</span> <span class="o">=</span> <span class="mf">0.0</span> <span class="c1"># Not timesteps[0] because sfr_input[0] must be</span>
                    <span class="c1"># used from t = 0 to t = timesteps[0]</span>

        <span class="c1"># Variable to keep track of the total stellar mass from the input SFH</span>
        <span class="n">m_stel_sfr_in</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="c1"># Open the file containing the SFR vs time</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="n">path_sfh_in</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">sfr_file</span><span class="p">:</span>

            <span class="c1"># Read the first line  (col 0 : t, col 1 : SFR)</span>
            <span class="n">line_1_str</span> <span class="o">=</span> <span class="n">sfr_file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="n">parts_1</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">line_1_str</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>

            <span class="c1"># For every remaining line ...</span>
            <span class="k">for</span> <span class="n">line_2_str</span> <span class="ow">in</span> <span class="n">sfr_file</span><span class="p">:</span>

                <span class="c1"># Extract data</span>
                <span class="n">parts_2</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">line_2_str</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>
 
                <span class="c1"># Calculate the interpolation coefficients (SFR = a*t + b)</span>
                <span class="n">a_csi</span> <span class="o">=</span> <span class="p">(</span><span class="n">parts_2</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">parts_1</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="p">(</span><span class="n">parts_2</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">parts_1</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">b_csi</span> <span class="o">=</span> <span class="n">parts_1</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">a_csi</span> <span class="o">*</span> <span class="n">parts_1</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

                <span class="c1"># While we stay in the same time bin ...</span>
                <span class="k">while</span> <span class="n">t_csi</span> <span class="o">&lt;=</span> <span class="n">parts_2</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>

                    <span class="c1"># Calculate the right SFR for the specific OMEGA timestep</span>
                    <span class="c1">#self.sfr_input[i_dt_csi] = a_csi * t_csi + b_csi</span>

                    <span class="c1"># Calculate the average SFR for the specific OMEGA timestep</span>
                    <span class="k">if</span> <span class="n">i_dt_csi</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span> <span class="o">=</span> <span class="n">a_csi</span> <span class="o">*</span> <span class="p">(</span><span class="n">t_csi</span> <span class="o">+</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.5</span><span class="p">)</span> <span class="o">+</span> <span class="n">b_csi</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span> <span class="o">=</span> <span class="n">a_csi</span> <span class="o">*</span> <span class="n">t_csi</span> <span class="o">+</span> <span class="n">b_csi</span>

                    <span class="c1"># Cumulate the mass of stars formed</span>
                    <span class="k">if</span> <span class="n">i_dt_csi</span> <span class="o">&lt;</span> <span class="n">nb_dt_csi</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
                        <span class="n">m_stel_sfr_in</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span> <span class="o">*</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span>

                        <span class="c1"># Calculate the new time</span>
                        <span class="n">t_csi</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span>

                    <span class="c1"># Go to the next time step</span>
                    <span class="n">i_dt_csi</span> <span class="o">+=</span> <span class="mi">1</span>

                    <span class="c1"># Exit the loop if the array is full</span>
                    <span class="k">if</span> <span class="n">i_dt_csi</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csi</span><span class="p">:</span>
                        <span class="k">break</span>
               
                <span class="c1"># Exit the loop if the array is full</span>
                <span class="k">if</span> <span class="n">i_dt_csi</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csi</span><span class="p">:</span>
                    <span class="k">break</span>

                <span class="c1"># Copie the last read line</span>
                <span class="n">parts_1</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">parts_2</span><span class="p">)</span>

        <span class="c1"># Close the file</span>
        <span class="n">sfr_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="c1"># If the file has been read completely, but the sfr_input array is</span>
        <span class="c1"># not full, fill the rest of the array with the last read value</span>
        <span class="k">while</span> <span class="n">i_dt_csi</span> <span class="o">&lt;</span> <span class="n">nb_dt_csi</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">i_dt_csi</span> <span class="o">&lt;</span> <span class="n">nb_dt_csi</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">m_stel_sfr_in</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csi</span><span class="p">]</span>
            <span class="n">i_dt_csi</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># Normalise the SFR in order to be consistent with the input current</span>
        <span class="c1"># stellar mass (if the stellar mass is known)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="n">norm_sfr_in</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">/</span> <span class="p">((</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span><span class="p">)</span> <span class="o">*</span> <span class="n">m_stel_sfr_in</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i_csi</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">nb_dt_csi</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span> <span class="o">*</span> <span class="n">norm_sfr_in</span>


    <span class="c1">##############################################</span>
    <span class="c1">#             Generate Rand SFH              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__generate_rand_sfh</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function generates a random SFH. This should only be used for </span>
<span class="sd">        testing purpose in order to look at how the uncertainty associated to the</span>
<span class="sd">        SFH can affects the results.</span>

<span class="sd">        The self.rand_sfh sets the maximum ratio between the maximum and the</span>
<span class="sd">        minimum values for the SFR.  This parameter sets how &quot;bursty&quot; or constant</span>
<span class="sd">        a SFH is.  self.rand_sfh = 1 means a constant SFH.</span>
<span class="sd">         </span>
<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Variable to keep track of the total stellar mass from the random SFH</span>
        <span class="n">m_stel_sfr_in</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="c1"># For each timestep</span>
        <span class="k">for</span> <span class="n">i_csi</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randrange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">rand_sfh</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>

            <span class="c1"># Cumulate the total mass of stars formed</span>
            <span class="k">if</span> <span class="n">i_csi</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>
                <span class="n">m_stel_sfr_in</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span>

        <span class="c1"># Normalise the SFR in order to be consistent with the input</span>
        <span class="c1"># current stellar mass</span>
        <span class="n">norm_sfr_in</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stellar_mass_0</span> <span class="o">/</span> <span class="p">((</span><span class="mi">1</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_frac_SSP</span><span class="p">)</span> <span class="o">*</span> <span class="n">m_stel_sfr_in</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i_csi</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">timesteps</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_csi</span><span class="p">]</span> <span class="o">*</span> <span class="n">norm_sfr_in</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Fill Evol Arrays              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__fill_evol_arrays</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function fills the arrays used to follow the evolution of the</span>
<span class="sd">        galaxy regarding its growth and the exchange of gas with its surrounding.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Execute this function only if needed</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>

            <span class="c1"># Calculate the redshift for every timestep, if needed</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_redshift_t</span><span class="p">()</span>

            <span class="c1"># Calculate the mass of the dark matter halo at every timestep</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_m_DM_t</span><span class="p">()</span>

            <span class="c1"># Calculate the virial radius and velocity at every timestep</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_virial</span><span class="p">()</span>

            <span class="c1"># Calculate the critical, mass below which no SFR, at every dt</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_m_crit_t</span><span class="p">()</span>

            <span class="c1"># Calculate the star formation timescale at every timestep</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_t_SF_t</span><span class="p">()</span>

            <span class="c1"># Calculate the gas mass of the ISM at every timestep</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_m_tot_ISM_t</span><span class="p">()</span>

            <span class="c1"># Calculate the mass-loading factor and ouflow mass at every timestep</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__calculate_outflow_t</span><span class="p">()</span>


    <span class="c1">##############################################</span>
    <span class="c1">#               Get t From z                 #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__get_t_from_z</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">z_gttfz</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function returns the age of the Universe at a given redshift.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          z_gttfz : Redshift that needs to be converted into age.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Return the age of the Universe</span>
        <span class="n">temp_var</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">lambda_0</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">omega_0</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">z_gttfz</span><span class="p">)</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">x_var</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">log</span><span class="p">(</span> <span class="n">temp_var</span> <span class="o">+</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span> <span class="n">temp_var</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="mi">1</span> <span class="p">)</span> <span class="p">)</span>
        <span class="k">return</span> <span class="mi">2</span> <span class="o">/</span> <span class="p">(</span> <span class="mi">3</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">H_0</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lambda_0</span><span class="p">))</span> <span class="o">*</span> \
               <span class="n">x_var</span> <span class="o">*</span> <span class="mf">9.77793067e11</span>


    <span class="c1">##############################################</span>
    <span class="c1">#               Get z From t                 #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__get_z_from_t</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t_gtzft</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function returns the redshift of a given Universe age.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          t_gtzft : Age of the Universe that needs to be converted into redshift.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Return the redshift</span>
        <span class="n">temp_var</span> <span class="o">=</span> <span class="mf">1.5340669e-12</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">lambda_0</span><span class="o">**</span><span class="mf">0.5</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">H_0</span> <span class="o">*</span> <span class="n">t_gtzft</span>
        <span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">lambda_0</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">omega_0</span><span class="p">)</span><span class="o">**</span><span class="mf">0.3333333</span> <span class="o">/</span> \
                <span class="n">math</span><span class="o">.</span><span class="n">sinh</span><span class="p">(</span><span class="n">temp_var</span><span class="p">)</span><span class="o">**</span><span class="mf">0.66666667</span> <span class="o">-</span> <span class="mi">1</span>


    <span class="c1">##############################################</span>
    <span class="c1">#           Calculate redshift(t)            #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_redshift_t</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the redshift associated to every timestep</span>
<span class="sd">        assuming that &#39;tend&#39; represents redshift zero.</span>

<span class="sd">        &#39;&#39;&#39;</span>
 
        <span class="c1"># Execute the function only if needed</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>

            <span class="c1"># Calculate the current age of the Universe (LambdaCDM - z = 0)</span>
            <span class="n">current_age_czt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_t_from_z</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">redshift_f</span><span class="p">)</span>

            <span class="c1"># Calculate the age of the Universe when the galaxy forms</span>
            <span class="n">age_formation_czt</span> <span class="o">=</span> <span class="n">current_age_czt</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span>

            <span class="c1"># Initiate the age of the galaxy</span>
            <span class="n">t_czt</span> <span class="o">=</span> <span class="mf">0.0</span>

            <span class="c1">#For each timestep</span>
            <span class="k">for</span> <span class="n">i_czt</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

                <span class="c1">#Calculate the age of the Universe at that time [yr]</span>
                <span class="n">age_universe_czt</span> <span class="o">=</span> <span class="n">age_formation_czt</span> <span class="o">+</span> <span class="n">t_czt</span>

                <span class="c1">#Calculate the redshift at that time</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_czt</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_z_from_t</span><span class="p">(</span><span class="n">age_universe_czt</span><span class="p">)</span>

                <span class="c1">#Udpate the age of the galaxy [yr]</span>
                <span class="k">if</span> <span class="n">i_czt</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>
                    <span class="n">t_czt</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_czt</span><span class="p">]</span>

            <span class="c1">#Correction for last digit error (e.g. z = -2.124325345e-8)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mf">0.0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Calculate M_DM(t)             #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_m_DM_t</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This functions calculates the mass of the dark matter halo at each</span>
<span class="sd">        timestep.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># If the mass of the dark matter halo is kept at a constant value ...</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>

            <span class="c1"># Use the current value for every timestep</span>
            <span class="k">for</span> <span class="n">i_cmdt</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span>

        <span class="c1"># If the mass of the dark matter halo evolves with time ...</span>
        <span class="k">else</span><span class="p">:</span>

          <span class="c1"># If the dark matter evolution is an input array ...</span>
          <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>

            <span class="c1"># Copy the input values</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__copy_DM_input</span><span class="p">()</span>

          <span class="c1"># If the dark matter evolution is taken from Millenium simulations ...</span>
          <span class="k">else</span><span class="p">:</span>

            <span class="c1"># Calculate the polynomial coefficient for the evolution of</span>
            <span class="c1"># the dark matter mass</span>
            <span class="n">poly_up_dm</span><span class="p">,</span> <span class="n">poly_low_dm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_DM_bdy</span><span class="p">()</span>

            <span class="c1"># For each timestep ...</span>
            <span class="k">for</span> <span class="n">i_cmdt</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

                <span class="c1"># Calculate the lower and upper dark matter mass boundaries</span>
                <span class="n">log_m_dm_up</span> <span class="o">=</span> <span class="n">poly_up_dm</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> \
                    <span class="n">poly_up_dm</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">poly_up_dm</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">+</span> <span class="n">poly_up_dm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
                <span class="n">log_m_dm_low</span> <span class="o">=</span> <span class="n">poly_low_dm</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span><span class="o">**</span><span class="mi">3</span> <span class="o">+</span> \
                    <span class="n">poly_low_dm</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">poly_low_dm</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">*</span>\
                        <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">+</span> <span class="n">poly_low_dm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>

                <span class="c1"># If the dark matter mass is too low for the available fit ...</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_too_low</span><span class="p">:</span>

                    <span class="c1"># Scale the fit using the current input mass</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">=</span> <span class="mi">10</span><span class="o">**</span><span class="n">log_m_dm_low</span> <span class="o">*</span> \
                                            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">/</span> <span class="mi">10</span><span class="o">**</span><span class="n">poly_low_dm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>

                <span class="c1"># If the dark matter mass can be interpolated</span>
                <span class="k">else</span><span class="p">:</span>

                    <span class="c1"># Use a linear interpolation with the log of the mass</span>
                    <span class="n">a</span> <span class="o">=</span> <span class="p">(</span><span class="n">log_m_dm_up</span> <span class="o">-</span> <span class="n">log_m_dm_low</span><span class="p">)</span> <span class="o">/</span> \
                        <span class="p">(</span><span class="n">poly_up_dm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">-</span> <span class="n">poly_low_dm</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
                    <span class="n">b</span> <span class="o">=</span> <span class="n">log_m_dm_up</span> <span class="o">-</span> <span class="n">a</span> <span class="o">*</span> <span class="n">poly_up_dm</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">=</span> <span class="mi">10</span><span class="o">**</span><span class="p">(</span> <span class="n">a</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span><span class="p">)</span> <span class="o">+</span> <span class="n">b</span> <span class="p">)</span>

            <span class="c1"># If the simulation does not stop at redshift zero ...</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_f</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>

                <span class="c1"># Scale the DM mass (because the fits look at M_DM_0 at z=0)</span>
                <span class="n">m_dm_scale</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">i_cmdt</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cmdt</span><span class="p">]</span> <span class="o">*</span> <span class="n">m_dm_scale</span>


    <span class="c1">##############################################</span>
    <span class="c1">#               Copy DM Input                #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__copy_DM_input</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function interpolates the DM masses from an input array</span>
<span class="sd">        and add the masses to the corresponding OMEGA step</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Variable to keep track of the OMEGA&#39;s timestep</span>
        <span class="n">i_dt_csa</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">t_csa</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="n">nb_dt_csa</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">+</span> <span class="mi">1</span>

        <span class="c1"># If just one entry ...</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># If DM values need to be interpolated ...</span>
        <span class="k">else</span><span class="p">:</span>

          <span class="c1"># For every timestep given in the array (starting at the second step)</span>
          <span class="k">for</span> <span class="n">i_csa</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">)):</span>

            <span class="c1"># Calculate the DM interpolation coefficient</span>
            <span class="n">a_DM</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">b_DM</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">a_DM</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>

            <span class="c1"># While we stay in the same time bin ...</span>
            <span class="k">while</span> <span class="n">t_csa</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>

                <span class="c1"># Interpolate the SFR</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="n">a_DM</span> <span class="o">*</span> <span class="n">t_csa</span> <span class="o">+</span> <span class="n">b_DM</span>

                <span class="c1"># Exit the loop if the array is full</span>
                <span class="k">if</span> <span class="n">i_dt_csa</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
                    <span class="k">break</span>

                <span class="c1"># Calculate the new time</span>
                <span class="n">t_csa</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span>
                <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="c1"># Exit the loop if the array is full</span>
            <span class="k">if</span> <span class="n">i_dt_csa</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
                <span class="k">break</span>

        <span class="c1"># If the array has been read completely, but the DM array is</span>
        <span class="c1"># not full, fil the rest of the array with the last read value</span>
        <span class="k">while</span> <span class="n">i_dt_csa</span> <span class="o">&lt;</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_array</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                  Get DM Bdy                #</span>
    <span class="c1">##############################################</span>
    <span class="c1"># Return the fit coefficients for the interpolation of the dark matter mass</span>
    <span class="k">def</span> <span class="nf">__get_DM_bdy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates and returns the fit coefficients for the</span>
<span class="sd">        interpolation of the evolution of the dark matter mass as a function </span>
<span class="sd">        of time.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Open the file containing the coefficient of the 3rd order polynomial fit</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="s2">&quot;m_dm_evolution/poly3_fits.txt&quot;</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">m_dm_file</span><span class="p">:</span>

            <span class="c1"># Read the first line</span>
            <span class="n">line_str</span> <span class="o">=</span> <span class="n">m_dm_file</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
            <span class="n">parts_1</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">line_str</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>

            <span class="c1"># If the input dark matter mass is higher than the ones provided</span>
            <span class="c1"># by the fits ...</span>
            <span class="k">if</span> <span class="n">math</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">parts_1</span><span class="p">[</span><span class="mi">3</span><span class="p">]:</span>

                <span class="c1"># Use the highest dark matter mass available</span>
                <span class="n">parts_2</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">parts_1</span><span class="p">)</span>
                <span class="k">print</span> <span class="s1">&#39;Warning - Current dark matter mass too high for&#39;</span> \
                      <span class="s1">&#39;the available fits.&#39;</span>

            <span class="c1"># If the input dark matter mass is in the available range ...</span>
            <span class="c1"># Find the mass boundary for the interpolation.</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="c1"># For every remaining line ...</span>
                <span class="k">for</span> <span class="n">line_str</span> <span class="ow">in</span> <span class="n">m_dm_file</span><span class="p">:</span>

                    <span class="c1"># Extract data</span>
                    <span class="n">parts_2</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">line_str</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>

                    <span class="c1"># If the read mass is lower than the input dark matter mass</span>
                    <span class="k">if</span> <span class="n">math</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">parts_2</span><span class="p">[</span><span class="mi">3</span><span class="p">]:</span>
                        <span class="c1"># Exit the loop and use the current interpolation boundary</span>
                        <span class="k">break</span>

                    <span class="c1"># Copy the current read line</span>
                    <span class="n">parts_1</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">parts_2</span><span class="p">)</span>

            <span class="c1"># Keep track if the input dark matter mass is too low ...</span>
            <span class="k">if</span> <span class="n">parts_1</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="n">parts_2</span><span class="p">[</span><span class="mi">3</span><span class="p">]:</span>
                 <span class="bp">self</span><span class="o">.</span><span class="n">DM_too_low</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="c1">#Close the file</span>
        <span class="n">m_dm_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="k">return</span> <span class="n">parts_1</span><span class="p">,</span> <span class="n">parts_2</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Calculate Virial              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_virial</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="c1"># Average current mass density of the Universe [Mo Mpc^-3]</span>
        <span class="n">rho_0_uni</span> <span class="o">=</span> <span class="mf">3.7765e10</span>

        <span class="c1"># For each timestep ...</span>
        <span class="k">for</span> <span class="n">i_cv</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

            <span class="c1"># Calculate the virial radius of the dark matter halo [kpc]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">r_vir_DM_t</span><span class="p">[</span><span class="n">i_cv</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.0e3</span> <span class="o">*</span> <span class="mf">0.106078</span> <span class="o">*</span> \
                <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cv</span><span class="p">]</span> <span class="o">/</span> <span class="n">rho_0_uni</span><span class="p">)</span><span class="o">**</span><span class="mf">0.3333333</span> <span class="o">/</span> \
                <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_cv</span><span class="p">])</span>

            <span class="c1">#Calculate the virial velocity of the dark matter &quot;particles&quot; [km/s]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">v_vir_DM_t</span><span class="p">[</span><span class="n">i_cv</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span> <span class="mf">4.302e-6</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_cv</span><span class="p">]</span> <span class="o">/</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">r_vir_DM_t</span><span class="p">[</span><span class="n">i_cv</span><span class="p">]</span> <span class="p">)</span><span class="o">**</span> <span class="mf">0.5</span>


    <span class="c1">##############################################</span>
    <span class="c1">#             Calculate M_crit_t             #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_m_crit_t</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="c1">#For each timestep ...</span>
        <span class="k">for</span> <span class="n">i_ctst</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

            <span class="c1"># If m_crit_t is wanted ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_on</span><span class="p">:</span>

                <span class="c1"># Calculate the critical mass (Croton et al. 2006)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">norm_crit_m</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">v_vir_DM_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">*</span> <span class="mf">0.1</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">r_vir_DM_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">/</span> <span class="mf">2000.0</span>

            <span class="c1"># If m_crit_t is not wanted ...</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Set the critical mass to zero</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>


    <span class="c1">##############################################</span>
    <span class="c1">#             Calculate t_SF(t)              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_t_SF_t</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the star formation timescale at every timestep.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Execute this function only if needed</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>

            <span class="c1"># If the star formation timescale is kept constant ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_star</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>

                <span class="c1"># Use the same value for every timestep</span>
                <span class="k">for</span> <span class="n">i_ctst</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_star</span>

            <span class="c1"># If the timescale follows the halo dynamical time ...</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Set the timescale to a fraction of the halo dynamical time</span>
                <span class="c1"># See White &amp; Frenk (1991); Springel et al. (2001)</span>
                <span class="k">for</span> <span class="n">i_ctst</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

                    <span class="c1"># If the dark matter mass is evolving ...</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">f_dyn</span> <span class="o">*</span> <span class="mf">0.1</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">])</span><span class="o">**</span><span class="p">((</span><span class="o">-</span><span class="mf">1.5</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">t_sf_z_dep</span><span class="p">)</span> \
                                <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">H_0</span> <span class="o">*</span> <span class="mf">9.7759839e11</span>

                    <span class="c1"># If the dark matter mass is not evolving ...</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_ctst</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">f_dyn</span> <span class="o">*</span> <span class="mf">0.1</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">H_0</span> <span class="o">*</span> \
                                <span class="mf">9.7759839e11</span>


    <span class="c1">##############################################</span>
    <span class="c1">#           Calculate M_tot ISM(t)           #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_m_tot_ISM_t</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the mass of the gas reservoir at every </span>
<span class="sd">        timestep using a classical star formation law.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># If the evolution of the mass of the ISM is an input ...</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>

            <span class="c1"># Copy and adjust the input array for the OMEGA timesteps</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__copy_m_tot_ISM_input</span><span class="p">()</span>

        <span class="c1"># If the ISM has a constant mass ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">cte_m_gas</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># For each timestep ...</span>
            <span class="k">for</span> <span class="n">i_cm</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cte_m_gas</span>

        <span class="c1"># If the mass of gas is tighted to the SFH ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">SF_law</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>

            <span class="c1"># For each timestep ...</span>
            <span class="k">for</span> <span class="n">i_cm</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

                <span class="c1"># If it&#39;s the last timestep ... use the previous sfr_input</span>
                <span class="k">if</span> <span class="n">i_cm</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>

                    <span class="c1"># Calculate the total mass of the ISM using the previous SFR</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_cm</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span>

                <span class="c1"># If it&#39;s not the last timestep ...</span>
                <span class="k">else</span><span class="p">:</span>

                    <span class="c1"># Calculate the total mass of the ISM using the current SFR</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_crit_t</span><span class="p">[</span><span class="n">i_cm</span><span class="p">]</span>

        <span class="c1"># If the IO model ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mgal</span>

        <span class="c1"># Scale the initial gas reservoir that was already set</span>
        <span class="n">scale_m_tot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">for</span> <span class="n">k_cm</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">])):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">k_cm</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">k_cm</span><span class="p">]</span> <span class="o">*</span> <span class="n">scale_m_tot</span>


    <span class="c1">##############################################</span>
    <span class="c1">#            Copy M_tot_ISM Input            #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__copy_m_tot_ISM_input</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function interpolates the gas masses from an input array</span>
<span class="sd">        and add the masses to the corresponding OMEGA step</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Variable to keep track of the OMEGA&#39;s timestep</span>
        <span class="n">i_dt_csa</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">t_csa</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="n">nb_dt_csa</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span> <span class="o">+</span> <span class="mi">1</span>

        <span class="c1"># If just one entry ...</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="c1"># If DM values need to be interpolated ...</span>
        <span class="k">else</span><span class="p">:</span>

          <span class="c1"># For every timestep given in the array (starting at the second step)</span>
          <span class="k">for</span> <span class="n">i_csa</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">)):</span>

            <span class="c1"># Calculate the DM interpolation coefficient</span>
            <span class="n">a_gas</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> \
                    <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">b_gas</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">a_gas</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>

            <span class="c1"># While we stay in the same time bin ...</span>
            <span class="k">while</span> <span class="n">t_csa</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="n">i_csa</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>

                <span class="c1"># Interpolate the SFR</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="n">a_gas</span> <span class="o">*</span> <span class="n">t_csa</span> <span class="o">+</span> <span class="n">b_gas</span>

                <span class="c1"># Exit the loop if the array is full</span>
                <span class="k">if</span> <span class="n">i_dt_csa</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
                    <span class="k">break</span>

                <span class="c1"># Calculate the new time</span>
                <span class="n">t_csa</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span>
                <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="c1"># Exit the loop if the array is full</span>
            <span class="k">if</span> <span class="n">i_dt_csa</span> <span class="o">&gt;=</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
                <span class="k">break</span>

        <span class="c1"># If the array has been read completely, but the DM array is</span>
        <span class="c1"># not full, fil the rest of the array with the last read value</span>
        <span class="k">while</span> <span class="n">i_dt_csa</span> <span class="o">&lt;</span> <span class="n">nb_dt_csa</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i_dt_csa</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t_in</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">i_dt_csa</span> <span class="o">+=</span> <span class="mi">1</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Calculate Outflow             #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__calculate_outflow_t</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the mass-loading factor and the mass of outflow </span>
<span class="sd">        at every timestep.</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># If the outflow rate is kept constant ...</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">outflow_rate</span> <span class="o">&gt;=</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># Use the input value for each timestep</span>
            <span class="k">for</span> <span class="n">i_ceo</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">outflow_rate</span> <span class="o">/</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">outflow_rate</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span>

        <span class="c1"># If the outflow rate is connected to the SFR ...</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="c1"># If the mass of the dark matter halo is not evolving</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">DM_evolution</span><span class="p">:</span>

                <span class="c1">#For each timestep ...</span>
                <span class="k">for</span> <span class="n">i_ceo</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>

                    <span class="c1"># Use the input mass-loading factor</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_loading</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span>
                  
            <span class="c1"># If the mass of the dark matter halo is evolving</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Use the input mass-loading factor to normalize the evolution</span>
                <span class="c1"># of this factor as a function of time</span>
                <span class="n">eta_norm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_loading</span> <span class="o">*</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_0</span><span class="o">**</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">exp_ml</span><span class="o">*</span><span class="mf">0.33333</span><span class="p">)</span><span class="o">*</span> \
                        <span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">redshift_f</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="mf">0.5</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">exp_ml</span><span class="p">)</span>

                <span class="c1"># For each timestep ...</span>
                <span class="k">for</span> <span class="n">i_ceo</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">):</span>

                    <span class="c1"># Calculate the mass-loading factor with redshift dependence</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">z_dependent</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="n">eta_norm</span> <span class="o">*</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span><span class="o">**</span><span class="p">((</span><span class="o">-</span><span class="mf">0.3333</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">exp_ml</span><span class="p">)</span> <span class="o">*</span> \
                                <span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">])</span><span class="o">**</span><span class="p">(</span><span class="o">-</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">exp_ml</span><span class="p">)</span>

                    <span class="c1"># Calculate the mass-loading factor without redshift dependence</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="n">eta_norm</span> <span class="o">*</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span><span class="o">**</span><span class="p">((</span><span class="o">-</span><span class="mf">0.3333</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">exp_ml</span><span class="p">)</span>

                    <span class="c1"># Calculate the outflow mass during the current timestep</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_ceo</span><span class="p">]</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                Add Ext. M_dot              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__add_ext_mdot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function adds the stellar ejecta of external galaxies that</span>
<span class="sd">        just merged in the mdot array of the current galaxy.  This function</span>
<span class="sd">        assumes that the times and the number of timesteps of the merging</span>
<span class="sd">        galaxies are different from the current galaxy.</span>

<span class="sd">        Notes</span>
<span class="sd">        =====</span>

<span class="sd">            i_ext : Step index in the &quot;external&quot; merging mdot array</span>
<span class="sd">            i_cur : Step index in the &quot;current&quot; galaxy mdot array</span>
<span class="sd">            t_cur_prev : Lower time limit in the current i_cur bin</span>
<span class="sd">            t_cur : Upper time limit in the current i_cur bin</span>

<span class="sd">            M_dot_ini has an extra slot in the isotopes for the time,</span>
<span class="sd">            which is t = 0.0 for i_ext = 0.</span>
<span class="sd">         </span>
<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># For every merging galaxy (every branch of a merger tree)</span>
        <span class="k">for</span> <span class="n">i_merg</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini</span><span class="p">)):</span>

            <span class="c1"># Initialisation of the local variables</span>
            <span class="n">i_ext</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">i_cur</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">t_cur_prev</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="n">t_cur</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">t_ext_prev</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="n">t_ext</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini_t</span><span class="p">[</span><span class="n">i_merg</span><span class="p">][</span><span class="n">i_ext</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>

            <span class="c1"># While the external ejecta has not been fully transfered...</span>
            <span class="n">len_mdot_ini_i_merg</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini</span><span class="p">[</span><span class="n">i_merg</span><span class="p">])</span>
            <span class="k">while</span> <span class="n">i_ext</span> <span class="o">&lt;</span> <span class="n">len_mdot_ini_i_merg</span> <span class="ow">and</span> <span class="n">i_cur</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>

                <span class="c1"># While we need to change the external time bin ...</span>
                <span class="k">while</span> <span class="n">t_ext</span> <span class="o">&lt;=</span> <span class="n">t_cur</span><span class="p">:</span>

                    <span class="c1"># Calculate the overlap time between ext. and cur. bins</span>
                    <span class="n">dt_trans</span> <span class="o">=</span> <span class="n">t_ext</span> <span class="o">-</span> <span class="nb">max</span><span class="p">([</span><span class="n">t_ext_prev</span><span class="p">,</span> <span class="n">t_cur_prev</span><span class="p">])</span>

                    <span class="c1"># Calculate the mass fraction that needs to be transfered</span>
                    <span class="n">f_dt</span> <span class="o">=</span> <span class="n">dt_trans</span> <span class="o">/</span> <span class="p">(</span><span class="n">t_ext</span> <span class="o">-</span> <span class="n">t_ext_prev</span><span class="p">)</span>

                    <span class="c1"># Transfer all isotopes in the current mdot array</span>
                    <span class="k">for</span> <span class="n">i_iso</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">mdot</span><span class="p">[</span><span class="n">i_cur</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span> <span class="o">+=</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini</span><span class="p">[</span><span class="n">i_merg</span><span class="p">][</span><span class="n">i_ext</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span> <span class="o">*</span> <span class="n">f_dt</span>

                    <span class="c1"># Move to the next external bin</span>
                    <span class="n">i_ext</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="n">i_ext</span> <span class="o">==</span> <span class="n">len_mdot_ini_i_merg</span><span class="p">:</span>
                        <span class="k">break</span>
                    <span class="n">t_ext_prev</span> <span class="o">=</span> <span class="n">t_ext</span>
                    <span class="n">t_ext</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini_t</span><span class="p">[</span><span class="n">i_merg</span><span class="p">][</span><span class="n">i_ext</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>

                <span class="c1"># Quit the loop if all external bins have been considered</span>
                <span class="k">if</span> <span class="n">i_ext</span> <span class="o">==</span> <span class="n">len_mdot_ini_i_merg</span><span class="p">:</span>
                    <span class="k">break</span>

                <span class="c1"># While we need to change the current time bin ...</span>
                <span class="k">while</span> <span class="n">t_cur</span> <span class="o">&lt;</span> <span class="n">t_ext</span><span class="p">:</span>

                    <span class="c1"># Calculate the overlap time between ext. and cur. bins</span>
                    <span class="n">dt_trans</span> <span class="o">=</span> <span class="n">t_cur</span> <span class="o">-</span> <span class="nb">max</span><span class="p">([</span><span class="n">t_ext_prev</span><span class="p">,</span> <span class="n">t_cur_prev</span><span class="p">])</span> 

                    <span class="c1"># Calculate the mass fraction that needs to be transfered</span>
                    <span class="n">f_dt</span> <span class="o">=</span> <span class="n">dt_trans</span> <span class="o">/</span> <span class="p">(</span><span class="n">t_ext</span> <span class="o">-</span> <span class="n">t_ext_prev</span><span class="p">)</span>

                    <span class="c1"># Transfer all isotopes in the current mdot array</span>
                    <span class="k">for</span> <span class="n">i_iso</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">mdot</span><span class="p">[</span><span class="n">i_cur</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span> <span class="o">+=</span> \
                            <span class="bp">self</span><span class="o">.</span><span class="n">mdot_ini</span><span class="p">[</span><span class="n">i_merg</span><span class="p">][</span><span class="n">i_ext</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span> <span class="o">*</span> <span class="n">f_dt</span>

                    <span class="c1"># Move to the next current bin</span>
                    <span class="n">i_cur</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="k">if</span> <span class="n">i_cur</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>
                        <span class="k">break</span>
                    <span class="n">t_cur_prev</span> <span class="o">=</span> <span class="n">t_cur</span>
                    <span class="n">t_cur</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_cur</span><span class="p">]</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                Run Simulation              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__run_simulation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mass_sampled</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> \
                         <span class="n">scale_cor</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the evolution of the chemical abundances of a</span>
<span class="sd">        galaxy as a function of time.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          mass_sampled : Stars sampled in the IMF by an external program.</span>
<span class="sd">          scale_cor : Envelope correction for the IMF.</span>
<span class="sd">         </span>
<span class="sd">        &#39;&#39;&#39;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">test</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># For every timestep i considered in the simulation ...</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

            <span class="c1"># If the IMF must be sampled ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_rnd_sampling</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_pop_max</span> <span class="o">&gt;=</span> \
               <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
                
                <span class="c1"># Get the sampled masses</span>
                <span class="n">mass_sampled</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_mass_sampled</span><span class="p">(</span>\
                    <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mass_sampled</span><span class="p">)</span>

            <span class="c1"># No mass sampled if using the full IMF ...</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">mass_sampled</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])</span>

            <span class="c1"># Run a timestep using the input SFR</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">run_step</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> \
                <span class="n">mass_sampled</span><span class="o">=</span><span class="n">mass_sampled</span><span class="p">,</span> <span class="n">scale_cor</span><span class="o">=</span><span class="n">scale_cor</span><span class="p">)</span>
            
        <span class="c1"># Calculate the last SFR at the end point of the simulation</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cl_SF_law</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe_gcs</span> <span class="o">*</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                   Run Step                 #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.run_step"><a class="viewcode-back" href="../omega.html#omega.omega.run_step">[docs]</a>    <span class="k">def</span> <span class="nf">run_step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">sfr_rs</span><span class="p">,</span> <span class="n">m_added</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">m_lost</span> <span class="o">=</span> <span class="mf">0.0</span><span class="p">,</span> \
                 <span class="n">mass_sampled</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([]),</span> <span class="n">scale_cor</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the evolution of one single step in the</span>
<span class="sd">        chemical evolution.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          i : Index of the timestep.</span>
<span class="sd">          sfr_rs : Input star formation rate [Mo/yr] for the step i.</span>
<span class="sd">          m_added : Mass (and composition) added for the step i.</span>
<span class="sd">          m_lost : Mass lost for the step i.</span>
<span class="sd">          mass_sampled : Stars sampled in the IMF by an external program.</span>
<span class="sd">          scale_cor : Envelope correction for the IMF.</span>
<span class="sd">         </span>
<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Make sure that the the number of timestep is not exceeded</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">i</span> <span class="o">==</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>

            <span class="c1">#test</span>
            <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">sfr_test</span> <span class="o">=</span> <span class="n">sfr_rs</span>

            <span class="c1"># Calculate the current mass fraction of gas converted into stars</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__cal_m_frac_stars</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">sfr_rs</span><span class="p">)</span>

            <span class="c1"># Run the timestep i (!need to be right after __cal_m_frac_stars!)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_evol_stars</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">mass_sampled</span><span class="p">,</span> <span class="n">scale_cor</span><span class="p">)</span>

            <span class="c1"># Delay outflow is needed (following SNe rather than SFR) ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_follows_E_rate</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">__delay_outflow</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="c1"># Add the incoming gas (if any)</span>
            <span class="n">len_m_added</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">m_added</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">k_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">len_m_added</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">+=</span> <span class="n">m_added</span><span class="p">[</span><span class="n">k_op</span><span class="p">]</span>

            <span class="c1"># If gas needs to be removed ...</span>
            <span class="k">if</span> <span class="n">m_lost</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>

                <span class="c1"># Calculate the gas fraction lost</span>
                <span class="n">f_lost</span> <span class="o">=</span> <span class="n">m_lost</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">f_lost</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>
                    <span class="n">f_lost</span> <span class="o">=</span> <span class="mf">1.0</span>
                    <span class="k">print</span> <span class="s1">&#39;!!Warning -- Remove more mass than available!!&#39;</span>
                
                <span class="c1"># Remove the mass for each isotope</span>
                <span class="n">f_lost_2</span> <span class="o">=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">f_lost</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">k_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">=</span> <span class="n">f_lost_2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_agb</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">=</span> <span class="n">f_lost_2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_agb</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_1a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">=</span> <span class="n">f_lost_2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_1a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>
		    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_nsm</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">=</span> <span class="n">f_lost_2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_nsm</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>
		    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_bhnsm</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">=</span> <span class="n">f_lost_2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_bhnsm</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_massive</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">=</span> <span class="n">f_lost_2</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal_massive</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>

            <span class="c1"># If the open box scenario is used ...</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>

                <span class="c1"># Calculate the total mass of the gas reservoir at timstep i</span>
                <span class="c1"># after the star formation and the stellar ejecta</span>
                <span class="n">m_tot_current</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">for</span> <span class="n">k_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
                    <span class="n">m_tot_current</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span>

                <span class="c1"># Get the current mass of inflow</span>
                <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_m_inflow</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">m_tot_current</span><span class="p">)</span>

                <span class="c1"># Add primordial gas coming with the inflow</span>
                <span class="k">if</span> <span class="n">m_inflow_current</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
                    <span class="n">ym_inflow</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">prim_comp</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">quantity</span><span class="o">=</span><span class="s1">&#39;Yields&#39;</span><span class="p">)</span> <span class="o">*</span> \
                                <span class="n">m_inflow_current</span>
                    <span class="k">for</span> <span class="n">k_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">+=</span> <span class="n">ym_inflow</span><span class="p">[</span><span class="n">k_op</span><span class="p">]</span>
                
                <span class="c1">#Calculate the fraction of gas removed by the outflow</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">m_tot_current</span> <span class="o">+</span> <span class="n">m_inflow_current</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>
                    <span class="n">frac_rem</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">/</span> \
                        <span class="p">(</span><span class="n">m_tot_current</span> <span class="o">+</span> <span class="n">m_inflow_current</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">frac_rem</span> <span class="o">=</span> <span class="mf">0.0</span>

                <span class="c1"># Limit the outflow mass to the amount of available gas</span>
                <span class="k">if</span> <span class="n">frac_rem</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>
                    <span class="n">frac_rem</span> <span class="o">=</span> <span class="mf">1.0</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">m_tot_current</span> <span class="o">+</span> <span class="n">m_inflow_current</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">print_off</span><span class="p">:</span>
                        <span class="k">print</span> <span class="s1">&#39;Warning - &#39;</span>\
                          <span class="s1">&#39;Outflows eject more mass than available.  &#39;</span> \
                          <span class="s1">&#39;It has been reduced to the amount of available gas.&#39;</span>

                <span class="c1"># Remove mass from the ISM because of the outflow</span>
                <span class="k">for</span> <span class="n">k_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_rem</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_agb</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_rem</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_1a</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_rem</span><span class="p">)</span>
		    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_nsm</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_rem</span><span class="p">)</span>
		    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_bhnsm</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_rem</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">ymgal_massive</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">k_op</span><span class="p">]</span> <span class="o">*=</span> <span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">frac_rem</span><span class="p">)</span>

            <span class="c1"># Get the new metallicity of the gas</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">zmetal</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_getmetallicity</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="c1"># Update the history class</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_update_history</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="c1"># If this is the last step ...</span>
            <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_timesteps</span><span class="p">:</span>

                <span class="c1"># Do the final update of the history class</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_update_history_final</span><span class="p">()</span>

                <span class="c1"># Add the evolution arrays to the history class</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_DM_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_DM_t</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_tot_ISM_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_outflow_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_inflow_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_inflow_t</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">eta_outflow_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">eta_outflow_t</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">t_SF_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_SF_t</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">redshift_t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">redshift_t</span>

                <span class="c1"># If external control ...</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">external_control</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

                <span class="c1"># Calculate the total mass of gas</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_stel_tot</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">for</span> <span class="n">i_tot</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">m_stel_tot</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i_tot</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_tot</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">m_stel_tot</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_stel_tot</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">f_m_stel_tot</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">m_temp</span> <span class="o">=</span> <span class="mf">0.0</span>
                <span class="k">for</span> <span class="n">i_tot</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)):</span>
                    <span class="n">m_temp</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i_tot</span><span class="p">]</span> <span class="o">*</span> \
                        <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_tot</span><span class="p">]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">f_m_stel_tot</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m_temp</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">m_stel_tot</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">f_m_stel_tot</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">f_m_stel_tot</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

                <span class="c1"># Announce the end of the simulation</span>
                <span class="k">print</span> <span class="s1">&#39;   OMEGA run completed -&#39;</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">_gettime</span><span class="p">()</span>

        <span class="c1"># Error message</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;The simulation is already over.&#39;</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#              Get Mass Sampled              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">_get_mass_sampled</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m_pop</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function samples randomly the IMF using a Monte Carlo</span>
<span class="sd">        approach and returns an array with all masses sampled (not</span>
<span class="sd">        in increasing or decreasing orders).</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          m_pop : Mass of the considered stellar population</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Initialization of the sampling arrays</span>
        <span class="n">mass_sampled_gms</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">m_tot_temp</span> <span class="o">=</span> <span class="mf">0.0</span>
    
        <span class="c1"># Define the sampling precision in Msun</span>
        <span class="n">precision</span> <span class="o">=</span> <span class="mf">0.5</span>

        <span class="c1"># Copy the lower and upper mass limit of the IMF</span>
        <span class="n">m_low_imf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_bdys</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">m_up_imf</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_bdys</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

        <span class="c1"># Normalize the IMF as in the initialization function</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">imfnorm</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">imf_norm_sampled</span>
    
        <span class="c1"># While the total stellar mass is not formed ...</span>
        <span class="k">while</span> <span class="nb">abs</span><span class="p">(</span><span class="n">m_tot_temp</span> <span class="o">-</span> <span class="n">m_pop</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">precision</span><span class="p">:</span>
 
            <span class="c1"># Choose randomly a (m,nb) coordinate</span>
            <span class="n">rand_m</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="n">m_low_imf</span><span class="p">,</span> <span class="n">m_up_imf</span><span class="p">)</span>
            <span class="n">rand_y</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">imf_max</span><span class="p">)</span>
        
            <span class="c1"># If the coordinate is below the IMF curve</span>
            <span class="k">if</span> <span class="n">rand_y</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_imf</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span><span class="mf">2.0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="n">mass</span><span class="o">=</span><span class="n">rand_m</span><span class="p">):</span>
            
                <span class="c1"># Add the stellar mass only if it doesn&#39;t</span>
                <span class="c1"># form to much mass compared to m_pop</span>
                <span class="k">if</span> <span class="p">(</span><span class="n">m_tot_temp</span> <span class="o">+</span> <span class="n">rand_m</span><span class="p">)</span> <span class="o">-</span> <span class="n">m_pop</span> <span class="o">&lt;=</span> <span class="n">precision</span><span class="p">:</span>
                    <span class="n">mass_sampled_gms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rand_m</span><span class="p">)</span>
                    <span class="n">m_tot_temp</span> <span class="o">+=</span> <span class="n">rand_m</span>

        <span class="c1"># Return the stellar masses sampled using Monte Carlo</span>
        <span class="k">return</span> <span class="n">mass_sampled_gms</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Cal M Frac Stars              #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__cal_m_frac_stars</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">sfr_rs</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates the mass fraction of the gas reservoir that</span>
<span class="sd">        is converted into stars at a given timestep.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          i : Index of the timestep.</span>
<span class="sd">          sfr_rs : Star formation rate [Mo/yr] for the timestep i</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># If the SFR is calculated from a star formation law (closed box)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cl_SF_law</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfe_gcs</span> <span class="o">*</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfrin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

        <span class="k">else</span><span class="p">:</span>

            <span class="c1"># Calculate the total mass of stars formed during this timestep</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sfrin</span> <span class="o">=</span> <span class="n">sfr_rs</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">sfr_rs</span>

        <span class="c1"># Calculate the mass fraction of gas converted into stars</span>
        <span class="n">mgal_tot</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">for</span> <span class="n">k_ml</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">nb_isotopes</span><span class="p">):</span>
            <span class="n">mgal_tot</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ymgal</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="n">k_ml</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sfrin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfrin</span> <span class="o">/</span> <span class="n">mgal_tot</span>

        <span class="c1"># Modify the history of SFR if there is not enough gas</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfrin</span> <span class="o">&gt;</span> <span class="mf">1.0</span><span class="p">:</span>
           <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">mgal_tot</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                Delay Outflow               #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__delay_outflow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function convert the instantaneous outflow rate (vs SFR) into a delayed</span>
<span class="sd">        rate where Mout follows the number of CC SNe.</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          i : Index of the timestep.</span>


<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Calculate the 1 / (total number of CC SNe in the SSP)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_locked</span> <span class="o">&lt;=</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="n">nb_cc_sne_inv</span> <span class="o">=</span> <span class="mf">1.0e+30</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">zmetal</span> <span class="o">&lt;=</span> <span class="mf">0.0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">Z_trans</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="n">nb_cc_sne_inv</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_ccsne_per_m_pop3</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_locked</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">nb_cc_sne_inv</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nb_ccsne_per_m</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_locked</span><span class="p">)</span>

        <span class="c1"># Calculate the fraction of CC SNe in each future timesteps</span>
        <span class="n">len_ssp_nb_cc_sne</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssp_nb_cc_sne</span><span class="p">)</span>
        <span class="n">f_nb_cc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">len_ssp_nb_cc_sne</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float64</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i_nb_cc</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">len_ssp_nb_cc_sne</span><span class="p">):</span>
            <span class="n">f_nb_cc</span><span class="p">[</span><span class="n">i_nb_cc</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ssp_nb_cc_sne</span><span class="p">[</span><span class="n">i_nb_cc</span><span class="p">]</span> <span class="o">*</span> <span class="n">nb_cc_sne_inv</span>

        <span class="c1"># Copy the original instanteneous mass outflow [Msun]</span>
        <span class="n">m_out_inst</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t_vs_SFR</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

        <span class="c1"># For each future timesteps including the current one ...</span>
        <span class="k">for</span> <span class="n">i_do</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">len_ssp_nb_cc_sne</span><span class="p">):</span>

            <span class="c1"># Add the delayed mass outflow</span>
            <span class="c1">#print i, i_do, i+i_do, len(self.m_outflow_t)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="o">+</span><span class="n">i_do</span><span class="p">]</span> <span class="o">+=</span> <span class="n">m_out_inst</span> <span class="o">*</span> <span class="n">f_nb_cc</span><span class="p">[</span><span class="n">i_do</span><span class="p">]</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                Get M Inflow                #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__get_m_inflow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">m_tot_current</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        This function calculates and returns the inflow mass at a given timestep</span>

<span class="sd">        Argument</span>
<span class="sd">        ========</span>

<span class="sd">          i : Index of the timestep. </span>
<span class="sd">          m_tot_current : Total mass of the gas reservoir at step i</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># If the constant inflow rate is kept constant ...</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">inflow_rate</span> <span class="o">&gt;=</span> <span class="mf">0.0</span><span class="p">:</span>

            <span class="c1"># Use the input rate to calculate the inflow mass</span>
            <span class="c1"># Note : i-1 --&gt; current timestep, see __copy_sfr_input()</span>
            <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">inflow_rate</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

        <span class="c1"># If the inflow rate follows the outflow rate ...</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_control</span><span class="p">:</span>

            <span class="c1"># Use the input scale factor to calculate the inflow mass</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">out_follows_E_rate</span><span class="p">:</span>
                <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_ratio</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t_vs_SFR</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">in_out_ratio</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

        <span class="c1"># If the inflow rate is calculated from the main equation ...</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="c1"># If SFR = 0 and we do not want to use the main equation ..</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sfr_input</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">skip_zero</span><span class="p">:</span>
                <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="mf">0.0</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Calculate the mass of the inflow </span>
                <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_tot_ISM_t</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">-</span> \
                    <span class="n">m_tot_current</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

                <span class="c1"># If the inflow mass is negative ...</span>
                <span class="k">if</span> <span class="n">m_inflow_current</span> <span class="o">&lt;</span> <span class="mf">0.0</span><span class="p">:</span>

                    <span class="c1"># Convert the negative inflow into positive outflow</span>
                    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">skip_zero</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="o">-</span><span class="mf">1.0</span><span class="p">)</span> <span class="o">*</span> <span class="n">m_inflow_current</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">print_off</span><span class="p">:</span>
                            <span class="k">print</span> <span class="s1">&#39;Warning - Negative inflow.  &#39;</span> \
                              <span class="s1">&#39;The outflow rate has been increased.&#39;</span><span class="p">,</span> <span class="n">i</span>

                    <span class="c1"># Assume no inflow</span>
                    <span class="n">m_inflow_current</span> <span class="o">=</span> <span class="mf">0.0</span>

        <span class="c1"># Keep the mass of inflow in memory</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m_inflow_t</span><span class="p">[</span><span class="n">i</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">m_inflow_current</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">m_inflow_current</span>


<span class="c1">###############################################################################################</span>
<span class="c1">######################## Here start the analysis methods ######################################</span>
<span class="c1">###############################################################################################</span>

<div class="viewcode-block" id="omega.plot_abu_distr"><a class="viewcode-back" href="../omega.html#omega.omega.plot_abu_distr">[docs]</a>    <span class="k">def</span> <span class="nf">plot_abu_distr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">species</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">norm</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span><span class="n">multiplot</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">return_x_y</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	 Plot abundance distribution at point in time normalized to solar system distribution.</span>
<span class="sd">	</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>


<span class="sd">	species : array</span>
<span class="sd">             isotopes or element names, in the form [&#39;C&#39;] or [&#39;C-12&#39;]</span>
<span class="sd">	time : float</span>
<span class="sd">	     Time in yrs telling when to extract abundances, e.g. birth SS 9.2Gyr</span>
<span class="sd">	source : string</span>
<span class="sd">             Specifies if yields come from</span>
<span class="sd">	     all sources (&#39;all&#39;), including</span>
<span class="sd">	     AGB+SN1a, massive stars. Or from</span>
<span class="sd">	     distinctive sources:</span>
<span class="sd">	     only agb stars (&#39;agb&#39;), only</span>
<span class="sd">	     SN1a (&#39;SN1a&#39;), or only massive stars</span>
<span class="sd">             (&#39;massive&#39;)</span>
<span class="sd">        norm : string</span>
<span class="sd">             Choose the solar abundances, e.g. &#39;Grevesse_Noels_1993&#39;, same notation as in stellab?</span>
<span class="sd">	label : string</span>
<span class="sd">	     figure label</span>
<span class="sd">	marker : string</span>
<span class="sd">	     figure marker</span>
<span class="sd">	shape : string</span>
<span class="sd">	     line style	</span>
<span class="sd">	color : string</span>
<span class="sd">	     color of line</span>
<span class="sd">        fig : string,float</span>
<span class="sd">	     to name the plot figure       </span>
<span class="sd"> 	       </span>
<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; s.plot_abu_distr(species=[&#39;C-12&#39;,&#39;O-16&#39;],time=9.2e9,norm=&#39;Asplund_et_al_2009&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

	<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Do stuff here.</span>

<span class="sd">        yaxis=specie</span>
<span class="sd">        if len(label)&lt;1:</span>
<span class="sd">                label=yaxis</span>
<span class="sd">                if source==&#39;agb&#39;:</span>
<span class="sd">                        label=yaxis+&#39;, AGB&#39;</span>
<span class="sd">                if source==&#39;massive&#39;:</span>
<span class="sd">                        label=yaxis+&#39;, Massive&#39;</span>
<span class="sd">                if source==&#39;sn1a&#39;:</span>
<span class="sd">                        label=yaxis+&#39;, SNIa&#39;</span>

<span class="sd">        #Reserved for plotting</span>
<span class="sd">        if not return_x_y:</span>
<span class="sd">            shape,marker,color=self.__msc(source,shape,marker,color)</span>

<span class="sd">        x=self.history.age</span>
<span class="sd">        self.x=x</span>
<span class="sd">        y=[]</span>
<span class="sd">        yields_evol_all=self.history.ism_elem_yield</span>
<span class="sd">        if yaxis in self.history.elements:</span>
<span class="sd">            if source == &#39;all&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_elem_yield</span>
<span class="sd">            elif source ==&#39;agb&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_elem_yield_agb</span>
<span class="sd">            elif source == &#39;sn1a&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_elem_yield_1a</span>
<span class="sd">            elif source == &#39;massive&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_elem_yield_massive</span>
<span class="sd">            idx=self.history.elements.index(yaxis)</span>
<span class="sd">        elif yaxis in self.history.isotopes:</span>
<span class="sd">            if source == &#39;all&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_iso_yield</span>
<span class="sd">            elif source ==&#39;agb&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_iso_yield_agb</span>
<span class="sd">            elif source == &#39;sn1a&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_iso_yield_1a</span>
<span class="sd">            elif source == &#39;massive&#39;:</span>
<span class="sd">                yields_evol=self.history.ism_iso_yield_massive</span>
<span class="sd">            idx=self.history.isotopes.index(yaxis)</span>
<span class="sd">        else:</span>
<span class="sd">            print &#39;Isotope or element not available&#39;</span>
<span class="sd">            return 0</span>
<span class="sd">        for k in range(0,len(yields_evol)):</span>
<span class="sd">            if norm == False:</span>
<span class="sd">                y.append(yields_evol[k][idx])</span>
<span class="sd">            else:</span>
<span class="sd">                y.append( yields_evol[k][idx]/yields_evol_all[k][idx])</span>

<span class="sd">	#most important stuff not implemented yet.</span>
<span class="sd">	&#39;&#39;&#39;</span></div>

<div class="viewcode-block" id="omega.plot_mass"><a class="viewcode-back" href="../omega.html#omega.omega.plot_mass">[docs]</a>    <span class="k">def</span> <span class="nf">plot_mass</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="n">specie</span><span class="o">=</span><span class="s1">&#39;C&#39;</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">norm</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span><span class="n">multiplot</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">return_x_y</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">show_legend</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
    
        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	 mass evolution (in Msun) of an element or isotope vs time.</span>
<span class="sd">	</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>


<span class="sd">	specie : string</span>
<span class="sd">             isotope or element name, in the form &#39;C&#39; or &#39;C-12&#39;</span>
<span class="sd">	source : string</span>
<span class="sd">             Specifies if yields come from</span>
<span class="sd">	     all sources (&#39;all&#39;), including</span>
<span class="sd">	     AGB+SN1a, massive stars. Or from</span>
<span class="sd">	     distinctive sources:</span>
<span class="sd">	     only agb stars (&#39;agb&#39;), only</span>
<span class="sd">	     SN1a (&#39;SN1a&#39;), or only massive stars</span>
<span class="sd">             (&#39;massive&#39;)</span>
<span class="sd">        norm : boolean</span>
<span class="sd">             If True, normalize to current total ISM mass</span>
<span class="sd">	label : string</span>
<span class="sd">	     figure label</span>
<span class="sd">	marker : string</span>
<span class="sd">	     figure marker</span>
<span class="sd">	shape : string</span>
<span class="sd">	     line style	</span>
<span class="sd">	color : string</span>
<span class="sd">	     color of line</span>
<span class="sd">        fig : string,float</span>
<span class="sd">	     to name the plot figure    </span>
<span class="sd">        show_legend : boolean</span>
<span class="sd">             Default True. Show or not the legend   </span>
<span class="sd"> 	       </span>
<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; s.plot(&#39;C-12&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>
	<span class="n">yaxis</span><span class="o">=</span><span class="n">specie</span>
	<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">:</span>
		<span class="n">label</span><span class="o">=</span><span class="n">yaxis</span>
		<span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;, AGB&#39;</span>
		<span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;massive&#39;</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;, Massive&#39;</span>
		<span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;, SNIa&#39;</span>

        <span class="c1">#Reserved for plotting</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span><span class="p">:</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>

        <span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="o">=</span><span class="n">x</span>
        <span class="n">y</span><span class="o">=</span><span class="p">[]</span>
        <span class="n">yields_evol_all</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>
        <span class="k">if</span> <span class="n">yaxis</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_agb</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_1a</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_massive</span>
            <span class="n">idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">yaxis</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_agb</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_1a</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_massive</span>
            <span class="n">idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Isotope or element not available&#39;</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="bp">False</span><span class="p">:</span>
                <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idx</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idx</span><span class="p">]</span><span class="o">/</span><span class="n">yields_evol_all</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idx</span><span class="p">])</span>


        <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
        <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
        <span class="k">if</span> <span class="n">multiplot</span><span class="o">==</span><span class="bp">True</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span>  

        <span class="c1">#Reserved for plotting</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span><span class="p">:</span>
           <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
           <span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
           <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;log-scaled age [yrs]&#39;</span><span class="p">)</span>
           <span class="k">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="bp">False</span><span class="p">:</span>
               <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;yields [Msun]&#39;</span><span class="p">)</span>
               <span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
           <span class="k">else</span><span class="p">:</span>
               <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;(IMF-weighted) fraction of ejecta&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="o">=</span><span class="n">y</span>

        <span class="c1">#If x and y need to be returned ...</span>
        <span class="k">if</span> <span class="n">return_x_y</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">show_legend</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>
	    <span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">dt</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span><span class="p">)</span>	
	    <span class="c1">#return x,y</span>
	    <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Age[yrs]&#39;</span><span class="p">,</span><span class="n">specie</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span></div>


<div class="viewcode-block" id="omega.plot_massfrac"><a class="viewcode-back" href="../omega.html#omega.omega.plot_massfrac">[docs]</a>    <span class="k">def</span> <span class="nf">plot_massfrac</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">xaxis</span><span class="o">=</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="n">yaxis</span><span class="o">=</span><span class="s1">&#39;O-16&#39;</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">norm</span><span class="o">=</span><span class="s1">&#39;no&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Plots mass fraction of isotope or element</span>
<span class="sd">	vs either time or other isotope or element.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">	xaxis : string </span>
<span class="sd">            either &#39;age&#39; for time</span>
<span class="sd">	    or isotope name, in the form e.g. &#39;C-12&#39;</span>
<span class="sd">	yaxis : string</span>
<span class="sd">            isotope name, in the same form as for xaxis</span>

<span class="sd">	source : string</span>
<span class="sd">            Specifies if yields come from</span>
<span class="sd">	    all sources (&#39;all&#39;), including</span>
<span class="sd">	    AGB+SN1a, massive stars. Or from</span>
<span class="sd">	    distinctive sources:</span>
<span class="sd">	    only agb stars (&#39;agb&#39;), only</span>
<span class="sd">	    SN1a (&#39;SN1a&#39;), or only massive stars</span>
<span class="sd">            (&#39;massive&#39;)</span>

<span class="sd">        norm : string</span>
<span class="sd">            if &#39;no&#39;, no normalization of mass fraction</span>
<span class="sd">            if &#39;ini&#39;, normalization ot initial abundance</span>
<span class="sd">        label : string</span>
<span class="sd">             figure label</span>
<span class="sd">        marker : string</span>
<span class="sd">             figure marker</span>
<span class="sd">        shape : string</span>
<span class="sd">             line style </span>
<span class="sd">        color : string</span>
<span class="sd">             color of line</span>
<span class="sd">        fig : string,float</span>
<span class="sd">             to name the plot figure       </span>

<span class="sd">        </span>
<span class="sd">        Examples</span>
<span class="sd">        ----------</span>

<span class="sd">	&gt;&gt;&gt; s.plot_massfrac(&#39;age&#39;,&#39;C-12&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">:</span>
                <span class="n">label</span><span class="o">=</span><span class="n">yaxis</span>

	<span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>



        <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

 
        <span class="c1">#Input X-axis</span>
        <span class="k">if</span> <span class="s1">&#39;-&#39;</span> <span class="ow">in</span> <span class="n">xaxis</span><span class="p">:</span>
        <span class="c1">#to test the different contributions</span>
	    <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
	       <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
	    <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
	      <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_agb</span>
	    <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
	      <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_1a</span>
	    <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
	     <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_massive</span>
	     <span class="n">iso_idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis</span><span class="p">)</span>
            <span class="n">x</span><span class="o">=</span><span class="p">[]</span>
	    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
	       <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;no&#39;</span><span class="p">:</span>
	           <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
	       <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;ini&#39;</span><span class="p">:</span>
	           <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">/</span><span class="n">yields_evol</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">])</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;log-scaled X(&#39;</span><span class="o">+</span><span class="n">xaxis</span><span class="o">+</span><span class="s1">&#39;)&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="s1">&#39;age&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
            <span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="c1">#[1:]</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;log-scaled Age [yrs]&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="s1">&#39;Z&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
            <span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">metallicity</span><span class="c1">#[1:]</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;ISM metallicity&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">xaxis</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_agb</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_1a</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_massive</span>
            <span class="n">iso_idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis</span><span class="p">)</span>
            <span class="n">x</span><span class="o">=</span><span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;no&#39;</span><span class="p">:</span>
                    <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
                <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;ini&#39;</span><span class="p">:</span>
                    <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">/</span><span class="n">yields_evol</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">])</span>
                    <span class="k">print</span> <span class="n">yields_evol</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span>

            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;log-scaled X(&#39;</span><span class="o">+</span><span class="n">xaxis</span><span class="o">+</span><span class="s1">&#39;)&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>


        <span class="c1">#Input Y-axis</span>
        <span class="k">if</span> <span class="s1">&#39;-&#39;</span> <span class="ow">in</span> <span class="n">yaxis</span><span class="p">:</span>
            <span class="c1">#to test the different contributions</span>
            <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_agb</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_1a</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_massive</span>
            <span class="n">iso_idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis</span><span class="p">)</span>
            <span class="n">y</span><span class="o">=</span><span class="p">[]</span>
            <span class="c1">#change of xaxis array &#39;age &#39;due to continue statement below</span>
            <span class="k">if</span> <span class="n">xaxis</span><span class="o">==</span><span class="s1">&#39;age&#39;</span><span class="p">:</span>
                <span class="n">x_age</span><span class="o">=</span><span class="n">x</span>
                <span class="n">x</span><span class="o">=</span><span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
                <span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span><span class="mi">0</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;no&#39;</span><span class="p">:</span>
                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
                <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;ini&#39;</span><span class="p">:</span>
                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">/</span><span class="n">yields_evol</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">])</span>

                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;X(&#39;</span><span class="o">+</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;)&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="o">=</span><span class="n">y</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="s1">&#39;Z&#39;</span> <span class="o">==</span> <span class="n">yaxis</span><span class="p">:</span>
            <span class="n">y</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">metallicity</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;ISM metallicity&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">yaxis</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_agb</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_1a</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_massive</span>
            <span class="n">iso_idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis</span><span class="p">)</span>
            <span class="n">y</span><span class="o">=</span><span class="p">[]</span>
            <span class="c1">#change of xaxis array &#39;age &#39;due to continue statement below</span>
            <span class="k">if</span> <span class="n">xaxis</span><span class="o">==</span><span class="s1">&#39;age&#39;</span><span class="p">:</span>
                <span class="n">x_age</span><span class="o">=</span><span class="n">x</span>
                <span class="n">x</span><span class="o">=</span><span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
                <span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span><span class="mi">0</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;no&#39;</span><span class="p">:</span>
                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
                <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;ini&#39;</span><span class="p">:</span>
                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">/</span><span class="n">yields_evol</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">iso_idx</span><span class="p">])</span>

                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="c1">#plt.yscale(&#39;log&#39;)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;X(&#39;</span><span class="o">+</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;)&#39;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="o">=</span><span class="n">y</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
        <span class="c1">#To prevent 0 +log scale</span>
        <span class="k">if</span> <span class="s1">&#39;age&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
                <span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">dt</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
        <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>
	<span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="n">xaxis</span><span class="p">,</span><span class="n">yaxis</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span></div>

<div class="viewcode-block" id="omega.plot_spectro"><a class="viewcode-back" href="../omega.html#omega.omega.plot_spectro">[docs]</a>    <span class="k">def</span> <span class="nf">plot_spectro</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span><span class="n">xaxis</span><span class="o">=</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="n">yaxis</span><span class="o">=</span><span class="s1">&#39;[Fe/H]&#39;</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;-&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span><span class="n">show_data</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">show_sculptor</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">show_legend</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">return_x_y</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">sub_plot</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span><span class="n">sub</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span><span class="n">plot_data</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">only_one_iso</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">solar_ab</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">sfr_thresh</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span><span class="n">m_formed_thresh</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span><span class="n">solar_norm</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">        Plots elements in spectroscopic notation:</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">	xaxis : string</span>
<span class="sd">            Elements spectroscopic notation e.g. [Fe/H]</span>
<span class="sd">	    if &#39;age&#39;: time evolution in years</span>
<span class="sd">	yaxis : string</span>
<span class="sd">                Elements in spectroscopic notation, e.g. [C/Fe]</span>
<span class="sd">	source : string</span>
<span class="sd">                If yields come from</span>
<span class="sd">		all sources use &#39;all&#39; (include</span>
<span class="sd">		AGB+SN1a, massive stars.)</span>

<span class="sd">		If yields come from distinctive source:</span>
<span class="sd">		only agb stars use &#39;agb&#39;, only</span>
<span class="sd">		SN1a (&#39;SN1a&#39;), or only massive stars</span>
<span class="sd">		(&#39;massive&#39;)</span>

<span class="sd">        label : string</span>
<span class="sd">             figure label</span>
<span class="sd">        marker : string</span>
<span class="sd">             figure marker</span>
<span class="sd">        shape : string</span>
<span class="sd">             line style </span>
<span class="sd">        color : string</span>
<span class="sd">             color of line</span>
<span class="sd">        fig : string,float</span>
<span class="sd">             to name the plot figure       </span>

<span class="sd">        Examples</span>
<span class="sd">        ----------</span>
<span class="sd">	&gt;&gt;&gt; plt.plot_spectro(&#39;[Fe/H]&#39;,&#39;[C/Fe]&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1">#Error message if there is the &quot;subplot&quot; has not been provided</span>
        <span class="k">if</span> <span class="n">sub_plot</span> <span class="ow">and</span> <span class="n">sub</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;!! Error - You need to use the </span><span class="se">\&#39;</span><span class="s1">sub</span><span class="se">\&#39;</span><span class="s1"> parameter and provide the frame for the plot !!&#39;</span>
            <span class="k">return</span>

        <span class="c1">#Operations associated with plot visual aspects</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sub_plot</span><span class="p">:</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">:</span>
                    <span class="n">label</span><span class="o">=</span><span class="n">yaxis</span>

            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>

        <span class="c1">#Set the figure output</span>
        <span class="k">if</span> <span class="n">sub_plot</span><span class="p">:</span>
            <span class="n">plt_ps</span> <span class="o">=</span> <span class="n">sub</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">plt_ps</span> <span class="o">=</span> <span class="n">plt</span>


        <span class="c1">#Access solar abundance</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">solar_ab</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">iniabu</span><span class="o">=</span><span class="n">ry</span><span class="o">.</span><span class="n">iniabu</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="n">solar_ab</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">iniabu</span><span class="o">=</span><span class="n">ry</span><span class="o">.</span><span class="n">iniabu</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="s1">&#39;yield_tables/iniabu/iniab2.0E-02GN93.ppn&#39;</span><span class="p">)</span>

        <span class="c1"># If a solar normalization is used ..</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">solar_norm</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>

            <span class="c1"># Mass number of the most abundant isotopes</span>
            <span class="n">el_norm</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;H&#39;</span><span class="p">,</span> <span class="s1">&#39;He&#39;</span><span class="p">,</span> <span class="s1">&#39;Li&#39;</span><span class="p">,</span> <span class="s1">&#39;Be&#39;</span><span class="p">,</span> <span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">,</span> <span class="s1">&#39;N&#39;</span><span class="p">,</span> <span class="s1">&#39;O&#39;</span><span class="p">,</span> <span class="s1">&#39;F&#39;</span><span class="p">,</span> <span class="s1">&#39;Ne&#39;</span><span class="p">,</span> <span class="s1">&#39;Na&#39;</span><span class="p">,</span> <span class="s1">&#39;Mg&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Al&#39;</span><span class="p">,</span> <span class="s1">&#39;Si&#39;</span><span class="p">,</span> <span class="s1">&#39;P&#39;</span><span class="p">,</span> <span class="s1">&#39;S&#39;</span><span class="p">,</span> <span class="s1">&#39;Cl&#39;</span><span class="p">,</span> <span class="s1">&#39;Ar&#39;</span><span class="p">,</span> <span class="s1">&#39;K&#39;</span><span class="p">,</span> <span class="s1">&#39;Ca&#39;</span><span class="p">,</span> <span class="s1">&#39;Sc&#39;</span><span class="p">,</span> <span class="s1">&#39;Ti&#39;</span><span class="p">,</span> <span class="s1">&#39;V&#39;</span><span class="p">,</span> <span class="s1">&#39;Cr&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Mn&#39;</span><span class="p">,</span> <span class="s1">&#39;Fe&#39;</span><span class="p">,</span> <span class="s1">&#39;Co&#39;</span><span class="p">,</span> <span class="s1">&#39;Ni&#39;</span><span class="p">,</span> <span class="s1">&#39;Cu&#39;</span><span class="p">,</span> <span class="s1">&#39;Zn&#39;</span><span class="p">,</span> <span class="s1">&#39;Ga&#39;</span><span class="p">,</span> <span class="s1">&#39;Ge&#39;</span><span class="p">,</span> <span class="s1">&#39;As&#39;</span><span class="p">,</span> <span class="s1">&#39;Se&#39;</span><span class="p">,</span> <span class="s1">&#39;Br&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Kr&#39;</span><span class="p">,</span> <span class="s1">&#39;Rb&#39;</span><span class="p">,</span> <span class="s1">&#39;Sr&#39;</span><span class="p">,</span> <span class="s1">&#39;Y&#39;</span><span class="p">,</span> <span class="s1">&#39;Zr&#39;</span><span class="p">,</span> <span class="s1">&#39;Nb&#39;</span><span class="p">,</span> <span class="s1">&#39;Mo&#39;</span><span class="p">,</span> <span class="s1">&#39;Ru&#39;</span><span class="p">,</span> <span class="s1">&#39;Rh&#39;</span><span class="p">,</span> <span class="s1">&#39;Pd&#39;</span><span class="p">,</span> <span class="s1">&#39;Ag&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Cd&#39;</span><span class="p">,</span> <span class="s1">&#39;In&#39;</span><span class="p">,</span> <span class="s1">&#39;Sn&#39;</span><span class="p">,</span> <span class="s1">&#39;Sb&#39;</span><span class="p">,</span> <span class="s1">&#39;Te&#39;</span><span class="p">,</span> <span class="s1">&#39;I&#39;</span><span class="p">,</span> <span class="s1">&#39;Xe&#39;</span><span class="p">,</span> <span class="s1">&#39;Cs&#39;</span><span class="p">,</span> <span class="s1">&#39;Ba&#39;</span><span class="p">,</span> <span class="s1">&#39;La&#39;</span><span class="p">,</span> <span class="s1">&#39;Ce&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Pr&#39;</span><span class="p">,</span> <span class="s1">&#39;Nd&#39;</span><span class="p">,</span> <span class="s1">&#39;Sm&#39;</span><span class="p">,</span> <span class="s1">&#39;Eu&#39;</span><span class="p">,</span> <span class="s1">&#39;Gd&#39;</span><span class="p">,</span> <span class="s1">&#39;Tb&#39;</span><span class="p">,</span> <span class="s1">&#39;Dy&#39;</span><span class="p">,</span> <span class="s1">&#39;Ho&#39;</span><span class="p">,</span> <span class="s1">&#39;Er&#39;</span><span class="p">,</span> <span class="s1">&#39;Tm&#39;</span><span class="p">,</span> <span class="s1">&#39;Yb&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Lu&#39;</span><span class="p">,</span> <span class="s1">&#39;Hf&#39;</span><span class="p">,</span> <span class="s1">&#39;Ta&#39;</span><span class="p">,</span> <span class="s1">&#39;W&#39;</span><span class="p">,</span> <span class="s1">&#39;Re&#39;</span><span class="p">,</span> <span class="s1">&#39;Os&#39;</span><span class="p">,</span> <span class="s1">&#39;Ir&#39;</span><span class="p">,</span> <span class="s1">&#39;Pt&#39;</span><span class="p">,</span> <span class="s1">&#39;Au&#39;</span><span class="p">,</span> <span class="s1">&#39;Hg&#39;</span><span class="p">,</span> <span class="s1">&#39;Tl&#39;</span><span class="p">,</span>\
                       <span class="s1">&#39;Pb&#39;</span><span class="p">,</span> <span class="s1">&#39;Bi&#39;</span><span class="p">,</span> <span class="s1">&#39;Th&#39;</span><span class="p">,</span> <span class="s1">&#39;U&#39;</span><span class="p">]</span>
            <span class="n">mn_norm</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.0000200000000001</span><span class="p">,</span> <span class="mf">3.999834</span><span class="p">,</span> <span class="mf">6.924099999999999</span><span class="p">,</span> <span class="mf">9.0</span><span class="p">,</span> <span class="mf">10.801</span><span class="p">,</span>\
                       <span class="mf">12.011061999999999</span><span class="p">,</span> <span class="mf">14.00229</span><span class="p">,</span> <span class="mf">16.004379000000004</span><span class="p">,</span> <span class="mf">19.0</span><span class="p">,</span> <span class="mf">20.13891</span><span class="p">,</span>\
                       <span class="mf">23.0</span><span class="p">,</span> <span class="mf">24.3202</span><span class="p">,</span> <span class="mf">27.0</span><span class="p">,</span> <span class="mf">28.108575891424106</span><span class="p">,</span> <span class="mf">31.0</span><span class="p">,</span> <span class="mf">32.094199999999994</span><span class="p">,</span>\
                       <span class="mf">35.4844</span><span class="p">,</span> <span class="mf">36.30859999999999</span><span class="p">,</span> <span class="mf">39.13588999999999</span><span class="p">,</span> <span class="mf">40.115629999999996</span><span class="p">,</span>\
                       <span class="mf">45.0</span><span class="p">,</span> <span class="mf">47.9183</span><span class="p">,</span> <span class="mf">50.9975</span><span class="p">,</span> <span class="mf">52.05541</span><span class="p">,</span> <span class="mf">55.0</span><span class="p">,</span> <span class="mf">55.90993</span><span class="p">,</span> <span class="mf">59.0</span><span class="p">,</span> <span class="mf">58.759575</span><span class="p">,</span>\
                       <span class="mf">63.6166</span><span class="p">,</span> <span class="mf">65.4682</span><span class="p">,</span> <span class="mf">69.79784000000001</span><span class="p">,</span> <span class="mf">72.69049999999999</span><span class="p">,</span> <span class="mf">75.0</span><span class="p">,</span> <span class="mf">79.0421</span><span class="p">,</span>\
                       <span class="mf">79.9862</span><span class="p">,</span> <span class="mf">83.88084</span><span class="p">,</span> <span class="mf">85.58312</span><span class="p">,</span> <span class="mf">87.71136299999999</span><span class="p">,</span> <span class="mf">89.0</span><span class="p">,</span> <span class="mf">91.31840000000001</span><span class="p">,</span>\
                       <span class="mf">93.0</span><span class="p">,</span> <span class="mf">96.05436999999998</span><span class="p">,</span> <span class="mf">101.1598</span><span class="p">,</span> <span class="mf">103.0</span><span class="p">,</span> <span class="mf">106.5111</span><span class="p">,</span> <span class="mf">107.96322</span><span class="p">,</span>\
                       <span class="mf">112.508</span><span class="p">,</span> <span class="mf">114.9142</span><span class="p">,</span> <span class="mf">118.8077</span><span class="p">,</span> <span class="mf">121.85580000000002</span><span class="p">,</span> <span class="mf">127.69839999999999</span><span class="p">,</span>\
                       <span class="mf">127.0</span><span class="p">,</span> <span class="mf">131.28810000000001</span><span class="p">,</span> <span class="mf">133.0</span><span class="p">,</span> <span class="mf">137.42162</span><span class="p">,</span> <span class="mf">138.99909000000002</span><span class="p">,</span>\
                       <span class="mf">140.20986</span><span class="p">,</span> <span class="mf">141.0</span><span class="p">,</span> <span class="mf">144.33351666483335</span><span class="p">,</span> <span class="mf">150.4481</span><span class="p">,</span> <span class="mf">152.0438</span><span class="p">,</span> <span class="mf">157.3281</span><span class="p">,</span>\
                       <span class="mf">159.0</span><span class="p">,</span> <span class="mf">162.57152999999997</span><span class="p">,</span> <span class="mf">165.0</span><span class="p">,</span> <span class="mf">167.32707000000002</span><span class="p">,</span> <span class="mf">169.0</span><span class="p">,</span>\
                       <span class="mf">173.11618838116186</span><span class="p">,</span> <span class="mf">175.02820514102572</span><span class="p">,</span> <span class="mf">178.54163</span><span class="p">,</span> <span class="mf">180.99988000000002</span><span class="p">,</span>\
                       <span class="mf">183.89069999999998</span><span class="p">,</span> <span class="mf">186.28676</span><span class="p">,</span> <span class="mf">190.28879711202887</span><span class="p">,</span> <span class="mf">192.254</span><span class="p">,</span>\
                       <span class="mf">195.11347999999998</span><span class="p">,</span> <span class="mf">197.0</span><span class="p">,</span> <span class="mf">200.6297</span><span class="p">,</span> <span class="mf">204.40952</span><span class="p">,</span> <span class="mf">207.34285</span><span class="p">,</span> <span class="mf">209.0</span><span class="p">,</span>\
                       <span class="mf">232.0</span><span class="p">,</span> <span class="mf">237.27134</span><span class="p">]</span>

            <span class="c1"># Solar values</span>
            <span class="n">sol_values_el</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">sol_values_ab</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="c1"># Open the data file</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="s1">&#39;solar_normalization/&#39;</span><span class="o">+</span><span class="n">solar_norm</span><span class="o">+</span><span class="s1">&#39;.txt&#39;</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">data_file</span><span class="p">:</span>

                <span class="c1"># For every line (for each element) ...</span>
                <span class="n">i_elem</span> <span class="o">=</span> <span class="mi">0</span>
                <span class="k">for</span> <span class="n">line_1_str</span> <span class="ow">in</span> <span class="n">data_file</span><span class="p">:</span>

                    <span class="c1"># Split the line</span>
                    <span class="n">split</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">x_split</span><span class="p">)</span> <span class="k">for</span> <span class="n">x_split</span> <span class="ow">in</span> <span class="n">line_1_str</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>

                    <span class="c1"># Copy the element and the solar value</span>
                    <span class="n">sol_values_el</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
                    <span class="n">sol_values_ab</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>

                    <span class="c1"># Go to the next element</span>
                    <span class="n">i_elem</span> <span class="o">+=</span> <span class="mi">1</span>

            <span class="c1"># Close the file</span>
            <span class="n">data_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="n">x_ini_iso</span><span class="o">=</span><span class="n">iniabu</span><span class="o">.</span><span class="n">iso_abundance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">)</span>
        <span class="n">elements</span><span class="p">,</span><span class="n">x_ini</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_iso_abu_to_elem</span><span class="p">(</span><span class="n">x_ini_iso</span><span class="p">)</span>
        <span class="c1">#to test the different contributions</span>
        <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>
        <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_agb</span>
        <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_1a</span>
        <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_massive</span>

        <span class="c1">#Operations associated with plot visual aspects</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sub_plot</span><span class="p">:</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>


        <span class="k">if</span> <span class="s1">&#39;age&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
            <span class="n">x</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>

            <span class="c1">#Operations associated with plot visual aspects</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sub_plot</span><span class="p">:</span>
                <span class="c1">#plt.xscale(&#39;log&#39;)</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yr]&#39;</span><span class="p">)</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="o">=</span><span class="n">x</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="n">xaxis_elem1</span><span class="o">=</span><span class="n">xaxis</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">xaxis_elem2</span><span class="o">=</span><span class="n">xaxis</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

            <span class="c1">#print xaxis_elem1, xaxis_elem2</span>

            <span class="c1">#X-axis ini values</span>
            <span class="n">x_elem1_ini</span><span class="o">=</span><span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)]</span>
            <span class="n">x_elem2_ini</span><span class="o">=</span><span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)]</span>

            <span class="c1">#X-axis gce values</span>
            <span class="n">elem_idx1</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)</span>
            <span class="n">elem_idx2</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)</span>

            <span class="c1"># Take only 56-Fe is needed</span>
            <span class="k">if</span> <span class="n">only_one_iso</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">yaxis_elem1</span> <span class="o">==</span> <span class="s1">&#39;Fe&#39;</span><span class="p">:</span>
                    <span class="n">yields_evol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
                    <span class="n">elem_idx1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;Fe-56&#39;</span><span class="p">)</span>

            <span class="n">x</span><span class="o">=</span><span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
                <span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span><span class="mi">0</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="c1">#in case no contribution during timestep</span>
                <span class="n">x1</span><span class="o">=</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx1</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                <span class="n">x2</span><span class="o">=</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx2</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">x1</span> <span class="o">&lt;=</span> <span class="mf">0.0</span> <span class="ow">or</span> <span class="n">x2</span> <span class="o">&lt;=</span> <span class="mf">0.0</span><span class="p">:</span>
                    <span class="n">spec</span> <span class="o">=</span> <span class="o">-</span><span class="mf">30.0</span>
                <span class="k">else</span><span class="p">:</span>
                  <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">solar_norm</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                      <span class="n">index_1</span> <span class="o">=</span> <span class="n">el_norm</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)</span>
                      <span class="n">index_2</span> <span class="o">=</span> <span class="n">el_norm</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)</span>
                      <span class="n">i_xx_sol_1</span> <span class="o">=</span> <span class="n">sol_values_el</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)</span>
                      <span class="n">i_xx_sol_2</span> <span class="o">=</span> <span class="n">sol_values_el</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)</span>
                      <span class="n">aaa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx1</span><span class="p">]</span><span class="o">*</span><span class="n">mn_norm</span><span class="p">[</span><span class="n">index_2</span><span class="p">]</span> <span class="o">/</span>\
                            <span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx2</span><span class="p">]</span><span class="o">*</span><span class="n">mn_norm</span><span class="p">[</span><span class="n">index_1</span><span class="p">]))</span>
                      <span class="n">bbb</span> <span class="o">=</span> <span class="n">sol_values_ab</span><span class="p">[</span><span class="n">i_xx_sol_1</span><span class="p">]</span> <span class="o">-</span> <span class="n">sol_values_ab</span><span class="p">[</span><span class="n">i_xx_sol_2</span><span class="p">]</span>
                      <span class="n">spec</span><span class="o">=</span> <span class="n">aaa</span> <span class="o">-</span> <span class="n">bbb</span>
                  <span class="k">else</span><span class="p">:</span>
                    <span class="n">spec</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x1</span><span class="o">/</span><span class="n">x2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x_elem1_ini</span><span class="o">/</span><span class="n">x_elem2_ini</span><span class="p">)</span>
                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>
            <span class="c1">#Operations associated with plot visual aspects</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sub_plot</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="n">xaxis</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">x</span><span class="o">=</span><span class="n">x</span>


        <span class="n">yaxis_elem1</span><span class="o">=</span><span class="n">yaxis</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span>
        <span class="n">yaxis_elem2</span><span class="o">=</span><span class="n">yaxis</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

        <span class="c1">#y=axis ini values</span>
        <span class="n">x_elem1_ini</span><span class="o">=</span><span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem1</span><span class="p">)]</span>
        <span class="n">x_elem2_ini</span><span class="o">=</span><span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem2</span><span class="p">)]</span>
        <span class="c1">#print &#39;Fe_sol = &#39;,x_elem1_ini,&#39; , H_sol = &#39;,x_elem2_ini</span>

        <span class="c1">#Y-axis gce values</span>
        <span class="n">elem_idx1</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem1</span><span class="p">)</span>
        <span class="n">elem_idx2</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem2</span><span class="p">)</span>

        <span class="c1"># Take only 56-Fe is needed</span>
        <span class="k">if</span> <span class="n">only_one_iso</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">yaxis_elem1</span> <span class="o">==</span> <span class="s1">&#39;Fe&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
                <span class="n">elem_idx1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;Fe-56&#39;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">yaxis_elem2</span> <span class="o">==</span> <span class="s1">&#39;Fe&#39;</span><span class="p">:</span>
                <span class="n">yields_evol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
                <span class="n">elem_idx2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;Fe-56&#39;</span><span class="p">)</span>

        <span class="n">y</span><span class="o">=</span><span class="p">[]</span>
        <span class="k">if</span> <span class="n">xaxis</span><span class="o">==</span><span class="s1">&#39;age&#39;</span><span class="p">:</span>
            <span class="n">x_age</span><span class="o">=</span><span class="n">x</span>
            <span class="n">x</span><span class="o">=</span><span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
            <span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span><span class="mi">0</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="c1">#in case no contribution during timestep</span>
            <span class="n">x1</span><span class="o">=</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx1</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="n">x2</span><span class="o">=</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx2</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">x1</span> <span class="o">&lt;=</span> <span class="mf">0.0</span> <span class="ow">or</span> <span class="n">x2</span> <span class="o">&lt;=</span> <span class="mf">0.0</span><span class="p">:</span>
                <span class="n">spec</span> <span class="o">=</span> <span class="o">-</span><span class="mf">30.0</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1">#print &#39;Fe_sim = &#39;,x1, &#39; , H_sim = &#39;,x2</span>
                <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">solar_norm</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">index_1</span> <span class="o">=</span> <span class="n">el_norm</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem1</span><span class="p">)</span>
                    <span class="n">index_2</span> <span class="o">=</span> <span class="n">el_norm</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem2</span><span class="p">)</span>
                    <span class="n">i_xx_sol_1</span> <span class="o">=</span> <span class="n">sol_values_el</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem1</span><span class="p">)</span>
                    <span class="n">i_xx_sol_2</span> <span class="o">=</span> <span class="n">sol_values_el</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">yaxis_elem2</span><span class="p">)</span>
                    <span class="n">aaa</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx1</span><span class="p">]</span><span class="o">*</span><span class="n">mn_norm</span><span class="p">[</span><span class="n">index_2</span><span class="p">]</span> <span class="o">/</span>\
                          <span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx2</span><span class="p">]</span><span class="o">*</span><span class="n">mn_norm</span><span class="p">[</span><span class="n">index_1</span><span class="p">]))</span>
                    <span class="n">bbb</span> <span class="o">=</span> <span class="n">sol_values_ab</span><span class="p">[</span><span class="n">i_xx_sol_1</span><span class="p">]</span> <span class="o">-</span> <span class="n">sol_values_ab</span><span class="p">[</span><span class="n">i_xx_sol_2</span><span class="p">]</span>
                    <span class="n">spec</span><span class="o">=</span> <span class="n">aaa</span> <span class="o">-</span> <span class="n">bbb</span>
                <span class="k">else</span><span class="p">:</span>
                  <span class="n">spec</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x1</span><span class="o">/</span><span class="n">x2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x_elem1_ini</span><span class="o">/</span><span class="n">x_elem2_ini</span><span class="p">)</span>
            <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">xaxis</span><span class="o">==</span><span class="s1">&#39;age&#39;</span><span class="p">:</span>
                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Y values all zero&#39;</span>
        <span class="c1">#Operations associated with plot visual aspects</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sub_plot</span><span class="p">:</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="n">yaxis</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">y</span><span class="o">=</span><span class="n">y</span>
	<span class="c1">#To prevent 0 +log scale</span>
	<span class="k">if</span> <span class="s1">&#39;age&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
		<span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
		<span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                <span class="c1">#Operations associated with plot visual aspects</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sub_plot</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">dt</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span><span class="p">)</span>

        <span class="c1">#Remove values when SFR is zero, that is when no element is locked into stars</span>
        <span class="n">i_rem</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="n">m_formed_thresh</span> <span class="o">&lt;</span> <span class="mf">1.0</span> <span class="ow">or</span> <span class="n">sfr_thresh</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i_rem</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">sfr_thresh</span> <span class="ow">or</span> \
               <span class="bp">self</span><span class="o">.</span><span class="n">f_m_stel_tot</span><span class="p">[</span><span class="n">i_rem</span><span class="p">]</span> <span class="o">&gt;=</span> <span class="n">m_formed_thresh</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">y</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="k">del</span> <span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">i_rem</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span><span class="p">[</span><span class="n">i_rem</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.0</span><span class="p">:</span>
                <span class="k">del</span> <span class="n">y</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="k">del</span> <span class="n">x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="n">i_rem</span> <span class="o">-=</span> <span class="mi">1</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">plot_data</span><span class="p">:</span>

          <span class="c1"># Filtrate bad value</span>
          <span class="n">x_temp</span> <span class="o">=</span> <span class="p">[]</span>
          <span class="n">y_temp</span> <span class="o">=</span> <span class="p">[]</span>
          <span class="k">for</span> <span class="n">i_temp</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)):</span>
              <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">i_temp</span><span class="p">])</span> <span class="ow">and</span> <span class="n">np</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i_temp</span><span class="p">])</span>\
                 <span class="ow">and</span> <span class="n">x</span><span class="p">[</span><span class="n">i_temp</span><span class="p">]</span> <span class="o">&gt;</span> <span class="o">-</span><span class="mf">20.0</span> <span class="ow">and</span> <span class="n">y</span><span class="p">[</span><span class="n">i_temp</span><span class="p">]</span> <span class="o">&gt;</span> <span class="o">-</span><span class="mf">20.0</span><span class="p">:</span>
                  <span class="n">x_temp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">i_temp</span><span class="p">])</span>
                  <span class="n">y_temp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">i_temp</span><span class="p">])</span>
          <span class="n">x</span> <span class="o">=</span> <span class="n">x_temp</span>
          <span class="n">y</span> <span class="o">=</span> <span class="n">y_temp</span>

          <span class="c1">#If this function is supposed to return the x, y arrays only ...</span>
          <span class="k">if</span> <span class="n">return_x_y</span><span class="p">:</span>

            <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>

          <span class="c1">#If this is a sub-figure managed by an external module</span>
          <span class="k">elif</span> <span class="n">sub_plot</span><span class="p">:</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;none&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">show_legend</span><span class="p">:</span>
                    <span class="n">sub</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">sub</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">show_legend</span><span class="p">:</span>
                    <span class="n">sub</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">sub</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span> 

          <span class="c1">#If this function is supposed to plot ...</span>
          <span class="k">else</span><span class="p">:</span>

            <span class="c1">#Plot a thicker line for specific galaxies, since they must be visible with all the obs. data</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">galaxy</span> <span class="o">==</span> <span class="s1">&#39;none&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">show_legend</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">show_legend</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">linewidth</span><span class="o">=</span><span class="n">linewidth</span><span class="p">)</span>

            <span class="c1">#plt.plot([1.93,2.123123,3.23421321321],[4.123123132,5.214124142,6.11111],linestyle=&#39;--&#39;)</span>
            <span class="c1">#plt.plot([1.93,2.123123,3.23421321321],[4.123123132,5.214124142,6.11111],linestyle=&#39;--&#39;)</span>
	    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
	            <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>
	    <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="n">xaxis</span><span class="p">,</span><span class="n">yaxis</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span></div>


<div class="viewcode-block" id="omega.plot_totmasses"><a class="viewcode-back" href="../omega.html#omega.omega.plot_totmasses">[docs]</a>    <span class="k">def</span> <span class="nf">plot_totmasses</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span><span class="n">mass</span><span class="o">=</span><span class="s1">&#39;gas&#39;</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">norm</span><span class="o">=</span><span class="s1">&#39;no&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span><span class="n">log</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>
        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Plots either gas or star mass in fraction of total mass</span>
<span class="sd">	vs time.</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        mass : string</span>
<span class="sd">            either &#39;gas&#39; for ISM gas mass</span>
<span class="sd">            or &#39;stars&#39; for gas locked away in stars (totalgas - ISM gas)</span>

<span class="sd">        norm : string</span>
<span class="sd">            normalization, either &#39;no&#39; for no normalization (total gass mass in solar masses),</span>

<span class="sd">	    for normalization to the initial gas mass (mgal) with &#39;ini&#39;,</span>

<span class="sd">	    for normalization to the current total gas mass &#39;current&#39;.</span>
<span class="sd">	    The latter case makes sense when comparing different</span>
<span class="sd">	    sources (see below)</span>

<span class="sd">        source : string</span>
<span class="sd">            specificies if yields come from</span>
<span class="sd">	    all sources (&#39;all&#39;), including</span>
<span class="sd">	    AGB+SN1a, massive stars. Or from</span>
<span class="sd">	    distinctive sources:</span>
<span class="sd">	    only agb stars (&#39;agb&#39;), only</span>
<span class="sd">	    SN1a (&#39;sn1a&#39;), or only massive stars</span>
<span class="sd">	    (&#39;massive&#39;)</span>
<span class="sd">	log : boolean</span>
<span class="sd">            if true plot logarithmic y axis</span>
<span class="sd">        label : string</span>
<span class="sd">             figure label</span>
<span class="sd">        marker : string</span>
<span class="sd">             figure marker</span>
<span class="sd">        shape : string</span>
<span class="sd">             line style </span>
<span class="sd">        color : string</span>
<span class="sd">             color of line</span>
<span class="sd">        fig : string,float</span>
<span class="sd">             to name the plot figure       </span>

<span class="sd">        Examples</span>
<span class="sd">        ----------</span>
<span class="sd">        &gt;&gt;&gt; s.plot_totmasses()</span>


<span class="sd">        &#39;&#39;&#39;</span>

        <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>

        <span class="c1">#if len(label)&lt;1:</span>
        <span class="c1">#        label=mass+&#39;, &#39;+source</span>


        <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

        <span class="c1">#Assume isotope input</span>

	<span class="n">xaxis</span><span class="o">=</span><span class="s1">&#39;age&#39;</span>
	<span class="k">if</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;all&#39;</span><span class="p">:</span>
		<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;All&#39;</span>
	<span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;agb&#39;</span><span class="p">:</span>
		<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;AGB&#39;</span>
	<span class="k">if</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;massive&#39;</span><span class="p">:</span>
		<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;Massive&#39;</span>
	<span class="k">if</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
		<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;SNIa&#39;</span>
	
	<span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>

	<span class="k">if</span> <span class="s1">&#39;age&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
	    <span class="n">x_all</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="c1">#[1:]</span>
	    <span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
	    <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;log-scaled &#39;</span><span class="o">+</span><span class="n">xaxis</span><span class="o">+</span><span class="s1">&#39; [yrs]&#39;</span><span class="p">)</span>
	    <span class="c1">#self.x=x</span>

	<span class="n">gas_mass</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">gas_mass</span>

	<span class="c1">#to test the different contributions</span>
	<span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
            <span class="n">gas_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">gas_mass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
	        <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_agb</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
	        <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_1a</span>
            <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
	        <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_massive</span>
            <span class="n">gas_evol</span><span class="o">=</span><span class="p">[]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
	        <span class="n">gas_evol</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>

	<span class="n">ism_gasm</span><span class="o">=</span><span class="p">[]</span>
	<span class="n">star_m</span><span class="o">=</span><span class="p">[]</span>
	<span class="n">x</span><span class="o">=</span><span class="p">[]</span>
        <span class="c1">#To prevent 0 +log scale</span>
        <span class="k">if</span> <span class="s1">&#39;age&#39;</span> <span class="o">==</span> <span class="n">xaxis</span><span class="p">:</span>
                <span class="n">x_all</span><span class="o">=</span><span class="n">x_all</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                <span class="n">gas_evol</span><span class="o">=</span><span class="n">gas_evol</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
		<span class="n">gas_mass</span><span class="o">=</span><span class="n">gas_mass</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
	<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">gas_evol</span><span class="p">)):</span>
	    <span class="k">if</span> <span class="p">(</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">gas_mass</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">==</span><span class="mi">0</span><span class="p">):</span>
		<span class="k">continue</span>
	    <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_all</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;ini&#39;</span><span class="p">:</span>
	        <span class="n">ism_gasm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">mgal</span><span class="p">)</span>
	        <span class="n">star_m</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">mgal</span><span class="o">-</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">mgal</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">norm</span> <span class="o">==</span> <span class="s1">&#39;current&#39;</span><span class="p">:</span>
	        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">gas_mass</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">==</span><span class="mf">0.</span><span class="p">:</span>
	              <span class="n">ism_gasm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="n">gas_mass</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
	              <span class="n">star_m</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">mgal</span><span class="o">-</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span><span class="o">/</span><span class="n">gas_mass</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
	    <span class="c1">#else:</span>
	     <span class="c1">#   ism_gasm.append(0.)</span>
	      <span class="c1">#  star_m.append(0.)</span>
            <span class="k">elif</span> <span class="n">norm</span> <span class="o">==</span> <span class="s1">&#39;no&#39;</span><span class="p">:</span>
	        <span class="n">ism_gasm</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
	        <span class="n">star_m</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">mgal</span><span class="o">-</span><span class="n">gas_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">mass</span> <span class="o">==</span> <span class="s1">&#39;gas&#39;</span><span class="p">:</span>
	    <span class="n">y</span><span class="o">=</span><span class="n">ism_gasm</span>
        <span class="k">if</span> <span class="n">mass</span> <span class="o">==</span> <span class="s1">&#39;stars&#39;</span><span class="p">:</span>
	    <span class="n">y</span><span class="o">=</span><span class="n">star_m</span>
	<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>	
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;current&#39;</span><span class="p">:</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mf">1.2</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;no&#39;</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">mass</span><span class="o">==</span><span class="s1">&#39;gas&#39;</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;mass fraction&#39;</span><span class="p">)</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s1">&#39;Gas mass as a fraction of total gas mass&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;mass fraction&#39;</span><span class="p">)</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s1">&#39;Star mass as a fraction of total star mass&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">mass</span><span class="o">==</span><span class="s1">&#39;gas&#39;</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;ISM gas mass [Msun]&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;mass locked in stars [Msun]&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">mass</span><span class="o">==</span><span class="s1">&#39;gas&#39;</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;ISM gas mass [Msun]&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Mass locked in stars [Msun]&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">log</span><span class="o">==</span><span class="bp">True</span><span class="p">:</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
	    <span class="k">if</span> <span class="ow">not</span> <span class="n">norm</span><span class="o">==</span><span class="s1">&#39;no&#39;</span><span class="p">:</span>
            	<span class="n">plt</span><span class="o">.</span><span class="n">ylim</span><span class="p">(</span><span class="mf">1e-4</span><span class="p">,</span><span class="mf">1.2</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>
	<span class="n">plt</span><span class="o">.</span><span class="n">xlim</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">dt</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">tend</span><span class="p">)</span>
	<span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;mass&#39;</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span></div>


<div class="viewcode-block" id="omega.plot_sn_distr"><a class="viewcode-back" href="../omega.html#omega.omega.plot_sn_distr">[docs]</a>    <span class="k">def</span> <span class="nf">plot_sn_distr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span><span class="n">rate</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">rate_only</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">xaxis</span><span class="o">=</span><span class="s1">&#39;time&#39;</span><span class="p">,</span><span class="n">fraction</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">label1</span><span class="o">=</span><span class="s1">&#39;SNIa&#39;</span><span class="p">,</span><span class="n">label2</span><span class="o">=</span><span class="s1">&#39;SN2&#39;</span><span class="p">,</span><span class="n">shape1</span><span class="o">=</span><span class="s1">&#39;:&#39;</span><span class="p">,</span><span class="n">shape2</span><span class="o">=</span><span class="s1">&#39;--&#39;</span><span class="p">,</span><span class="n">marker1</span><span class="o">=</span><span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="n">marker2</span><span class="o">=</span><span class="s1">&#39;s&#39;</span><span class="p">,</span><span class="n">color1</span><span class="o">=</span><span class="s1">&#39;k&#39;</span><span class="p">,</span><span class="n">color2</span><span class="o">=</span><span class="s1">&#39;b&#39;</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Plots the SN1a distribution:</span>
<span class="sd">	The evolution of the number of SN1a and SN2</span>
<span class="sd">	#Add numbers/dt numbers/year...</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">	rate : boolean</span>
<span class="sd">            if true, calculate rate [1/century] </span>
<span class="sd">            else calculate numbers</span>
<span class="sd">	fraction ; boolean</span>
<span class="sd">	    if true, ignorate rate and calculate number fraction of SNIa per WD</span>
<span class="sd">        rate_only : string</span>
<span class="sd">	    if empty string, plot both rates (default)</span>

<span class="sd">            if &#39;sn1a&#39;, plot only SN1a rate</span>

<span class="sd">            if &#39;sn2&#39;, plot only SN2 rate</span>
<span class="sd">	xaxis: string</span>
<span class="sd">	    if &#39;time&#39; : time evolution</span>
<span class="sd">	    if &#39;redshift&#39;: experimental! use with caution; redshift evolution</span>
<span class="sd">        label : string</span>
<span class="sd">             figure label</span>
<span class="sd">        marker : string</span>
<span class="sd">             figure marker</span>
<span class="sd">        shape : string</span>
<span class="sd">             line style </span>
<span class="sd">        color : string</span>
<span class="sd">             color of line</span>
<span class="sd">        fig : string,float</span>
<span class="sd">             to name the plot figure       </span>

<span class="sd">        Examples</span>
<span class="sd">        ----------</span>
<span class="sd">        &gt;&gt;&gt; s.plot_sn_distr()</span>
<span class="sd">        &#39;&#39;&#39;</span>
	<span class="c1">#For Wiersma09</span>
	<span class="n">Hubble_0</span><span class="o">=</span><span class="mf">73.</span>
	<span class="n">Omega_lambda</span><span class="o">=</span><span class="mf">0.762</span>
	<span class="n">Omega_m</span><span class="o">=</span><span class="mf">0.238</span>

        <span class="n">figure</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
        <span class="n">age</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
        <span class="n">sn1anumbers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sn1a_numbers</span><span class="c1">#[:-1]</span>
        <span class="n">sn2numbers</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sn2_numbers</span>
	<span class="k">if</span> <span class="n">xaxis</span><span class="o">==</span><span class="s1">&#39;redshift&#39;</span><span class="p">:</span>
		<span class="k">print</span> <span class="s1">&#39;this features is not tested yet.&#39;</span>
		<span class="k">return</span> <span class="mi">0</span>
		<span class="n">age</span><span class="p">,</span><span class="n">idx</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__time_to_z</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">Hubble_0</span><span class="p">,</span><span class="n">Omega_lambda</span><span class="p">,</span><span class="n">Omega_m</span><span class="p">)</span>
		<span class="n">age</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">age</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Redshift z&#39;</span><span class="p">)</span>
		<span class="n">timesteps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">idx</span><span class="o">-</span><span class="mi">1</span><span class="p">:]</span>
		<span class="n">sn2numbers</span><span class="o">=</span><span class="n">sn2numbers</span><span class="p">[</span><span class="n">idx</span><span class="p">:]</span>
		<span class="n">sn1anumbers</span><span class="o">=</span><span class="n">sn1anumbers</span><span class="p">[</span><span class="n">idx</span><span class="p">:]</span>
	<span class="k">else</span><span class="p">:</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Log-scaled age [yrs]&#39;</span><span class="p">)</span>
		<span class="c1">#plt.xscale(&#39;log&#39;)</span>
        <span class="k">if</span> <span class="n">rate</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">fraction</span><span class="p">:</span>
	    <span class="k">if</span> <span class="n">xaxis</span><span class="o">==</span><span class="s1">&#39;redshift&#39;</span><span class="p">:</span>
			<span class="n">sn1a_rate</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sn1anumbers</span><span class="p">)</span><span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">timesteps</span><span class="p">)</span><span class="o">/</span><span class="mf">100.</span><span class="p">)</span>
			<span class="n">sn2_rate</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sn2numbers</span><span class="p">)</span><span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">timesteps</span><span class="p">)</span><span class="o">/</span><span class="mf">100.</span><span class="p">)</span>	
	    <span class="k">else</span><span class="p">:</span>
            		<span class="n">sn1a_rate</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sn1anumbers</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span><span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)</span><span class="o">/</span><span class="mf">100.</span><span class="p">)</span>
            		<span class="n">sn2_rate</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sn2numbers</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span><span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">)</span><span class="o">/</span><span class="mf">100.</span><span class="p">)</span>
	    <span class="n">sn1a_rate1</span><span class="o">=</span><span class="p">[]</span>
	    <span class="n">sn2_rate1</span><span class="o">=</span><span class="p">[]</span>
	    <span class="n">age</span><span class="o">=</span><span class="n">age</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
	    <span class="n">age_sn1a</span><span class="o">=</span><span class="p">[]</span> <span class="c1">#age[1:]</span>
	    <span class="n">age_sn2</span><span class="o">=</span><span class="p">[]</span>
	    <span class="c1">#correct sn1a rate</span>
	    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sn1a_rate</span><span class="p">)):</span>
		<span class="k">if</span> <span class="n">sn1a_rate</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">sn1a_rate1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sn1a_rate</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
			<span class="n">age_sn1a</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
			
	    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sn2_rate</span><span class="p">)):</span>
		<span class="k">if</span> <span class="n">sn2_rate</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">sn2_rate1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sn2_rate</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
			<span class="n">age_sn2</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
	

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">rate_only</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
		    <span class="n">x</span><span class="o">=</span><span class="p">[</span><span class="n">age_sn2</span><span class="p">,</span><span class="n">age_sn1a</span><span class="p">]</span>
		    <span class="n">y</span><span class="o">=</span><span class="p">[</span><span class="n">sn1a_rate1</span><span class="p">,</span><span class="n">sn2_rate1</span><span class="p">]</span>
		    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn1a</span><span class="p">,</span><span class="n">sn1a_rate1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape1</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color1</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label1</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker1</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
		    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn2</span><span class="p">,</span><span class="n">sn2_rate1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color2</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label2</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker2</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
            	    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SN rate [century$^{-1}$]&#39;</span><span class="p">)</span>
	    <span class="k">if</span> <span class="n">rate_only</span><span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
		    <span class="n">x</span><span class="o">=</span><span class="n">age_sn1a</span>
		    <span class="n">y</span><span class="o">=</span> <span class="n">sn1a_rate1</span>
		    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn1a</span><span class="p">,</span><span class="n">sn1a_rate1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape1</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color1</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label1</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker1</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
		    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SNIa rate [century$^{-1}$]&#39;</span><span class="p">)</span>
	    <span class="k">if</span> <span class="n">rate_only</span><span class="o">==</span><span class="s1">&#39;sn2&#39;</span><span class="p">:</span>
		    <span class="n">x</span><span class="o">=</span><span class="n">age_sn2</span>
		    <span class="n">y</span><span class="o">=</span><span class="n">sn2_rate</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn2</span><span class="p">,</span><span class="n">sn2_rate1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color2</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label2</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker2</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
		    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SN2 rate [century$^{-1}$]&#39;</span><span class="p">)</span>


        <span class="k">else</span><span class="p">:</span>
            <span class="c1">#if xaxis==&#39;redshift&#39;:</span>
		
                        <span class="c1">#sn1_numbers=np.array(sn1anumbers)/ (np.array(timesteps)/100.)</span>
                        <span class="c1">#sn2_numbers=np.array(sn2numbers)/ (np.array(timesteps)/100.)</span>
            <span class="c1">#True: #else:</span>
                        <span class="c1">#sn1a_rate=np.array(sn1anumbers[1:])/ (np.array(self.history.timesteps)/100.)</span>
                        <span class="c1">#sn2_rate=np.array(sn2numbers[1:])/ (np.array(self.history.timesteps)/100.)</span>

	    <span class="n">sn1a_numbers</span><span class="o">=</span><span class="n">sn1anumbers</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
	    <span class="n">sn2_numbers</span><span class="o">=</span><span class="n">sn2numbers</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>	
            <span class="n">sn1a_numbers1</span><span class="o">=</span><span class="p">[]</span>
	    <span class="n">sn2_numbers1</span><span class="o">=</span><span class="p">[]</span>
            <span class="n">age_sn1a</span><span class="o">=</span><span class="p">[]</span>
	    <span class="n">age_sn2</span><span class="o">=</span><span class="p">[]</span>
            <span class="n">age</span><span class="o">=</span><span class="n">age</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sn1a_numbers</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">sn1a_numbers</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
                        <span class="n">sn1a_numbers1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sn1a_numbers</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                        <span class="n">age_sn1a</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
	    <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sn2_numbers</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">sn2_numbers</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
                        <span class="n">sn2_numbers1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sn2_numbers</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                        <span class="n">age_sn2</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>

	    <span class="k">if</span> <span class="n">fraction</span><span class="p">:</span>
		<span class="n">age</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
		<span class="n">ratio</span><span class="o">=</span><span class="p">[]</span>
		<span class="n">age1</span><span class="o">=</span><span class="p">[]</span>
		<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">wd_sn1a_range1</span><span class="p">)):</span>
		    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">wd_sn1a_range1</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
			<span class="n">ratio</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sn1a_numbers</span><span class="p">[</span><span class="mi">1</span><span class="p">:][</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">wd_sn1a_range1</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
			<span class="n">age1</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age1</span><span class="p">,</span><span class="n">ratio</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
		<span class="c1">#plt.xscale(&#39;log&#39;)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Number of SNIa going off per WD born&#39;</span><span class="p">)</span>
		<span class="n">label</span><span class="o">=</span><span class="s1">&#39;SNIafractionperWD&#39;</span><span class="p">;</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;sn1a &#39;</span><span class="o">+</span><span class="n">label</span>
		<span class="n">x</span><span class="o">=</span><span class="n">age1</span>
		<span class="n">y</span><span class="o">=</span><span class="n">ratio</span>
		<span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="n">label</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span>		
		<span class="k">return</span> 
	    <span class="k">else</span><span class="p">:</span>
		    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">rate_only</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
			    <span class="n">x</span><span class="o">=</span><span class="p">[</span><span class="n">age_sn1a</span><span class="p">,</span><span class="n">age_sn2</span><span class="p">]</span>
			    <span class="n">y</span><span class="o">=</span><span class="p">[</span><span class="n">sn1a_numbers</span><span class="p">,</span><span class="n">sn2_numbers</span><span class="p">]</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn1a</span><span class="p">,</span><span class="n">sn1a_numbers1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape1</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color1</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label1</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker1</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn2</span><span class="p">,</span><span class="n">sn2_numbers1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color2</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label2</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker2</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SN numbers&#39;</span><span class="p">)</span>
		    <span class="k">if</span> <span class="n">rate_only</span><span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
			    <span class="n">x</span><span class="o">=</span> <span class="n">age1</span>
			    <span class="n">y</span><span class="o">=</span> <span class="n">sn1anumbers1</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn1a</span><span class="p">,</span><span class="n">sn1a_numbers1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape1</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color1</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label1</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker1</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markever</span><span class="p">)</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SN numbers&#39;</span><span class="p">)</span>
		    <span class="k">if</span> <span class="n">rate_only</span><span class="o">==</span><span class="s1">&#39;sn2&#39;</span><span class="p">:</span>
			    <span class="n">x</span><span class="o">=</span> <span class="n">age</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
			    <span class="n">y</span><span class="o">=</span> <span class="n">sn2numbers</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age_sn2</span><span class="p">,</span><span class="n">sn2_numbers1</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape2</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color2</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label2</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker2</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
			    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SN numbers&#39;</span><span class="p">)</span>

	<span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
	<span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
	<span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>
	<span class="k">if</span> <span class="n">rate</span><span class="p">:</span>
		<span class="n">label</span><span class="o">=</span><span class="s1">&#39;rate&#39;</span>
	<span class="k">else</span><span class="p">:</span>
		<span class="n">label</span><span class="o">=</span><span class="s1">&#39;number&#39;</span>	
	<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">rate_only</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
		<span class="k">if</span> <span class="n">rate</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;rate&#39;</span>
		<span class="k">else</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;number&#39;</span>
		<span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;SNIa &#39;</span><span class="o">+</span><span class="n">label</span><span class="p">,</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;CCSN &#39;</span><span class="o">+</span><span class="n">label</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">y</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span>
	<span class="k">else</span><span class="p">:</span>
		<span class="k">if</span> <span class="n">rate_only</span><span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;sn1a &#39;</span><span class="o">+</span><span class="n">label</span>
		<span class="k">else</span><span class="p">:</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;ccsn &#39;</span><span class="o">+</span><span class="n">label</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="n">label</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span></div>


<div class="viewcode-block" id="omega.save_data"><a class="viewcode-back" href="../omega.html#omega.omega.save_data">[docs]</a>    <span class="k">def</span> <span class="nf">save_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">header</span><span class="o">=</span><span class="p">[],</span><span class="n">data</span><span class="o">=</span><span class="p">[],</span><span class="n">filename</span><span class="o">=</span><span class="s1">&#39;plot_data.txt&#39;</span><span class="p">):</span>
	<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">		Writes data into a text file. data entries</span>
<span class="sd">		can have different lengths</span>
<span class="sd">	&#39;&#39;&#39;</span>
	<span class="n">out</span><span class="o">=</span><span class="s1">&#39; &#39;</span>
        <span class="c1">#header</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">header</span><span class="p">)):</span>
            <span class="n">out</span><span class="o">+=</span> <span class="p">(</span><span class="s1">&#39;&amp;&#39;</span><span class="o">+</span><span class="n">header</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">+</span><span class="p">((</span><span class="mi">10</span><span class="o">-</span><span class="nb">len</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="n">i</span><span class="p">]))</span><span class="o">*</span><span class="s1">&#39; &#39;</span><span class="p">))</span>
        <span class="c1">#data</span>
	<span class="n">out</span><span class="o">+=</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
	<span class="n">max_data</span><span class="o">=</span><span class="p">[]</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)):</span>
		<span class="n">max_data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]))</span>
        <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">max_data</span><span class="p">)):</span>
            <span class="c1">#out+=(&#39;&amp;&#39;+&#39;{:.3E}&#39;.format(data[t]))</span>
            <span class="c1">#out+=(&#39; &amp;&#39;+&#39;{:.3E}&#39;.format(frac_yields[t]))</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)):</span>
		<span class="k">if</span> <span class="n">t</span><span class="o">&gt;</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>
			<span class="n">out</span><span class="o">+=</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span> <span class="s1">&#39; &amp;&#39;</span><span class="o">+</span> <span class="s1">&#39;{:.3E}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">0</span><span class="p">)))</span>
		<span class="k">else</span><span class="p">:</span>
                	<span class="n">out</span><span class="o">+=</span> <span class="p">(</span> <span class="s1">&#39; &amp;&#39;</span><span class="o">+</span> <span class="s1">&#39;{:.3E}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">t</span><span class="p">]))</span>
            <span class="c1">#out+=( &#39; &amp;&#39;+ &#39;{:.3E}&#39;.format(mtot_gas[t]))</span>
            <span class="n">out</span><span class="o">+=</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
	<span class="c1">#import os.path</span>
	<span class="c1">#if os.path.isfile(filename) </span>
	<span class="c1">#overwrite existing file for now</span>
	<span class="n">f1</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="s1">&#39;w&#39;</span><span class="p">)</span>
	<span class="n">f1</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">out</span><span class="p">)</span>
	<span class="n">f1</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>



    <span class="c1">##############################################</span>
    <span class="c1">#          Plot Star Formation Rate          #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_star_formation_rate"><a class="viewcode-back" href="../omega.html#omega.omega.plot_star_formation_rate">[docs]</a>    <span class="k">def</span> <span class="nf">plot_star_formation_rate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span><span class="n">fraction</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">abs_unit</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>
	<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Plots the star formation rate over time.</span>
<span class="sd">	Shows fraction of ISM mass which transforms into stars.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">	fraction : boolean</span>
<span class="sd">		if true: fraction of ISM which transforms into stars;</span>
<span class="sd">		else: mass of ISM which goes into stars</span>

<span class="sd">	source : string</span>
<span class="sd">		either &#39;all&#39; for total star formation rate; &#39;agb&#39; for AGB and &#39;massive&#39; for massive stars</span>

<span class="sd">	marker : string</span>
<span class="sd">		marker type</span>
<span class="sd">	shape : string</span>
<span class="sd">		line shape type</span>
<span class="sd">	fig: figure id</span>
<span class="sd">	</span>
<span class="sd">        Examples</span>
<span class="sd">        ----------</span>
<span class="sd">        &gt;&gt;&gt; s.star_formation_rate()</span>
<span class="sd">	</span>
<span class="sd">	&#39;&#39;&#39;</span>

	<span class="k">if</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">marker</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">color</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
		<span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
	<span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
	<span class="c1">#maybe a histogram for display the SFR?</span>
	<span class="k">if</span> <span class="bp">False</span><span class="p">:</span>
		<span class="n">age</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
		<span class="c1">#age=[0.1]+self.history.age[1:-1]</span>
		<span class="n">sfr</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Log-scaled age [yrs]&#39;</span><span class="p">)</span>
		<span class="c1">#plt.xscale(&#39;log&#39;)</span>
		<span class="n">mean_age</span><span class="o">=</span><span class="p">[]</span>
		<span class="n">color</span><span class="o">=</span><span class="s1">&#39;r&#39;</span>
		<span class="n">label</span><span class="o">=</span><span class="s1">&#39;aa&#39;</span>
		<span class="n">age_bdy</span><span class="o">=</span><span class="p">[]</span>
		<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">age</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>
			<span class="n">mean_age</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1">#age[k+1]-age[k])</span>
		<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">age</span><span class="p">)):</span>
			<span class="n">age_bdy</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">age</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>	
		<span class="k">print</span> <span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">mean_age</span><span class="p">)</span>
		<span class="k">print</span> <span class="s1">&#39;weights&#39;</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">sfr</span><span class="p">)</span>
		<span class="k">print</span> <span class="s1">&#39;bdy&#39;</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">age_bdy</span><span class="p">)</span>
		<span class="k">print</span> <span class="n">sfr</span><span class="p">[:</span><span class="mi">5</span><span class="p">]</span>
	        <span class="n">p1</span> <span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">mean_age</span><span class="p">,</span> <span class="n">bins</span><span class="o">=</span><span class="n">age_bdy</span><span class="p">,</span><span class="n">weights</span><span class="o">=</span><span class="n">sfr</span><span class="p">,</span><span class="n">facecolor</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>

        <span class="c1">#Plot the SFR in [Mo yr^-1]</span>
        <span class="k">if</span> <span class="n">abs_unit</span><span class="p">:</span>

            <span class="c1">#Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>

            <span class="c1">#Recover the SFR by dividing the mass locked into stars, at</span>
            <span class="c1">#each timestep, by the duration of the timestep</span>
            <span class="n">age</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
            <span class="c1">#sfr_plot = self.history.m_locked / self.history.timesteps</span>
            <span class="n">sfr_plot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr_abs</span>
            
            <span class="c1">#Label and display axis</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;SFR [Mo/yr]&#39;</span><span class="p">)</span>	

            <span class="c1">#Plot</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">sfr_plot</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#self.save_data(header=[&#39;age&#39;,&#39;SFR&#39;],data=[age,sfr_plot])</span>

        <span class="c1">#Plot the mass fraction of gas available converted into stars</span>
	<span class="k">elif</span> <span class="n">fraction</span><span class="p">:</span>
		<span class="n">sfr</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">sfr</span>
                <span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;all&#39;</span><span class="p">:</span>
                        <span class="n">label</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>
                <span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
			<span class="n">sfr</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sfr</span><span class="p">)</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked_agb</span><span class="p">)</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked</span><span class="p">)</span>
                        <span class="n">label</span><span class="o">=</span><span class="s1">&#39;AGB&#39;</span>
                <span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                        <span class="n">masslocked</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked_massive</span>
			<span class="n">sfr</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">sfr</span><span class="p">)</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked_massive</span><span class="p">)</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked</span><span class="p">)</span>
                        <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Massive&#39;</span>
		<span class="n">age</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
		<span class="k">print</span> <span class="nb">len</span><span class="p">(</span><span class="n">age</span><span class="p">),</span><span class="nb">len</span><span class="p">(</span><span class="n">sfr</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">sfr</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Fraction of current gas mass into stars&#39;</span><span class="p">)</span>	
        	<span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;SFR&#39;</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">sfr</span><span class="p">])</span>

        <span class="c1">#Plot the mass converted into stars</span>
	<span class="k">else</span><span class="p">:</span>
		<span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;all&#39;</span><span class="p">:</span>
			<span class="n">masslocked</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>
		<span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
			<span class="n">masslocked</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked_agb</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;AGB&#39;</span>
		<span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;massive&#39;</span><span class="p">:</span>
			<span class="n">masslocked</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked_massive</span>
			<span class="n">label</span><span class="o">=</span><span class="s1">&#39;Massive&#39;</span>
		<span class="n">age</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">masslocked</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;ISM Mass transformed into stars&#39;</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">xscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">);</span><span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
		<span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>

        <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span></div>

	<span class="c1">#print &#39;Total mass transformed in stars, total mass transformed in AGBs, total mass transformed in massive stars:&#39;</span>
	<span class="c1">#print sum(self.history.m_locked),sum(self.history.m_locked_agb),sum(self.history.m_locked_massive)</span>



    <span class="k">def</span> <span class="nf">__time_to_z</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">time</span><span class="p">,</span><span class="n">Hubble_0</span><span class="p">,</span><span class="n">Omega_lambda</span><span class="p">,</span><span class="n">Omega_m</span><span class="p">):</span>
	<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Time to redshift conversion</span>

<span class="sd">	&#39;&#39;&#39;</span>
	<span class="kn">import</span> <span class="nn">time_to_redshift</span> <span class="kn">as</span> <span class="nn">tz</span>
	<span class="c1">#transform into Gyr</span>
	<span class="n">time_new</span><span class="o">=</span><span class="p">[]</span>
	<span class="n">firstidx</span><span class="o">=</span><span class="bp">True</span>
	<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">time</span><span class="p">)):</span>
		<span class="k">if</span> <span class="n">time</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">&gt;=</span><span class="mf">8e8</span><span class="p">:</span>
			<span class="n">time_new</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">time</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="mf">1e9</span><span class="p">)</span>
			<span class="k">if</span> <span class="n">firstidx</span><span class="p">:</span>
				<span class="n">index</span><span class="o">=</span><span class="n">k</span>
				<span class="n">firstidx</span><span class="o">=</span><span class="bp">False</span>	
	<span class="k">return</span> <span class="n">tz</span><span class="o">.</span><span class="n">t_to_z</span><span class="p">(</span><span class="n">time_new</span><span class="p">,</span><span class="n">Hubble_0</span><span class="p">,</span><span class="n">Omega_lambda</span><span class="p">,</span><span class="n">Omega_m</span><span class="p">),</span><span class="n">index</span>

    <span class="k">def</span> <span class="nf">__msc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">):</span>

	<span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Function checks if either of shape,color,marker</span>
<span class="sd">	is set. If not then assign in each case</span>
<span class="sd">	a unique property related to the source (&#39;agb&#39;,&#39;massive&#39;..)</span>
<span class="sd">	to the variable and returns all three</span>
<span class="sd">	&#39;&#39;&#39;</span>

	<span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;all&#39;</span><span class="p">:</span>
		<span class="n">shape1</span><span class="o">=</span><span class="s1">&#39;-&#39;</span>
		<span class="n">marker1</span><span class="o">=</span><span class="s1">&#39;o&#39;</span>
		<span class="n">color1</span><span class="o">=</span><span class="s1">&#39;k&#39;</span>
	<span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
		<span class="n">shape1</span><span class="o">=</span><span class="s1">&#39;--&#39;</span>
		<span class="n">marker1</span><span class="o">=</span><span class="s1">&#39;s&#39;</span>
		<span class="n">color1</span><span class="o">=</span><span class="s1">&#39;r&#39;</span>
	<span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;massive&#39;</span><span class="p">:</span>
		<span class="n">shape1</span><span class="o">=</span><span class="s1">&#39;-.&#39;</span>
		<span class="n">marker1</span><span class="o">=</span><span class="s1">&#39;D&#39;</span>
		<span class="n">color1</span><span class="o">=</span><span class="s1">&#39;b&#39;</span>
	<span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
		<span class="n">shape1</span><span class="o">=</span><span class="s1">&#39;:&#39;</span>
		<span class="n">marker1</span><span class="o">=</span><span class="s1">&#39;x&#39;</span>
		<span class="n">color1</span><span class="o">=</span><span class="s1">&#39;g&#39;</span>
	
	<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">shape</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
		<span class="n">shape</span><span class="o">=</span><span class="n">shape1</span>
	<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">marker</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
		<span class="n">marker</span><span class="o">=</span><span class="n">marker1</span>
	<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">color</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
		<span class="n">color</span><span class="o">=</span><span class="n">color1</span>

	<span class="k">return</span> <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                Fig Standard                #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__fig_standard</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span><span class="n">lwtickboth</span><span class="o">=</span><span class="p">[</span><span class="mi">6</span><span class="p">,</span><span class="mi">2</span><span class="p">],</span><span class="n">lwtickmajor</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">3</span><span class="p">],</span><span class="n">markersize</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span> <span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	Internal function in order to get standardized figure font sizes.</span>
<span class="sd">	It is used in the plotting functions.</span>
<span class="sd">        &#39;&#39;&#39;</span>

        <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span><span class="n">prop</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;size&#39;</span><span class="p">:</span><span class="n">legend_fontsize</span><span class="p">})</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">rcParams</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;font.size&#39;</span><span class="p">:</span> <span class="n">fontsize</span><span class="p">})</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">label</span><span class="o">.</span><span class="n">set_size</span><span class="p">(</span><span class="n">labelsize</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">label</span><span class="o">.</span><span class="n">set_size</span><span class="p">(</span><span class="n">labelsize</span><span class="p">)</span>
	<span class="c1">#ax.xaxis.set_tick_params(width=2)</span>
	<span class="c1">#ax.yaxis.set_tick_params(width=2)		</span>
	<span class="n">ax</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">length</span><span class="o">=</span><span class="n">lwtickboth</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">width</span><span class="o">=</span><span class="n">lwtickboth</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">which</span><span class="o">=</span><span class="s1">&#39;both&#39;</span><span class="p">)</span>
	<span class="n">ax</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">length</span><span class="o">=</span><span class="n">lwtickmajor</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">width</span><span class="o">=</span><span class="n">lwtickmajor</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">which</span><span class="o">=</span><span class="s1">&#39;major&#39;</span><span class="p">)</span>
	<span class="c1">#Add that line below at some point</span>
	<span class="c1">#ax.xaxis.set_tick_params(width=2)</span>
	<span class="c1">#ax.yaxis.set_tick_params(width=2)</span>
	<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">lines</span><span class="p">)</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
		<span class="k">for</span> <span class="n">h</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">lines</span><span class="p">)):</span>
			<span class="n">ax</span><span class="o">.</span><span class="n">lines</span><span class="p">[</span><span class="n">h</span><span class="p">]</span><span class="o">.</span><span class="n">set_markersize</span><span class="p">(</span><span class="n">markersize</span><span class="p">)</span>
	<span class="n">ax</span><span class="o">.</span><span class="n">legend</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="s1">&#39;center left&#39;</span><span class="p">,</span> <span class="n">bbox_to_anchor</span><span class="o">=</span><span class="p">(</span><span class="mf">1.01</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span><span class="n">markerscale</span><span class="o">=</span><span class="mf">0.8</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="n">plt</span><span class="o">.</span><span class="n">subplots_adjust</span><span class="p">(</span><span class="n">right</span><span class="o">=</span><span class="n">rspace</span><span class="p">)</span>
        <span class="n">plt</span><span class="o">.</span><span class="n">subplots_adjust</span><span class="p">(</span><span class="n">bottom</span><span class="o">=</span><span class="n">bspace</span><span class="p">)</span>


    <span class="c1">##############################################</span>
    <span class="c1">#              Plot Mass-Loading             #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_mass_loading"><a class="viewcode-back" href="../omega.html#omega.omega.plot_mass_loading">[docs]</a>    <span class="k">def</span> <span class="nf">plot_mass_loading</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
            <span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Mass-loading&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span>\
            <span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the mass-loading factor, which is the ratio</span>
<span class="sd">	between the mass outflow rate and the star formation rate, as a</span>
<span class="sd">	function of time.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_mass_loading(label=&#39;Mass-Loading Factor&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>

        <span class="c1">#Plot only if in the open box scenario</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>
 
            <span class="c1">#Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

            <span class="c1">#Display axis labels</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Mass-loading factor&#39;</span><span class="p">)</span>	

            <span class="c1">#Copy data for x and y axis</span>
            <span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">mass_lo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">eta_outflow_t</span>

            <span class="c1">#Plot data</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">mass_lo</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>\
                     <span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#Save plot</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;mass-loading&#39;</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">mass_lo</span><span class="p">])</span>

            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Not available with a closed box.&#39;</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#              Plot Outflow Rate             #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_outflow_rate"><a class="viewcode-back" href="../omega.html#omega.omega.plot_outflow_rate">[docs]</a>    <span class="k">def</span> <span class="nf">plot_outflow_rate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">9</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
            <span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Outflow&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span>\
            <span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the mass outflow rate as a function of time</span>
<span class="sd">        in units of [Mo/yr].</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_outflow_rate(label=&#39;Outflow Rate&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>

        <span class="c1">#Plot only if in the open box scenario</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>

            <span class="c1">#Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

            <span class="c1">#Display axis labels</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Outflow rate [Mo/yr]&#39;</span><span class="p">)</span>	

            <span class="c1">#Copy data for x and y axis</span>
            <span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">outflow_plot</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">age</span><span class="p">)):</span>
                <span class="n">outflow_plot</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_outflow_t</span><span class="p">[</span><span class="n">i_op</span><span class="p">]</span> <span class="o">/</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_op</span><span class="p">])</span>
            <span class="n">outflow_plot</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.0</span>

            <span class="c1">#Plot data</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">outflow_plot</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#Save plot</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;outflow rate&#39;</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">outflow_plot</span><span class="p">])</span>

            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Not available with a closed box.&#39;</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#              Plot Inflow Rate              #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_inflow_rate"><a class="viewcode-back" href="../omega.html#omega.omega.plot_inflow_rate">[docs]</a>    <span class="k">def</span> <span class="nf">plot_inflow_rate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Inflow&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span>\
            <span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the mass inflow rate as a function of time</span>
<span class="sd">        in units of [Mo/yr].</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_inflow_rate(label=&#39;Inflow Rate&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>

        <span class="c1">#Plot only if in the open box scenario</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>

            <span class="c1">#Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
	    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

            <span class="c1">#Display axis labels</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Inflow rate [Mo/yr]&#39;</span><span class="p">)</span>	

            <span class="c1">#Copy data for x and y axis</span>
            <span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">inflow_plot</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">i_op</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">age</span><span class="p">)):</span>
                <span class="n">inflow_plot</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_inflow_t</span><span class="p">[</span><span class="n">i_op</span><span class="p">]</span> <span class="o">/</span> \
                    <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span><span class="p">[</span><span class="n">i_op</span><span class="p">])</span>

            <span class="c1">#Plot data</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">inflow_plot</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#Save plot</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;inflow rate&#39;</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">inflow_plot</span><span class="p">])</span>

            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Not available with a closed box.&#39;</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#              Plot Dark Matter              #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_dark_matter"><a class="viewcode-back" href="../omega.html#omega.omega.plot_dark_matter">[docs]</a>    <span class="k">def</span> <span class="nf">plot_dark_matter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">11</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
            <span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Dark matter&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span> \
            <span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the dark matter halo mass of the galaxy as a </span>
<span class="sd">	function of time.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_dark_matter(label=&#39;Dark Matter&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>

        <span class="c1"># Plot only if in the open box scenario</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>

            <span class="c1"># Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
	    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

            <span class="c1">#Display axis labels</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Dark matter halo mass [Mo]&#39;</span><span class="p">)</span>	

            <span class="c1">#Copy data for x and y axis</span>
            <span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
            <span class="n">DM_plot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_DM_t</span>

            <span class="c1">#Plot data</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">DM_plot</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#Save plot</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;dark matter halo mass&#39;</span><span class="p">],</span>\
                           <span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">DM_plot</span><span class="p">])</span>

            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Not available with a closed box.&#39;</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#             Plot SF Timescale              #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_sf_timescale"><a class="viewcode-back" href="../omega.html#omega.omega.plot_sf_timescale">[docs]</a>    <span class="k">def</span> <span class="nf">plot_sf_timescale</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
            <span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span>\
            <span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the star formation timescale as a function of time</span>
<span class="sd">        in units of [yr].</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_sf_timescale(label=&#39;Star Formation Timescale&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>

        <span class="c1">#Plot only if in the open box scenario</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>

            <span class="c1">#Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
	    <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

            <span class="c1">#Display axis labels</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Star formation timescale [yr]&#39;</span><span class="p">)</span>	

            <span class="c1">#print len(self.history.age)</span>
            <span class="c1">#print len(self.history.t_SF_t)</span>

            <span class="c1">#Copy data for x and y axis</span>
            <span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
            <span class="n">t_SF_plot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">t_SF_t</span>

            <span class="c1">#Plot data</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">t_SF_plot</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#Save plot</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;star formation timescale&#39;</span><span class="p">],</span>\
                                   <span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">t_SF_plot</span><span class="p">])</span>

            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Not available with a closed box.&#39;</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#               Plot Redshift                #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_redshift"><a class="viewcode-back" href="../omega.html#omega.omega.plot_redshift">[docs]</a>    <span class="k">def</span> <span class="nf">plot_redshift</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">fig</span><span class="o">=</span><span class="mi">16</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
            <span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Redshift&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span>\
            <span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the redshift a function of time.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_redshift(label=&#39;Redshift&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>

        <span class="c1">#Plot only if in the open box scenario</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">open_box</span><span class="p">:</span>

            <span class="c1">#Define visual aspects</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>

            <span class="c1">#Display axis labels</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yrs]&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;Redshift&#39;</span><span class="p">)</span>	

            <span class="c1">#Copy data for x and y axis</span>
            <span class="n">age</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
            <span class="n">redshift_plot</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">redshift_t</span>

            <span class="c1">#Plot data</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">age</span><span class="p">,</span><span class="n">redshift_plot</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">)</span>

            <span class="c1">#Save plot</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="s1">&#39;redshift&#39;</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">age</span><span class="p">,</span><span class="n">redshift_plot</span><span class="p">])</span>

            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;Not available with a closed box.&#39;</span></div>


    <span class="c1">###################################################</span>
    <span class="c1">#                  Plot Iso Ratio                 #</span>
    <span class="c1">###################################################</span>
<div class="viewcode-block" id="omega.plot_iso_ratio"><a class="viewcode-back" href="../omega.html#omega.omega.plot_iso_ratio">[docs]</a>    <span class="k">def</span> <span class="nf">plot_iso_ratio</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">return_x_y</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
        <span class="n">xaxis</span><span class="o">=</span><span class="s1">&#39;age&#39;</span><span class="p">,</span><span class="n">yaxis</span><span class="o">=</span><span class="s1">&#39;C-12/C-13&#39;</span><span class="p">,</span>\
        <span class="n">solar_ab</span><span class="o">=</span><span class="s1">&#39;yield_tables/iniabu/iniab2.0E-02GN93.ppn&#39;</span><span class="p">,</span>\
        <span class="n">solar_iso</span><span class="o">=</span><span class="s1">&#39;solar_normalization/Asplund_et_al_2009_iso.txt&#39;</span><span class="p">,</span>\
        <span class="n">fig</span><span class="o">=</span><span class="mi">18</span><span class="p">,</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span>\
        <span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span>\
        <span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the evolution of an isotopic ratio as a function</span>
<span class="sd">	of time, as a function of an abundance ratio, or as a function of</span>
<span class="sd">	another isotopic ratio.  Isotopic ratios are given in the</span>
<span class="sd">	delta notation and abundances ratios are given in spectroscopic notation.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">	return_x_y : boolean</span>
<span class="sd">	     If False, show the plot.  If True, return two arrays containing</span>
<span class="sd">	     the X and Y axis data, respectively.</span>
<span class="sd">	xaxis : string</span>
<span class="sd">	     X axis, either &#39;age&#39;, an abundance ratio such as &#39;[Fe/H]&#39;, or an</span>
<span class="sd">	     isotopic ratio such as &#39;C-12/C-13&#39;.</span>
<span class="sd">	yaxis : string</span>
<span class="sd">	     Y axis, isotopic ratio such as &#39;C-12/C-13&#39;.</span>
<span class="sd">	solar_ab : string</span>
<span class="sd">	     Path to the solar abundances used to normalize abundance ratios.</span>
<span class="sd">	solar_iso : string</span>
<span class="sd">	     Path to the solar isotopes used to normalize the isotopic ratios.</span>
<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">        source : string</span>
<span class="sd">            Specificies if yields come from</span>
<span class="sd">	    all sources (&#39;all&#39;) or from</span>
<span class="sd">	    distinctive sources:</span>
<span class="sd">	    only AGB stars (&#39;agb&#39;), only</span>
<span class="sd">	    SN Ia (&#39;sn1a&#39;), or only massive stars</span>
<span class="sd">	    (&#39;massive&#39;)</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_iso_ratio(xaxis=&#39;[Fe/H]&#39;, yaxis=&#39;C-12/C-13&#39;)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Marker on the plots</span>
        <span class="n">markevery</span><span class="o">=</span><span class="mi">500</span>

        <span class="c1"># Declaration of the array to plot</span>
        <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1">#Access solar abundance</span>
        <span class="n">iniabu</span><span class="o">=</span><span class="n">ry</span><span class="o">.</span><span class="n">iniabu</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="n">solar_ab</span><span class="p">)</span>
        <span class="n">x_ini_iso</span><span class="o">=</span><span class="n">iniabu</span><span class="o">.</span><span class="n">iso_abundance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">)</span>
        <span class="n">elements</span><span class="p">,</span><span class="n">x_ini</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_iso_abu_to_elem</span><span class="p">(</span><span class="n">x_ini_iso</span><span class="p">)</span>

        <span class="c1"># Get the wanted source</span>
        <span class="k">if</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;all&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span>
            <span class="n">yields_evol_el</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>
        <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_agb</span>
            <span class="n">yields_evol_el</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_agb</span>
        <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_1a</span>
            <span class="n">yields_evol_el</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_1a</span>
        <span class="k">elif</span> <span class="n">source</span> <span class="o">==</span> <span class="s1">&#39;massive&#39;</span><span class="p">:</span>
            <span class="n">yields_evol</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield_massive</span>
            <span class="n">yields_evol_el</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield_massive</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;!! Source not valid !!&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Verify the X-axis</span>
        <span class="n">xaxis_ratio</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="n">xaxis</span> <span class="o">==</span> <span class="s1">&#39;age&#39;</span><span class="p">:</span>
            <span class="n">x</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
        <span class="k">elif</span> <span class="n">xaxis</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;[&#39;</span> <span class="ow">and</span> <span class="n">xaxis</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;]&#39;</span><span class="p">:</span>
            <span class="n">xaxis_elem1</span> <span class="o">=</span><span class="n">xaxis</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span>
            <span class="n">xaxis_elem2</span> <span class="o">=</span><span class="n">xaxis</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">xaxis_elem1</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span> <span class="ow">and</span> \
               <span class="ow">not</span> <span class="n">xaxis_elem2</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="p">:</span>
                 <span class="k">print</span> <span class="s1">&#39;!! Elements in xaxis are not valid !!&#39;</span>
                 <span class="k">return</span>

            <span class="c1">#X-axis ini values</span>
            <span class="n">x_elem1_ini</span><span class="o">=</span><span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)]</span>
            <span class="n">x_elem2_ini</span><span class="o">=</span><span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)]</span>

            <span class="c1">#X-axis gce values</span>
            <span class="n">elem_idx1</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)</span>
            <span class="n">elem_idx2</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol_el</span><span class="p">)):</span>
                <span class="k">if</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol_el</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="c1">#in case no contribution during timestep</span>
                <span class="n">x1</span><span class="o">=</span><span class="n">yields_evol_el</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx1</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol_el</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                <span class="n">x2</span><span class="o">=</span><span class="n">yields_evol_el</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx2</span><span class="p">]</span><span class="o">/</span><span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol_el</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
                <span class="n">spec</span><span class="o">=</span><span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x1</span><span class="o">/</span><span class="n">x2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x_elem1_ini</span><span class="o">/</span><span class="n">x_elem2_ini</span><span class="p">)</span>
                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">xaxis_ratio</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">x_1</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="n">x_2</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="n">is_x_1</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">for</span> <span class="n">ix</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">xaxis</span><span class="p">)):</span>
                <span class="k">if</span> <span class="n">xaxis</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;/&#39;</span> <span class="ow">and</span> <span class="n">is_x_1</span><span class="p">:</span>
                    <span class="n">is_x_1</span> <span class="o">=</span> <span class="bp">False</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">is_x_1</span><span class="p">:</span>
                        <span class="n">x_1</span> <span class="o">+=</span> <span class="n">xaxis</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">x_2</span> <span class="o">+=</span> <span class="n">xaxis</span><span class="p">[</span><span class="n">ix</span><span class="p">]</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">x_2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">print</span> <span class="s1">&#39;!! xaxis not valid.  Need to be </span><span class="se">\&#39;</span><span class="s1">age</span><span class="se">\&#39;</span><span class="s1"> or a ratio !!&#39;</span>
                <span class="k">return</span>

        <span class="c1"># Verify the Y-axis</span>
        <span class="n">y_1</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="n">y_2</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="n">is_y_1</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="k">for</span> <span class="n">iy</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yaxis</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">yaxis</span><span class="p">[</span><span class="n">iy</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;/&#39;</span> <span class="ow">and</span> <span class="n">is_y_1</span><span class="p">:</span>
                <span class="n">is_y_1</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">is_y_1</span><span class="p">:</span>
                    <span class="n">y_1</span> <span class="o">+=</span> <span class="n">yaxis</span><span class="p">[</span><span class="n">iy</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">y_2</span> <span class="o">+=</span> <span class="n">yaxis</span><span class="p">[</span><span class="n">iy</span><span class="p">]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">y_2</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;!! yaxis not valid.  Need to be a ratio !!&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Get the isotopes for X-axis</span>
        <span class="k">if</span> <span class="n">xaxis_ratio</span><span class="p">:</span>
          <span class="k">if</span> <span class="n">x_1</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span> <span class="ow">and</span> <span class="n">x_2</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">:</span>
            <span class="n">idx_1</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">x_1</span><span class="p">)</span>
            <span class="n">idx_2</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">x_2</span><span class="p">)</span>
            <span class="n">x1_elem</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">x_1</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">x2_elem</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">x_2</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">x1_at_nb</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">x_1</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">x2_at_nb</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">x_2</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
          <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;!! Isotopes in xaxis are not valid !!&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Get the isotopes for Y-axis</span>
        <span class="k">if</span> <span class="n">y_1</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span> <span class="ow">and</span> <span class="n">y_2</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">:</span>
            <span class="n">idy_1</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">y_1</span><span class="p">)</span>
            <span class="n">idy_2</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">y_2</span><span class="p">)</span>
            <span class="n">y1_elem</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">y_1</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">y2_elem</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">y_2</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">y1_at_nb</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">y_1</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">y2_at_nb</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">y_2</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">print</span> <span class="s1">&#39;!! Isotopes in yaxis are not valid !!&#39;</span>
            <span class="k">return</span>

        <span class="c1"># Set the default label .. if not defined</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&lt;</span><span class="mi">1</span><span class="p">:</span>
            <span class="n">label</span><span class="o">=</span><span class="n">yaxis</span>
            <span class="k">if</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;agb&#39;</span><span class="p">:</span>
                <span class="n">label</span><span class="o">=</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;, AGB&#39;</span>
            <span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;massive&#39;</span><span class="p">:</span>
                <span class="n">label</span><span class="o">=</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;, Massive&#39;</span>
            <span class="k">elif</span> <span class="n">source</span><span class="o">==</span><span class="s1">&#39;sn1a&#39;</span><span class="p">:</span>
                <span class="n">label</span><span class="o">=</span><span class="n">yaxis</span><span class="o">+</span><span class="s1">&#39;, SNIa&#39;</span>

        <span class="c1"># Get the solar values</span>
        <span class="k">if</span> <span class="n">xaxis_ratio</span><span class="p">:</span>
            <span class="n">x1_sol</span><span class="p">,</span> <span class="n">x2_sol</span><span class="p">,</span> <span class="n">y1_sol</span><span class="p">,</span> <span class="n">y2_sol</span> <span class="o">=</span> \
              <span class="bp">self</span><span class="o">.</span><span class="n">__read_solar_iso</span><span class="p">(</span><span class="n">solar_iso</span><span class="p">,</span> <span class="n">x_1</span><span class="p">,</span> <span class="n">x_2</span><span class="p">,</span> <span class="n">y_1</span><span class="p">,</span> <span class="n">y_2</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">x1_sol</span><span class="p">,</span> <span class="n">x2_sol</span><span class="p">,</span> <span class="n">y1_sol</span><span class="p">,</span> <span class="n">y2_sol</span> <span class="o">=</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">__read_solar_iso</span><span class="p">(</span><span class="n">solar_iso</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">y_1</span><span class="p">,</span> <span class="n">y_2</span><span class="p">)</span>

        <span class="c1"># Calculate the isotope ratios (delta notation)</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">xaxis_ratio</span><span class="p">:</span>
                <span class="n">ratio_sample</span> <span class="o">=</span> <span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idx_1</span><span class="p">]</span><span class="o">/</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idx_2</span><span class="p">])</span><span class="o">*</span>\
                               <span class="p">(</span><span class="n">x2_at_nb</span> <span class="o">/</span> <span class="n">x1_at_nb</span><span class="p">)</span>
                <span class="n">ratio_std</span> <span class="o">=</span> <span class="n">x1_sol</span> <span class="o">/</span> <span class="n">x2_sol</span>
                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="p">((</span><span class="n">ratio_sample</span><span class="o">/</span><span class="n">ratio_std</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">)</span>
            <span class="n">ratio_sample</span> <span class="o">=</span> <span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idy_1</span><span class="p">]</span><span class="o">/</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">idy_2</span><span class="p">])</span><span class="o">*</span>\
                           <span class="p">(</span><span class="n">y2_at_nb</span> <span class="o">/</span> <span class="n">y1_at_nb</span><span class="p">)</span>
            <span class="n">ratio_std</span> <span class="o">=</span> <span class="n">y1_sol</span> <span class="o">/</span> <span class="n">y2_sol</span>
            <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="p">((</span><span class="n">ratio_sample</span><span class="o">/</span><span class="n">ratio_std</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mi">1000</span><span class="p">)</span>
  
        <span class="c1"># Make sure the length of array are the same when xaxis = &#39;[X/Y]&#39;</span>
        <span class="n">too_much</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)</span><span class="o">-</span><span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[</span><span class="n">too_much</span><span class="p">:]</span>

        <span class="c1">#Reserved for plotting</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span><span class="p">:</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>

        <span class="c1">#Reserved for plotting</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span><span class="p">:</span>
           <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
               <span class="c1">#if xaxis == &#39;age&#39;:</span>
               <span class="c1">#plt.xscale(&#39;log&#39;)</span>
           <span class="c1">#plt.yscale(&#39;log&#39;)</span>
           <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s2">&quot;$\delta$($^{&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">y1_at_nb</span><span class="p">))</span><span class="o">+</span><span class="s2">&quot;}$&quot;</span><span class="o">+</span><span class="n">y1_elem</span><span class="o">+</span><span class="s2">&quot;/$^{&quot;</span><span class="o">+</span>\
                           <span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">y2_at_nb</span><span class="p">))</span><span class="o">+</span><span class="s2">&quot;}$&quot;</span><span class="o">+</span><span class="n">y2_elem</span><span class="o">+</span><span class="s2">&quot;)&quot;</span><span class="p">)</span>
           <span class="k">if</span> <span class="n">xaxis</span> <span class="o">==</span> <span class="s1">&#39;age&#39;</span><span class="p">:</span>
               <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Age [yr]&#39;</span><span class="p">)</span>
           <span class="k">elif</span> <span class="n">xaxis_ratio</span><span class="p">:</span>
               <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s2">&quot;$\delta$($^{&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">x1_at_nb</span><span class="p">))</span><span class="o">+</span><span class="s2">&quot;}$&quot;</span><span class="o">+</span><span class="n">x1_elem</span><span class="o">+</span><span class="s2">&quot;/$^{&quot;</span><span class="o">+</span>\
                           <span class="nb">str</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">x2_at_nb</span><span class="p">))</span><span class="o">+</span><span class="s2">&quot;}$&quot;</span><span class="o">+</span><span class="n">x2_elem</span><span class="o">+</span><span class="s2">&quot;)&quot;</span><span class="p">)</span>
           <span class="k">else</span><span class="p">:</span>
               <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="n">xaxis</span><span class="p">)</span>

        <span class="c1">#If x and y need to be returned ...</span>
        <span class="k">if</span> <span class="n">return_x_y</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                  <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>
	    <span class="c1">#plt.xlim(self.history.dt,self.history.tend)	</span>
	    <span class="bp">self</span><span class="o">.</span><span class="n">save_data</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Iso mass ratio&#39;</span><span class="p">,</span><span class="n">yaxis</span><span class="p">],</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">])</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#               Read Solar Iso               #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__read_solar_iso</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">file_path</span><span class="p">,</span> <span class="n">xx1</span><span class="p">,</span> <span class="n">xx2</span><span class="p">,</span> <span class="n">yy1</span><span class="p">,</span> <span class="n">yy2</span><span class="p">):</span>

        <span class="c1"># Initialisation of the variable to be returned</span>
        <span class="n">x1_rsi</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        <span class="n">x2_rsi</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        <span class="n">y1_rsi</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        <span class="n">y2_rsi</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>

        <span class="c1"># Open the data file</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="n">file_path</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">data_file</span><span class="p">:</span>

            <span class="c1"># For every line (for each isotope) ...</span>
            <span class="k">for</span> <span class="n">line_1_str</span> <span class="ow">in</span> <span class="n">data_file</span><span class="p">:</span>

                <span class="c1"># Split the line</span>
                <span class="n">split</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">line_1_str</span><span class="o">.</span><span class="n">split</span><span class="p">()]</span>

                <span class="c1"># Copy the number fraction of the isotopes (if found)</span>
                <span class="k">if</span> <span class="n">split</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">xx1</span><span class="p">:</span>
                    <span class="n">x1_rsi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">split</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">xx2</span><span class="p">:</span>
                    <span class="n">x2_rsi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">split</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">yy1</span><span class="p">:</span>
                    <span class="n">y1_rsi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
                <span class="k">if</span> <span class="n">split</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="n">yy2</span><span class="p">:</span>
                    <span class="n">y2_rsi</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

        <span class="c1"># Close the file</span>
        <span class="n">data_file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

        <span class="c1"># Return the number fractions</span>
        <span class="k">return</span> <span class="n">x1_rsi</span><span class="p">,</span> <span class="n">x2_rsi</span><span class="p">,</span> <span class="n">y1_rsi</span><span class="p">,</span> <span class="n">y2_rsi</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                  Plot MDF                  #</span>
    <span class="c1">##############################################</span>
<div class="viewcode-block" id="omega.plot_mdf"><a class="viewcode-back" href="../omega.html#omega.omega.plot_mdf">[docs]</a>    <span class="k">def</span> <span class="nf">plot_mdf</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fig</span><span class="o">=</span><span class="mi">19</span><span class="p">,</span> <span class="n">return_x_y</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">axis_mdf</span> <span class="o">=</span> <span class="s1">&#39;[Fe/H]&#39;</span><span class="p">,</span>\
        <span class="n">dx</span> <span class="o">=</span> <span class="mf">0.05</span><span class="p">,</span> <span class="n">solar_ab</span><span class="o">=</span><span class="s1">&#39;yield_tables/iniabu/iniab2.0E-02GN93.ppn&#39;</span><span class="p">,</span>\
        <span class="n">sigma_gauss</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">nb_sigma</span> <span class="o">=</span> <span class="mf">3.0</span><span class="p">,</span>\
        <span class="n">marker</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">norm</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>\
        <span class="n">color</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span><span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span>\
        <span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the stellar metallicity distribution function (MDF),</span>
<span class="sd">	or the distribution function of any other abundance ratio.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>

<span class="sd">	return_x_y : boolean</span>
<span class="sd">	     If False, show the plot.  If True, return two arrays containing</span>
<span class="sd">	     the X and Y axis data, respectively.</span>
<span class="sd">	axis_mdf : string</span>
<span class="sd">	     Abundance ratio for the distribution such as &#39;[Fe/H]&#39; or &#39;[Mg/H]&#39;.</span>
<span class="sd">	dx : float</span>
<span class="sd">	     Bin resolution of the distribution.</span>
<span class="sd">	solar_ab : string</span>
<span class="sd">	     Path to the solar abundances used to normalize abundance ratios.</span>
<span class="sd">	sigma_gauss : float</span>
<span class="sd">	     Each point in the MDF can be associated with a gaussian. This implies</span>
<span class="sd">	     that in reality, the metallicity should have a certain dispersion </span>
<span class="sd">	     when stars form at each timestep (instead of using only a single</span>
<span class="sd">	     average value).  The sigma_guass parameter sets the sigma value eac</span>
<span class="sd">	     gaussian function.</span>
<span class="sd">	nb_sigma : float</span>
<span class="sd">	     When sigma_gauss is greater than zero, nb_sigma is the number of</span>
<span class="sd">	     sigma by which the X axis range is expanded.</span>
<span class="sd">        norm : boolean</span>
<span class="sd">             Normalize the MDF is True</span>
<span class="sd">             Default : True</span>
<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	       Font size of the legend.</span>

<span class="sd">        Examples</span>
<span class="sd">	----------</span>

<span class="sd">	&gt;&gt;&gt; o1.plot_mdf(axis_mdf=&#39;[Fe/H]&#39;, sigma_gauss=0.2)</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Define variable only used for plot visual</span>
        <span class="n">source</span><span class="o">=</span><span class="s1">&#39;all&#39;</span>
        <span class="n">markevery</span> <span class="o">=</span> <span class="mi">10000</span>

        <span class="c1"># Get the [X/Y] values</span>
        <span class="n">x_min</span><span class="p">,</span> <span class="n">x_max</span><span class="p">,</span> <span class="n">x_all</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__get_XY</span><span class="p">(</span><span class="n">axis_mdf</span><span class="p">,</span> <span class="n">solar_ab</span><span class="p">)</span>

        <span class="c1"># Construct the x axis for the MDF (lower boundary of the bin)</span>
        <span class="n">mdf_x</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">mdf_y</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">x_i</span> <span class="o">=</span> <span class="n">x_min</span>
        <span class="k">while</span> <span class="n">x_i</span> <span class="o">&lt;=</span> <span class="n">x_max</span><span class="p">:</span>
            <span class="n">mdf_x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_i</span><span class="p">)</span>
            <span class="n">mdf_y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="n">x_i</span> <span class="o">+=</span> <span class="n">dx</span>
        <span class="n">mdf_x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_i</span><span class="p">)</span>
        <span class="n">mdf_y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>

        <span class="c1"># For each step in the simulation ...</span>
        <span class="c1"># len(x_all)-1 because we move by [low,up] using i_sim and i_sim+1</span>
        <span class="k">for</span> <span class="n">i_sim</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">x_all</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>

          <span class="c1"># Check if the values are ok</span>
          <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">])</span> <span class="ow">and</span> <span class="n">np</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]):</span>

            <span class="c1"># Calculate delta X / Mlocked</span>
            <span class="n">f_mlocked</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">m_locked</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span> <span class="o">/</span> \
              <span class="p">(</span><span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">])</span>

            <span class="c1"># For each MDF x bin ...</span>
            <span class="c1"># len(mdf_x)-1 because mdf_x[-1] = last upper lim</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">mdf_x</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span>

              <span class="c1"># If there is an overlap, add the corresponding mass in the bin</span>
              <span class="c1"># Bin is overlaping the lower-boundary of the simulation</span>
              <span class="k">if</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span> <span class="ow">and</span> \
                 <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> \
                 <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]:</span>
                  <span class="n">mdf_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">])</span> <span class="o">*</span> <span class="n">f_mlocked</span>

              <span class="c1"># Bin is totaly within the boundarie of the simulation </span>
              <span class="k">elif</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="ow">and</span> \
                <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]:</span>
                  <span class="n">mdf_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">f_mlocked</span> 

              <span class="c1"># Bin is overlaping the uper-boundary of the simulation</span>
              <span class="k">elif</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="ow">and</span> \
                <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="ow">and</span> \
                <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]:</span>
                  <span class="n">mdf_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">*</span> <span class="n">f_mlocked</span>

              <span class="c1"># Bin is totaly overlaping the simulation</span>
              <span class="k">elif</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;=</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span> <span class="ow">and</span> \
                <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]:</span>
                  <span class="n">mdf_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">x_all</span><span class="p">[</span><span class="n">i_sim</span><span class="p">])</span> <span class="o">*</span> <span class="n">f_mlocked</span>

        <span class="c1"># Correct the x axis to use the middle value of each bin</span>
        <span class="n">x_cor</span> <span class="o">=</span> <span class="n">dx</span><span class="o">/</span><span class="mf">2.0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">mdf_x</span><span class="p">)):</span>
            <span class="n">mdf_x</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="n">x_cor</span>

        <span class="c1"># Normalisation to 1.0 (max value)</span>
        <span class="k">if</span> <span class="n">norm</span><span class="p">:</span>
            <span class="n">cte</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="nb">max</span><span class="p">(</span><span class="n">mdf_y</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">mdf_y</span><span class="p">)):</span>
                <span class="n">mdf_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">mdf_y</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">cte</span>

        <span class="c1"># If the gaussian approximation is wanted ...</span>
        <span class="k">if</span> <span class="n">sigma_gauss</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
            <span class="n">mdf_x</span><span class="p">,</span> <span class="n">mdf_y</span> <span class="o">=</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">__gauss_approx</span><span class="p">(</span><span class="n">mdf_x</span><span class="p">,</span> <span class="n">mdf_y</span><span class="p">,</span> <span class="n">sigma_gauss</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="n">nb_sigma</span><span class="p">,</span> <span class="n">norm</span><span class="p">)</span>

        <span class="c1"># Reserved for plotting</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">return_x_y</span><span class="p">:</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="n">axis_mdf</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;$N_\star$&#39;</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">mdf_x</span><span class="p">,</span><span class="n">mdf_y</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">markevery</span><span class="o">=</span><span class="n">markevery</span><span class="p">)</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
                  <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">)</span>

        <span class="c1"># If the MDF should be returned ...</span>
        <span class="k">else</span> <span class="p">:</span>
            <span class="k">return</span> <span class="n">mdf_x</span><span class="p">,</span> <span class="n">mdf_y</span></div>


    <span class="c1">##############################################</span>
    <span class="c1">#                 Get [X/Y]                  #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__get_XY</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">axis_mdf</span> <span class="o">=</span> <span class="s1">&#39;[Fe/H]&#39;</span><span class="p">,</span> \
             <span class="n">solar_ab</span><span class="o">=</span><span class="s1">&#39;yield_tables/iniabu/iniab2.0E-02GN93.ppn&#39;</span><span class="p">):</span>

        <span class="c1"># Access solar abundance</span>
        <span class="n">iniabu</span> <span class="o">=</span> <span class="n">ry</span><span class="o">.</span><span class="n">iniabu</span><span class="p">(</span><span class="n">global_path</span><span class="o">+</span><span class="n">solar_ab</span><span class="p">)</span>
        <span class="n">x_ini_iso</span> <span class="o">=</span> <span class="n">iniabu</span><span class="o">.</span><span class="n">iso_abundance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">)</span>

        <span class="c1"># Access </span>
        <span class="n">elements</span><span class="p">,</span> <span class="n">x_ini</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_iso_abu_to_elem</span><span class="p">(</span><span class="n">x_ini_iso</span><span class="p">)</span>
        <span class="n">yields_evol</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span>

        <span class="c1"># Isolate the X and Y in [X/Y]</span>
        <span class="n">xaxis_elem1</span> <span class="o">=</span> <span class="n">axis_mdf</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span>
        <span class="n">xaxis_elem2</span> <span class="o">=</span> <span class="n">axis_mdf</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

        <span class="c1"># Get the solar values</span>
        <span class="n">x_elem1_ini</span> <span class="o">=</span> <span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)]</span>
        <span class="n">x_elem2_ini</span> <span class="o">=</span> <span class="n">x_ini</span><span class="p">[</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)]</span>

        <span class="c1"># Get the simulation values</span>
        <span class="n">elem_idx1</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem1</span><span class="p">)</span>
        <span class="n">elem_idx2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">xaxis_elem2</span><span class="p">)</span>

        <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">x_no_inf</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># Calculate [X/Y] at each timestep</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">)):</span>
            <span class="n">x1</span> <span class="o">=</span> <span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx1</span><span class="p">]</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="n">x2</span> <span class="o">=</span> <span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">elem_idx2</span><span class="p">]</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">yields_evol</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
            <span class="n">spec</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x1</span><span class="o">/</span><span class="n">x2</span><span class="p">)</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">log10</span><span class="p">(</span><span class="n">x_elem1_ini</span><span class="o">/</span><span class="n">x_elem2_ini</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">spec</span><span class="p">):</span>
                <span class="n">x_no_inf</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>
            <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>

        <span class="c1"># Return [X/Y]_min, [X/Y]_max, and the [X/Y] array</span>
        <span class="n">x_no_inf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">x_no_inf</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">x_no_inf</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">x_no_inf</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">x</span>


    <span class="c1">##############################################</span>
    <span class="c1">#               Gauss Approx.                #</span>
    <span class="c1">##############################################</span>
    <span class="k">def</span> <span class="nf">__gauss_approx</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mdf_x</span><span class="p">,</span> <span class="n">mdf_y</span><span class="p">,</span> <span class="n">sigma_gauss</span><span class="p">,</span> <span class="n">dx</span><span class="p">,</span> <span class="n">nb_sigma</span><span class="p">,</span> <span class="n">norm</span><span class="p">):</span>

        <span class="c1"># Declaration of the MDF after the gaussian approximation</span>
        <span class="n">mdf_y_ga</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Number of bins</span>
        <span class="n">nb_bin_ga</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">mdf_x</span><span class="p">)</span>

        <span class="c1"># Constant in the gaussian</span>
        <span class="n">cte_ga</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">sigma_gauss</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

        <span class="c1"># For each bin on the x axis ...</span>
        <span class="k">for</span> <span class="n">i_ga</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">nb_bin_ga</span><span class="p">):</span>

            <span class="c1"># Add the contribution of all the other bins</span>
            <span class="n">mdf_y_ga</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">j_ga</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">nb_bin_ga</span><span class="p">):</span>
                <span class="n">mdf_y_ga</span><span class="p">[</span><span class="n">i_ga</span><span class="p">]</span> <span class="o">+=</span> <span class="n">mdf_y</span><span class="p">[</span><span class="n">j_ga</span><span class="p">]</span> <span class="o">*</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">((</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">cte_ga</span> <span class="o">*</span> <span class="p">(</span><span class="n">mdf_x</span><span class="p">[</span><span class="n">i_ga</span><span class="p">]</span><span class="o">-</span><span class="n">mdf_x</span><span class="p">[</span><span class="n">j_ga</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>

        <span class="c1"># Add a few sigma at higher Z ...</span>
        <span class="n">x_ga</span> <span class="o">=</span> <span class="n">mdf_x</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">dx</span>
        <span class="n">x_ga_max</span> <span class="o">=</span> <span class="n">x_ga</span> <span class="o">+</span> <span class="n">nb_sigma</span> <span class="o">*</span> <span class="n">sigma_gauss</span>
        <span class="n">i_ga</span> <span class="o">=</span> <span class="n">nb_bin_ga</span>
        <span class="k">while</span> <span class="n">x_ga</span> <span class="o">&lt;</span> <span class="n">x_ga_max</span><span class="p">:</span>
            <span class="n">mdf_x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">x_ga</span><span class="p">)</span>
            <span class="n">mdf_y_ga</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">j_ga</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">nb_bin_ga</span><span class="p">):</span>
                <span class="n">mdf_y_ga</span><span class="p">[</span><span class="n">i_ga</span><span class="p">]</span> <span class="o">+=</span> <span class="n">mdf_y</span><span class="p">[</span><span class="n">j_ga</span><span class="p">]</span> <span class="o">*</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">((</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="n">cte_ga</span> <span class="o">*</span> <span class="p">(</span><span class="n">mdf_x</span><span class="p">[</span><span class="n">i_ga</span><span class="p">]</span><span class="o">-</span><span class="n">mdf_x</span><span class="p">[</span><span class="n">j_ga</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">i_ga</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">x_ga</span> <span class="o">+=</span> <span class="n">dx</span>

        <span class="c1"># Renormalization to one (max value)</span>
        <span class="k">if</span> <span class="n">norm</span><span class="p">:</span>
            <span class="n">cte</span> <span class="o">=</span> <span class="mf">1.0</span> <span class="o">/</span> <span class="nb">max</span><span class="p">(</span><span class="n">mdf_y_ga</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">mdf_y_ga</span><span class="p">)):</span>
                <span class="n">mdf_y_ga</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">mdf_y_ga</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> <span class="n">cte</span>       

        <span class="k">return</span> <span class="n">mdf_x</span><span class="p">,</span> <span class="n">mdf_y_ga</span>


    <span class="c1">##############################################</span>
    <span class="c1">#                 Plot Abun                  #</span>
    <span class="c1">##############################################</span>

<div class="viewcode-block" id="omega.plot_abun"><a class="viewcode-back" href="../omega.html#omega.omega.plot_abun">[docs]</a>    <span class="k">def</span> <span class="nf">plot_abun</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fig</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">age</span><span class="o">=</span><span class="mf">9.2e9</span><span class="p">,</span>\
        <span class="n">solar_norm</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">iso_on</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
        <span class="n">list_elem</span><span class="o">=</span><span class="p">[],</span> <span class="n">list_iso</span><span class="o">=</span><span class="p">[],</span><span class="n">return_x_y</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">over_plot_solar</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>\
        <span class="n">solar_ab_m</span><span class="o">=</span><span class="s1">&#39;yield_tables/iniabu/iniab2.0E-02GN93.ppn&#39;</span><span class="p">,</span> <span class="n">f_y_annotate</span><span class="o">=</span><span class="mf">0.9</span><span class="p">,</span>\
        <span class="n">marker</span><span class="o">=</span><span class="s1">&#39;o&#39;</span><span class="p">,</span><span class="n">marker_s</span><span class="o">=</span><span class="s1">&#39;^&#39;</span><span class="p">,</span><span class="n">shape</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="n">shape_s</span><span class="o">=</span><span class="s1">&#39;-&#39;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">color_s</span><span class="o">=</span><span class="s1">&#39;r&#39;</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s1">&#39;Prediction&#39;</span><span class="p">,</span><span class="n">label_s</span><span class="o">=</span><span class="s1">&#39;solar&#39;</span><span class="p">,</span><span class="n">fsize</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mf">4.5</span><span class="p">],</span>\
        <span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span><span class="n">rspace</span><span class="o">=</span><span class="mf">0.6</span><span class="p">,</span><span class="n">bspace</span><span class="o">=</span><span class="mf">0.15</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>\
        <span class="n">legend_fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="mi">5</span><span class="p">):</span>

        <span class="sd">&#39;&#39;&#39;</span>
<span class="sd">	This function plots the abundance distribution in mass</span>
<span class="sd">        fraction at any given point in time or at any given metallicity.</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">	age : float</span>
<span class="sd">	     Time passed since the beginning of the simulation at which abundance distribution is taken.</span>
<span class="sd">             Default: Time until the formation of the pre-solar cloud. </span>
<span class="sd">        solar_norm: boolean</span>
<span class="sd">             If True, the abundances will be divide by the solar abundances.</span>
<span class="sd">             If False, there is no normalization.</span>
<span class="sd">             Default: False</span>
<span class="sd">        iso_on : boolean</span>
<span class="sd">             If True, the abundances will be in terms of isotopes.</span>
<span class="sd">             If False, the abundances will be in terms of elements.</span>
<span class="sd">        list_elem : array of strings</span>
<span class="sd">             Contain the list of elements included in the abundances distribution.</span>
<span class="sd">             Default: [], all elements will be included.</span>
<span class="sd">             Example: list_elem=[&#39;H&#39;,&#39;He&#39;,&#39;C&#39;,&#39;N&#39;,&#39;O&#39;,&#39;Fe&#39;]</span>
<span class="sd">        list_iso : array of strings</span>
<span class="sd">             Contain the list of isotopes included in the abundances distribution.</span>
<span class="sd">             Default: [], all isotopes will be included.</span>
<span class="sd">             Example: list_iso=[&#39;H-1&#39;,&#39;C-12&#39;,&#39;C-13&#39;,&#39;N-14&#39;,&#39;N-15&#39;]</span>
<span class="sd">             Note: list_iso dominates over list_elem is both are used.</span>
<span class="sd">	return_x_y : boolean</span>
<span class="sd">	     If False, show the plot.</span>
<span class="sd">             If True, return two arrays containing the X and Y axis data, respectively.</span>
<span class="sd">             If True and iso_list=True, return a multi-D array [i][j][:] where</span>
<span class="sd">             j=0 -&gt; list of mass numbers A for the isotopes associated with the element i,</span>
<span class="sd">             j=1 -&gt; list of abundances</span>
<span class="sd">        over_plot_solar : boolean</span>
<span class="sd">             If True, plot the solar abundances distribution along with the predictions</span>
<span class="sd">             Note: This option is desactivated if solar_norm=True</span>
<span class="sd">        solar_ab_m : string</span>
<span class="sd">             Path of the solar normalization containing the mass fraction of each isotope</span>
<span class="sd">             Default: solar_ab_m=&#39;yield_tables/iniabu/iniab2.0E-02GN93.ppn&#39;</span>
<span class="sd">        f_y_annotate : float (between 0 and 1)</span>
<span class="sd">             Fraction of the Y axis where the name of the element will be shown</span>
<span class="sd">             Default: f_y_annotate=0.9</span>
<span class="sd">        fig : string, float</span>
<span class="sd">	     Figure name.</span>
<span class="sd">	marker : string</span>
<span class="sd">	     Figure marker.</span>
<span class="sd">	marker_s : string</span>
<span class="sd">	     Marker of the solar abundance distribution.</span>
<span class="sd">	shape : string</span>
<span class="sd">	     Line style.</span>
<span class="sd">        shape_s : string</span>
<span class="sd">	     Line style of the solar abundance distribution.</span>
<span class="sd">	color : string</span>
<span class="sd">	     Line color.</span>
<span class="sd">	color_s : string</span>
<span class="sd">	     Line color of the solar abundances pattern.</span>
<span class="sd">	label : string</span>
<span class="sd">	     Figure label.</span>
<span class="sd">	label_s : string</span>
<span class="sd">            Label of the solar abundance distribution.</span>
<span class="sd">	fsize : 2D float array</span>
<span class="sd">	     Figure dimension/size.</span>
<span class="sd">	fontsize : integer</span>
<span class="sd">	     Font size of the numbers on the X and Y axis.</span>
<span class="sd">	rspace : float</span>
<span class="sd">	     Extra space on the right for the legend.</span>
<span class="sd">	bspace : float</span>
<span class="sd">	     Extra space at the bottom for the Y axis label.</span>
<span class="sd">	labelsize : integer</span>
<span class="sd">	     Font size of the X and Y axis labels.</span>
<span class="sd">	legend_fontsize : integer</span>
<span class="sd"> 	     Font size of the legend.</span>
<span class="sd">        markersize : float</span>
<span class="sd">             Size of the markers</span>
<span class="sd">             Default: markersize=5</span>

<span class="sd">        &#39;&#39;&#39;</span>

        <span class="c1"># Copy the list of selected isotopes</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_iso</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="n">iso_list_raw</span> <span class="o">=</span> <span class="n">list_iso</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">iso_list_raw</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span>

        <span class="c1"># Make sure to remove Pb, as it is not in the right order in the yields..</span>
        <span class="c1"># This is causing problems.</span>
        <span class="n">iso_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_list_raw</span><span class="p">)):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">iso_list_raw</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Pb&#39;</span><span class="p">:</span>
                <span class="n">iso_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">iso_list_raw</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>

        <span class="c1"># Read the solar normalization</span>
        <span class="n">solar_file</span> <span class="o">=</span> <span class="n">ry</span><span class="o">.</span><span class="n">iniabu</span><span class="p">(</span><span class="n">global_path</span> <span class="o">+</span> <span class="n">solar_ab_m</span><span class="p">)</span>

        <span class="c1"># Make sure the wanted isotopes are available</span>
        <span class="k">for</span> <span class="n">i_iso</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">iso_list</span><span class="p">)):</span>
            <span class="k">if</span> <span class="n">iso_list</span><span class="p">[</span><span class="n">i_iso</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="p">:</span>
                <span class="k">print</span> <span class="n">iso_list</span><span class="p">[</span><span class="n">i_iso</span><span class="p">],</span> <span class="s1">&#39; is not available..&#39;</span>
                <span class="k">return</span>

        <span class="c1"># Recover the solar isotopes mass fractions</span>
        <span class="n">iso_sol</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">solar_file</span><span class="o">.</span><span class="n">iso_abundance</span><span class="p">(</span><span class="n">iso_list</span><span class="p">))</span>

        <span class="c1"># Copy the name of selected elements and isotopes</span>
        <span class="n">iso_names_lower</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i_el</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_list</span><span class="p">)):</span>
            <span class="n">iso_names_lower</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">iso_list</span><span class="p">[</span><span class="n">i_el</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>

        <span class="c1"># Copy the list of selected elements</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_elem</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">list_iso</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
             <span class="k">print</span> <span class="s1">&#39;The list_elem option is not implemented yet..&#39;</span>
        <span class="c1">#    if elements are selected </span>
        <span class="k">if</span> <span class="bp">True</span><span class="p">:</span>  <span class="c1"># Shoul be else once the list_elem is implemented..</span>
            <span class="n">elem_sol_temp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_iso_abu_to_elem</span><span class="p">(</span><span class="n">iso_sol</span><span class="p">,</span> <span class="n">iso_list</span><span class="o">=</span><span class="n">iso_list</span><span class="p">)</span>
            <span class="n">elem_names</span> <span class="o">=</span> <span class="n">elem_sol_temp</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>  <span class="c1"># Name of element</span>
            <span class="n">elem_sol</span> <span class="o">=</span> <span class="n">elem_sol_temp</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>    <span class="c1"># Solar elemental abundances</span>

        <span class="c1"># Define the charges (Z)</span>
        <span class="n">Z_numbers</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Define the iso array [element][0 -&gt; A; 1 -&gt; abundance]</span>
        <span class="n">iso_array_sol</span> <span class="o">=</span> <span class="p">[]</span>
    
        <span class="c1"># For all isotopes found in the solar file</span>
        <span class="n">i_Z_index</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        <span class="k">for</span> <span class="n">i_iso</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">solar_file</span><span class="o">.</span><span class="n">names</span><span class="p">)):</span>
    
            <span class="c1"># Extract the name (in lower cases) and the A number</span>
            <span class="n">name_temp</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="n">A_temp</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="k">for</span> <span class="n">i_el</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">solar_file</span><span class="o">.</span><span class="n">names</span><span class="p">[</span><span class="n">i_iso</span><span class="p">])):</span>
                <span class="k">if</span> <span class="n">solar_file</span><span class="o">.</span><span class="n">names</span><span class="p">[</span><span class="n">i_iso</span><span class="p">][</span><span class="n">i_el</span><span class="p">]</span><span class="o">.</span><span class="n">isdigit</span><span class="p">():</span>
                    <span class="n">A_temp</span> <span class="o">+=</span> <span class="n">solar_file</span><span class="o">.</span><span class="n">names</span><span class="p">[</span><span class="n">i_iso</span><span class="p">][</span><span class="n">i_el</span><span class="p">]</span>
                <span class="k">elif</span> <span class="ow">not</span> <span class="n">solar_file</span><span class="o">.</span><span class="n">names</span><span class="p">[</span><span class="n">i_iso</span><span class="p">][</span><span class="n">i_el</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39; &#39;</span><span class="p">:</span>
                    <span class="n">name_temp</span> <span class="o">+=</span> <span class="n">solar_file</span><span class="o">.</span><span class="n">names</span><span class="p">[</span><span class="n">i_iso</span><span class="p">][</span><span class="n">i_el</span><span class="p">]</span>
            <span class="n">A_temp</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">A_temp</span><span class="p">)</span>
            <span class="n">iso_temp</span> <span class="o">=</span> <span class="n">name_temp</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">A_temp</span><span class="p">)</span>
            <span class="n">name_temp_upper</span> <span class="o">=</span> <span class="n">name_temp</span><span class="o">.</span><span class="n">title</span><span class="p">()</span>
    
            <span class="c1"># If the isotope or element is considered ..</span>
            <span class="n">considered</span> <span class="o">=</span> <span class="bp">False</span>
            <span class="c1">#if len(list_elem) &gt; 0 and len(list_iso) == 0:</span>
            <span class="c1">#    if name_temp_upper in elem_sol:</span>
            <span class="c1">#        considered = True</span>
            <span class="k">if</span> <span class="n">iso_temp</span> <span class="ow">in</span> <span class="n">iso_names_lower</span><span class="p">:</span>
                <span class="n">considered</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="k">if</span> <span class="n">considered</span><span class="p">:</span>

                <span class="c1"># Add the selected Z and A numbers</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">solar_file</span><span class="o">.</span><span class="n">z</span><span class="p">[</span><span class="n">i_iso</span><span class="p">]</span> <span class="ow">in</span> <span class="n">Z_numbers</span><span class="p">:</span>
                    <span class="n">Z_numbers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">solar_file</span><span class="o">.</span><span class="n">z</span><span class="p">[</span><span class="n">i_iso</span><span class="p">])</span>
                    <span class="c1"># Should take the solar element abundances here..</span>
                    <span class="n">i_Z_index</span> <span class="o">+=</span> <span class="mi">1</span>
                    <span class="n">iso_array_sol</span><span class="o">.</span><span class="n">append</span><span class="p">([[],[],[],[]])</span>
                <span class="n">i_iso_index</span> <span class="o">=</span> <span class="n">iso_names_lower</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">iso_temp</span><span class="p">)</span>
                <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">A_temp</span><span class="p">)</span>
                <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">iso_sol</span><span class="p">[</span><span class="n">i_iso_index</span><span class="p">])</span>
                <span class="n">iso_name_index</span> <span class="o">=</span> <span class="n">iso_names_lower</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">iso_temp</span><span class="p">)</span>
                <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">iso_list</span><span class="p">[</span><span class="n">iso_name_index</span><span class="p">])</span>
                <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name_temp_upper</span><span class="p">)</span>

	<span class="c1"># Get the index for given age</span>
	<span class="n">ages</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">age</span>
	<span class="n">timesteps</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">timesteps</span>
	<span class="n">i_sim</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">ages</span><span class="p">)),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="nb">abs</span><span class="p">(</span><span class="n">ages</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-</span><span class="n">age</span><span class="p">))</span>

	<span class="k">print</span> <span class="s1">&#39;Extract abundance from closest available time &#39;</span><span class="p">,</span><span class="s1">&#39;{:.3E}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ages</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]),</span><span class="s1">&#39; yrs&#39;</span>	

        <span class="c1"># Get the mass of elements and isotopes at the desired time</span>
        <span class="n">ymgal_el_sim</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_elem_yield</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span>
        <span class="n">ymgal_iso_sim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">ism_iso_yield</span><span class="p">[</span><span class="n">i_sim</span><span class="p">]</span>
        <span class="n">ism_mass_sim</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">ymgal_el_sim</span><span class="p">)</span>

        <span class="c1"># Define the predicted element and isotope mass fractions</span>
        <span class="n">elem_m_frac_sim</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">iso_m_frac_sim</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i_Z_index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">)):</span>
            <span class="n">iso_m_frac_sim</span><span class="o">.</span><span class="n">append</span><span class="p">([])</span>

        <span class="c1"># For each selected element and isotope ..</span>
        <span class="k">for</span> <span class="n">i_Z_index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">)):</span>
    
            <span class="c1"># Get the mass of the current element</span>
            <span class="n">i_Z_sim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">elements</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">3</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
            <span class="n">elem_m_frac_sim</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ymgal_el_sim</span><span class="p">[</span><span class="n">i_Z_sim</span><span class="p">]</span><span class="o">/</span><span class="n">ism_mass_sim</span><span class="p">)</span>
    
            <span class="c1"># For isotope having the same Z number ..</span>
            <span class="k">for</span> <span class="n">i_iso_index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">0</span><span class="p">])):</span>
                <span class="n">i_iso_sim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">history</span><span class="o">.</span><span class="n">isotopes</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">][</span><span class="mi">2</span><span class="p">][</span><span class="n">i_iso_index</span><span class="p">])</span>
                <span class="n">iso_m_frac_sim</span><span class="p">[</span><span class="n">i_Z_index</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ymgal_iso_sim</span><span class="p">[</span><span class="n">i_iso_sim</span><span class="p">]</span><span class="o">/</span><span class="n">ism_mass_sim</span><span class="p">)</span>

        <span class="c1"># Normalize the predictions if needed ..</span>
        <span class="k">if</span> <span class="n">solar_norm</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i_Z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">)):</span>
                <span class="n">elem_m_frac_sim</span><span class="p">[</span><span class="n">i_Z</span><span class="p">]</span> <span class="o">=</span> <span class="n">elem_m_frac_sim</span><span class="p">[</span><span class="n">i_Z</span><span class="p">]</span> <span class="o">/</span> <span class="n">elem_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">i_iso</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">1</span><span class="p">])):</span>
                    <span class="n">iso_m_frac_sim</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span> <span class="o">=</span> <span class="n">iso_m_frac_sim</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span> <span class="o">/</span> <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">1</span><span class="p">][</span><span class="n">i_iso</span><span class="p">]</span>

        <span class="c1"># Calculate the min and max value of the A number</span>
        <span class="n">A_nb_min</span> <span class="o">=</span> <span class="mi">1000</span>
        <span class="n">A_nb_max</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1000</span>
        <span class="k">for</span> <span class="n">i_Z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">)):</span>
            <span class="k">if</span> <span class="nb">max</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">&gt;</span> <span class="n">A_nb_max</span><span class="p">:</span>
                <span class="n">A_nb_max</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>
            <span class="k">if</span> <span class="nb">min</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">&lt;</span> <span class="n">A_nb_min</span><span class="p">:</span>
                <span class="n">A_nb_min</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>

        <span class="c1"># If the data needs to be returned ..</span>
        <span class="k">if</span> <span class="n">return_x_y</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">iso_on</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">iso_m_frac_sim</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="n">Z_numbers</span><span class="p">,</span> <span class="n">elem_m_frac_sim</span>

        <span class="c1"># If a figure is generated ..</span>
        <span class="k">else</span><span class="p">:</span>

            <span class="c1"># Plot the frame</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="n">fig</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="n">fsize</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fsize</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
            <span class="n">source</span> <span class="o">=</span> <span class="s1">&#39;all&#39;</span>
            <span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">__msc</span><span class="p">(</span><span class="n">source</span><span class="p">,</span><span class="n">shape</span><span class="p">,</span><span class="n">marker</span><span class="p">,</span><span class="n">color</span><span class="p">)</span>

            <span class="c1"># If isotopes abundances ..</span>
            <span class="k">if</span> <span class="n">iso_on</span><span class="p">:</span>

                <span class="c1"># Plot the isotopes of each elements</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">solar_norm</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;X(A)/X(A)$_\odot$&#39;</span><span class="p">)</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">A_nb_min</span><span class="p">,</span><span class="n">A_nb_max</span><span class="p">],[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;--k&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;X(A)&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">over_plot_solar</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">i_Z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">)):</span>
                            <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">&#39;--&#39;</span><span class="p">,</span>\
                                 <span class="n">color</span><span class="o">=</span><span class="n">color_s</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span>
                        <span class="c1"># Get the legend</span>
                        <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">1</span><span class="p">],</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">&#39;--&#39;</span><span class="p">,</span>\
                             <span class="n">color</span><span class="o">=</span><span class="n">color_s</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="s1">&#39;Solar&#39;</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">i_Z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">)):</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">iso_m_frac_sim</span><span class="p">[</span><span class="n">i_Z</span><span class="p">],</span> <span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span>\
                         <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span>
                <span class="c1"># Get the legend</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">iso_array_sol</span><span class="p">[</span><span class="n">i_Z</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">iso_m_frac_sim</span><span class="p">[</span><span class="n">i_Z</span><span class="p">],</span> <span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span>\
                     <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span>

                <span class="c1"># Annotate the element</span>
                <span class="c1">#ylimm = np.array(plt.gca().get_ylim())</span>
                <span class="c1">#if ylimm[0] == 0.0:</span>
                <span class="c1">#    ylimm[0] = 1.0e-15</span>
                <span class="c1">#print ylimm</span>
                <span class="c1">#yrange = np.log10(ylimm[1]) - np.log10(ylimm[0])</span>
                <span class="c1">#y_an = 10**(ylimm[1] - yrange * (1 - f_y_annotate))</span>
                <span class="c1">#for i_Z in range(len(iso_array_sol)):</span>
                <span class="c1">#    plt.annotate(iso_array_sol[i_Z][3][0], xy=(iso_array_sol[i_Z][0][0],y_an))</span>
                <span class="c1">#    print iso_array_sol[i_Z][3][0], iso_array_sol[i_Z][0][0],y_an</span>

            <span class="c1"># If elemental abundances ..</span>
            <span class="k">else</span><span class="p">:</span>

                <span class="c1"># Plot the isotopes of each elements</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s1">&#39;Z&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">solar_norm</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;X(Z)/X(Z)$_\odot$&#39;</span><span class="p">)</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="n">Z_numbers</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">Z_numbers</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]],[</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;--k&#39;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s1">&#39;X(Z)&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">over_plot_solar</span><span class="p">:</span>
                        <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Z_numbers</span><span class="p">,</span> <span class="n">elem_sol</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="n">shape_s</span><span class="p">,</span>\
                             <span class="n">color</span><span class="o">=</span><span class="n">color_s</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label_s</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker_s</span><span class="p">,</span><span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span>
                <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">Z_numbers</span><span class="p">,</span> <span class="n">elem_m_frac_sim</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span>\
                         <span class="n">color</span><span class="o">=</span><span class="n">color</span><span class="p">,</span><span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span><span class="n">marker</span><span class="o">=</span><span class="n">marker</span><span class="p">,</span><span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span>

            <span class="c1"># Plot visual aspect</span>
            <span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">&#39;log&#39;</span><span class="p">)</span>
	    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">label</span><span class="p">)</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">:</span>
	            <span class="n">plt</span><span class="o">.</span><span class="n">legend</span><span class="p">()</span>
            <span class="n">ax</span><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">__fig_standard</span><span class="p">(</span><span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span><span class="n">fontsize</span><span class="o">=</span><span class="n">fontsize</span><span class="p">,</span><span class="n">labelsize</span><span class="o">=</span><span class="n">labelsize</span><span class="p">,</span>\
               <span class="n">rspace</span><span class="o">=</span><span class="n">rspace</span><span class="p">,</span> <span class="n">bspace</span><span class="o">=</span><span class="n">bspace</span><span class="p">,</span><span class="n">legend_fontsize</span><span class="o">=</span><span class="n">legend_fontsize</span><span class="p">,</span> <span class="n">markersize</span><span class="o">=</span><span class="n">markersize</span><span class="p">)</span></div></div>

</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">SYGMA DOC v1.0 documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &copy; Copyright 2014, Christian Ritter.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.5.
    </div>
  </body>
</html>