Plot_me.py
Go to the documentation of this file.
1 # Author: M. Reichert
2 # Date: 09.07.22
3 import numpy as np
4 import matplotlib.pyplot as plt
5 # Import the WinNet python plot-routine
6 # Note that you can also just append the path to your .bashrc
7 import sys
8 sys.path.append('../../bin')
9 from class_files.winnet_class import winnet
10 
11 # This script will plot the mass fractions and energy generation
12 # of CO burning. The plot can be compared to the one on cococubed:
13 # https://cococubed.com/code_pages/burn_helium.shtml
14 
15 # Set up the figure
16 fig = plt.figure()
17 ax = fig.gca()
18 ax.set_title("Hydrostatic CO burning")
19 
20 
22  """
23  Function to convert the element string that is given by WinNet
24  to a latex style string.
25  Example:
26  create_nucleus_name("ne20")
27  will output: r"$^{20}$Ne"
28  """
29  digits =""
30  chars =""
31  for d in s:
32  if d.isdigit():
33  digits+=d
34  else:
35  chars+=d
36  nuc_name = r"$^{"+digits+"}$"+chars[0].upper()+chars[1:]
37  return nuc_name
38 
39 # Read the mass fractions of the elements
40 w = winnet(".")
41 w.read_tracked_nuclei()
42 names = w.get_tracked_nuclei_names()
43 time = w.get_tracked_time()
44 
45 # Define the x-position of each element label
46 xpos_dic = {"he4":4e-7,"c12":3.8e-5,"o16":1e-7,"ne20":5e-3,"mg24":4e2,"si28":4e2,\
47  "s32":4e2,"ar36":4e2,"ca40":5e9,"ti44":4e2,"cr48":5e6,"fe52":1e10,"ni56":1e10}
48 
49 for n in names:
50  # Plot the mass fractions of each element
51  X = w.get_tracked_nuclei(n)
52  line, = ax.plot(time,X)
53  # Plot the element labels
54  if n in xpos_dic:
55  out_name = create_nucleus_name(n)
56  idx = np.argmin(abs(time-xpos_dic[n]))
57  ax.text(xpos_dic[n],X[idx],out_name,ha="left",va="bottom",color=line.get_color())
58 
59 # Plot also the generated energy on a second y-axis
60 ax_energy = ax.twinx()
61 time_energy,energy = np.loadtxt("generated_energy.dat",unpack=True,usecols=[0,1])
62 ax_energy.plot(time_energy,energy,ls="--",lw=1,color="saddlebrown",zorder=-30,alpha=0.8)
63 ax_energy.text(5e-9,2e25,r"$\epsilon$",color="k")
64 ax_energy.set_yscale("log")
65 ax_energy.set_ylabel(r"Energy [erg g$^{-1}$ s$^{-1}$]")
66 ax_energy.set_ylim(1e11,1e27)
67 
68 # Set the labels, limits, and scales
69 ax.set_xlabel("Time [s]")
70 ax.set_ylabel("Mass fraction")
71 ax.loglog()
72 ax.set_xlim(1e-11,1e12)
73 ax.set_ylim(1e-8,1e1)
74 plt.savefig("CO_burning.pdf",bbox_inches="tight")
75 plt.show()
Plot_me.create_nucleus_name
def create_nucleus_name(s)
Definition: Plot_me.py:21