Plot_me.py
Go to the documentation of this file.
1 # Author: M. Reichert
2 import numpy as np
3 import matplotlib.pyplot as plt
4 # Import the WinNet python plot-routine
5 # Note that you can also just append the path to your .bashrc
6 import sys
7 import os
8 sys.path.append('../../bin')
9 from class_files.nucleus_multiple_class import nucleus_multiple
10 
11 def sum_over(A,Y):
12  """
13  Function to sum up mass fractions or abundances over equal A.
14  """
15  A = A.astype(int)
16  max_A = max(A)
17  # second_dimension = len(Y[0,:])
18  Y_new = np.zeros([max_A+1,])
19  for i in range(len(A)):
20  Y_new[int(A[i])] += Y[i]
21  return np.array(range(max_A+1)),Y_new
22 
23 # Set up two figures
24 fig = plt.figure(figsize=(5,2.5))
25 ax = fig.gca()
26 
27 fig2 = plt.figure(figsize=(5,2.5))
28 ax2 = fig2.gca()
29 
30 # Read and plot initial mass fractions
31 A,X = np.loadtxt("../../data/Example_data/Example_AGB_nishimura/iniab1.4E-02As09.ppn",
32  unpack=True,usecols=[2,3])
33 Asum,Xsum = sum_over(A,X)
34 ax2.plot(Asum,Xsum,label="Initial")
35 
36 # Read the result
37 A,Z,N,Y,X = np.loadtxt("finab.dat",unpack=True,usecols=[0,1,2,3,4])
38 # Convert to integers
39 A = A.astype(int)
40 Z = Z.astype(int)
41 # Create a nucleus multiple instance. This is a class to
42 # deal with abundances.
43 nm_winnet = nucleus_multiple(A=A,Z=Z,Y=Y)
44 
45 Asum,Xsum = nm_winnet.A_X
46 ax2.plot(Asum,Xsum,label="Final")
47 
48 # Read the solar abundances
49 Z,A,Y=np.loadtxt("solar_abu_lodders.txt",unpack=True)
50 Z = Z.astype(int)
51 A = A.astype(int)
52 # Also put them in a nucleus multiple class
53 nm_solar = nucleus_multiple(A=A,Z=Z,Y=Y)
54 
55 Asum,Xsum = nm_solar.A_X
56 ax2.plot(Asum,Xsum,label="Solar",lw=0.5)
57 
58 # Calculate overproduction
59 nm_overprod= nm_winnet/nm_solar
60 
61 # Get unique amount of protons to loop through
62 Z = np.unique(nm_overprod.Z)
63 
64 # List with the elementnames, at place Z is the name of the element, e.g., elementnames[1]="h"
65 elementnames = ('neutron','h','he','li','be','b','c','n','o','f','ne','na','mg','al','si','p','s','cl','ar','k','ca','sc','ti','v','cr','mn','fe',
66  'co','ni','cu','zn','ga','ge','as','se','br','kr','rb','sr','y','zr','nb','mo','tc','ru','rh','pd','ag','cd','in','sn','sb',
67  'te', 'i','xe','cs','ba','la','ce','pr','nd','pm','sm','eu','gd','tb','dy','ho','er','tm','yb','lu','hf','ta','w','re','os',
68  'ir','pt','au','hg','tl','pb','bi','po','at','rn','fr','ra','ac','th','pa','u','np','pu','am','cm','bk','cf','es','fm','md',
69  'no','lr','rf','db','sg','bh','hs','mt','ds','rg','ub','ut','uq','up','uh','us','uo')
70 
71 # Loop through it, plot the overproduction chains
72 # and write the correct name at the correct place
73 for Ztmp in Z:
74  Y = nm_overprod.Y[(nm_overprod.Z==Ztmp) & (nm_overprod.Y>=1e-2)]
75  A = nm_overprod.A[(nm_overprod.Z==Ztmp) & (nm_overprod.Y>=1e-2)]
76  # The "try" is necessary for empty sequences
77  try:
78  maxY_arg = np.argmax(Y)
79  except:
80  continue
81  ion_name = elementnames[Ztmp][0].upper()+elementnames[Ztmp][1:]
82  ax.scatter(A,Y,s=10)
83  p = ax.plot(A,Y)
84  ax.text(A[maxY_arg],Y[maxY_arg]*1.1,ion_name,clip_on=True,ha="center",color=p[0].get_color())
85 
86 # Make lines as in the Nishimura paper
87 ax.axhline(1e-1,color="lightgrey",zorder=-1,lw=0.8,ls="--")
88 ax.axhline(1e0 ,color="lightgrey",zorder=-1,lw=0.8,ls="dotted")
89 ax.axhline(1e1 ,color="lightgrey",zorder=-1,lw=0.8,ls="--")
90 
91 # Set the limits and scales
92 ax.set_ylim(1e-2,1e3)
93 ax.set_xlim(40,160)
94 ax.set_yscale("log")
95 # Write the labels
96 ax.set_ylabel(r"Overproduction X/X$_\odot$")
97 ax.set_xlabel("Mass number")
98 
99 ax2.legend()
100 ax2.set_yscale("log")
101 ax2.set_ylim(1e-11,1)
102 ax2.set_xlim(0,220)
103 ax2.set_xlabel("Mass number")
104 ax2.set_ylabel("Mass fraction")
105 
106 # Save and show the plots
107 fig.savefig("overproduction.pdf",bbox_inches="tight")
108 fig2.savefig("mass_fractions.pdf",bbox_inches="tight")
109 plt.show()
Plot_me.sum_over
def sum_over(A, Y)
Definition: Plot_me.py:11