def nearest_stars_hist(): t = np.genfromtxt(join("data", "MH08_table13.txt"), delimiter=';', dtype=str, skip_header=75) bv, rhk = t[:, 6].astype(np.float), t[:, 8].astype(np.float) #mask = (const.BV_RANGE[0] <= bv) & (bv <= const.BV_RANGE[1]) & \ mask = (.8 <= bv) & (bv <= .9) & \ (const.METAL_RANGE[0] <= rhk) & (rhk <= const.METAL_RANGE[1]) bv, rhk = bv[mask], rhk[mask] baf = baffles.age_estimator('calcium') for i in range(1): ages = [] #,array = [],np.zeros(1000) for b, r in zip(bv, rhk): p = baf.get_posterior(b, r) #chance = p.array/np.sum(p.array) a = p.stats[2] #np.random.choice(const.AGE,p=chance) ages.append(a) #array += p.array #plt.hist(ages) #plt.xlabel("Age (Myr)") #plt.ylabel("Frequency") #plt.show() plt.hist(ages) plt.xlabel("Age (Myr)") plt.ylabel("Frequency") plt.title(".8 <= B-V <= .9") plt.show()
def moving_group(): name = join('plots','moving_group_age.pdf') pp = PdfPages(name) baf = baffles.age_estimator('lithium') abdor = readData.abdor() fit = my_fits.poly_fit(abdor[0],abdor[1],2,scatter=True) plt.title("AB Dor") #my_plot.plot_fits([abdor],[fit],METAL,pdfPage=pp,showPlots=False) p = baf.posterior_product(abdor[0],abdor[1],None,abdor[2],pdfPage=pp,showPlot=False, showStars=True,title='AB Dor',givenAge=149,givenErr=[-19,51]) tuc = readData.tuchor() fit = my_fits.poly_fit(tuc[0],tuc[1],2,scatter=True) plt.title("Tuc/Hor") #my_plot.plot_fits([tuc],[fit],METAL,pdfPage=pp,showPlots=False) p2 = baf.posterior_product(tuc[0],tuc[1],None,tuc[2],pdfPage=pp,showPlot=False, showStars=True,title='Tuc/Hor',givenAge=45,givenErr=4) print("We derive ages for AB Dor: $%d_{%d}^{+%d}$ Myr, and Tuc/Hor: $%d_{%d}^{+%d}$ Myr" \ % (p.stats[2],p.stats[1]-p.stats[2],p.stats[3]-p.stats[2], p2.stats[2],p2.stats[1]-p2.stats[2],p2.stats[3]-p2.stats[2])) pp.close() printName(name)
def get_CI_hyades_no_ul(): const = utils.init_constants(METAL) baf_default = baffles.age_estimator(METAL) mask = (~np.array(upper_lim[8])) | (bv_m[8][0] > 0.55) print("Total stars:",len(bv_m[8][0])) print("Stars selsected=:",np.sum(mask)) b,l,ul = bv_m[8][0][mask],bv_m[8][1][mask],np.array(upper_lim[8])[mask] baf_default.posterior_product(b,l,upperLim_arr=ul,showPlot=True,showStars=True,title='Hyades B-V > .55',givenAge=700)
def combined_validation(): #Omitting each cluster name = join('plots',METAL + '_combined_validation.pdf') pp=PdfPages(name) baf_default = baffles.age_estimator(METAL) for i in range(len(bv_m)): print(const.CLUSTER_NAMES[i]) baf = baffles.age_estimator(METAL,default_grids=False) baf.make_grids(bv_m,fits,omit_cluster=i) p_val = baf.posterior_product(bv_m[i][0],bv_m[i][1],upperLim_arr=upper_lim[i]) plt.plot(const.AGE,p_val.array,linewidth=2,linestyle='--',label='Posterior with removal') p = baf_default.posterior_product(bv_m[i][0],bv_m[i][1],upperLim_arr=upper_lim[i],\ pdfPage=pp,showPlot=False,\ showStars=True,givenAge=const.CLUSTER_AGES[i],\ title= const.CLUSTER_NAMES[i]) printName(name) pp.close()
def get_CI(): const = utils.init_constants(METAL) baf_default = baffles.age_estimator(METAL) for index,i in enumerate([1,2,7,9]): print("\n", const.CLUSTER_NAMES[i]) bv_arr = bv_m[i][0] p = baf_default.posterior_product(bv_m[i][0],bv_m[i][1],upperLim_arr=upper_lim[i],showStars=True) age,y = const.AGE,p.array givenAge=const.CLUSTER_AGES[i] print('Isochronal age exists within %f %% CI' % prob.get_percentile(age,y,givenAge))
def main(): date = datetime.datetime.now().strftime("%m%d%y") bv_m,fits = readData.read_calcium(fromFile=False,saveToFile=True) baf = baffles.age_estimator('calcium',default_grids=False,load_pdf_fit=False) baf.make_grids(bv_m,fits,medianSavefile=join('grids','median_rhk_'+date),\ setAsDefaults=True) _,res_arr = my_fits.get_fit_residuals(bv_m,fits,'calcium',None,li_range=None, linSpace=False,scale_by_std= False,vs_age_fit=True,zero_center=True) my_fits.fit_histogram('calcium',residual_arr=res_arr,fromFile=False,saveToFile=True) const = utils.init_constants('lithium') bv_m, upper_lim, fits = readData.read_lithium(fromFile=False,saveToFile=True) baf2 = baffles.age_estimator('lithium',default_grids=False,load_pdf_fit=False) baf2.make_grids(bv_m,fits,upper_lim,join('grids','median_li_'+date),setAsDefaults=True) my_fits.MIST_primordial_li(ngc2264_fit=fits[const.CLUSTER_NAMES.index('NGC2264')][0], fromFile=False, saveToFile=True) _,res_arr= my_fits.get_fit_residuals(bv_m,fits,'lithium',upper_lim,li_range=None,linSpace=False, vs_age_fit=True,zero_center=True) my_fits.fit_histogram('lithium',residual_arr=res_arr,fromFile=False,saveToFile=True)
def omitting(validation=False): #Omitting each cluster #name = join('plots',METAL + '_self_validation.pdf') name = join('plots',METAL + '_omit_clusters.pdf') if not validation else \ join('plots',METAL + '_self_validation.pdf') pp=PdfPages(name) baf = baffles.age_estimator(METAL,default_grids=False) for i in range(len(bv_m)): print(const.CLUSTER_NAMES[i]) if not validation: baf.make_grids(bv_m,fits,omit_cluster=i) p = baf.posterior_product(bv_m[i][0],bv_m[i][1],pdfPage=pp,showPlot=False,\ showStars=True,givenAge=const.CLUSTER_AGES[i],\ title= const.CLUSTER_NAMES[i]) printName(name) pp.close()
def posteriors(): #Making posteriors name = join('plots', METAL + '_posteriors.pdf') pp = PdfPages(name) baf = baffles.age_estimator(METAL, default_grids=False) baf.make_grids(bv_m, fits, upper_lim) #,omit_cluster=0) for bv in [0.65]: for li in np.linspace(-3.8, -5, 5): p = baf.get_posterior(bv, li, pdfPage=pp, showPlot=True, logPlot=False, upperLim=False, mamajekAge=True) printName(name) pp.close()
def combined_validation_subplots(): const = utils.init_constants(METAL) #Omitting each cluster name = join('plots', METAL + '_combined_validation_subplots.pdf') pp = PdfPages(name) baf_default = baffles.age_estimator(METAL) fig, ax = plt.subplots(3, 2, figsize=(14, 15)) cmap = plt.cm.get_cmap('RdYlBu_r') norm = mpl.colors.Normalize(vmin=const.BV_RANGE[0], vmax=const.BV_RANGE[1]) sc = plt.scatter([], [], c=[], norm=norm, cmap=cmap) fig.tight_layout(pad=.4, w_pad=1, h_pad=2) fig.subplots_adjust(left=0.06) fig.subplots_adjust(bottom=0.06) fig.subplots_adjust(top=.95) fig.subplots_adjust(right=0.9) #cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7]) cbar_ax = fig.add_axes([0.92, 0.25, 0.02, 0.5]) fig.colorbar(sc, cax=cbar_ax) for index, i in enumerate([1, 3, 5, 6, 7, 8]): #[0,4,5,6,7,8] for submission 2! print(const.CLUSTER_NAMES[i]) baf = baffles.age_estimator(METAL, default_grids=False) baf.make_grids(bv_m, fits, omit_cluster=i) p_val = baf.posterior_product(bv_m[i][0], bv_m[i][1]) pl = ax[int(index / 2), index % 2] pl.plot(const.AGE, p_val.array, linewidth=2, linestyle='--', label='Posterior with removal') pl.set_title(const.CLUSTER_NAMES[i], size=my_plot.TITLE_SIZE) bv_arr = bv_m[i][0] p = baf_default.posterior_product(bv_m[i][0], bv_m[i][1], upperLim_arr=None, showStars=True) #print(p.stars_posteriors) age, y = const.AGE, p.array givenAge = const.CLUSTER_AGES[i] for star, post in enumerate(p.stars_posteriors): color = cmap(norm(bv_arr[star])) prob.scale_to_height(post, np.max(y)) pl.plot(const.AGE, post, alpha=1, linewidth=1, color=color, zorder=0) if (givenAge): print('Isochronal age exists within %f %% CI' % prob.get_percentile(age, y, givenAge)) pl.axvline(x=givenAge, color='r', label='Isochronal age: %d Myr' % givenAge) #if (givenErr): # if (type(givenErr) == float or type(givenErr) == int): # givenErr = [-1*givenErr,givenErr] # pl.axvspan(givenAge+givenErr[0], givenAge+givenErr[1], alpha=0.2, color='r',zorder=0) #if (mamajekAge): # plt.axvline(x=mamajekAge,color='C2',label='MH08 age: %d' % mamajekAge) pl.plot(age, y, color='C0', linewidth=2) stat = p.stats age2 = np.linspace(stat[0], stat[-1], 500) interp = my_fits.piecewise(age, y) y2 = interp(age2) pl.vlines(x=stat[2],ymin= 0,ymax= interp(stat[2]), \ label='BAFFLES median age: %.3g Myr' % stat[2] ,color = 'orange') pl.fill_between(age2,y2, where= (age2 >= stat[1]) & (age2 <= stat[3]),color='.3', \ label='68%% CI: %.2g - %.2g' % (stat[1],stat[-2])) pl.fill_between(age2,y2, where= (age2 >= stat[0]) & (age2 <= stat[-1]),color='.6',\ alpha=0.5, label='95%% CI: %.2g - %.2g' % (stat[0],stat[-1])) pl.set_ylim([0, np.max(y) * 1.5]) r = my_plot.getAgeRange(p.stats, p.stars_posteriors, givenAge) pl.set_xlim(r) pl.legend() pl.minorticks_on() pl.tick_params(axis='both', which='both', right=True, top=True) # Set common labels fig.text(0.5, 0.02, 'Age (Myr)', size=my_plot.AXIS_LABEL_SIZE, ha='center', va='center') fig.text(0.01, 0.5, 'Probability Density (Myr^-1)', size=my_plot.AXIS_LABEL_SIZE, ha='center', va='center', rotation='vertical') fig.text(0.99, 0.5, 'B-V', size=my_plot.AXIS_LABEL_SIZE, ha='center', va='center', rotation='vertical') pp.savefig() plt.close() printName(name) pp.close()
def notable_stars(): li_const = utils.init_constants('lithium') name = join('plots','notable_stars.pdf') names = ["HR 2562","HD 206893","TW PsA"] bv = [.45,.44,1.1] bv_err = [np.sqrt(.014**2+.01**2),np.sqrt(.02**2+.01**2),.03] # .03 b-v error for TW PsA? rhk = [-4.55,-4.466,None] mamaAge = [utils.getMamaAge(rhk[0]),utils.getMamaAge(rhk[1]),None] li = [21,28.5,33] li_err = [5,7,2] markers = ['*','*','*'] markerSize = 25 colors = ['gold','green','darkmagenta'] age = [None,None,440] age_range = [[300,900],[200,2100],[400,480]] pp=PdfPages(name) my_plot.metal_vs_bv(bv_ca,ca_fits,'calcium',None,False,specific_clusters=[0,5,7,8], legend=False,textlabels=True) plt.plot(bv,rhk,marker='s',markersize=markerSize,color='w',linestyle='None',zorder=9) for i in [0,1]: plt.plot(bv[i],rhk[i],marker=markers[i],markersize=markerSize,color=colors[i], linestyle='None',zorder=10,label=names[i]) plt.legend() plt.xlim([.42,.9]) pp.savefig() #plt.show() plt.close() my_plot.metal_vs_bv(bv_m,fits,'lithium',None,False,upper_lim=upper_lim,specific_clusters=[0,1,4,6,8,9]) plt.plot(bv,li,marker='s',markersize=markerSize,color='w',linestyle='None',zorder=9) for i in [0,1,2]: plt.plot(bv[i],np.log10(li[i]),marker=markers[i],markersize=markerSize,color=colors[i], linestyle='None',zorder=10,label=names[i]) plt.legend() pp.savefig() #plt.show() plt.close() baf_ca = baffles.age_estimator('calcium') baf_li = baffles.age_estimator('lithium') for i in [0,1]: print(names[i]) plt.plot([],[],'C0',linewidth=2,label='Final Age Posterior') p_li = baf_li.get_posterior(bv[i],li[i],bv_uncertainty=bv_err[i],measure_err=li_err[i],upperLim=False) p_ca = baf_ca.get_posterior(None,rhk[i]) product = prob.normalize(const.AGE,p_ca.array*p_li.array) prod_stats=prob.stats(const.AGE,product) my_plot.posterior(const.AGE, product, prod_stats,names[i],logPlot=False) plt.plot(const.AGE, p_ca.array,color='C3',label="Calcium Posterior") plt.plot(const.AGE, p_li.array,color='C2',label="Lithium Posterior") plt.axvspan(age_range[i][0],age_range[i][1], alpha=0.2, color='r', label=r'Literature age: %d - %d Myr' % tuple(age_range[i]),zorder=0) plt.axvline(x=mamaAge[i],color='C5',linestyle='--',label='MH08 age: %d' % mamaAge[i]) #plt.xlim([0,490]) plt.legend() pp.savefig() #plt.show() plt.close() print("%d Myr (68\\%%CI: %d - %d Myr)" % (utils.round_sigs(p_ca.stats[2],2), utils.round_sigs(p_ca.stats[1],2),utils.round_sigs(p_ca.stats[3],2))) print("%.1f Gyr (68\\%%CI: %.1f - %.1f Gyr)" % (p_li.stats[2]/1000,p_li.stats[1]/1000,p_li.stats[3]/1000)) print("%d Myr, with a 68\\%% confidence interval between %d Myr - %d Myr" % (utils.round_sigs(prod_stats[2],2), utils.round_sigs(prod_stats[1],2),utils.round_sigs(prod_stats[3],2))) print("TW PsA") plt.axvspan(age_range[-1][0],age_range[-1][1], alpha=0.2, color='r',zorder = 0) plt.axvspan(360-140,360+140, alpha=0.2, color='b',zorder=0) p_li = baf_li.get_posterior(bv[2],li[2],bv_uncertainty=bv_err[2],measure_err=li_err[2],upperLim=False) print("we report an age of %d Myr with a 68\\%% confidence interval between %d Myr - %d Myr\ (third panel of Fig. \\ref{fig:notable_stars}), consistent with Mamajek's lithium age,\ but a factor of $\sim$%.1f too young for his final adopted age." % (p_li.stats[2],p_li.stats[1],p_li.stats[3], 440/p_li.stats[2])) my_plot.posterior(const.AGE, p_li.array, p_li.stats,names[2],None,False, logPlot=False) plt.axvline(x=age[-1],color='r',label=r'Literature age: %d $\pm$ 40 Myr' % age[-1]) plt.axvline(x=360,color='b',label=r"M'12 Li age: 360 $\pm$ 140 Myr") plt.xlim([-30,510]) plt.legend() pp.savefig() #plt.show() plt.close() plt.axvline(x=age[-1],color='r',label=r'Literature age: %d $\pm$ 40 Myr' % age[-1]) plt.axvspan(age_range[-1][0],age_range[-1][1], alpha=0.2, color='r',zorder = 0) robs_f = robs_fomalhaut() plt.plot(const.AGE,robs_f(const.AGE),'k--',label='Nielsen 2019 Fomalhaut PDF') plt.plot(const.AGE,p_li.array,'g',label='BAFFLES Li posterior') y = prob.normalize(const.AGE,p_li.array*robs_f(const.AGE)) plt.plot(const.AGE,y,color = 'C0',linewidth=2,label='Final Age') stat = prob.stats(const.AGE,y) print("to get a final age for the system, $%d^{+%d}_{%d}$ Myr." % (stat[2],stat[3]-stat[2],stat[1]-stat[2])) plt.vlines(x=stat[2],ymin= 0,ymax= y[bisect.bisect_left(const.AGE,stat[2])], \ label='Final median age: %.3g Myr' % stat[2] ,color = 'orange') plt.fill_between(const.AGE,y, where= (const.AGE >= stat[1]) & (const.AGE <= stat[3]),color='.4', \ label='68%% CI: %.2g - %.2g' % (stat[1],stat[-2])) plt.title(names[2],size=my_plot.TITLE_SIZE) plt.xlim([0,1200]) plt.legend() plt.ylabel('Probability Density (Myr^-1)',size=my_plot.AXIS_LABEL_SIZE) plt.xlabel("Age (Myr)",size=my_plot.AXIS_LABEL_SIZE) plt.tight_layout() plt.minorticks_on() plt.tick_params(axis='both',which='both',right=True,top=True) pp.savefig() #plt.show() plt.close() printName(name) pp.close()
def baffles_vs_mamajek(bv_rhk, fits, i, pdfPage=None, showPlots=False, title=None, mamaProduct=False): import ca_constants as const baf = baffles.age_estimator('calcium') #baf.make_grids(bv_rhk,fits,omit_cluster=i) my_ages = [] my_error = [] mamajek_ages = [] post_prod = 0 for j in range(len(bv_rhk[i][0])): b, r = bv_rhk[i][0][j], bv_rhk[i][1][j] mamajek_ages.append(utils.getMamaAge(r)) post = baf.get_posterior(b, r) post_prod += np.log(post.array) stat = post.stats my_ages.append(stat[2]) my_error.append((stat[2] - stat[1], stat[3] - stat[2])) post_prod = prob.normalize(const.AGE, np.exp(post_prod)) baffles_age = prob.stats(const.AGE, post_prod)[2] plt.Line2D([0], [0], color='C%d' % i, marker=const.MARKERS[i], label=const.CLUSTER_NAMES[i]) plt.axis([.4, 14000, .4, 14000]) plt.title(const.CLUSTER_NAMES[i], size=TITLE_SIZE) plt.xlabel(r'Age derived from M & H (2008)', size=AXIS_LABEL_SIZE) plt.ylabel(u'BAFFLES Age (Myr)', size=AXIS_LABEL_SIZE) for j in range(len(my_ages)): if (j == 0): plt.errorbar(mamajek_ages[j], my_ages[j], np.array([my_error[j]]).T, color=const.COLORS[i], marker=const.MARKERS[i]) else: plt.errorbar(mamajek_ages[j], my_ages[j], np.array([my_error[j]]).T, color=const.COLORS[i], marker=const.MARKERS[i]) plt.hlines(y=baffles_age,xmin= 0,xmax= baffles_age, \ label='BAFFLES cluster age: %.3g Myr' % baffles_age ,linestyle='--',color = 'C0') if mamaProduct: age = utils.getMamaProductAge(bv_rhk[i][1]) plt.vlines(x=age,ymin= 0,ymax= age, \ label='M & H (2008): %.3g Myr' % age ,linestyle='--',color = 'C2') plt.plot([0, 10000], [0, 10000], dashes=[2, 2], color='k') plt.plot(const.CLUSTER_AGES[i], const.CLUSTER_AGES[i], marker='*', markersize=18, color='C1', linestyle='None', label='Isochronal cluster age: %d Myr' % const.CLUSTER_AGES[i], alpha=1, zorder=10) ax = plt.gca() ax.set_yscale('log') ax.set_xscale('log') plt.legend(loc=2) plt.tight_layout() plt.minorticks_on() plt.tick_params(axis='both', which='both', right=True, top=True) if (pdfPage): pdfPage.savefig() if (showPlots): plt.show() if pdfPage: plt.close()
def make_table(MR=False): ca_const = utils.init_constants('calcium') li_const = utils.init_constants('lithium') empty = '' """ table = [] #[Object,RA,Dec,Sp Type,B-V,R'HK,Li EW,Source] #first read in all the 4 tables and create a single big table, which then I sort and merge t = np.genfromtxt('data/nielsen_2010_table2.csv',delimiter=',',dtype=str,skip_header=1) for row in t: if not utils.isFloat(row[1]) or not (.45 <= float(row[1]) <= 1.9): continue arr = [] arr.append(row[21].strip()) ra,dec = ra_dec(row[22]) arr.append(ra) arr.append(dec) arr.append(row[4].strip()) arr.append(row[1]) arr.append(row[13]) arr.append(row[7]) arr.append("1") if arr[0] == '' or not (utils.isFloat(arr[5]) or utils.isFloat(arr[6])): continue table.append(arr) bv_to_teff = my_fits.magic_table_convert('bv','teff') t = np.genfromtxt('data/brandt_2014_table.csv',delimiter=',',dtype=str,skip_header=2) for row in t: bv = None if utils.isFloat(row[2]) and utils.isFloat(row[3]): bv = float(row[2]) - float(row[3]) if bv is None or not (.45 <= bv <= 1.9): continue arr = [] arr.append(row[14].strip()) ra,dec = ra_dec(row[15]) arr.append(ra) arr.append(dec) arr.append(row[4].strip()) arr.append("%f" % bv) arr.append(row[7]) if row[9].find('A') != -1: nli = float(row[9].split()[-1]) teff = bv_to_teff(bv) ew = 10** my_fits.teff_nli_to_li([teff],[nli])[0] arr.append("%d" % ew) elif utils.isFloat(row[9]): arr.append(row[9]) else: arr.append(empty) arr.append("2") if arr[0] == '' or not (utils.isFloat(arr[5]) or utils.isFloat(arr[6])): continue table.append(arr) t = np.genfromtxt("data/nearbyStars_Boro_Saikia_2018.txt",delimiter='\t',dtype=str,skip_header=58) for row in t: if not utils.isFloat(row[5]) or not (.45 <= float(row[5]) <= 1.9): continue arr = [] arr.append(row[16].strip()) ra,dec = ra_dec(row[17]) arr.append(ra) arr.append(dec) arr.append(row[18].strip()) arr.append(row[5]) arr.append(row[10]) arr.append(empty) arr.append("3") if arr[0] == '' or not (utils.isFloat(arr[5]) or utils.isFloat(arr[6])): continue table.append(arr) t = np.genfromtxt("data/guillot_2009_li_survey.txt",delimiter='\t',dtype=str,skip_header=77) for row in t: if not utils.isFloat(row[7]) or not (.45 <= float(row[7]) <= 1.9): continue arr = [] arr.append(row[22].strip()) ra,dec = ra_dec(row[23]) arr.append(ra) arr.append(dec) arr.append(row[24].strip()) arr.append(row[7]) arr.append(empty) arr.append(row[16]) arr.append("4") if arr[0] == '' or not (utils.isFloat(arr[5]) or utils.isFloat(arr[6])): continue table.append(arr) table = np.array(table) name_sorted = table[table[:,0].argsort()] thinned = [] #averaging b-v,measurements, sources as 1,4 for name in set(name_sorted[:,0]): subset = name_sorted[name_sorted[:,0]==name] if len(subset) == 1: thinned.append(subset[0]) else: arr = copy.deepcopy(subset[0]) arr[4] = average(subset[:,4]) arr[5] = average(subset[:,5]) arr[6] = average(subset[:,6]) x = list(set(subset[:,7])) x.sort() arr[7] = ','.join(x) thinned.append(arr) thinned = np.array(thinned) final_table = thinned[thinned[:,1].argsort()] np.save("final_table",final_table) exit() """ final_table = np.load("data/merged_nielsen_brandt_saikia_guillot.npy") delimiterMR = ',' baf_li = baffles.age_estimator('lithium') baf_ca = baffles.age_estimator('calcium') #[Object,RA,Dec,Sp Type,B-V,R'HK,Li EW,Source] f = open("baffles_table2_latex.txt", 'w+') fMR = open("baffles_table2.csv", 'w+') cdf = ['2.5%', '16%', '50%', '84%', '97.5%'] column_head = [ 'Name', 'RA', 'Dec', 'Sp. Type', 'B-V', "logR'HK", 'Li EW', 'Ref.' ] column_head += ["R'HK Age at CDF=" + x for x in cdf] column_head += ["Li EW Age at CDF=" + x for x in cdf] column_head += ["Final Age at CDF=" + x for x in cdf] units = [ '', 'h m s', 'h m s', '', 'mags', " ", 'mA', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' ] fMR.write(delimiterMR.join(column_head)) fMR.write('\n') fMR.write(delimiterMR.join(units)) fMR.write('\n') for row in final_table: arr = [] arrMR = [] arr += [x.replace('V* ', '').replace('_', '-') for x in row[0:4]] arrMR += [x.replace('$', '').replace('V* ', '') for x in row[0:4]] bv = float(row[4]) arr.append("%.2f" % bv) arrMR.append("%.3g" % bv) p_ca, p_li = None, None if utils.isFloat(row[5]): rhk = float(row[5]) arr.append('$%.2f$' % rhk) arrMR.append('%.3f' % rhk) if ca_const.inRange(bv, rhk): p_ca = baf_ca.get_posterior(bv, rhk, showPlot=False) else: arr.append(empty) arrMR.append(empty) ew = None if utils.isFloat(row[6]): ew = float(row[6]) arr.append('%d' % ew) arrMR.append('%g' % ew) else: arr.append(empty) arrMR.append(empty) arr.append(row[7]) arrMR.append(row[7].replace(',', ';')) if bv is not None and ew is not None and ew > 0 and li_const.inRange( bv, np.log10(ew)): p_li = baf_li.get_posterior(bv, ew, showPlot=False) if p_ca is not None: arr += printStats(p_ca.stats) arrMR += printStats(p_ca.stats, MR=True) else: arr += [empty] * 5 arrMR += [empty] * 5 if p_li is not None: arr += printStats(p_li.stats) arrMR += printStats(p_li.stats, MR=True) else: arr += [empty] * 5 arrMR += [empty] * 5 if p_ca is None and p_li is None: continue if p_ca is not None and p_li is not None: prod = p_ca.array * p_li.array prob.normalize(ca_const.AGE, prod) stats = prob.stats(ca_const.AGE, prod) arr += printStats(stats) arrMR += printStats(stats, MR=True) elif p_ca is not None: arr += printStats(p_ca.stats) arrMR += printStats(p_ca.stats, MR=True) elif p_li is not None: arr += printStats(p_li.stats) arrMR += printStats(p_li.stats, MR=True) else: arr += [empty] * 5 arrMR += [empty] * 5 f.write(' & '.join(arr) + " \\\\") f.write('\n') fMR.write(delimiterMR.join(arrMR)) fMR.write('\n') f.close() fMR.close()