In [1]:
%matplotlib inline
import sygma
import numpy as np
import matplotlib.pyplot as plt
mpl.use('Agg')
mpl.rcParams['hatch.linewidth'] = 8
from matplotlib import rc, cm
viridis = cm.get_cmap('viridis')
magma   = cm.get_cmap('magma')
plasma  = cm.get_cmap('plasma')

fsize = 17
rc('text', usetex=False)
rc('font', size=fsize)#, ftype=42)
line_width = 3.5
point_size = 30


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-1cc4927af270> in <module>()
      1 get_ipython().magic(u'matplotlib inline')
----> 2 import sygma
      3 import numpy as np
      4 import matplotlib.pyplot as plt
      5 mpl.use('Agg')

ImportError: No module named sygma

In [3]:


In [52]:
s0   = sygma.sygma(mgal=1.0, iniZ=0.0001)
s1   = sygma.sygma(mgal=1.0, iniZ=0.001)
s2   = sygma.sygma(mgal=1.0, iniZ=0.006)
s3   = sygma.sygma(mgal=1.0, iniZ=0.01)
s4   = sygma.sygma(mgal=1.0, iniZ=0.02)
s4   = sygma.sygma(mgal=1.0, iniZ=0.03)


SYGMA run in progress..
   SYGMA run completed - Run time: 0.36s
SYGMA run in progress..
   SYGMA run completed - Run time: 0.36s
SYGMA run in progress..
   SYGMA run completed - Run time: 0.36s
SYGMA run in progress..
   SYGMA run completed - Run time: 0.37s
SYGMA run in progress..
   SYGMA run completed - Run time: 0.37s

UnboundLocalErrorTraceback (most recent call last)
<ipython-input-52-914119975926> in <module>()
      4 s3   = sygma.sygma(mgal=1.0, iniZ=0.01)
      5 s4   = sygma.sygma(mgal=1.0, iniZ=0.02)
----> 6 s4   = sygma.sygma(mgal=1.0, iniZ=0.03)

/opt/NuPyCEE/sygma.py in __init__(self, sfr, imf_type, alphaimf, imf_bdys, sn1a_rate, iniZ, dt, special_timesteps, nsmerger_bdys, tend, mgal, transitionmass, iolevel, ini_alpha, table, hardsetZ, sn1a_on, sn1a_table, sn1a_energy, ns_merger_on, bhns_merger_on, f_binary, f_merger, t_merger_max, m_ej_nsm, nsm_dtd_power, m_ej_bhnsm, bhnsmerger_table, nsmerger_table, iniabu_table, extra_source_on, nb_nsm_per_m, t_nsm_coal, extra_source_table, f_extra_source, pre_calculate_SSPs, extra_source_mass_range, extra_source_exclude_Z, pop3_table, imf_bdys_pop3, imf_yields_range_pop3, starbursts, beta_pow, gauss_dtd, exp_dtd, nb_1a_per_m, direct_norm_1a, Z_trans, f_arfo, imf_yields_range, exclude_masses, netyields_on, wiersmamod, yield_interp, stellar_param_on, t_dtd_poly_split, stellar_param_table, tau_ferrini, delayed_extra_log, dt_in, nsmerger_dtd_array, bhnsmerger_dtd_array, ytables_in, zm_lifetime_grid_nugrid_in, isotopes_in, ytables_pop3_in, zm_lifetime_grid_pop3_in, ytables_1a_in, mass_sampled, scale_cor, poly_fit_dtd_5th, poly_fit_range, ytables_nsmerger_in, dt_split_info, delayed_extra_dtd, delayed_extra_dtd_norm, delayed_extra_yields, delayed_extra_yields_norm)
    187                  delayed_extra_dtd_norm=delayed_extra_dtd_norm,\
    188                  delayed_extra_yields=delayed_extra_yields,\
--> 189                  delayed_extra_yields_norm=delayed_extra_yields_norm)
    190 
    191         if self.need_to_quit:

/opt/NuPyCEE/chem_evol.py in __init__(self, imf_type, alphaimf, imf_bdys, sn1a_rate, iniZ, dt, special_timesteps, nsmerger_bdys, tend, mgal, transitionmass, iolevel, ini_alpha, table, hardsetZ, sn1a_on, sn1a_table, sn1a_energy, ns_merger_on, bhns_merger_on, f_binary, f_merger, t_merger_max, m_ej_nsm, nb_nsm_per_m, t_nsm_coal, m_ej_bhnsm, nsm_dtd_power, bhnsmerger_table, nsmerger_table, iniabu_table, extra_source_on, extra_source_table, f_extra_source, pre_calculate_SSPs, extra_source_mass_range, extra_source_exclude_Z, pop3_table, imf_bdys_pop3, imf_yields_range_pop3, starbursts, beta_pow, gauss_dtd, exp_dtd, nb_1a_per_m, direct_norm_1a, Z_trans, f_arfo, imf_yields_range, exclude_masses, netyields_on, wiersmamod, yield_interp, total_ejecta_interp, tau_ferrini, input_yields, t_merge, stellar_param_on, stellar_param_table, popIII_on, out_follows_E_rate, t_dtd_poly_split, delayed_extra_log, ism_ini, nsmerger_dtd_array, bhnsmerger_dtd_array, ytables_in, zm_lifetime_grid_nugrid_in, isotopes_in, ytables_pop3_in, zm_lifetime_grid_pop3_in, ytables_1a_in, ytables_nsmerger_in, dt_in_SSPs, dt_in, dt_split_info, ej_massive, ej_agb, ej_sn1a, ej_massive_coef, ej_agb_coef, ej_sn1a_coef, dt_ssp, poly_fit_dtd_5th, mass_sampled_ssp, scale_cor_ssp, poly_fit_range, SSPs_in, delayed_extra_dtd, delayed_extra_dtd_norm, delayed_extra_yields, delayed_extra_yields_norm)
    628 
    629         # Initialisation of the composition of the gas reservoir
--> 630         ymgal = self._get_iniabu()
    631         self.len_ymgal = len(ymgal)
    632 

/opt/NuPyCEE/chem_evol.py in _get_iniabu(self)
    905 
    906             # Assign the composition to the gas reservoir
--> 907             ymgal_gi = np.array(iniabu.iso_abundance(self.history.isotopes)) * \
    908                        self.mgal
    909 

UnboundLocalError: local variable 'iniabu' referenced before assignment

In [14]:
def compute_y(data, field):
    x = data.history.age
    x = np.array(x[1:])/1.0E9
    yields  = data.history.ism_elem_yield
    agb     = data.history.ism_elem_yield_agb
    massive = data.history.ism_elem_yield_massive

    idx=data.history.elements.index(field)
    y = []
    yagb = []
    ymassive = []
    for k in range(len(yields)):
        y.append(yields[k][idx])
        yagb.append(agb[k][idx])
        ymassive.append(massive[k][idx])

    yplot = np.array(yagb[1:]) / np.array(y[1:])
    
    return x, yplot

def compute_agb_fraction(data, field, time):
    
    t, y = compute_y(data, field) # grabs agb fraction vs. time

    return np.interp(time, t, y)

In [45]:
all_elements  = s0.history.elements[2:55]
plot_elements = []
for f in all_elements:
    if (compute_agb_fraction(s3, f, 10.0) > 0.5):
        plot_elements.append(f)


/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:17: RuntimeWarning: invalid value encountered in divide

In [46]:
print plot_elements, np.size(plot_elements)


['Li', 'B', 'C', 'N', 'F', 'Pb', 'Rb', 'Y', 'Zr', 'Nb', 'Mo', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba'] 24

In [71]:
fields = ['C','N','O','Na','Mg','Si','S','Ca','Mn','Fe','Ni','As','Sr','Y','Ba']

fields = ['Li','C','N','F','O','Ne','Na','Mg','Al','As','Sr','Pb','Y','Ag','Ba']

DF = s1
outname = 'Half_AGB_Fraction_elements_s1.png'


all_times = [40, 100, 1000, 10000]
t_label   = {40 : '40 Myr',100:'100 Myr',1000:'1 Gyr',10000:'10 Gyr'}
colors    = {40 : "C0", 100 : "C1", 1000 : "C2", 10000 : "C3"}
markers =  {40 : 'o', 100 : 's' , 1000 : 'd' , 10000 : '*'}

fig, ax = plt.subplots()
fig.set_size_inches(12,6)

index = np.arange(np.size(fields))
ax.set_xticks(index)
ax.set_xticklabels(fields)

for time in all_times:
    yvals = np.zeros(np.size(fields))
    
    i = 0
    for f in fields:
        yvals[i] = compute_agb_fraction(DF, f, time / 1.0E3)
        i = i + 1
        
    ax.scatter(index, yvals, color = colors[time], marker = markers[time],
               s = 80, label = t_label[time])
    ax.scatter(index, yvals, color = colors[time], lw = 1.5)
    
x = np.arange(-5,np.size(fields)+2)
ax.plot(x,[0.5]*np.size(x), ls = '--', color = 'black', lw = 2)

ax.set_xlim(-1,np.size(fields))
ax.legend(loc='lower left', ncol = 4)
ax.semilogy()
ax.set_ylim(0.006, 1.0)
ax.set_ylabel('AGB Contribution Fraction')
fig.savefig(outname)


/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:17: RuntimeWarning: invalid value encountered in divide

In [25]:
fields = ['C','N','O','Na','Mg','Si','S','Ca','Mn','Fe','Ni','As','Sr','Y','Ba']

fields = ['C','N','O','F','Ne','Na','Mg','Al','As','Sr','Y','Ag','Ba','Eu']

all_times = [40, 100, 1000, 10000]
t_label   = {40 : '40 Myr',100:'100 Myr',1000:'1 Gyr',10000:'10 Gyr'}
colors    = {40 : "C0", 100 : "C1", 1000 : "C2", 10000 : "C3"}

markers = {}
for k in colors.keys():
    markers[k] = 'o'


fig, ax = plt.subplots()
fig.set_size_inches(12,6)

index = np.arange(np.size(fields))
ax.set_xticks(index)
ax.set_xticklabels(fields)

for time in all_times:
    yvals = np.zeros(np.size(fields))
    
    i = 0
    for f in fields:
        yvals[i] = compute_agb_fraction(s0, f, time / 1.0E3)
        i = i + 1
        
    ax.scatter(index, yvals, color = colors[time], marker = markers[time],
               s = 40, label = t_label[time])
ax.legend(loc='best')
ax.semilogy()
ax.set_ylim(0.01, 1.0)
ax.set_ylabel('AGB Contribution Fraction')
fig.savefig('AGB_Fraction_elements.png')


/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:17: RuntimeWarning: invalid value encountered in divide

In [41]:
fig, ax = plt.subplots()
fig.set_size_inches(8,8)

x,y = compute_y(s0, 'C')
ax.plot(x, y, lw = 3, color = 'C0', ls = '-', label = 'C')
x,y = compute_y(s1, 'C')
ax.plot(x, y, lw = 3, color = 'C0', ls = '--')
x,y = compute_y(s3, 'C')
ax.plot(x, y, lw = 3, color = 'C0', ls = ':')

x,y = compute_y(s0, 'N')
ax.plot(x, y, lw = 3, color = 'C1', ls = '-', label = 'N')
x,y = compute_y(s1, 'N')
ax.plot(x, y, lw = 3, color = 'C1', ls = '--')
x,y = compute_y(s3, 'N')
ax.plot(x, y, lw = 3, color = 'C1', ls = ':')

#x,y = compute_y(s0, 'Ba')
#ax.plot(x, y, lw = 3, color = 'C2', ls = '-', label = 'Sr')
#x,y = compute_y(s1, 'Ba')
#ax.plot(x, y, lw = 3, color = 'C2', ls = '--')
#x,y = compute_y(s3, 'Ba')
#ax.plot(x, y, lw = 3, color = 'C2', ls = ':')


ax.semilogx()
ax.semilogy()
ax.set_ylim(1.0E-2, 1.0)

ax.plot([1.0,1.0],ax.get_ylim(),lw = 2.0, ls = '--', color ='C3')

ax.plot([0.0001,0.0001],ax.get_ylim(),lw = 3.0, ls = '-', color ='black', label = r'Z = 10$^{-4}$')
ax.plot([0.0001,0.0001],ax.get_ylim(),lw = 3.0, ls = '--', color ='black',  label = r'Z = 10$^{-3}$')
ax.plot([0.0001,0.0001],ax.get_ylim(),lw = 3.0, ls = ':', color ='black',  label = r'Z = 10$^{-2}$')
ax.set_xlim(0.01, 14.0)


ax.set_ylabel(r'AGB Contribution Fraction')
ax.set_xlabel(r'Time (Gyr)')
ax.legend(loc='best')
plt.tight_layout()
fig.savefig('C_N_evolution.png')


/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:19: RuntimeWarning: invalid value encountered in divide

In [23]:
data = s4

x = data.history.age
x = np.array(x[1:])/1.0E9
yields  = data.history.ism_elem_yield
agb     = data.history.ism_elem_yield_agb
massive = data.history.ism_elem_yield_massive


fig, ax = plt.subplots()
fig.set_size_inches(8,8)

idx=data.history.elements.index('C')
y = []
yagb = []
ymassive = []
for k in range(len(yields)):
    y.append(yields[k][idx])
    yagb.append(agb[k][idx])
    ymassive.append(massive[k][idx])

yplot = np.array(yagb[1:]) / np.array(y[1:])

ax.plot(x, yplot, lw = 3, color = 'C0', ls = '-', label = 'All')
#ax.plot(x, yagb[1:], lw = 3, color = 'C0', ls = ':', label = 'AGB')
#ax.plot(x, ymassive[1:], lw = 3, color = 'C0', ls = '--', label = 'Massive')

idx=data.history.elements.index('N')
y = []
yagb = []
ymassive = []
for k in range(len(yields)):
    y.append(yields[k][idx])
    yagb.append(agb[k][idx])
    ymassive.append(massive[k][idx])
yplot = np.array(yagb[1:]) / np.array(y[1:])

ax.plot(x, yplot, lw = 3, color = 'C1', ls = '-', label = 'All')

ax.semilogx()
ax.semilogy()
ax.set_ylim(1.0E-2, 1.0)
ax.set_ylabel(r'log(Mass [M$_{\odot}$]')
ax.set_xlabel(r'Time (Gyr)')


/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:22: RuntimeWarning: invalid value encountered in divide
/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py:36: RuntimeWarning: invalid value encountered in divide
Out[23]:
<matplotlib.text.Text at 0x7feaaf2b0190>

In [ ]: