Plot_me.py
Go to the documentation of this file.
1 # Author: M. Reichert
2 # Date: 07.06.22
3 import numpy as np
4 import matplotlib.pyplot as plt
5 import matplotlib.gridspec as gridspec
6 from matplotlib import cm
7 # Import the WinNet python plot-routine
8 # Note that you can also just append the path to your .bashrc
9 import sys
10 sys.path.append('../../bin')
11 from class_files.winnet_class import winnet
12 
13 
14 
15 # Create Figure object
16 fig = plt.figure(figsize=(5,6))
17 
18 # Make a grid for the plot
19 gs = fig.add_gridspec(nrows=3, ncols=6,
20  hspace=0, wspace=0.0)
21 
22 # The mass fractions should have a large panel
23 ax0 = fig.add_subplot(gs[0, :])
24 # Panels splitted in the middle for the rest of the plots
25 ax1 = fig.add_subplot(gs[1, 0:3])
26 ax2 = fig.add_subplot(gs[1, 3:])
27 ax3 = fig.add_subplot(gs[2, 0:3])
28 ax4 = fig.add_subplot(gs[2, 3:])
29 
30 # Reshape axes into different shape
31 ax = np.array([[ax1,ax2],[ax3,ax4]])
32 
33 
34 def plot_tr(path,color,ls2='--',ls3='-',label=""):
35  """
36  Function to plot mass fractions, temperature, density, radius, and electron
37  fraction of one WinNet run.
38  """
39  # Get information of the run
40  w = winnet(path)
41  # Read the template and get the path to the trajectory
42  w.read_template()
43  path_trajectory = w.get_trajectory_path()
44  # Read the mainout and the finab of the run
45  w.read_mainout()
46  w.read_finab()
47  # Get mass numbers and mass fractions
48  A,X=w.get_final_A_X()
49  # Be sure that they are arrays
50  A = np.array(A)
51  X = np.array(X)
52 
53  # Plot the final mass fractions
54  ax0.plot(A[A<220],X[A<220],color=color,ls=ls3,lw=2,label=label)
55  # Make diamonds for the actinides
56  ax0.scatter(A[A>220],X[A>220],color=color,marker="d",s=10)
57  # Configure the axis
58  ax0.set_yscale("log")
59  ax0.set_ylim(2e-6,2)
60  ax0.set_xlim(0,240)
61  ax0.set_xlabel("Mass number")
62  # Change the style of the plot, move the ticks to the top, etc.
63  ax0.xaxis.tick_top()
64  ax0.xaxis.set_label_position("top")
65  ax0.spines["bottom"].set_linewidth(2.5)
66 
67  # Choose a linewidth of 2
68  lw = 2
69  # Get mainout quantities
70  mainout_iteration, mainout_time, mainout_temp, mainout_dens, mainout_ye, mainout_rad, \
71  mainout_yn, mainout_yp, mainout_ya, mainout_ylight, mainout_yheavy, mainout_zbar, \
72  mainout_abar, mainout_entropy = w.get_mainout()
73  # Read the trajectory file
74  time,temp,dens,ye = np.loadtxt(path_trajectory,unpack=True,usecols=[0,1,2,4])
75  # Get final and initial time
76  tf = time[-1]
77  t0 = mainout_time[0]
78  # Create masks in order to be able to plot dashed lines for the expansion
79  mask = mainout_time<tf
80  mask2 = ~mask
81 
82  # Plot the temperature
83  ax[0,0].plot(mainout_time[mask]-t0,mainout_temp[mask],lw=lw,color=color)
84  ax[0,0].plot(mainout_time[mask2]-t0,mainout_temp[mask2],lw=lw,color=color,ls=ls2)
85  ax[0,0].set_xlim(-0.1,2)
86 
87  # Plot the density
88  ax[0,1].plot(mainout_time[mask]-t0,mainout_dens[mask],lw=lw,color=color)
89  ax[0,1].plot(mainout_time[mask2]-t0,mainout_dens[mask2],lw=lw,color=color,ls=ls2)
90  ax[0,1].set_yscale('log')
91  ax[0,1].set_xlim(-0.1,2)
92  ax[0,1].set_ylim(2e1,5e9)
93  ax[0,1].yaxis.tick_right()
94  ax[0,1].yaxis.set_label_position("right")
95  ax[0,1].set_ylabel(r"Density [g cm$^{-3}$]")
96 
97  # Plot the electron fraction
98  ax[1,0].plot(mainout_time[mask]-t0,mainout_ye[mask],lw=lw,color=color)
99  ax[1,0].plot(mainout_time[mask2]-t0,mainout_ye[mask2],lw=lw,color=color,ls=ls2)
100  ax[0,0].set_ylim(0.1,9)
101  ax[1,0].set_xlim(-0.1,2)
102 
103  # Plot the radius
104  ax[1,1].plot(mainout_time[mask]-t0,mainout_rad[mask],lw=lw,color=color)
105  ax[1,1].plot(mainout_time[mask2]-t0,mainout_rad[mask2],lw=lw,color=color,ls=ls2)
106  ax[1,1].set_yscale('log')
107  ax[1,1].set_xlim(-0.1,2)
108  ax[1,1].set_ylim(1e2,4e6)
109  ax[1,1].yaxis.tick_right()
110  ax[1,1].yaxis.set_label_position("right")
111  ax[1,1].set_ylabel(r"Radius [km]")
112 
113 
114 
115 # First plot the trajectory that get ejected promptly
116 path = "tr_Prompt"
117 plot_tr(path,"#005AA9",label="Prompt")
118 # Second, plot the trajectory that get ejected via a PNS shape change
119 path = "tr_PNS_shape"
120 plot_tr(path,"#009D81",label="PNS-shape")
121 # Third, plot the trajectory that has a high entropy
122 path = "tr_High_entropy"
123 plot_tr(path,"#EC6500",label="High entropy")
124 
125 # Make the legend for the uppermost axis
126 ax0.legend()
127 
128 # Write time on the lower end of the figure
129 fig.text(0.5,0.05,"Time [s]",ha="center")
130 
131 # Make the xscale logarithmic and set proper time limits
132 for a in ax.flatten():
133  a.set_xscale("log")
134  a.set_xlim(5e-4,2e1)
135 
136 # Write Mass fraction on the top axis
137 # Alternatively, one can just type ax0.set_ylabel("Mass fraction"),
138 # however, this will not put the y-labels on the same height
139 xpos = 0.02
140 pos = ax0.get_position()
141 totpos = (pos.y1+pos.y0)/2.
142 fig.text(xpos,totpos,"Mass fraction",rotation=90,ha="center",va="center")
143 
144 # Rest of the y-labels
145 l = ["Temperature [GK]",r"Electron fraction"]
146 for i,a in enumerate(ax[:,0]):
147  pos = a.get_position()
148  totpos = (pos.y1+pos.y0)/2.
149  fig.text(xpos,totpos,l[i],rotation=90,ha="center",va="center")
150 
151 fig.savefig("comparison_rprocess.pdf",bbox_inches="tight")
152 
153 
154 
155 
156 
158  """
159  Plot the nuclear chart at neutron freezeout, i.e., Yn/Yh = 1.
160  """
161  w = winnet(path)
162  w.read_mainout()
163  time = w.get_mainout_time()
164  yheavy = w.get_mainout_yheavy()
165  yn = w.get_mainout_yn()
166  # get index and time for neutron freezout
167  index = np.argmin(abs(yn/yheavy-1))
168  t_freezout = time[index]
169 
170  lw = 0.1 # Linewidth of nuclei
171  min_X = 1e-10 # Min of mass fraction
172  max_X = 1e-1 # Max of mass fraction
173  cmap = cm.jet # Use the jet colormap
174  # Plot the path in the nuclear chart
175  w.plot_nuclear_chart_at(t_freezout,figure=ax,axes_label=False,element_labels=False,fig_is_ax=True,colorbar=True,
176  colorbar_position=[0.27, 0.85, 0.5, 0.025],colorbar_inset=True,min_X=min_X,max_X=max_X,
177  cmap= cmap,nuclei_linewidths=lw)
178 
179  ax.text(0.01,0.98,label,transform=ax.transAxes,va="top",ha="left")
180  ax.set_xlim(60,170)
181  ax.set_ylim(40,95)
182 
183 fig_chart,ax_chart = plt.subplots(1,3,figsize=(15,4),sharex=True,sharey=True)
184 
185 plt.subplots_adjust(wspace=0)
186 
187 # First plot the trajectory that get ejected promptly
188 path = "tr_Prompt"
189 plot_nuclear_chart_at_freezeout(path,ax_chart[0],"Prompt")
190 # Second, plot the trajectory that get ejected via a PNS shape change
191 path = "tr_PNS_shape"
192 plot_nuclear_chart_at_freezeout(path,ax_chart[1],"PNS shape")
193 # Third, plot the trajectory that has a high entropy
194 path = "tr_High_entropy"
195 plot_nuclear_chart_at_freezeout(path,ax_chart[2],"High entropy")
196 
197 fig_chart.savefig("nuclear_chart_at_freezeout.pdf",bbox_inches="tight")
198 plt.show()
Plot_me.plot_tr
def plot_tr(path, color, ls2='--', ls3='-', label="")
Definition: Plot_me.py:34
Plot_me.plot_nuclear_chart_at_freezeout
def plot_nuclear_chart_at_freezeout(path, ax, label)
Definition: Plot_me.py:157