Plot_me.py
Go to the documentation of this file.
1 # Default skeleton for python files
2 import numpy as np
3 import matplotlib.pyplot as plt
4 import sys
5 sys.path.append('../../bin')
6 from class_files.nucleus_multiple_class import nucleus_multiple
7 
8 # Create a figure to determine the figure size
9 fig = plt.figure(figsize=(5,3))
10 
11 
12 # Read and plot reference final abundances
13 # A bit lengthy due to the file format
14 path = "final_abundances.txt"
15 
16 abundances = []
17 nuclei = []
18 with open(path,"r") as f:
19  lines = f.readlines()
20 
21  mode = 'nuc'
22  for l in lines[2:]:
23  nuc = ""
24  abu = ""
25  for char in l:
26  if mode == "nuc":
27  if char == "=" and nuc.strip()!="":
28  mode = "abund"
29  nuc = nuc.strip().replace(" ","")
30  # Take care of protons, deuterons, and tritium
31  if nuc.lower()=="prot":
32  nuc = "p"
33  elif nuc.lower()=="deut":
34  nuc = "d"
35  elif nuc.lower()=="trit":
36  nuc = "t"
37  elif (nuc.lower()[:4]=="al26"):
38  nuc = "al26"
39 
40  # Take care of excited states of al26
41  if (nuc!="al26") or (not ("al26" in nuclei)):
42  nuclei.append(nuc)
43  else:
44  continue
45 
46  else:
47  nuc = nuc+char
48  if mode== "abund":
49  if ((char == " ") or (char == "\n")) and abu.strip()!="":
50  # Take care of excited states of al26
51  if nuc!="al26":
52  abundances.append(float(abu.replace("D","e")))
53  else:
54  idx = nuclei.index("al26")
55  if idx == len(abundances):
56  abundances.append(float(abu.replace("D","e")))
57  else:
58  abundances[idx] = abundances[idx] + float(abu.replace("D","e"))
59  abu = ""
60  nuc = ""
61  mode = "nuc"
62  else:
63  if char!="=":
64  abu = abu+char
65 
66 # Convert to arrays
67 abundances = np.array(abundances)
68 nuclei = np.array(nuclei)
69 
70 # Note that the abundances are mass fractions here
71 nm = nucleus_multiple(nuclei,X=abundances)
72 # Get the mass fractions summed over mass number
73 A,X = nm.A_X
74 plt.plot(A,X,label="Mean composition\n(Jose & Hernanz 1998, model ONe5)")
75 
76 # Plot initial composition, again the file contains mass fractions
77 Z,A,X = np.loadtxt("iniab.txt",unpack=True,usecols=[0,2,3])
78 Z = Z.astype(int)
79 A = A.astype(int)
80 # Sum over equal A with the nucleus multiple class
81 nm = nucleus_multiple(Z=Z,A=A,X=X)
82 A,X = nm.A_X
83 plt.plot(A,X,label="Initial composition",ls="--")
84 
85 
86 
87 A,Y,X = np.loadtxt("finabsum.dat",unpack=True)
88 
89 plt.plot(A,X,label="WinNet, single trajectory")
90 
91 
92 
93 plt.yscale("log")
94 plt.ylim(1e-8,1)
95 plt.xlim(0,55)
96 
97 plt.legend(loc="upper right",bbox_to_anchor=(1.0,1.4))
98 plt.ylabel("Mass fraction")
99 plt.xlabel("Mass number")
100 plt.savefig('massfractions.pdf',bbox_inches='tight')
101 plt.show()