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 pandas as pd
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 # Create a first Figure.
12 fig,ax = plt.subplots(1,2,figsize=(10,4),sharex=True)
13 plt.subplots_adjust(wspace=0)
14 
15 # Load data from the mainout
16 nsm_example = winnet('.')
17 nsm_example.read_mainout()
18 time = nsm_example.get_mainout_time()
19 yheavy = nsm_example.get_mainout_yheavy()
20 yn = nsm_example.get_mainout_yn()
21 
22 # Plot the neutron to seed ratio
23 ax[0].plot(time,yn/yheavy,lw=2)
24 # Calculate freezeout point
25 index_freezout = np.argmin(abs(yn/yheavy-1))
26 time_freezout = time[index_freezout]
27 # ... and plot it
28 ax[0].plot([time_freezout,time_freezout],[0,1],ls='--',color='grey',lw=2)
29 ax[0].text(time_freezout,1e-6,"t = "+str(round(time_freezout,3))+' s',ha='right',va='center',rotation=90,color='k',fontsize=9)
30 ax[0].plot([0,time_freezout],[1,1],ls='--',color='grey',lw=2)
31 ax[0].text(5e-2,1,r"Y$_n$/Y$_{\mathrm{Heavy}}$ = 1",ha='center',va='bottom',color='k',fontsize=9)
32 ax[0].scatter(time_freezout,1,marker='x',color='r',s=100)
33 ax[0].text(time_freezout+1,1.1,"Neutron freezout",ha='left',va='center',color='r',fontsize=9)
34 
35 # Read the energy generation
36 energy_file = "generated_energy.dat"
37 df = pd.read_csv(energy_file,skiprows=2,header=None,sep='\s+')
38 with open(energy_file,"r") as f:
39  lines = f.readlines()
40  header = lines[1].split()[1:]
41 header = list(map(lambda x: x.strip(),header))
42 df.columns = header
43 
44 time = df["time[s]"].values
45 engen = df["Engen(Total)"].values
46 # ... and plot it
47 ax[1].plot(time,engen,label="Total",lw=2.5)
48 ax[1].plot(time,df["Engen(fiss)"].values,color="tab:orange" ,label="Fission",lw=1)
49 ax[1].plot(time,df["Engen(weak)"].values,color="tab:cyan" ,label="Weak",lw=1)
50 ax[1].plot(time,df["Engen(n,g)"].values,color="tab:green" ,label=r"($n,\gamma$)",lw=1)
51 ax[1].plot(time,df["Engen(a,g)"].values,color="saddlebrown" ,label=r"($\alpha,\gamma$)",lw=1)
52 index_freezout = np.argmin(np.abs(time-time_freezout))
53 time_freezout = time[index_freezout]
54 ax[1].plot([time_freezout,time_freezout],[0,engen[index_freezout]],ls='--',color='grey',lw=2)
55 ax[1].scatter(time_freezout,engen[index_freezout],marker='x',color='r',s=100,zorder=100)
56 ax[1].text(time_freezout+1,1.1*engen[index_freezout],"Neutron freezout",ha='left',va='center',color='r',fontsize=9)
57 ax[1].text(5e-2,2.3*engen[index_freezout],r"$\propto$ constant",ha='center',va='center',color='k',fontsize=10)
58 ax[1].text(5e2,1e14,r"$\propto$ t$^{- \alpha}$",ha='center',va='center',rotation=-42,color='k',fontsize=10)
59 
60 ax[1].legend()
61 
62 # Set the range and labels of the plots
63 ax[0].set_xlim(3e-3,5e5)
64 ax[0].set_ylim(1e-9,1e5)
65 ax[1].set_ylim(1e9,1e20)
66 ax[0].loglog()
67 ax[1].loglog()
68 ax[0].set_ylabel(r"Y$_n$/Y$_{\mathrm{Heavy}}$")
69 ax[1].set_ylabel(r"Energy generation [$\mathrm{erg} \, \mathrm{g}^{-1} \, \mathrm{s}^{-1}$]")
70 fig.text(0.5,0.008,r"Time [s]")
71 
72 # Set the ticks of the right plot to the right
73 ax[1].yaxis.set_label_position("right")
74 ax[1].yaxis.tick_right()
75 
76 
77 
78 # Also plot the final abundances
79 fig2 = plt.figure()
80 ax = fig2.gca()
81 # Read the finab
82 nsm_example.read_finab()
83 A,X = nsm_example.get_final_A_X()
84 # Plot the massfraction, summed over equal mass numbers
85 ax.plot(A,X)
86 ax.set_ylabel("Mass fraction")
87 ax.set_xlabel("Mass number")
88 ax.set_yscale("log")
89 ax.set_xlim(0,249)
90 ax.set_ylim(1e-8,1)
91 
92 fig.savefig("Neutron_to_seed_and_heating_power_nsm_dyn_ejecta_rosswog.pdf",bbox_inches="tight")
93 fig2.savefig("Final_mass_fractions_nsm_dyn_ejecta_rosswog.pdf",bbox_inches="tight")
94 
95 plt.show()