def Plot_HRD(root_dir='.', show_legend=False): ''' Creates HRD for with every system found in the specified directory Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used show_legend : Bool If True, display the legend on the HRD ''' for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": # print(subdir) try: ms.history_data(subdir).hrd(label=str(subdir[0:4]), colour='k') except: pass plt.title("HRD") if show_legend: plt.legend() plt.show()
def Plot_PMdotM(root_dir="."): ''' Plots the relative mass loss per binary cycle Parameters ---------- root_dir : string path to the directory containing the history.data file to be used Returns ------- Plots : 1. Relative mass loss of the system with each step ''' m1 = ms.history_data(root_dir) xval = m1.get("model_number") yval = mesa_calc.Calc_PMdotM(root_dir) plt.plot(xval, yval) plt.xlabel("model number") plt.ylabel("PMdot/M") plt.show()
def Find_Value(root_dir=".", value=None): ''' Finds the initial and final value of a user given property. If the system is broken return "broken". Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' value_matrix = [["directory", "initial", "final"]] # value = raw_input("what value? ") for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": try: m1 = ms.history_data(subdir) x_i = m1.get(value)[0] x_f = m1.get(value)[-1] except: x_i = "broken" x_f = "broken" # preface = subdir + " : " x_i_string = "initial " + str(value) + " : " + str(x_i) x_f_string = "final " + str(value) + " : " + str(x_f) # print(preface) # print(x_i_string) # print(x_f_string) value_matrix.append([subdir, x_i_string, x_f_string]) return value_matrix
def Calc_PMdotM(root_dir="."): ''' Calculates the relative mass loss per cycle of a binary system Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used Returns ------- pmdotm : array_like relative amount of mass lost per binary period ''' m1 = ms.history_data(root_dir) i = 0 m1m = m1.get("star_1_mass") m1lgmdot = m1.get("lg_mstar_dot_1") m1p = m1.get("period_days") pmdotm = [] for i in xrange(len(m1m)): pmdotm.append((10**(m1lgmdot[i])) / (m1m[i]) * (m1p[i] / 365)) return pmdotm
def Find_Prob(root_dir="."): # Check weird files ''' Determine if the files were corrupted in any way by checking if the results iterate correctly Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' Weirdness = [] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": print(subdir) try: m1 = ms.history_data(subdir) model = m1.get('model_number') for row in len(1, xrange(model)): if model[row - 1] > model[row]: Weirdness.append(subdir) break print(subdir) except: pass return Weirdness
def Plot_EvenSpacing(root_dir, separation): ''' Creates a HRD with data points "evenly" spaced along the curve Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used separation : int Distance between subsequent datapoints Returns ------- Plots A HRD with the entirel data set with the evenly spaced points overlayed on top ''' m1 = ms.history_data(root_dir) L = m1.get("log_L") Teff = m1.get("log_Teff") newL = [] newT = [] point_index = val_find.Find_EvenSpacing(Teff, separation) print(point_index) for i in point_index: newL.append(L[i]) newT.append(Teff[i]) m1.hrd() plt.plot(newT, newL, 'o')
def Plot_Bifurcation(root_dir='.', show_legend=False): ''' Creates period vs mass plot for with every system found in the specified directory Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used show_legend : Bool If True, display the legend on the HRD ''' for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": # print(subdir) try: m1 = ms.history_data(subdir) plt.plot(m1.get('star_1_mass'), m1.get('period_days')) except: pass if show_legend: plt.legend() plt.show()
def Find_Bifurcation(root_dir="."): mass = [] bifur_period = [] ordered_period_list = [] convergence = [] mass_dirs = os.walk(root_dir).next()[1] mass_dirs.sort() for mass_dir in mass_dirs: bp_found = False print(mass_dir) mass.append(mass_dir) os.chdir(mass_dir) period_dirs = [] sub_dirs = filter(os.path.isdir, os.listdir(os.getcwd())) for directory in sub_dirs: split_vals = directory.split('_') period_val = split_vals[1][0:-1] period_dirs.append(float(period_val)) sub_dirs = np.array(sub_dirs[0:len(period_dirs)]) period_dirs = np.array(period_dirs) period_inds = period_dirs.argsort() sorted_dirs = sub_dirs[period_inds] ordered_period_list.append(sorted_dirs) sub_converge = [] os.chdir("../") # print(sorted_dirs) for subdir in sorted_dirs: try: file_str = mass_dir + "/" + subdir + "/LOGS" m1 = ms.history_data(file_str) period = m1.get('period_days') if period[-1] > period[0]: sub_converge.append(False) else: sub_converge.append(True) except: sub_converge.append(True) convergence.append(sub_converge) i = 0 while not bp_found: if sub_converge[i] != sub_converge[i + 1]: print(sorted_dirs[i], sorted_dirs[i + 1]) bifur_period.append((sorted_dirs[i], sorted_dirs[i + 1])) bp_found = True else: i += 1 return mass, ordered_period_list, convergence, bifur_period
def Find_Ongoing_RLOF(root_dir="."): ''' Determine if the system was still in RLOF when it stopped running Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' RLOF_list = [] rerun = [] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": try: m1 = ms.history_data(subdir) rel_RLOF = m1.get('lg_mtransfer_rate')[-1] if rel_RLOF > -12: RLOF_list.append(subdir[0:-5]) except: pass RLOF_list.sort() for RLOF_dirs in RLOF_list: file_to_open = RLOF_dirs + "/run_log" runlog = open(file_to_open, 'r') runlog.seek(0) data = runlog.readlines() if ('max_age' in data[-7]) or ('dt_is_zero' in data[-3]): # print(RLOF_dirs + " needs to continue") found = False i = 0 while not found: if 'last photo' not in data[i]: i = i - 1 else: lp_index = i + 1 lp_find = False p_index = 0 while not lp_find: if data[lp_index][p_index] != '/': p_index = p_index - 1 else: p_index = p_index + 1 lp_find = True found = True lp = data[lp_index][p_index:-1] dnf_string = RLOF_dirs + " last photo: " + str(lp) rerun.append(dnf_string) runlog.close() return rerun, RLOF_list
def Find_Outburst(root_dir=".", outburst_tol=0.1, number_tol=0, time_tol=1e6, plot=False): outburst_list = [] outnum_list = [] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": # print(subdir) try: outburst_num = 0 m1 = ms.history_data(subdir) m1mt1 = 10**m1.get('lg_mstar_dot_1')[0:-1] m1mt2 = 10**m1.get('lg_mstar_dot_1')[1:] delta_MT = abs(m1mt1 - m1mt2) percent_delta = (delta_MT / m1mt1) m1_age = m1.get('star_age') # model = m1.get('model_number') delta_list = np.where(percent_delta >= outburst_tol)[0] for k, g in groupby(enumerate(delta_list), lambda (i, x): i - x): group = map(itemgetter(1), g) if len(group) > 2: delta_list = np.setdiff1d(delta_list, group) i = 0 tries = 10 while i <= len(delta_list) - 2 and tries > 0 \ and len(delta_list) > 1: if abs(m1_age[delta_list[i]] - m1_age[delta_list[i + 1]]) <= time_tol: # print(abs(m1_age[i] - m1_age[i + 1])) # print('restart') delta_list = np.delete(delta_list, i) i = 0 tries -= 1 else: tries = 10 i += 1 if plot: plt.clf() plt.plot(m1_age[1:], np.log10(percent_delta)) if len(delta_list) >= 2: plt.plot(m1_age[1:][delta_list], np.log10(percent_delta)[delta_list], 'or') outburst_num = len(delta_list) // 2 print(subdir, outburst_num) if outburst_num > number_tol: outburst_list.append(subdir) outnum_list.append(outburst_num) except: print("Convergence issues")
def Plot_CoreMass(root_dir="."): ''' Plots the masses of the core for the following elements: Hydrogen (H) Helium (He) Carbon (C) Oxygen (0) Silicon (Si) Iron (Fe) Parameters ---------- root_dir : string path to the directory containing the history.data file to be used Returns ------- Plots : 1. The core masses of the various elements as the star evoloves ''' m1 = ms.history_data(root_dir) age = m1.get('star_age') total_mass = m1.get('star_mass') conv_core = m1.get('mass_conv_core') he_core = m1.get('he_core_mass') c_core = m1.get('c_core_mass') o_core = m1.get('o_core_mass') si_core = m1.get('si_core_mass') fe_core = m1.get('fe_core_mass') plt.plot(age, total_mass, label='total mass') plt.plot(age, conv_core, label='Convective core') plt.plot(age, he_core, label='He core') plt.plot(age, c_core, label='C core') plt.plot(age, o_core, label='O core') plt.plot(age, si_core, label='Si core') plt.plot(age, fe_core, label='Fe core') plt.xlabel("Time") plt.ylabel("M_sun") plt.legend(loc=3) try: output_string = mesa_calc.Calc_MassVals(root_dir) plt.figtext(0.15, 0.75, output_string) except: pass plt.show()
def Plot_Gen_Quick(root_dir="."): i = 0 for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": try: i = i + 1 plt.figure(i) plt.clf() m1 = ms.history_data(subdir) plt.plot(m1.get('star_age'), m1.get('lg_mstar_dot_1')) plt.title(subdir) plt.savefig(root_dir + str(i)) except: pass
def Calc_MassVals(root_dir="."): ''' Calculates the relative mass of each element in the core Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used Returns- ------- output_string : string string of the masses of the various elements near the core ''' m1 = ms.history_data(root_dir) age = m1.get('star_age') # conv_core = m1.get('mass_conv_core') he_core = m1.get('he_core_mass') c_core = m1.get('c_core_mass') o_core = m1.get('o_core_mass') si_core = m1.get('si_core_mass') fe_core = m1.get('fe_core_mass') h1_frac = m1.get('center_h1') zero_point = np.where(h1_frac == 0)[0][0] zero_time = age[zero_point] he_mass = he_core[zero_point] c_mass = c_core[zero_point] o_mass = o_core[zero_point] si_mass = si_core[zero_point] fe_mass = fe_core[zero_point] output_string = ("Time:" + str(zero_time) + ' yrs\n' + "He Mass:" + str(he_mass) + ' M_sun\n' + "C Mass:" + str(c_mass) + '\n' + "O Mass:" + str(o_mass) + '\n' + "Si Mass:" + str(si_mass) + '\n' + "Fe Mass:" + str(fe_mass) ) return output_string
def Plot_CoreFrac(root_dir="."): ''' Plots the mass fractions of the core for the following elements: Hydrogen (H) Helium (He) Carbon (C) Oxygen (0) Parameters ---------- root_dir : string path to the directory containing the history.data file to be used Returns ------- Plots : 1. The core mass fractions of the various elements as the star evoloves ''' m1 = ms.history_data(root_dir) age = m1.get('star_age') h1_frac = m1.get('center_h1') he4_frac = m1.get('center_he4') c12_frac = m1.get('center_c12') o16_frac = m1.get('center_o16') plt.plot(age, h1_frac, label='H Fraction') plt.plot(age, he4_frac, label='He Fraction') plt.plot(age, c12_frac, label='C Fraction') plt.plot(age, o16_frac, label='O Fraction') plt.xlabel("Time") plt.legend(loc=3) try: output_string = mesa_calc.Calc_MassVals(root_dir) plt.figtext(0.15, 0.75, output_string) except: pass plt.show()
def Plot_Gen_Init_Mesh(): """ Creates a plot showing a mesh of the initial systems after one timestep. MESA data output doesn't include the 0th step so the mesh is technically not an "initial" mesh. """ for subdir, dirs, files in os.walk("."): for file_name in files: if file_name == "history.data": try: m1 = ms.history_data(subdir) plt.plot(m1.get('star_1_mass')[0], np.log10(m1.get('period_days')[0]), 'k+') except: pass plt.title("Initial Parameter Mesh") plt.savefig("init_mesh")
def Plot_Gen(*args): ''' Creates seperate plots for each argument given Parameters ---------- args : string Paths to the directories containing the history.log files to be plotted Returns ------- Plots : One plot per argument with x and y variables defined by the user ''' history_list = [] for dirs in args: history_list.append(ms.history_data(dirs)) for colname in sorted(history_list[0].cols): print(colname) xaxis = raw_input("Enter x axis variable: ") lg_mtransfer_rate = raw_input("Enter y axis variables: ") for vals in history_list: xvariable = vals.get(xaxis) yvariable = vals.get(lg_mtransfer_rate) varlabel = raw_input("label: ") plt.plot(xvariable, yvariable, label=varlabel) userxlabel = raw_input("Enter x label: ") userylabel = raw_input("Enter y label: ") usertitle = raw_input("Enter title: ") plt.xlabel(userxlabel) plt.ylabel(userylabel) plt.title(usertitle) plt.legend() plt.show()
def Find_End_Result(root_dir="."): ''' Determine the final result of the star. This can be one of the following results: 1. Merger 2. Star has a convective core 3. Star does not have a convective core 4. Star has a convective core but angular momentum issues Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' no_conv_core = ["no convective cores : "] conv_core = ["convective cores : "] conv_core_bad_J = ["bad angular momentum and convective : "] merged = ["mergers : "] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": print(subdir) try: m1 = ms.history_data(subdir) sep = m1.get('binary_separation') if True in (sep <= 0.1): merged.append(subdir) else: if m1.get("mass_conv_core")[-1] == 0: no_conv_core.append(subdir) else: conv_core.append(subdir) except: pass for new_dir in conv_core[1:]: conv_core_bad_J.append(Find_Bad_J(new_dir[:-5])) return merged, conv_core, no_conv_core, conv_core_bad_J
def Plot_Gen_HRD_wPeriod(): m1 = ms.history_data("default/3.202R_2.19d_Def/LOGS") m2 = ms.history_data("div_10/3.202R_2.19d_Def/LOGS") m3 = ms.history_data("div_100/3.202R_2.19d_Def/LOGS") m4 = ms.history_data("default/3.202R_2.19d_Mod/LOGS") m5 = ms.history_data("div_10/3.202R_2.19d_Mod/LOGS") m6 = ms.history_data("div_100/3.202R_2.19d_Mod/LOGS") fig1, ax1 = plt.subplots(1, figsize=(10, 7.5)) ax1.plot(m3.get('star_age'), m3.get('lg_mstar_dot_1'), lw=0.1) ax1.plot(m2.get('star_age'), m2.get('lg_mstar_dot_1'), lw=0.5) ax1.plot(m1.get('star_age'), m1.get('lg_mstar_dot_1'), lw=1.0) ax1.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax1.set_xlim(4E7, 5E7) ax1.set_ylim(-14, -6) ax1.set_ylabel(r'Mass Trasnfer Rate log$(\dot{M_\odot})$', fontsize=20) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.grid() ax1.set_title("Default Magnetic Braking", fontsize=26) xtext1 = ax1.xaxis.get_offset_text() xtext1.set_size(20) ytext1 = ax1.yaxis.get_offset_text() ytext1.set_size(20) fig1.tight_layout() # plt.show() fig1.savefig("2a") fig2, ax2 = plt.subplots(1, figsize=(10, 7.5)) ax2.plot(m6.get('star_age'), m6.get('lg_mstar_dot_1'), lw=0.1) ax2.plot(m5.get('star_age'), m5.get('lg_mstar_dot_1'), lw=0.5) ax2.plot(m4.get('star_age'), m4.get('lg_mstar_dot_1'), lw=1.0) ax2.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax2.set_xlim(4E7, 5E7) ax2.set_ylim(-14, -6) ax2.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax2.tick_params(axis='both', which='major', labelsize=20) ax2.grid() ax2.set_title("Modified Magnetic Braking", fontsize=26) xtext2 = ax2.xaxis.get_offset_text() xtext2.set_size(20) ytext2 = ax2.yaxis.get_offset_text() ytext2.set_size(20) fig2.tight_layout() # plt.show() fig2.savefig("HRD_wPer")
def Plot_Gen_Rel_Overflow(): m1 = ms.history_data("default/3.202R_2.19d_Def/LOGS") m2 = ms.history_data("div_10/3.202R_2.19d_Def/LOGS") m3 = ms.history_data("div_100/3.202R_2.19d_Def/LOGS") m4 = ms.history_data("default/3.202R_2.19d_Mod/LOGS") m5 = ms.history_data("div_10/3.202R_2.19d_Mod/LOGS") m6 = ms.history_data("div_100/3.202R_2.19d_Mod/LOGS") fig1, ax1 = plt.subplots(1, figsize=(10, 7.5)) ax1.plot(m1.get('star_age'), m1.get('rl_relative_overflow_1')) ax1.plot(m2.get('star_age'), m2.get('rl_relative_overflow_1')) ax1.plot(m3.get('star_age'), m3.get('rl_relative_overflow_1')) ax1.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax1.set_xlim(0, 4E8) ax1.set_ylabel(r'Relative Roche Lobe Overflow', fontsize=20) ax1.set_ylim(-0.5, 0.5) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.grid() ax1.set_title("Default Magnetic Braking", fontsize=26) xtext1 = ax1.xaxis.get_offset_text() xtext1.set_size(20) ytext1 = ax1.yaxis.get_offset_text() ytext1.set_size(20) fig1.tight_layout() # plt.show() fig1.savefig("RO_a") fig2, ax2 = plt.subplots(1, figsize=(10, 7.5)) ax2.plot(m4.get('star_age'), m4.get('rl_relative_overflow_1')) ax2.plot(m5.get('star_age'), m5.get('rl_relative_overflow_1')) ax2.plot(m6.get('star_age'), m6.get('rl_relative_overflow_1')) ax2.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax2.set_xlim(0, 1.5E8) ax2.set_ylabel(r'Relative Roche Lobe Overflow', fontsize=20) ax2.set_ylim(-0.5, 0.5) ax2.tick_params(axis='both', which='major', labelsize=20) ax2.grid() ax2.set_title("Default Magnetic Braking", fontsize=26) xtext2 = ax2.xaxis.get_offset_text() xtext2.set_size(20) ytext2 = ax2.yaxis.get_offset_text() ytext2.set_size(20) fig2.tight_layout() # plt.show() fig2.savefig("RO_b")
def Plot_RLOF(root_dir="."): ''' Goes into the inputted directory and plots the relative roche lobe overflow from the donor star. Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used Returns ------- Plots : 1. The relative roche lobe overflow of the desired system with the various properties of the system at this time. ''' m1 = ms.history_data(root_dir) yval = m1.get("rl_relative_overflow_1") xaxis = raw_input("Enter x axis variable: ") xval = m1.get(xaxis) plt.plot(xval, yval) plt.ylabel("rl_relative_overflow_1") plt.xlabel(xaxis) plt.ylim(0, max(yval)) try: output_string = val_find.Find_RLOF_Prop(root_dir) plt.figtext(0.15, 0.75, output_string) except: pass plt.show()
def Find_RLOF_Check(root_dir="."): ''' Loops through the directories to determine of a system goes into RLOF. If it does then list the time it goes into RLOF and if it is still in that state Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' rlof_cont = ["rlof ongoing"] no_rlof = ["no rlof"] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": # print(subdir) try: m1 = ms.history_data(subdir) except: print("Convergence issues") preface = subdir + " : " print(preface) try: m1rlof = m1.get('rl_relative_overflow_1') rlof_index = np.where(m1rlof > 0)[0] # rlof_start = [] rlof_ends = [] i = 0 while ((rlof_index[i + 1] - rlof_index[i]) < 100)\ and (i < len(rlof_index) - 2): rlof_ends.append(rlof_index[i]) i = i + 1 if len(rlof_ends) == 0: rlof_ends = [rlof_index[-1]] rlof_start = rlof_index[1] rlof_end = rlof_ends[-1] # print("RLOF Success") # # initial star age t_i = m1.get("star_age")[rlof_start] # evolution time dt = m1.get("star_age")[rlof_end] - t_i if m1rlof[rlof_end] == m1rlof[-1]: rlof_cont.append(subdir + " " + str(dt)) # print("RLOF still ongoing") except: pass # print("no RLOF") # print("RLOF still ongoing: ") # for line in rlof_cont: # print(line) # print("") # print("No RLOF: ") # for line in no_rlof: # print(line) return rlof_cont, no_rlof
def Find_RLOF_Prop(root_dir="."): ''' Determine the value of various properties at the beginning of RLOF and at the end of RLOF. NOTE: The values representing the "end" of RLOF may not be correct, The star can easily stop transferring mass and restart multiple times, therefore the "end" value represents the last value in the simulations that had a relative RLOF greater than 0 Values given: Initial time of RLOF Final donor mass after RLOF Final companion mass after RLOF Initial radius at the start of RLOF of donor Final radius after RLOF of donor Final period after RLOF Total time or RLOF Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' value_matrix = [["directory", "rlof start", "final star 1 mass", "final star 2 mass", "initial radius", "final radius", "initial period", "final period", "evolution time"]] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": m1 = ms.history_data(subdir) preface = subdir + " : " print(preface) try: m1rlof = m1.get('rl_relative_overflow_1') rlof_index = np.where(m1rlof > 0)[0] # rlof_start = [] rlof_ends = [] i = 0 while ((rlof_index[i + 1] - rlof_index[i]) < 100)\ and (i < len(rlof_index) - 2): rlof_ends.append(rlof_index[i]) i = i + 1 if len(rlof_ends) == 0: rlof_ends = [rlof_index[-1]] rlof_start = rlof_index[1] rlof_end = rlof_ends[-1] # # initial star age t_i = m1.get("star_age")[rlof_start] # final masses M1_f = m1.get("star_1_mass")[rlof_end] M2_f = m1.get("star_2_mass")[rlof_end] # final period P_f = m1.get("period_days")[rlof_end] P_i = m1.get("period_days")[rlof_start] # evolution time dt = m1.get("star_age")[rlof_end] - t_i # radius r_i = 10**m1.get("log_R")[rlof_start] r_f = 10**m1.get("log_R")[rlof_end] # t_i_string = "RLOF starts at: " + str(t_i) # M1_f_string = "final star 1 mass: " + str(M1_f) # M2_f_string = "final star 2 mass: " + str(M2_f) # r_i_string = "initial radius: " + str(r_i) # r_f_string = "final radius: " + str(r_f) # P_i_string = "initial period: " + str(P_i) # P_f_string = "final period: " + str(P_f) # dt_string = "RLOF time: " + str(dt) # print(t_i_string) # print(M1_f_string) # print(M2_f_string) # print(r_i_string) # print(r_f_string) # print(P_i_string) # print(P_f_string) # print(dt_string) value_matrix.append([subdir, t_i, M1_f, M2_f, r_i, r_f, P_i, P_f, dt]) except: print("no RLOF") return value_matrix
def Plot_Gen_Mdot_Compare(): mi_1 = ms.history_data("mod_6/LOGS") mi_2 = ms.history_data("mod_8/LOGS") # mi_3 = ms.history_data("mod_9/LOGS") mi_4 = ms.history_data("mod_11/LOGS") # mi_5 = ms.history_data("mod_10/LOGS") mi_6 = ms.history_data("mod_12/LOGS") me_1 = ms.history_data("mod_7/LOGS") me_2 = ms.history_data("mod_13/LOGS") me_3 = ms.history_data("mod_14/LOGS") # m_str = "/home/kvan/mesa_work_dirs/8677_outburst_check/def_tol_test/LOGS" # m_old = ms.history_data(m_str) mi_1_label = "Implicit MT, No Max dt, Def Tolerances" mi_2_label = "Implicit MT, 1E6 Max dt, Def Tolerances" # mi_3_label = "Implicit MT, 1E6 Max dt, Strict Tol, Def Norms" mi_4_label = "Implicit MT, 1E6 Max dt, Strict Tolerances" # mi_5_label = "Implicit MT, 1E5 Max dt, Strict Tol/Norms" mi_6_label = "Implicit MT, No Max dt, Strict Tolerances" me_1_label = "Explicit MT, No Max dt, Def Tolerances" me_2_label = "Explicit MT, 1E6 Max dt, Def Tolerances" me_3_label = "Explicit MT, 1E6 Max dt, Strict Tolerances" # m_old_label = "Previous Results" fig1, ax1 = plt.subplots(1, figsize=(24, 13.5)) ax1.plot(mi_1.get('star_age'), mi_1.get('lg_mstar_dot_1'), label=mi_1_label) ax1.plot(mi_2.get('star_age'), mi_2.get('lg_mstar_dot_1') - 0.5, label=mi_2_label) # ax1.plot(mi_3.get('star_age'), mi_3.get('lg_mstar_dot_1') - 1.0, # label=mi_3_label) ax1.plot(mi_4.get('star_age'), mi_4.get('lg_mstar_dot_1') - 1.0, label=mi_4_label) # ax1.plot(mi_5.get('star_age'), mi_5.get('lg_mstar_dot_1') - 2.0, # label=mi_5_label) ax1.plot(mi_6.get('star_age'), mi_6.get('lg_mstar_dot_1') - 1.5, label=mi_6_label) ax1.plot(me_1.get('star_age'), me_1.get('lg_mstar_dot_1') - 2.0, label=me_1_label) ax1.plot(me_2.get('star_age'), me_2.get('lg_mstar_dot_1') - 2.5, label=me_2_label) ax1.plot(me_3.get('star_age'), me_3.get('lg_mstar_dot_1') - 3.0, label=me_3_label) # ax1.plot(m_old.get('star_age'), m_old.get('lg_mstar_dot_1') - 4.5, # label=m_old_label) ax1.set_xlabel(r'years', fontsize=20) ax1.set_ylabel(r'Mass Loss Rate log($\dot{M_\odot}$)', fontsize=20) xtext1 = ax1.xaxis.get_offset_text() xtext1.set_size(20) ytext1 = ax1.yaxis.get_offset_text() ytext1.set_size(20) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.grid() ax1.legend(loc=3) fig1.tight_layout() # plt.show() fig1.savefig("Mdot_Compare")
def Plot_Gen_Simp_Mdot(): m1 = ms.history_data("def_mdot/3.202R_2.19d_Def/LOGS") m2 = ms.history_data("implicit_test/3.202R_2.19d_Def/LOGS") m3 = ms.history_data("def_mdot/3.202R_2.19d_Mod/LOGS") m4 = ms.history_data("implicit_test/3.202R_2.19d_Mod/LOGS") fig1, ax1 = plt.subplots(1, figsize=(10, 7.5)) ax1.plot(m1.get('star_age'), m1.get('lg_mstar_dot_1')) ax1.plot(m2.get('star_age'), m2.get('lg_mstar_dot_1') - 0.5) ax1.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax1.set_xlim(0, 4E8) ax1.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.grid() ax1.set_title("Default Magnetic Braking", fontsize=26) xtext1 = ax1.xaxis.get_offset_text() xtext1.set_size(20) ytext1 = ax1.yaxis.get_offset_text() ytext1.set_size(20) fig1.tight_layout() # plt.show() fig1.savefig("Mdota") fig2, ax2 = plt.subplots(1, figsize=(10, 7.5)) ax2.plot(m3.get('star_age'), m3.get('lg_mstar_dot_1')) ax2.plot(m4.get('star_age'), m4.get('lg_mstar_dot_1') - 0.5) ax2.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax2.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax2.tick_params(axis='both', which='major', labelsize=20) ax2.grid() ax2.set_title("Modified Magnetic Braking", fontsize=26) xtext2 = ax2.xaxis.get_offset_text() xtext2.set_size(20) ytext2 = ax2.yaxis.get_offset_text() ytext2.set_size(20) fig2.tight_layout() # plt.show() fig2.savefig("Mdotb") fig3, ax3 = plt.subplots(1, figsize=(10, 7.5)) ax3.plot(m1.get('period_days'), m1.get('lg_mstar_dot_1')) ax3.plot(m2.get('period_days'), m2.get('lg_mstar_dot_1') - 0.5) ax3.set_xlabel(r'Period (Days)', fontsize=20) ax3.set_xscale('log') ax3.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax3.tick_params(axis='both', which='major', labelsize=20) ax3.grid() ax3.set_title("Default Magnetic Braking", fontsize=26) fig3.tight_layout() # plt.show() fig3.savefig("Mdotc") fig4, ax4 = plt.subplots(1, figsize=(10, 7.5)) ax4.plot(m3.get('period_days'), m3.get('lg_mstar_dot_1')) ax4.plot(m4.get('period_days'), m4.get('lg_mstar_dot_1') - 0.5) ax4.set_xlabel(r'Period (Days)', fontsize=20) ax4.set_xscale('log') ax4.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax4.tick_params(axis='both', which='major', labelsize=20) ax4.grid() ax4.set_title("Modified Magnetic Braking", fontsize=26) fig4.tight_layout() # plt.show() fig4.savefig("Mdotd")
def Plot_Gen_Mdot_Tol_MB(): m01 = ms.history_data("def_mdot/3.202R_2.19d_Def/LOGS") m02 = ms.history_data("tol_converg_test/3.202R_2.19d_Def/LOGS") m03 = ms.history_data("tol_converg_test2/3.202R_2.19d_Def/LOGS") m04 = ms.history_data("fr_test/3.202R_2.19d_Def/LOGS") m05 = ms.history_data("cur_mdot_0_test/3.202R_2.19d_Def/LOGS") m06 = ms.history_data("def_mdot/3.202R_2.19d_Mod/LOGS") m07 = ms.history_data("tol_converg_test/3.202R_2.19d_Mod/LOGS") m08 = ms.history_data("tol_converg_test2/3.202R_2.19d_Mod/LOGS") m09 = ms.history_data("fr_test/3.202R_2.19d_Mod/LOGS") m10 = ms.history_data("cur_mdot_0_test/3.202R_2.19d_Mod/LOGS") fig1, ax1 = plt.subplots(1, figsize=(10, 7.5)) ax1.plot(m01.get('star_age'), m01.get('lg_mstar_dot_1'), label='Default Tolerance') ax1.plot(m02.get('star_age'), m02.get('lg_mstar_dot_1') - 0.5, label=r'$\frac{1}{10}$ Tolerance') ax1.plot(m03.get('star_age'), m03.get('lg_mstar_dot_1') - 1.0, label=r'$\frac{1}{100}$ Tolerance') ax1.plot(m04.get('star_age'), m04.get('lg_mstar_dot_1') - 1.5, label=r'$\frac{1}{10}$ $\frac{R-R_l}{R}$') ax1.plot(m05.get('star_age'), m05.get('lg_mstar_dot_1') - 2.0, label=r'Independent $\dot{M}$ Calculation') ax1.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax1.set_xlim(0, 4E8) ax1.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax1.set_ylim(-18, -6) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.grid() ax1.legend(loc=4) ax1.set_title("Default Magnetic Braking", fontsize=26) xtext1 = ax1.xaxis.get_offset_text() xtext1.set_size(20) ytext1 = ax1.yaxis.get_offset_text() ytext1.set_size(20) fig1.tight_layout() # plt.show() fig1.savefig("Mdot_Age_Def") fig2, ax2 = plt.subplots(1, figsize=(10, 7.5)) ax2.plot(m01.get('period_days'), m01.get('lg_mstar_dot_1')) ax2.plot(m02.get('period_days'), m02.get('lg_mstar_dot_1') - 0.5) ax2.plot(m03.get('period_days'), m03.get('lg_mstar_dot_1') - 1.0) ax2.plot(m04.get('period_days'), m04.get('lg_mstar_dot_1') - 1.5) ax2.plot(m05.get('period_days'), m05.get('lg_mstar_dot_1') - 2.0) ax2.set_xlabel(r'Period (Days)', fontsize=20) ax2.set_xscale('log') ax2.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax2.set_ylim(-18, -6) ax2.tick_params(axis='both', which='major', labelsize=20) ax2.grid() ax2.set_title("Default Magnetic Braking", fontsize=26) fig2.tight_layout() # plt.show() fig2.savefig("Mdot_Per_Def") fig3, ax3 = plt.subplots(1, figsize=(10, 7.5)) ax3.plot(m06.get('star_age'), m06.get('lg_mstar_dot_1')) ax3.plot(m07.get('star_age'), m07.get('lg_mstar_dot_1') - 0.5) ax3.plot(m08.get('star_age'), m08.get('lg_mstar_dot_1') - 1.0) ax3.plot(m09.get('star_age'), m09.get('lg_mstar_dot_1') - 1.5) ax3.plot(m10.get('star_age'), m10.get('lg_mstar_dot_1') - 2.0) ax3.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax3.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax3.set_ylim(-18, -6) ax3.tick_params(axis='both', which='major', labelsize=20) ax3.grid() ax3.set_title("Modified Magnetic Braking", fontsize=26) xtext3 = ax3.xaxis.get_offset_text() xtext3.set_size(20) ytext3 = ax3.yaxis.get_offset_text() ytext3.set_size(20) fig3.tight_layout() # plt.show() fig3.savefig("Mdot_Age_Mod") fig4, ax4 = plt.subplots(1, figsize=(10, 7.5)) ax4.plot(m06.get('period_days'), m06.get('lg_mstar_dot_1')) ax4.plot(m07.get('period_days'), m07.get('lg_mstar_dot_1') - 0.5) ax4.plot(m08.get('period_days'), m08.get('lg_mstar_dot_1') - 1.0) ax4.plot(m09.get('period_days'), m09.get('lg_mstar_dot_1') - 1.5) ax4.plot(m10.get('period_days'), m10.get('lg_mstar_dot_1') - 2.0) ax4.set_xlabel(r'Period (Days)', fontsize=20) ax4.set_xscale('log') ax4.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax4.set_ylim(-18, -6) ax4.tick_params(axis='both', which='major', labelsize=20) ax4.grid() ax4.set_title("Modified Magnetic Braking", fontsize=26) fig4.tight_layout() # plt.show() fig4.savefig("Mdot_Per_Mod")
def Plot_Gen_MDot_Per_Age(): m1 = ms.history_data("def_mdot/3.202R_2.19d_Def/LOGS") m2 = ms.history_data("def_mdot_10/3.202R_2.19d_Def/LOGS") m3 = ms.history_data("def_mdot_100/3.202R_2.19d_Def/LOGS") m4 = ms.history_data("def_mdot/3.202R_2.19d_Mod/LOGS") m5 = ms.history_data("def_mdot_10/3.202R_2.19d_Mod/LOGS") m6 = ms.history_data("def_mdot_100/3.202R_2.19d_Mod/LOGS") fig1, ax1 = plt.subplots(1, figsize=(10, 7.5)) ax1.plot(m1.get('star_age'), m1.get('lg_mstar_dot_1'), label='Default MB, 1E5 Timestep') ax1.plot(m2.get('star_age'), m2.get('lg_mstar_dot_1'), label='1E4 Timestep') ax1.plot(m3.get('star_age'), m3.get('lg_mstar_dot_1'), label='1E3 Timestep') ax1.plot(m4.get('star_age'), m4.get('lg_mstar_dot_1'), label='Modified MB, 1E5 Timestep') ax1.plot(m5.get('star_age'), m5.get('lg_mstar_dot_1'), label='1E4 Timestep') ax1.plot(m6.get('star_age'), m6.get('lg_mstar_dot_1'), label='1E3 Timestep') ax1.set_xlabel(r'Time Since Binary Formation (years)', fontsize=20) ax1.set_xlim(0, 4E8) ax1.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax1.tick_params(axis='both', which='major', labelsize=20) ax1.grid() ax1.legend(loc=4) xtext1 = ax1.xaxis.get_offset_text() xtext1.set_size(20) ytext1 = ax1.yaxis.get_offset_text() ytext1.set_size(20) fig1.tight_layout() # plt.show() fig1.savefig("Mdot_Age") fig2, ax2 = plt.subplots(1, figsize=(10, 7.5)) ax2.plot(m1.get('period_days')[0], m1.get('lg_mstar_dot_1')[0], 'k*', ms=15) ax2.plot(m1.get('period_days'), m1.get('lg_mstar_dot_1')) ax2.plot(m2.get('period_days'), m2.get('lg_mstar_dot_1')) ax2.plot(m3.get('period_days'), m3.get('lg_mstar_dot_1')) ax2.plot(m4.get('period_days'), m4.get('lg_mstar_dot_1')) ax2.plot(m5.get('period_days'), m5.get('lg_mstar_dot_1')) ax2.plot(m6.get('period_days'), m6.get('lg_mstar_dot_1')) ax2.set_xlabel(r'Period (Days)', fontsize=20) ax2.set_xscale('log') ax2.set_ylabel(r'Mass Loss Rate log$(\dot{M_\odot})$', fontsize=20) ax2.tick_params(axis='both', which='major', labelsize=20) ax2.grid() ax2.legend(loc=3) xtext2 = ax1.xaxis.get_offset_text() xtext2.set_size(20) ytext2 = ax1.yaxis.get_offset_text() ytext2.set_size(20) fig2.tight_layout() # plt.show() fig2.savefig("Mdot_Per")
def Plot_HRD_Detailed(root_dir="."): ''' Should be in the directory containing all the single star evolutions. Creates an HRD diagram with mass values listed next to the evolution curves. Adds data points to selected points where we begin binary evolution, in this case we have it at the periods of 1 day, 2 days 10 days and 100 days. Parameters ---------- root_dir : string Path to the directory containing various single star evolutions used in later to create binaries Returns ------- A detailed HRD plot containing all single star evolutions with points showing select periods for binary formation Figure 1 in paper ''' d1_plotted = False d2_plotted = False d10_plotted = False d100_plotted = False mass_dirs = next(os.walk(root_dir))[1] mass_dirs.sort() per_100_list = [] per_10_list = [] per_2_list = [] per_1_list = [] for mass in mass_dirs: rad_dirs = next(os.walk(mass))[1] rad_dirs.sort() for i in xrange(len(rad_dirs)): # Cut the 'R' character off the directory to sort radii rad_dirs[i] = float(rad_dirs[i][0:-1]) rad_dirs.sort() per_100_str = mass + '/' + str(format(rad_dirs[-1], '.3f')) + 'R/LOGS' per_100_list.append(per_100_str) per_10_str = mass + '/' + str(format(rad_dirs[28], '.3f')) + 'R/LOGS' per_10_list.append(per_10_str) per_2_str = mass + '/' + str(format(rad_dirs[14], '.3f')) + 'R/LOGS' per_2_list.append(per_2_str) per_1_str = mass + '/' + str(format(rad_dirs[8], '.3f')) + 'R/LOGS' per_1_list.append(per_1_str) plt.figure(1, figsize=(24, 13.5)) plt.clf() for index in xrange(len(per_100_list)): model_100 = ms.history_data(per_100_list[index]) model_10 = ms.history_data(per_10_list[index]) model_2 = ms.history_data(per_2_list[index]) model_1 = ms.history_data(per_1_list[index]) model_100.hrd(colour='k', s2ms=True) h1 = model_100.get('center_h1') idx = np.where(h1[0] - h1 >= 3.e-3)[0][0] plt.text(model_100.get('log_Teff')[idx] + 0.01, model_100.get('log_L')[idx] - 0.1, str(model_100.get('star_mass')[0]) + r'$\dot{M_\odot}$') if not d1_plotted: d1_plotted = True plt.plot(model_1.get('log_Teff')[-1], model_1.get('log_L')[-1], 'r*', ms=8, label="P=1 d") plt.plot(model_1.get('log_Teff')[-1], model_1.get('log_L')[-1], 'r*', ms=12) if not d2_plotted: d2_plotted = True plt.plot(model_2.get('log_Teff')[-1], model_2.get('log_L')[-1], 'bo', ms=8, label="P=2 d") plt.plot(model_2.get('log_Teff')[-1], model_2.get('log_L')[-1], 'bo', ms=10) if not d10_plotted: d10_plotted = True plt.plot(model_10.get('log_Teff')[-1], model_10.get('log_L')[-1], 'cs', ms=8, label="P=10 d") plt.plot(model_10.get('log_Teff')[-1], model_10.get('log_L')[-1], 'cs', ms=8) if not d100_plotted: d100_plotted = True plt.plot(model_100.get('log_Teff')[-1], model_100.get('log_L')[-1], 'g^', ms=8, label="P=100 d") plt.plot(model_100.get('log_Teff')[-1], model_100.get('log_L')[-1], 'g^', ms=10) plt.xlabel(r'log$T_{eff}$', fontsize=26) plt.ylabel(r'log$L$', fontsize=26) plt.tick_params(axis='both', which='major', labelsize=20) plt.legend(loc=2, numpoints=1) plt.grid() plt.savefig('Detailed_HRD')
def Plot_Outburst_Props(file_path="filtered_data.npy", tol1=0.05, tol2=10, mk_mdot=True, mk_rstar=False, mk_rlobe=False, mk_rho=False, mk_delta_rho=False, mk_t_dyn=False, mk_sep=False, mk_mstar=False, mk_mratio=False): ''' Uses a saved numpy file and randomly chooses an outburst to analyze Parameters ---------- file_path : string Path and name to the numpy file to be loaded tol1 : float The tolerance for change in mass transfer rate between data points to be considered important to the analysis tol2 : float The number of subsequent data points that are ignored after determing a point to be important to the analysis mk_mdot : boolean Determine if the function should create the mass transfer rate plot mk_rstar : boolean Determine if the function should create the stellar radius plot mk_rlobe : boolean Determine if the function should create the Roche lobe radius plot mk_rho : boolean Determine if the funection should create the density profile plot mk_delta_rho : boolean Determine if the funection should create a plot showing the difference in density profiles mk_t_dyn : boolean Determine if the funection should create a plot comparing dynamic time and the period of the system mk_sep : boolean Determine if the funection should create a plot showing the evolution of binary separation between stars mk_mstar : boolean Determine if the function should create a plot showing the mass evolution of the companion star mk_mratio : boolean Determineif the funection should create a plot showing the evolution of the mass ratio Returns ------- Plots : 1. Donor star mass transfer rate as a function of time 2. Donor star radius as a function of time 3. Donor star roche lobe as a function of time 4. Density profile of donor star before and at outburst peak 5. Change in density profile of donor star 6. A comparison between period and dynamic timescale 7. Separation over the course of an outburst 8. Donor mass over the course of an outburst 9. The mass ratio of the system over the course of an outburst ''' try: filtered_results = np.load(file_path) start_index = np.where(filtered_results[:, 3] < -7)[0][0] filtered_results = filtered_results[start_index:] filtered_model = filtered_results[:, 0] filtered_period = filtered_results[:, 1] filtered_sep = filtered_results[:, 2] filtered_mtransfer = filtered_results[:, 3] filtered_mass1 = filtered_results[:, 4] filtered_mass2 = filtered_results[:, 5] filtered_dt = filtered_results[:, 6] filtered_index = filtered_results[:, 7] filtered_times = filtered_results[:, 8] # Other important properties not used filtered_age = filtered_results[:, 9] filtered_radius = filtered_results[:, 10] filtered_rl1 = filtered_results[:, 11] filtered_rl2 = filtered_results[:, 12] filtered_mdot1 = filtered_results[:, 13] filtered_wind1 = filtered_results[:, 14] except: filtered_results = ms.history_data("./LOGS") MT = filtered_results.get('lg_mtransfer_rate') start_index = np.where(MT < -3)[0][0] filtered_results = filtered_results[start_index:] filtered_model = filtered_results.get('model_number') filtered_period = filtered_results.get('period_days') filtered_sep = filtered_results.get('binary_separation') filtered_mtransfer = filtered_results.get('lg_mtransfer_rate') filtered_mass1 = filtered_results.get('star_1_mass') filtered_mass2 = filtered_results.get('star_2_mass') filtered_age = filtered_results.get('star_age') filtered_radius = 10**filtered_results.get('log_R') filtered_rl1 = filtered_results.get('rl_relative_overflow_1') quiescent_index = [0] for i in xrange(1, len(filtered_mtransfer) - 1): if filtered_mtransfer[i + 1] > -7: quiescent_index.append(i) plt.plot(filtered_age[i], filtered_mtransfer[i], 'or') if (abs(filtered_mtransfer[i + 1] - filtered_mtransfer[i]) > tol1): i += 1 else: # print(i - quiescent_index[-1]) if abs(i - quiescent_index[-1]) > tol2: if filtered_mtransfer[i] < filtered_mtransfer[i + 1]: if (filtered_mtransfer[quiescent_index[-1]:i] > -8).any(): quiescent_index.append(i) plt.plot(filtered_age[i], filtered_mtransfer[i], 'ok') else: i += 1 else: i += 1 else: i += 1 temp_ind = np.random.randint(len(quiescent_index), size=1)[0] if filtered_mtransfer[quiescent_index[temp_ind] + 1] > -7: # print("ind1 = temp_ind") ind1 = quiescent_index[temp_ind] ind2 = quiescent_index[temp_ind + 1] else: # print("ind2 = temp_ind") ind1 = quiescent_index[temp_ind - 1] ind2 = quiescent_index[temp_ind] quiescent_model = filtered_model[ind1] outburst_model = filtered_model[ind1 + 1] if mk_rho or mk_delta_rho: q_profile = ms.mesa_profile('LOGS', quiescent_model) o_profile = ms.mesa_profile('LOGS', outburst_model) else: print("quiescent_model = " + str(quiescent_model)) print("outburst_model = " + str(outburst_model)) if mk_mdot: print("Creating mass transfer outburst plot") vert_line = np.linspace(-6, -12, 100) xpos1 = np.linspace(filtered_age[ind1], filtered_age[ind1], 100) xpos2 = np.linspace(filtered_age[ind2], filtered_age[ind2], 100) plt.figure(1, figsize=(24, 13.5)) plt.clf() plt.plot(filtered_age[ind1:ind2], filtered_mtransfer[ind1:ind2], 'o') plt.plot(filtered_age, filtered_mtransfer, '-', lw=0.5) plt.plot(xpos1, vert_line, 'k') plt.plot(xpos2, vert_line, 'k') # plt.xlim(filtered_age[ind1-10], filtered_age[ind2+10]) plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Mass Transfer Rate log$(\dot{M_\odot})$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title('Mass Transfer of the Binary System During Outburst', fontsize=26) plt.grid() figname = 'outburst_mdot' plt.savefig(figname) # plt.show() if mk_rstar: print("Creating radius outburst plot") plt.figure(2, figsize=(24, 13.5)) plt.clf() plt.plot(filtered_age[ind1:ind2], filtered_radius[ind1:ind2], 'o') plt.plot(filtered_age[ind1:ind2], filtered_radius[ind1:ind2], '-', lw=0.5) plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Star 1 Radius $(R_\odot)$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title('Radius of Star 1 During Outburst', fontsize=26) plt.grid() figname = 'outburst_radius' plt.savefig(figname) # plt.show() if mk_rlobe: print("Creating roche lobe radius outburst plot") plt.figure(3, figsize=(24, 13.5)) plt.clf() plt.plot(filtered_age[ind1:ind2], filtered_rl1[ind1:ind2], 'o') plt.plot(filtered_age[ind1:ind2], filtered_rl1[ind1:ind2], '-', lw=0.5) # plt.plot(filtered_age[ind1:ind2], filtered_rl2[ind1:ind2], '.', # label='Accretor Roche Lobe') # plt.plot(filtered_age[ind1:ind2], filtered_rl2[ind1:ind2], '-', # lw=0.5) plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Roche Lobe Radius $(R_\odot)$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title('Roche Lobe Radius During Outburst', fontsize=26) plt.grid() # plt.legend() figname = 'outburst_roche_lobe_radius' plt.savefig(figname) # plt.show() if mk_rho: print("Creating density profile") plt.figure(4, figsize=(24, 13.5)) plt.clf() # q_profile.density_profile(ixaxis='radius', ifig=4, label="Quiescent") # o_profile.density_profile(ixaxis='radius', ifig=4, label="Outburst") q_r = q_profile.get("logR") o_r = o_profile.get("logR") # q_m = q_profile.get("mass") # o_m = o_profile.get("mass") q_rho = q_profile.get("logRho") o_rho = o_profile.get("logRho") plt.plot(o_r, o_rho, label="Outburst") plt.plot(q_r, q_rho, label="Quiescent") plt.xlabel(r'Radius log$_{10}(R/R_\odot)$', fontsize=20) plt.ylabel(r'Density log$_{10}(\rho/g cm^{-3})$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title("Density Profile Before and During Outburst") plt.grid() plt.legend() figname = 'density_profile' plt.savefig(figname) # plt.show() if mk_delta_rho: print("Creating difference in density profile") plt.figure(5, figsize=(24, 13.5)) plt.clf() if len(q_rho) > len(o_rho): q_rho = q_rho[0:len(o_rho)] q_r = q_r[0:len(o_rho)] elif len(q_rho) < len(o_rho): o_rho = o_rho[0:len(q_rho)] plt.plot(q_r, o_rho - q_rho) plt.xlabel(r'Radius log$_{10}(R/R_\odot)$', fontsize=20) plt.ylabel(r'Difference in density log$_{10}(\rho/g cm^{-3})$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title("Change in Density Profile Before and During Outburst") plt.grid() plt.legend() figname = 'delta_density_profile' plt.savefig(figname) # plt.show() if mk_t_dyn: print("Comparing period and dynamical timescale") plt.figure(6, figsize=(24, 13.5)) plt.clf() # Calculating dynamic timescale G = 3.5E8 # G in units of R_sun, M_sun, yr r3 = filtered_radius ** 3 t_dyn = np.sqrt(r3 / (2 * G * filtered_mass1)) plt.plot(filtered_age, np.log10(t_dyn), label='Dynamic timescale') # Need to convert period days to years plt.plot(filtered_age, np.log10(filtered_period * 0.00274), label='Period') plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Time log$$(years)', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title("Dynamic Timescale and Period of the System") plt.grid() plt.legend() figname = 'period_timescale_comparison' plt.savefig(figname) # plt.show() if mk_sep: print("Creating separation plot") plt.figure(7, figsize=(24, 13.5)) plt.clf() plt.plot(filtered_age[ind1:ind2], filtered_sep[ind1:ind2], 'o') plt.plot(filtered_age[ind1:ind2], filtered_sep[ind1:ind2], '-', lw=0.5) plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Binary Separation $(R_\odot)$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title('Binary Separation During Outburst', fontsize=26) plt.grid() figname = 'outburst_sep' plt.savefig(figname) # plt.show() if mk_mstar: print("Creating donor mass plot") plt.figure(8, figsize=(24, 13.5)) plt.clf() plt.plot(filtered_age[ind1:ind2], filtered_mass1[ind1:ind2], 'o') plt.plot(filtered_age[ind1:ind2], filtered_mass1[ind1:ind2], '-', lw=0.5) plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Donor Mass $(\dot{M_\odot})$', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title('Donor Mass During Outburst', fontsize=26) plt.grid() figname = 'outburst_mass' plt.savefig(figname) # plt.show() if mk_mratio: print("Creating mass ratio plot") plt.figure(9, figsize=(24, 13.5)) plt.clf() q = filtered_mass1[ind1:ind2] / filtered_mass2[ind1:ind2] plt.plot(filtered_age[ind1:ind2], q, 'o') plt.plot(filtered_age[ind1:ind2], q, '-', lw=0.5) plt.xlabel(r'Time Since Binary Formation (years)', fontsize=20) plt.ylabel(r'Mass Ratio', fontsize=20) plt.tick_params(axis='both', which='major', labelsize=20) plt.title('Mass Ratio During Outburst', fontsize=26) plt.grid() figname = 'outburst_mass_ratio' plt.savefig(figname)
def Find_F_Properties(root_dir="."): ''' Find the initial and final values of the following properties: Initial and final helium core fraction Final donor mass Final companion mass Initial radius of donor Final radius of donor Final orbital period Final model number Can easily add more properties as necessary Parameters ---------- root_dir : string Path to the directory containing the history.data file to be used ''' value_matrix = [["directory", "initial he core fraction", "final star 1 mass", "final star 2 mass", "initial radius", "final radius", "initial period", "final period", "evolution time", "final model number"]] for subdir, dirs, files in os.walk(root_dir): for file_name in files: if file_name == "history.data": m1 = ms.history_data(subdir) # want various values # initial center he core frac X_i = m1.get("center_he4")[0] # # initial star age t_i = m1.get("star_age")[0] # final masses M1_f = m1.get("star_1_mass")[-1] M2_f = m1.get("star_2_mass")[-1] # final period P_i = m1.get("period_days")[0] P_f = m1.get("period_days")[-1] # evolution time dt = m1.get("star_age")[-1] - t_i # radius r_i = 10**m1.get("log_R")[0] r_f = 10**m1.get("log_R")[-1] # model number model = m1.get("model_number")[-1] # preface = subdir + " : " # X_i_string = "initial he core frac: " + str(X_i) # M1_f_string = "final star 1 mass: " + str(M1_f) # M2_f_string = "final star 2 mass: " + str(M2_f) # r_i_string = "initial radius: " + str(r_i) # r_f_string = "final radius: " + str(r_f) # P_i_string = "initial period: " + str(P_i) # P_f_string = "final period: " + str(P_f) # dt_string = "evolution time: " + str(dt) # model_string = "final model number: " + str(model) # print(preface) # print(X_i_string) # print(M1_f_string) # print(M2_f_string) # print(r_i_string) # print(r_f_string) # print(P_i_string) # print(P_f_string) # print(dt_string) # print(model_string) value_matrix.append([subdir, X_i, M1_f, M2_f, r_i, r_f, P_i, P_f, dt, model]) return value_matrix
def Plot_Quick(dir1, dir2): m1 = ms.history_data(dir1) m2 = ms.history_data(dir2) m_age1 = m1.get("star_age") m_age2 = m2.get("star_age") log_R1 = m1.get('log_R') log_R2 = m2.get('log_R') log_W1 = m1.get('lg_wind_mdot_1') log_W2 = m2.get('lg_wind_mdot_1') lum1 = m1.get('luminosity') lum2 = m2.get('luminosity') mass1 = m1.get('star_1_mass') mass2 = m2.get('star_1_mass') mdot1 = m1.get('lg_mstar_dot_1') mdot2 = m2.get('lg_mstar_dot_1') he_core1 = m1.get('he_core_mass') he_core2 = m2.get('he_core_mass') # Age and Radius plt.figure(1) plt.clf() plt.plot(m_age1, log_R1, 'or', markeredgecolor='r', label="Default MB") plt.plot(m_age2, log_R2, '.b', markeredgecolor='b', label="Modified MB") plt.xlim(0, max(m_age2)) plt.ylim(min(min(log_R1), min(log_R2)), max(max(log_R1), max(log_R2))) plt.legend() plt.xlabel("Star Age") plt.ylabel("Log_R (R_sun)") plt.title("Radius") plt.savefig("Radius") # Age and wind plt.figure(2) plt.clf() plt.plot(m_age1, log_W1, 'or', markeredgecolor='r', label="Default MB") plt.plot(m_age2, log_W2, '.b', markeredgecolor='b', label="Modified MB") plt.xlim(0, max(m_age2)) plt.ylim(min(min(log_W1), min(log_W2)), max(max(log_W1), max(log_W2))) plt.legend() plt.xlabel("Star Age") plt.ylabel("Log_W (MSun)") plt.title("Stellar Wind") plt.savefig("Wind") # Age and luminosity plt.figure(3) plt.clf() plt.plot(m_age1, lum1, 'or', markeredgecolor='r', label="Default MB") plt.plot(m_age2, lum2, '.b', markeredgecolor='b', label="Modified MB") plt.xlim(0, max(m_age2)) plt.ylim(min(min(lum1), min(lum2)), max(max(lum1), max(lum2))) plt.legend() plt.xlabel("Star Age") plt.ylabel("Luminosity (L_sun)") plt.title("Luminosity") plt.savefig("Lum") # Age and mass loss plt.figure(4) plt.clf() plt.plot(m_age1, mdot1, 'or', markeredgecolor='r', label="Default MB") plt.plot(m_age2, mdot2, '.b', markeredgecolor='b', label="Modified MB") plt.xlim(0, max(m_age2)) plt.ylim(min(min(mdot1), min(mdot2)), max(max(mdot1), max(mdot2))) plt.legend() plt.xlabel("Star Age") plt.ylabel("Log_Mdot (Msun)") plt.title("Mass Loss") plt.savefig("Mdot") # Age and convective envelope plt.figure(5) plt.clf() plt.plot(m_age1, mass1 - he_core1, 'or', markeredgecolor='r', label="Default MB") plt.plot(m_age2, mass2 - he_core2, '.b', markeredgecolor='b', label="Modified MB") plt.xlim(0, max(m_age2)) plt.ylim(min(min(mass1 - he_core1), min(mass2 - he_core2)) * 0.9, max(max(mass1 - he_core1), max(mass2 - he_core2)) * 1.1) plt.legend() plt.xlabel("Star Age") plt.ylabel("Convective Envelope Mass") plt.title("Convective Envelope") plt.savefig("Conv") # Age and Mass plt.figure(6) plt.clf() plt.plot(m_age1, mass1, 'or', markeredgecolor='r', label="Default MB") plt.plot(m_age2, mass2, '.b', markeredgecolor='b', label="Modified MB") plt.xlim(0, max(m_age2)) plt.ylim(min(min(mass1), min(mass2)) * 0.9, max(max(mass1), max(mass2)) * 1.1) plt.legend() plt.xlabel("Star Age") plt.ylabel("Star Mass(Msun)") plt.title("Mass") plt.savefig("Mass")