def petersen_plot(fname, minValueFirst): #directory = '/home/janne/Gunter_project/44_tau/example_3ms/LOGS-1' list_number = [ os.path.join(fname, file) for file in sorted(os.listdir(fname)) if file.endswith('-freqs.dat') ] constraint_noprems = 480 periods = [] ratios = [] minima = [] alle = [] for file in list_number: #file.sort(key=lambda x: '{0:0>20}'.format(x)) pnum = re.search('profile(.+?)-freqs', file) if pnum: pnums = pnum.group(1) if int(pnums) >= int(constraint_noprems): #print(pnums) freqs = gyr.readmesa(file) if size(freqs) == 1: continue if not freqs[0][1] == 1 and freqs[1][1] == 2: continue allfrequencies = [freqs[0][4] / freqs[1][4], file, pnums] rat = freqs[0][4] / freqs[1][4] currentValueFirst = np.abs(rat - r) if minValueFirst == None: minValueFirst = currentValueFirst else: minValueFirst = min(minValueFirst, currentValueFirst) minima += [minValueFirst, pnums] ratios += [freqs[0][4] / freqs[1][4]] periods += [1. / freqs[0][4]] alle.append(allfrequencies) plt.plot(np.log10(1. / radial_funda), observed_ratio, 'k*') #legend() plt.plot(np.log10(periods), ratios, 'r-') #plt.gca().invert_xaxis() # plt.gca().invert_yaxis() ylabel(r'$\Pi_1/\Pi_0$') xlabel(r'$log\Pi_0$') plt.rcParams.update({'font.size': 15}) return alle, minValueFirst, ratios, periods
def getfundfreqs(fname): constraint_noprems = 400 fnumbers = [] alle = [] #fname = '/home/janne/Gunter_project/44_tau/output_postms_3ms/LOGS-1.5-0.02-0.7-0.2/' for root, dirs, files in sorted(os.walk(fname)): files.sort(key=lambda x: '{0:0>20}'.format(x)) for file in files: if not file.endswith('freqs.dat'): #and os.path.exists(file)==True: continue fdires = os.path.join(root,file) fdirec = os.path.join(root) finaldir = fdirec.strip("/") fdata = gar.readmesa(fdires) dire = finaldir.split('-') mass = float(dire[1]) z = float(dire[2]) y = float(dire[3]) mlt = float(dire[4]) #ove = [float(dire[5])] if fdata[0][1] == 1 and fdata[1][1] == 2: fnum = re.search('profile(.+?)-freqs.dat', fdires) if fnum: fnums = fnum.group(1) if int(fnums) >= int(constraint_noprems): fnumbers += [fnums] #STRUCTURE: radial fundamental, radial first, mass, z, y, mixing-length, profile number alle += [[fdata[0][4], fdata[1][4], mass, z, y, mlt, fnums]] np.asarray(alle) np.savetxt("test1.txt", alle, delimiter=",", newline = "\n", fmt="%s") #np.savetxt('test1.txt', alle, fmt='%10d' ) return #getfundfreqs('/home/janne/Gunter_project/44_tau/output_postms_3ms/LOGS-1.5-0.02-0.7-0.2/')
def allfreqs(fname): alldata = [] alle = [] print(fname) for root, dirs, files in sorted(os.walk(fname)): for file in files: if not file.endswith( 'freqs.dat'): #and os.path.exists(file)==True: continue dires = os.path.join(root, file) #data = gar.readmesa(list_number[file]) data = gar.readmesa(dires) #print(data) if data[0][1] == 1 and data[1][1] == 2: alle += [data, dires] #print(alldata) #dataset += [] #print(file, len(dataset)) alldata += [alle] return alldata
def get_freqs(fname): alle = [] fnumbers = [] allobs = [] for root, dirs, files in sorted(os.walk(fname)): files.sort(key=lambda x: '{0:0>20}'.format(x)) for file in files: if not file.endswith( 'freqs.dat'): #and os.path.exists(file)==True: continue fdires = os.path.join(root, file) fdata = gar.readmesa(fdires) if fdata[0][1] == 1 and fdata[1][1] == 2: fnum = re.search('profile(.+?)-freqs.dat', fdires) if fnum: fnums = fnum.group(1) if int(fnums) >= int(constraint_noprems): chi_radial = (np.abs(radial_funda - fdata[0][4]) / radial_funda_unc)**2 chi_first = (np.abs(radial_first - fdata[1][4]) / radial_first_unc)**2 fnumbers += [fnums] alle += [[chi_radial, chi_first, fnums]] for i in fnumbers: #print(i) obs = getprofile(fname, i) allobs += [obs] return alle, allobs
# -*- coding: utf-8 -*- """ Created on Fri Nov 2 15:21:06 2018 @author: janne data.dtype.names """ import gyre_output_read as gar import numpy as np import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages import seaborn as sns from pylab import * data, header = gar.readmesa( '/home/janne/Gunter_project/gunther_project/44_tau/44tau_nad_output.txt') harm_degree = data['l'] radial_order = data['n_pg'] acou_num = data['n_p'] grav_num = data['n_g'] #re_omega = data['Re(omega)'] #im_omega = data['Im(omega)'] #re_omega_int = data['Re(omega_int)'] #m_omega_int = data['Im(omega_int)'] re_freq = data[ 'Refreq'] # these are the frequencies that will be compared to Lenz and observations. im_freq = data['Imfreq'] #imaginary part of frequencies are not observable. cd_to_mhz = 11.58 freq_obs = [
def chis(fname, profname): finalarray = [] bm_array2 = [] models = 'profile{}-freqs.dat'.format(profname) for root, dirs, files in sorted(os.walk(fname)): for file in files: if not file.startswith(models): #and os.path.exists(file)==True: continue names = [] dires = os.path.join(root, file) data = gar.readmesa(dires) harm_degree = data['l'] radial_order = data['n_pg'] re_freq_theo = data[ 'Refreq'] # these are the frequencies that will be compared to Lenz and observations. #im_freq = data['Imfreq'] #imaginary part of frequencies are not observable. #print(re_freq_theo) re_freq_obs = [6.8980, 8.9607, 11.20, 13.48] re_freq_obs_unc = [ 2.762223525 * 10**(-7), 8.454940424 * 10**(-7), 1 * 10**(-7), 1 * 10**(-7) ] #print(len(np.atleast_1d(re_freq_theo))) #re_freq_obs_unc = np.ones(len(re_freq_obs)) * 0.1 remaining_obs = re_freq_obs #remaining_obs_unc = freq_obs_uncertainties remaining_theo = np.atleast_1d(re_freq_theo) remaining_ells = np.atleast_1d(harm_degree) remaining_radial = np.atleast_1d(radial_order) best_matching = [] #names = [] for ii in range( min(len(np.atleast_1d(re_freq_theo)), len(re_freq_obs)) ): #default: freq_obs, but depends if freq_obs is longer than re_freq best = np.inf bestjj = -1 bestkk = -1 #print(len(remaining_obs)) for jj in range(len(np.atleast_1d(remaining_theo))): for kk in range(len(remaining_obs)): val = (remaining_theo[jj] - remaining_obs[kk])**2 / 4 #put uncertainty here if (val < best): best = val bestjj = jj bestkk = kk # print(best, bestjj, bestkk) best_matching += [[ remaining_ells[bestjj], remaining_radial[bestjj], remaining_theo[bestjj], remaining_obs[bestkk] ]] remaining_theo = np.delete(remaining_theo, bestjj) remaining_ells = np.delete(remaining_ells, bestjj) remaining_obs = np.delete(remaining_obs, bestkk) #remaining_obs_unc = np.delete(remaining_obs_unc, bestkk) remaining_radial = np.delete(remaining_radial, bestjj) bm_array = np.asarray(best_matching) bm_array2 += [bm_array] finalarray += [[bm_array, file]] #print(finalarray) #print(bm_array2) temp = [] for i in range(len(bm_array2)): if len(bm_array2[i]) >= 2: #farr += finalarray.pop(i) temp.append(finalarray[i]) #else: #print(finalarray[i][1]) finalarray = temp chi2 = np.zeros(len(finalarray)) modelnos = np.zeros(len(finalarray)) #print(len(finalarray)) #number = [] for i, (array, modelno) in enumerate(finalarray): array = np.asarray(array) if len(array) == 4: m = re.search('profile(.+?)-freqs.dat', modelno) if m: modelnos[i] = m.group(1) #print(modelnos) delta = array[:, 2] - array[:, 3] chi2[i] = np.sum((delta**2) / (np.asarray(re_freq_obs_unc)**2)) chi2[i] /= len(delta) #test_result.append(modelnos + chi2) test_result = np.zeros((len(chi2), 2)) #rint(test_result) for i in range(0, len(modelnos)): test_result[i][0] = modelnos[i] test_result[i][1] = chi2[i] print(modelnos) print(chi2) #print(test_result) #print(results) return test_result, finalarray #c = '/home/janne/Gunter_project/44_tau/example_zs/LOGS-2.0-0.022-0.29-1.5' #a = '/home/janne/Gunter_project/gunther_project/LOGS_44_tau_testrun/' #b = '/home/janne/Gunter_project/44_tau/example_3ms/LOGS-1' # #results = chis(b, '14')
file) for file in os.listdir( '/home/janne/Gunter_project/gunther_project/LOGS_44_tau_testrun/') if file.endswith('.dat') ] finalarray = [] names = [] bm_array2 = [] for file in range(len(list_number)): if file == 4 or file == 6: continue #if os.path.exists(file)==False: # continue #print(file) data = gar.readmesa(list_number[file]) harm_degree = data['l'] radial_order = data['n_pg'] #acou_num = data['n_p'] #grav_num = data['n_g'] #re_omega = data['Re(omega)'] #im_omega = data['Im(omega)'] #re_omega_int = data['Re(omega_int)'] #m_omega_int = data['Im(omega_int)'] re_freq_theo = data[ 'Refreq'] # these are the frequencies that will be compared to Lenz and observations. #im_freq = data['Imfreq'] #imaginary part of frequencies are not observable. #print(re_freq_theo)
def to_get_chi2(fname): filename = 'results_l012.txt' final_list = [] with open(filename) as f: for line in f: inner_list = [elt.strip() for elt in line.split(',')] final_list.append(inner_list) a = np.asarray(final_list) profnums = a[:, 4] finalarray = [] bm_array2 = [] #fname = '/home/janne/Gunter_project/44_tau/output_postms_3ms/LOGS-1.5-0.02-0.7-0.2' for h in profnums: direc = fname + '/profile' + h + '-freqs.dat' #dires = os.path.join(root,file) data = gar.readmesa(direc) harm_degree = data['l'] radial_order = data['n_pg'] re_freq_theo = data[ 'Refreq'] # these are the frequencies that will be compared to Lenz and observations. #im_freq = data['Imfreq'] #imaginary part of frequencies are not observable. #print(re_freq_theo) re_freq_obs = [ 6.8980, 7.0060, 9.1175, 11.5196, 8.9606, 9.5613, 7.3034, 6.7953, 9.5801, 6.3391, 8.6393, 11.2919 ] re_freq_obs_unc = np.ones(len(re_freq_obs)) * 10**(-7) #print(len(np.atleast_1d(re_freq_theo))) #re_freq_obs_unc = np.ones(len(re_freq_obs)) * 0.1 remaining_obs = re_freq_obs #remaining_obs_unc = freq_obs_uncertainties remaining_theo = np.atleast_1d(re_freq_theo) remaining_ells = np.atleast_1d(harm_degree) remaining_radial = np.atleast_1d(radial_order) best_matching = [] #names = [] for ii in range( min(len(np.atleast_1d(re_freq_theo)), len(re_freq_obs)) ): #default: freq_obs, but depends if freq_obs is longer than re_freq best = np.inf bestjj = -1 bestkk = -1 #print(len(remaining_obs)) for jj in range(len(np.atleast_1d(remaining_theo))): for kk in range(len(remaining_obs)): val = (remaining_theo[jj] - remaining_obs[kk])**2 / 4 #put uncertainty here if (val < best): best = val bestjj = jj bestkk = kk # print(best, bestjj, bestkk) best_matching += [[ remaining_ells[bestjj], remaining_radial[bestjj], remaining_theo[bestjj], remaining_obs[bestkk] ]] remaining_theo = np.delete(remaining_theo, bestjj) remaining_ells = np.delete(remaining_ells, bestjj) remaining_obs = np.delete(remaining_obs, bestkk) #remaining_obs_unc = np.delete(remaining_obs_unc, bestkk) remaining_radial = np.delete(remaining_radial, bestjj) #diff = np.asarray(diff) #final = np.append(bm_array,diff) bm_array = np.asarray(best_matching) bm_array2 += [bm_array] finalarray += [[bm_array, h]] chi2sum = {} for i in range(len(finalarray)): for k in range(len(finalarray[i][0])): pname = finalarray[i][1] if pname not in chi2sum.keys(): chi2sum[pname] = 0 chi2sum[pname] = chi2sum[pname] + ( np.abs(finalarray[i][0][k][2] - finalarray[i][0][k][3]) / 1 * 10**(-7))**2 kolonne = chi2sum.values() output = np.column_stack((final_list, list(kolonne))) np.savetxt("results_l012.txt", output, delimiter=",", newline="\n", fmt="%s") return kolonne #kolonne = to_get_chi2('/home/janne/Gunter_project/44_tau/output_postms_3ms/LOGS-1.5-0.02-0.7-0.2', 'test3.txt')
dire = '/home/janne/Gunter_project/44_tau/example_3ms/LOGS-3' l = mr.MesaLogDir('/home/janne/Gunter_project/44_tau/example_3ms/LOGS-3') time_age = [] fund_freqs = [] modelno = [] for root, dirs, files in sorted(os.walk(dire)): files.sort(key=lambda x: '{0:0>20}'.format(x)) #natsorted(files, key=lambda y: y.lower()) for file in files: if file.endswith('freqs.dat'): #and os.path.exists(file)==True: dires = os.path.join(root, file) #print(dires) #print(dires) data = gar.readmesa(dires) re_freq_theo = data['Refreq'] radial_order = data['n_pg'] if radial_order[0] == 1: re_freq_fund = re_freq_theo[1] #print(re_freq_fund) m = re.search('profile(.+?)-freqs.dat', file) if m: modelnos = m.group(1) #print(modelno)
'/home/janne/Gunter_project/44_tau/example_10_masses/LOGS-1.50-0.02-0.7-0.4' )): files.sort(key=lambda x: '{0:0>20}'.format(x)) for file in files: if file.endswith('freqs.dat'): gyredirs = os.path.join(root, file) gyreroots = os.path.join(root) gnum = re.search('profile(.+?)-freqs.dat', gyredirs) if gnum: gnums = gnum.group(1) if int(gnums) >= int(constraint_noprems): #print(gnums) freqs = gyr.readmesa(gyredirs) if freqs[0][1] == 1 and freqs[1][1] == 2: difference_funda = np.abs(freqs[0][4] - radial_funda) difference_first = np.abs(freqs[1][4] - radial_first) #differences.append() currentValue = difference_funda if minValue == None: minValue = currentValue else: minValue = min(minValue, currentValue) differences.append(difference_funda) temp2 = [gyredirs, difference_funda]
def onedir(fname): Log_Teff_obs = 3.839 #Log_L_obs = 1.340 Log_g_obs = 3.6 Log_Teff_obs_unc = 0.007 #Log_L_obs_unc = 0.0065 Log_g_obs_unc = 0.1 n = 3 Log_Teff_ns = n*Log_Teff_obs_unc #Log_L_ns = n*Log_L_obs_unc Log_g_ns = n*Log_g_obs_unc Log_Teff_lower = Log_Teff_obs - Log_Teff_ns Log_Teff_upper = Log_Teff_obs + Log_Teff_ns #Log_L_lower = Log_L_obs - Log_L_ns #Log_L_upper = Log_L_obs + Log_L_ns Log_g_upper = Log_g_obs + Log_g_ns Log_g_lower = Log_g_obs - Log_g_ns radial_funda = 6.8980 #radial_first = 8.9606 #l = 10 #radial_unc = l* 0.05 #radial_funda_lower = radial_funda - radial_unc #radial_funda_upper = radial_funda + radial_unc #radial_first_upper = radial_first + radial_unc #radial_first_lower = radial_first - radial_unc frequencies = [] frequency_dirs = [] frequency_roots = [] temp = [] dires = [] test_result = [] logg_dires = [] diffsndirs = [] minimum = [] for root, dirs, files in sorted(os.walk(fname)): logdirs = os.path.join(root) dires += [logdirs] for file in files: if file.startswith('history'): #print(os.path.join(root,file)) direcs = os.path.join(root,file) rooties = os.path.join(root) #print(natsort.natsorted(dirs,reverse=True)) h = mr.MesaData(direcs) mass = h.initial_mass model = h.model_number index = h.star_age > 2.0e7 noms_model = model[index] noms_logg = h.log_g[index] logg_dir = [noms_logg, noms_model, rooties] logg_dires.append(logg_dir) noms_Teff = h.log_Teff[index] noms_L = h.log_L[index] test_result = np.zeros((len(noms_model),3)) #rint(test_result) for i in range(0,len(noms_model)): test_result[i][0] = noms_model[i] test_result[i][1] = noms_logg[i] test_result[i][2] = noms_Teff[i] plt.plot(noms_Teff, noms_logg, '-',label='M=%s' %mass) if file.startswith('profile') and file.endswith('.data'): profiledirs = os.path.join(root,file) pnum = re.search('profile(.+?).data', profiledirs) if pnum: pnums = pnum.group(1) profiles_indir = mr.MesaLogDir(fname) pr = profiles_indir.profile_data(profile_number=pnums) pr_modelnos = pr.model_number if pr_modelnos == noms_model[0]: cutoff = pnums if file.endswith('freqs.dat'): gyredirs = os.path.join(root,file) gyreroots = os.path.join(root) fnum = re.search('profile(.+?)-freqs.dat', gyredirs) if fnum: fnums = fnum.group(1) if int(cutoff) <= int(fnums): #print(fnums) #print(gyredirs) freqs = gyr.readmesa(gyredirs) frequencies += [freqs] frequency_dirs += [gyredirs] frequency_roots += [gyreroots] allfreqs = [freqs ,gyredirs,gyreroots] temp.append(allfreqs) profiles = [] differs = [] temp3 = [] minValue = None for i in range(0,len(temp)): if size(temp[i][0]) ==1: continue if temp[i][0][0][1] == 1 and temp[i][0][1][1] == 2: #print('hej') succesfull_profiles = temp[i][1] profile_directories = temp[i][2] difference = np.abs(temp[i][0][0][4]-radial_funda) #print(difference) #difference_next = np.abs(temp[i+1][0][0][4]-radial_funda) currentValue = difference if minValue == None: minValue = currentValue else: minValue = min(minValue, currentValue) temp2 = [succesfull_profiles, difference] diffsndirs.append(temp2) profiles.append(profile_directories) differs.append(difference) minimum = differs.index(minValue) minimum_profile = diffsndirs[minimum] gnum = re.search('profile(.+?)-freqs.dat', minimum_profile[0]) if gnum: gnums = gnum.group(1) profiledata = mr.MesaLogDir(fname) p = profiledata.profile_data(profile_number=gnums) teff = p.Teff #print(teff) logteff = np.log10(teff) lmodel = p.photosphere_L logl = np.log10(lmodel) modelno_profile = p.model_number entry = np.where(logg_dires[0][1]== modelno_profile) best_logg = logg_dires[0][0][entry] plt.plot(logteff,best_logg,'k.', MarkerSize = 15) """ results_final = [] for root, dirs, files in sorted(os.walk('/home/janne/Gunter_project/44_tau/example_3ms/')): for dire in dirs: plt.figure(dire) dires = os.path.join(root,dire) #print(dires) results = petersen_plot(dires) results_final.append(results) #print(results) results #print(logteff) #alllogteffs.append(logteffs) #plt.plot([alllogteffs[i][0],alllogteffs[i][-1]],[working_logg_dires[0], working_logg_dires[-1]],'k--') """ # set axis labels xlabel(r'$\logT_{eff}$') ylabel(r'$\log(g)$') legend() plt.gca().invert_xaxis() plt.gca().invert_yaxis() plt.rcParams.update({'font.size': 20}) #PLOT ERRORBOX: plt.plot([Log_Teff_lower, Log_Teff_upper, Log_Teff_upper, Log_Teff_lower, Log_Teff_lower], [Log_g_lower, Log_g_lower, Log_g_upper, Log_g_upper, Log_g_lower], 'r-.', alpha=0.5, linewidth=3) return best_logg,logteff
def chis(fname): finalarray = [] bm_array2 = [] for root, dirs, files in sorted(os.walk(fname)): for file in files: if not file.endswith( 'freqs.dat'): #and os.path.exists(file)==True: continue #print(file) names = [] # continue dires = os.path.join(root, file) #data = gar.readmesa(list_number[file]) data = gar.readmesa(dires) #print(dires, data) #print(dires) harm_degree = data['l'] radial_order = data['n_pg'] #print(type(harm_degree)) #acou_num = data['n_p'] #grav_num = data['n_g'] #re_omega = data['Re(omega)'] #im_omega = data['Im(omega)'] #re_omega_int = data['Re(omega_int)'] #m_omega_int = data['Im(omega_int)'] re_freq_theo = data[ 'Refreq'] # these are the frequencies that will be compared to Lenz and observations. #im_freq = data['Imfreq'] #imaginary part of frequencies are not observable. #print(re_freq_theo) re_freq_obs = [6.8980, 8.9607] re_freq_obs_unc = [2.762223525 * 10**(-7), 8.454940424 * 10**(-7)] #print(len(np.atleast_1d(re_freq_theo))) #re_freq_obs_unc = np.ones(len(re_freq_obs)) * 0.1 remaining_obs = re_freq_obs #remaining_obs_unc = freq_obs_uncertainties remaining_theo = np.atleast_1d(re_freq_theo) remaining_ells = np.atleast_1d(harm_degree) remaining_radial = np.atleast_1d(radial_order) best_matching = [] #names = [] for ii in range( min(len(np.atleast_1d(re_freq_theo)), len(re_freq_obs)) ): #default: freq_obs, but depends if freq_obs is longer than re_freq best = np.inf bestjj = -1 bestkk = -1 #print(len(remaining_obs)) for jj in range(len(np.atleast_1d(remaining_theo))): for kk in range(len(remaining_obs)): val = (remaining_theo[jj] - remaining_obs[kk])**2 / 4 #put uncertainty here if (val < best): best = val bestjj = jj bestkk = kk # print(best, bestjj, bestkk) best_matching += [[ remaining_ells[bestjj], remaining_radial[bestjj], remaining_theo[bestjj], remaining_obs[bestkk] ]] remaining_theo = np.delete(remaining_theo, bestjj) remaining_ells = np.delete(remaining_ells, bestjj) remaining_obs = np.delete(remaining_obs, bestkk) #remaining_obs_unc = np.delete(remaining_obs_unc, bestkk) remaining_radial = np.delete(remaining_radial, bestjj) #diff = np.asarray(diff) #final = np.append(bm_array,diff) bm_array = np.asarray(best_matching) bm_array2 += [bm_array] finalarray += [[bm_array, file]] #print(file) #print(finalarray) #print(bm_array2) #print(len(bm_array2[26])) = 1 #farr = [] temp = [] for i in range(len(bm_array2)): if len(bm_array2[i]) >= 2: #farr += finalarray.pop(i) temp.append(finalarray[i]) #else: #print(finalarray[i][1]) finalarray = temp chi2 = np.zeros(len(finalarray)) modelnos = np.zeros(len(finalarray)) #print(len(finalarray)) #number = [] for i, (array, modelno) in enumerate(finalarray): array = np.asarray(array) if len(array) == 4: m = re.search('profile(.+?)-freqs.dat', modelno) if m: modelnos[i] = m.group(1) #print(modelnos) delta = array[:, 2] - array[:, 3] chi2[i] = np.sum((delta**2) / (np.asarray(re_freq_obs_unc)**2)) chi2[i] /= len(delta) #test_result.append(modelnos + chi2) test_result = np.zeros((len(chi2), 2)) #rint(test_result) for i in range(0, len(modelnos)): test_result[i][0] = modelnos[i] test_result[i][1] = chi2[i] #, chi2[i]] #test_results += [test_result] #print(len(modelnos)) #print(modelnos) #print(chi2) plt.figure() plt.plot(modelnos, np.log(chi2), '*', linestyle='None') plt.xlabel('profile/model') plt.ylabel('log(chi2)') #print(test_result) #print(results) return test_results
def massconstrain(fname): Log_Teff_obs = 3.839 Log_g_obs = 3.6 Log_Teff_obs_unc = 0.007 #Log_L_obs_unc = 0.0065 Log_g_obs_unc = 0.1 n = 3 Log_Teff_ns = n * Log_Teff_obs_unc #Log_L_ns = n*Log_L_obs_unc Log_g_ns = n * Log_g_obs_unc Log_Teff_lower = Log_Teff_obs - Log_Teff_ns Log_Teff_upper = Log_Teff_obs + Log_Teff_ns #Log_L_lower = Log_L_obs - Log_L_ns #Log_L_upper = Log_L_obs + Log_L_ns Log_g_upper = Log_g_obs + Log_g_ns Log_g_lower = Log_g_obs - Log_g_ns radial_funda = 6.8980 radial_first = 8.9606 loggs = [] logteffs = [] profile_numbers = [] alle_final = [] #best_gs_radial = [] #best_teffs_radial = [] #best_gs_first = [] #best_teffs_first = [] for root, dirs, files in sorted(os.walk(fname)): files.sort(key=lambda x: '{0:0>20}'.format(x)) for file in files: if file.startswith('profile') and file.endswith('.data'): profiledirs = os.path.join(root, file) profileroots = os.path.join(root) constraint_noprems = 450 pnum = re.search('profile(.+?).data', profiledirs) if pnum: pnums = pnum.group(1) if int(pnums) >= int(constraint_noprems): #print(pnums) profiles_indir = mr.MesaLogDir(fname) pr = profiles_indir.profile_data(profile_number=pnums) pr_modelnos = pr.model_number teff = pr.Teff #logteff = np.log(teff)r = pr.photosphere_r r = pr.photosphere_r m = pr.initial_mass m_solar = 1.9892 * 10**(33) r_solar = 6.9598 * 10**(10) R = r * r_solar M = m * m_solar G = 6.67428 * 10**(-8) #logg = np.log(g) g = G * M / R**2 profile_numbers.append(pnums) loggs.append(g) logteffs.append(teff) alle = [g, teff, pnums] alle_final.append(alle) plt.plot(np.log10(logteffs), np.log10(loggs), label='mass = %f' % m) plt.plot([ Log_Teff_lower, Log_Teff_upper, Log_Teff_upper, Log_Teff_lower, Log_Teff_lower ], [Log_g_lower, Log_g_lower, Log_g_upper, Log_g_upper, Log_g_lower], 'r-.', alpha=0.5, linewidth=3) plt.plot(Log_Teff_obs, Log_g_obs, 'r*') #ax.set_xlim([3.7,4.05]) #ax.set_ylim([3.2,4.2]) alle = [] differences_radial = [] differences_first = [] minValueRadial = None minValueFirst = None diffsndirs_radial = [] diffsndirs_first = [] for root, dirs, files in sorted(os.walk(fname)): files.sort(key=lambda x: '{0:0>20}'.format(x)) for file in files: if file.endswith('freqs.dat'): gyredirs = os.path.join(root, file) gyreroots = os.path.join(root) gnum = re.search('profile(.+?)-freqs.dat', gyredirs) if gnum: gnums = gnum.group(1) if int(gnums) >= int(constraint_noprems): #print(gnums) freqs = gyr.readmesa(gyredirs) if freqs[0][1] == 1 and freqs[1][1] == 2: difference_funda = np.abs(freqs[0][4] - radial_funda) difference_first = np.abs(freqs[1][4] - radial_first) #differences.append() currentValueRadial = difference_funda if minValueRadial == None: minValueRadial = currentValueRadial else: minValueRadial = min(minValueRadial, currentValueRadial) currentValueFirst = difference_first if minValueFirst == None: minValueFirst = currentValueFirst else: minValueFirst = min(minValueFirst, currentValueFirst) differences_radial.append(difference_funda) differences_first.append(difference_first) temp_radial = [gyredirs, difference_funda] temp_first = [gyredirs, difference_first] diffsndirs_radial.append(temp_radial) diffsndirs_first.append(temp_first) minimum_radial = differences_radial.index(minValueRadial) minimum_profile_radial = diffsndirs_radial[minimum_radial] minimum_first = differences_first.index(minValueFirst) minimum_profile_first = diffsndirs_first[minimum_first] best_g_radial = alle_final[minimum_radial][0] best_teff_radial = alle_final[minimum_radial][1] best_g_first = alle_final[minimum_first][0] best_teff_first = alle_final[minimum_first][1] allbest_radial = [ best_g_radial, best_teff_radial, minimum_profile_radial[0] ] allbest_first = [best_g_first, best_teff_first, minimum_profile_first[0]] plt.plot(np.log10(best_teff_radial), np.log10(best_g_radial), 'k.', MarkerSize=15) plt.plot(np.log10(best_teff_first), np.log10(best_g_first), 'g.', MarkerSize=8) allbest = [allbest_radial, allbest_first] xlabel(r'$\logT_{eff}$') ylabel(r'$\log(g)$') legend() plt.rcParams.update({'font.size': 15}) #plt.axis((3.8,3.9,3.3,4.0)) plt.gca().invert_xaxis() plt.gca().invert_yaxis() return allbest