def get_e_release(results_dir): """Return a list of energy generation from all completed sub-directories in results_dir.""" import wdmerger_grid_diag_analysis as grid_diag import numpy as np dir_list = wdmerger.get_parameter_list(results_dir) if (dir_list == []): return diag_filename_list = [ results_dir + '/' + directory + '/output/grid_diag.out' for directory in dir_list ] e_arr = [ np.amax(wdmerger.get_column('TOTAL ENERGY', diag_filename)) - np.amin(wdmerger.get_column('TOTAL ENERGY', diag_filename)) for diag_filename in diag_filename_list ] # Divide by 10**51 e_arr = [e / 1.0e51 for e in e_arr] return e_arr
def get_ni56(results_dir, prefix=''): """Return a list of maximum 56Ni production from all completed sub-directories in results_dir.""" import numpy as np ni56_arr = [] dir_list = wdmerger.get_parameter_list(results_dir) # Strip out those directories that don't match the prefix. if (prefix != ''): dir_list = [dir for dir in dir_list if dir[0:len(prefix)] == prefix] if (dir_list == []): return ni56_arr diag_filename_list = [ results_dir + '/' + directory + '/output/species_diag.out' for directory in dir_list ] # Ensure all of the output files are there. for diag_file in diag_filename_list: if not os.path.isfile(diag_file): return ni56_arr ni56_arr = [ np.amax(wdmerger.get_column('Mass ni56', diag_filename)) - np.amin(wdmerger.get_column('Mass ni56', diag_filename)) for diag_filename in diag_filename_list ] return ni56_arr
def stellar_masses(eps_filename, results_base): """Plot the WD masses as a function of time.""" if not is_root(): return import os if not os.path.exists(results_base): return import matplotlib.pyplot as plt import numpy as np res_list = wdmerger.get_parameter_list(results_base) directory_list = [results_base + '/' + res for res in res_list] for i, directory in enumerate(directory_list): eps_filename_curr = eps_filename.replace('.eps', '_n_' + res_list[i][1:] + '.eps') if os.path.isfile(eps_filename_curr): continue p_diag = directory + '/output/primary_diag.out' s_diag = directory + '/output/secondary_diag.out' p_time = wdmerger.get_column('TIME', p_diag) p_mass = wdmerger.get_column('PRIMARY MASS', p_diag) s_time = wdmerger.get_column('TIME', s_diag) s_mass = wdmerger.get_column('SECONDARY MASS', s_diag) p_mask = np.where(p_time <= 100.0) s_mask = np.where(s_time <= 100.0) plt.plot(np.array(p_time)[p_mask], np.array(p_mass)[p_mask] / np.array(p_mass)[0], lw = 4.0, linestyle = linestyles[0], markersize = 12.0, markevery = 2000, label = 'Primary') plt.plot(np.array(s_time)[s_mask], np.array(s_mass)[s_mask] / np.array(s_mass)[0], lw = 4.0, linestyle = linestyles[1], markersize = 12.0, markevery = 2000, label = 'Secondary') plt.tick_params(labelsize = 20) plt.xlabel('Time (s)', fontsize = 24) plt.ylabel('WD Mass / Initial Mass', fontsize = 24) plt.legend(loc = 'best', prop = {'size':20}, fancybox = True, framealpha = 0.5) plt.tight_layout() plt.savefig(eps_filename_curr) plt.close()
def stellar_distance(eps_filename, results_base): """Plot the WD distance as a function of time.""" if not is_root(): return import os if os.path.isfile(eps_filename): return if not os.path.exists(results_base): return import matplotlib.pyplot as plt import numpy as np res_list = wdmerger.get_parameter_list(results_base) res_list = sorted([int(res[1:]) for res in res_list]) diag_list = [results_base + '/n' + str(res) + '/output/star_diag.out' for res in res_list] for i, diag in enumerate(diag_list): eps_filename_curr = eps_filename.replace('.eps', '_n_' + str(res_list[i]) + '.eps') if os.path.isfile(eps_filename_curr): return time = np.array(wdmerger.get_column('TIME', diag)) dist = np.array(wdmerger.get_column('WD DISTANCE', diag)) mask = np.where(dist > 0.0) plt.plot(time[mask], dist[mask] / dist[0], lw = 4.0, linestyle = linestyles[0]) plt.tick_params(labelsize = 20) plt.xlabel('Time (s)', fontsize = 24) plt.ylabel('WD Distance / Initial Distance', fontsize = 24) plt.tight_layout() plt.savefig(eps_filename_curr) plt.close()
def stellar_distance_convergence(eps_filename, results_base): """Plot the WD distance as a function of resolution.""" if not is_root(): return import os if os.path.isfile(eps_filename): return if not os.path.exists(results_base): return import matplotlib.pyplot as plt import numpy as np res_list = wdmerger.get_parameter_list(results_base) res_list = sorted([int(res[1:]) for res in res_list]) diag_list = [results_base + '/n' + str(res) + '/output/star_diag.out' for res in res_list] for i, diag in enumerate(diag_list): time = wdmerger.get_column('TIME', diag) dist = wdmerger.get_column('WD DISTANCE', diag) mask = np.where(time <= 50.0) plt.plot(np.array(time)[mask], np.array(dist)[mask] / np.array(dist)[0], lw = 4.0, linestyle = linestyles[i], marker = markers[i], markersize = 12.0, markevery = 2000, label = 'n = ' + str(res_list[i])) plt.tick_params(labelsize = 20) plt.xlabel('Time (s)', fontsize = 24) plt.ylabel('WD Distance / Initial Distance', fontsize = 24) plt.legend(loc = 'best', prop = {'size':20}, fancybox = True, framealpha = 0.5) plt.tight_layout() plt.savefig(eps_filename) plt.close()
def get_ni56(results_dir): """Return a list of maximum 56Ni production from all completed sub-directories in results_dir.""" import numpy as np dir_list = sorted(wdmerger.get_parameter_list(results_dir)) diag_filename_list = [ results_dir + '/' + directory + '/output/species_diag.out' for directory in dir_list ] ni56_arr = [ np.amax(wdmerger.get_column('Mass ni56', diag_filename)) for diag_filename in diag_filename_list ] return ni56_arr
def gravitational_wave_signal(eps_filename, results_dir): """Plot the gravitational radiation waveform.""" import os if os.path.isfile(eps_filename): return if not os.path.exists(results_dir): return from matplotlib import pyplot as plt print "Generating plot with filename " + eps_filename diag_file = results_dir + '/output/grid_diag.out' time = wdmerger.get_column('TIME', diag_file) strain_p_1 = wdmerger.get_column('h_+ (axis 1)', diag_file) strain_x_1 = wdmerger.get_column('h_x (axis 1)', diag_file) strain_p_2 = wdmerger.get_column('h_+ (axis 2)', diag_file) strain_x_2 = wdmerger.get_column('h_x (axis 2)', diag_file) strain_p_3 = wdmerger.get_column('h_+ (axis 3)', diag_file) strain_x_3 = wdmerger.get_column('h_x (axis 3)', diag_file) plt.plot(time, strain_p_1 / 1.e-22, lw=4.0, color=colors[0], linestyle=linestyles[0], marker=markers[0], markersize=12, markevery=250, label=r'$h^x_+$') plt.plot(time, strain_x_1 / 1.e-22, lw=4.0, color=colors[1], linestyle=linestyles[1], marker=markers[1], markersize=12, markevery=250, label=r'$h^x_\times$') plt.plot(time, strain_p_2 / 1.e-22, lw=4.0, color=colors[2], linestyle=linestyles[2], marker=markers[2], markersize=12, markevery=250, label=r'$h^y_+$') plt.plot(time, strain_x_2 / 1.e-22, lw=4.0, color=colors[3], linestyle=linestyles[3], marker=markers[3], markersize=12, markevery=250, label=r'$h^y_\times$') plt.plot(time, strain_p_3 / 1.e-22, lw=4.0, color=colors[4], linestyle=linestyles[4], marker=markers[4], markersize=12, markevery=250, label=r'$h^z_+$') plt.plot(time, strain_x_3 / 1.e-22, lw=4.0, color=colors[5], linestyle=linestyles[5], marker=markers[5], markersize=12, markevery=250, label=r'$h^z_\times$') plt.tick_params(labelsize=20) plt.xlabel(r'$t\ \mathrm{(s)}$', fontsize=24) plt.ylabel(r'$h\, /\, 10^{-22}$', fontsize=24) plt.legend(loc='best', prop={'size': 20}) plt.tight_layout() plt.savefig(eps_filename) wdmerger.insert_commits_into_eps(eps_filename, diag_file, 'diag') plt.close()
def gravitational_wave_signal(eps_filename, results_dir, max_time = 1.e20, markevery = None, scale_exp = -22, vary_lines = False): """Plot the gravitational radiation waveform.""" import os if os.path.isfile(eps_filename): return if not os.path.exists(results_dir): return from matplotlib import pyplot as plt import numpy as np print "Generating plot with filename " + eps_filename scale = 10.0**scale_exp if vary_lines: linestyles = ['-', '--', ':', '-', '--', ':'] markers = ['', '', '', 'o', 's', 'D'] colors = ['b', 'g', 'r', 'c', 'm', 'k'] else: linestyles = ['-', '--', '-', '--', '-', '--'] markers = ['', '', '', '', '', ''] colors = ['b', 'g', 'b', 'g', 'b', 'g'] diag_file = results_dir + '/output/grid_diag.out' time = np.array(wdmerger.get_column('TIME', diag_file)) strain_p_1 = np.array(wdmerger.get_column('h_+ (axis 1)', diag_file)) / scale strain_p_2 = np.array(wdmerger.get_column('h_+ (axis 2)', diag_file)) / scale strain_p_3 = np.array(wdmerger.get_column('h_+ (axis 3)', diag_file)) / scale strain_x_1 = np.array(wdmerger.get_column('h_x (axis 1)', diag_file)) / scale strain_x_2 = np.array(wdmerger.get_column('h_x (axis 2)', diag_file)) / scale strain_x_3 = np.array(wdmerger.get_column('h_x (axis 3)', diag_file)) / scale # Generate an offset for the x- and y- strains. Then round this to the nearest # integer for the convenience of the plot legend. offset = max( int(round(2.5 * (max(np.max(strain_p_3), np.max(strain_x_3)) - min(np.min(strain_p_2), np.min(strain_x_2))))), int(round(2.5 * (max(np.max(strain_p_2), np.max(strain_x_2)) - min(np.min(strain_p_1), np.min(strain_x_1))))) ) z_offset = 0 y_offset = offset x_offset = 2 * offset strain_p_1 += x_offset strain_p_2 += y_offset strain_p_3 += z_offset strain_x_1 += x_offset strain_x_2 += y_offset strain_x_3 += z_offset z_label_offset = '' y_label_offset = '+ {:d}'.format(y_offset) x_label_offset = '+ {:d}'.format(x_offset) label_p_1 = r'$h^x_+{}$'.format(x_label_offset) label_p_2 = r'$h^y_+{}$'.format(y_label_offset) label_p_3 = r'$h^z_+{}$'.format(z_label_offset) label_x_1 = r'$h^x_\times{}$'.format(x_label_offset) label_x_2 = r'$h^y_\times{}$'.format(y_label_offset) label_x_3 = r'$h^z_\times{}$'.format(z_label_offset) markersize = 12 mask = np.where(time <= max_time) plot_p_1, = plt.plot(time[mask], strain_p_1[mask], lw = 4.0, color = colors[0], linestyle = linestyles[0], marker = markers[0], markersize = markersize, markevery = markevery, label = label_p_1) plot_p_2, = plt.plot(time[mask], strain_p_2[mask], lw = 4.0, color = colors[2], linestyle = linestyles[2], marker = markers[2], markersize = markersize, markevery = markevery, label = label_p_2) plot_p_3, = plt.plot(time[mask], strain_p_3[mask], lw = 4.0, color = colors[4], linestyle = linestyles[4], marker = markers[4], markersize = markersize, markevery = markevery, label = label_p_3) plot_x_1, = plt.plot(time[mask], strain_x_1[mask], lw = 4.0, color = colors[1], linestyle = linestyles[1], marker = markers[1], markersize = markersize, markevery = markevery, label = label_x_1) plot_x_2, = plt.plot(time[mask], strain_x_2[mask], lw = 4.0, color = colors[3], linestyle = linestyles[3], marker = markers[3], markersize = markersize, markevery = markevery, label = label_x_2) plot_x_3, = plt.plot(time[mask], strain_x_3[mask], lw = 4.0, color = colors[5], linestyle = linestyles[5], marker = markers[5], markersize = markersize, markevery = markevery, label = label_x_3) plt.tick_params(labelsize=20) plt.xlabel(r'$t\ \mathrm{(s)}$', fontsize = 24) plt.ylabel(r'$h\, /\, 10^{}$'.format('{' + str(scale_exp) + '}'), fontsize = 24) xlim = [time[mask][0], time[mask][-1]] plt.xlim(xlim) ylim = [min(np.min(strain_p_3), np.min(strain_x_3)) - 0.05 * offset, max(np.max(strain_p_1), np.max(strain_x_1)) + 0.5 * offset] plt.ylim(ylim) # Taking a trick from http://matplotlib.org/users/legend_guide.html#multiple-legends-on-the-same-axes # to split the legend into three parts. legend_1 = plt.legend(handles = [plot_p_1, plot_x_1], loc = [0.1, 0.85], prop = {'size':20}, ncol = 2, fancybox = True) legend_2 = plt.legend(handles = [plot_p_2, plot_x_2], loc = [0.1, 0.55], prop = {'size':20}, ncol = 2, fancybox = True) legend_3 = plt.legend(handles = [plot_p_3, plot_x_3], loc = [0.1, 0.25], prop = {'size':20}, ncol = 2, fancybox = True) plt.gca().add_artist(legend_1) plt.gca().add_artist(legend_2) plt.gca().add_artist(legend_3) plt.tight_layout() plt.savefig(eps_filename) wdmerger.insert_commits_into_eps(eps_filename, diag_file, 'diag') plt.close()
def angular_momentum_comparison(eps_filename, results_base, ncell, subtract_grid_losses = False): """Plot the system angular momentum as a function of evolution method.""" if not is_root(): return import os if os.path.isfile(eps_filename): return if not os.path.exists(results_base): return import matplotlib.pyplot as plt import numpy as np idx = 0 for rot in ['0', '1']: for hybrid in ['0', '1']: results_dir = results_base + '/rot' + rot + '/hybrid' + hybrid + '/n' + ncell diag = results_dir + '/output/grid_diag.out' time = np.array(wdmerger.get_column('TIME', diag)) lerr = np.array(wdmerger.get_column('ANG. MOM. Z', diag)) if subtract_grid_losses: bndy_diag = results_dir + '/output/bndy_diag.out' bndy = np.array(wdmerger.get_column('ANG. MOM. Z LOST', bndy_diag)) lerr = lerr + bndy mask = np.where(time <= 100.0) title = '' if rot == '0': title += 'Inertial Frame' else: title += 'Rotating Frame' if hybrid == '0': title += ', Standard Equations' else: title += ', Hybrid Equations' plt.plot(time[mask], abs((lerr[mask] - lerr[0]) / lerr[0]), lw = 4.0, linestyle = linestyles[idx], marker = markers[idx], markersize = 12.0, markevery = 5000, label = title) idx += 1 plt.tick_params(labelsize = 20) plt.xlabel('Time (s)', fontsize = 24) plt.ylabel(r'Relative Change in $L_z$', fontsize = 24) plt.legend(loc = 'best', prop = {'size':16}, fancybox = True, framealpha = 0.5) plt.ylim([-5e-5, 1.e-3]) plt.tight_layout() plt.savefig(eps_filename) plt.close()