Exemplo n.º 1
0
def p_values_plot(model='Model2',sample='Sample1',test='MannWhitney',show=False,filtered=True,old=False,filename=None,ax=None):
    save = ax is None
    if ax is None:
        fig,ax = plt.subplots(1,1,figsize=size1c)

    if filename is None:
        filename = 'results/{:s}_{:s}_{:s}.pkl'.format(sample.replace(' ',''),model.replace(' ',''),test)
    x,f_false,y,z,dz = load_result(filename)
    z,dz = z[:,0,:],dz[:,0,:]
    
    # Gaussian filter for smoother data
    if filtered: z,dz = filter_data(z,dz)

    ls = ['solid','dashed','dotted']
    levels = [0.05,0.1,0.01]
    #lws = [lw,1.5*lw,lw/1.5]
    lws = [lw,lw,lw]
    for i in range(len(levels)):
        xs,ys = get_contour(x,y,z,np.log10(levels[i]))
        ax.plot(xs,ys,c=cc[1],lw=lws[i],ls=ls[i])
        idx = np.argmin(np.abs(xs-0.5))
        x0s = [0.475,0.44,0.5]
        shifts = [14,-3,25]
        rots = [-25,-23,-25]
        ax.annotate('p = {:.2f}'.format(levels[i]),xy=(x0s[i],ys[idx]+shifts[i]),color=cc[1],ha='center',va='center',rotation=rots[i])
    
        
        if i == 0:
            # Shaded region marking detectable correlation
            ys = ys
            ax.fill_between(xs,ys,ys+1e4,color='grey',alpha=0.15,lw=0)
    
    ax.set_xticks([0,0.25,0.5,0.75,1.0])
    ax.set_xticklabels(['{:d}%'.format(int(xt*100)) for xt in ax.get_xticks()],y=-0.01)
    ax.set_xlim([0,1])
    
    ax.grid(True,axis='y',which='major',lw=2)
    ax.grid(True,axis='y',which='minor',lw=0.3)
    
    ax.set_yscale('log')
    ax.set_ylim([10,1000])
    ax.set_yticks([10,100,1000])
    ax.set_yticklabels(['10','100','1000'])
    if do_lines:
        ax.axvline(0.1,linestyle='dashed',c='black',lw=2)
        ax.axvline(0.8,linestyle='dashed',c='black',lw=2)
    
    ax.set_ylabel('Number of exo-Earth candidates',fontsize=lfs)
    ax.set_xlabel('Fraction of exo-Earth candidates with life ($f_\mathrm{life}$)',ha='center',va='center',fontsize=lfs,labelpad=30)
     
    plt.subplots_adjust(left=0.13,bottom=0.14,right=0.88)
    
    if show:
        plt.show()
    elif save:
        init_outdir(outdir)
        plt.savefig(outdir+'/p_values.pdf')
        plt.close()
    else:
        return ax
Exemplo n.º 2
0
def contour_plot(models=['Model1','Model2','Model3'],sample='Sample1',test='MannWhitney',show=False,filtered=True,f_false=0.,old=False,xlog=False,ax=None,fontsize=lfs):
    save = ax is None
    if ax is None:
        fig,ax = plt.subplots(figsize=(1.1*size1c[0],size1c[1]))
        ax = [ax]
    else:
        ax = [ax]

    for j in range(len(models)):
        filename = 'results/{:s}_{:s}_{:s}.pkl'.format(sample.replace(' ',''),models[j].replace(' ',''),test)

        if old:
            x,y,z,dz = load_result(filename,old=True)
        else:
            x,f_falses,y,z,dz = load_result(filename)
            
            # Grab the slice for the correct value of f_false
            idx = np.argmin(np.abs(f_false-f_falses))
            z,dz = z[:,idx,:],dz[:,idx,:]
            if np.abs(f_false-f_falses[idx]) > 0.01:
                print("Warning: closest match to f_false = {:.4f} in the results pkl is f_false = {:.4f}".format(f_false,f_falses[idx]))
        
        # Gaussian filter for smoother data
        if filtered: z,dz = filter_data(z,dz)

        xs,ys = get_contour(x,y,z,np.log10(thresh))
        col = cc[j]
        ax[0].plot(xs,ys,c=col,lw=lw)
        
        x0 = [0.45,0.67,0.53]
        y0 = [0.2,0.152,0.34]
        rot = [-27,-23,-23]
        
        ax[0].annotate(model_names[models[j]],xy=(x0[j],y0[j]),xycoords='axes fraction',color=col,ha='center',va='center',
                        rotation=rot[j],zorder=100,weight='bold' if j == 1 else 'normal',fontsize=0.9*plt.rcParams['font.size'])

        if j == 1:
            # Shaded region marking detectable correlation
            ys = ys
            ax[0].fill_between(xs,ys,ys+1e4,color='grey',alpha=0.15,lw=0)
            ax[0].annotate('Detectable correlation',xy=(0.5,0.69),xycoords='axes fraction',ha='center',va='center',color='grey',rotation=0)
    
    if xlog:
        ax[0].set_xscale('log')
    else:
        ax[0].set_xticks([0,0.25,0.5,0.75,1.0])
        ax[0].set_xticklabels(['   {:d}%'.format(int(xt*100)) for xt in ax[0].get_xticks()],y=-0.01)
    ax[0].set_xlim([0,1])
    
    ax[0].grid(True,axis='y',which='major',lw=2)
    ax[0].grid(True,axis='y',which='minor',lw=0.3)
    
    ax[0].set_yscale('log')
    ax[0].set_ylim([10,1000])
    ax[0].set_yticks([10,100,1000])
    ax[0].set_yticklabels(['10','100','1000'])
    
    ax[0].axvline(0.1,linestyle='dashed',c='black',lw=2)
    ax[0].axvline(0.8,linestyle='dashed',c='black',lw=2)
    ax[0].annotate('Optimistic',xy=(0.81,950),rotation=90,va='top',ha='left',fontsize=1.25*afs)
    ax[0].annotate('Pessimistic',xy=(0.11,950),rotation=90,va='top',ha='left',fontsize=1.25*afs)
    
        
    # Estimates for LUVOIR, Nautilus, LIFE, Origins
    obs_names = ['LUVOIR','Nautilus Space\nObservatory','LIFE','Origins Space\nTelescope']
    obs_vals = [55.5,986,44.5,26]
    ax2 = ax[0].twinx()
    ax2.set_ylim([1,3])
    ax2.set_yticks(np.log10(obs_vals))
    ax2.set_yticklabels(obs_names,fontsize=1.25*afs)
    
    ax2.tick_params(axis='y',width=4,length=15,pad=15)

    ax[0].set_ylabel('Number of\nexo-Earth candidates',fontsize=fontsize)
    ax[0].set_xlabel('Fraction of exo-Earth candidates with life ($f_\mathrm{life}$)',ha='center',va='center',fontsize=fontsize,labelpad=30)
        
    plt.subplots_adjust(left=0.22,bottom=0.14,right=0.78)
    
    if show:
        plt.show()
    elif save:
        init_outdir(outdir)
        plt.savefig(outdir+'/Figure_2.pdf')
        plt.close()
    else:
        return ax[0]    
Exemplo n.º 3
0
def sample_selection_plot(model='Model2',samples=['Sample1','Sample2','Sample4'],test='MannWhitney',show=False,filtered=True,old=False,ax=None):
    save = ax is None
    if ax is None:
        fig,ax = plt.subplots(1,1,figsize=size1c)

    for i in range(len(samples)):
        filename = 'results/{:s}_{:s}_{:s}.pkl'.format(samples[i].replace(' ',''),model.replace(' ',''),test)
        x,f_false,y,z,dz = load_result(filename)
        z,dz = z[:,0,:],dz[:,0,:]
        
        # Gaussian filter for smoother data
        if filtered: z,dz = filter_data(z,dz)

        ls = ['solid','dashed','dotted']
        labels = ['All planets','Young and old planets only','No young planets']
    
        xs,ys = get_contour(x,y,z,np.log10(thresh))
        ax.plot(xs,ys,c=cc[1],lw=lw,ls=ls[i])
        idx = np.argmin(np.abs(xs-0.45))
        shifts = [11,-1.75,5]
        xshifts = [0,-.085,.08]
        rots = [-25,-24,-25]
        ax.annotate(labels[i],xy=(0.45+xshifts[i],ys[idx]+shifts[i]),color=cc[1],ha='center',va='center',rotation=rots[i])
    
    
        if i == 0:
            # Shaded region marking detectable correlation
            ys = ys
            ax.fill_between(xs,ys,ys+1e4,color='grey',alpha=0.15,lw=0)
            ax.annotate('Detectable correlation',xy=(0.95,0.92),xycoords='axes fraction',ha='right',va='center',color='grey',rotation=0,weight='bold',
                        bbox=dict(boxstyle='round',fc='grey',lw=0,alpha=0.05))
    
    ax.set_xticks([0,0.25,0.5,0.75,1.0])
    ax.set_xticklabels(['{:d}%'.format(int(xt*100)) for xt in ax.get_xticks()],y=-0.01)
    ax.set_xlim([0,1])
    
    ax.grid(True,axis='y',which='major',lw=2)
    ax.grid(True,axis='y',which='minor',lw=0.3)
    
    ax.set_yscale('log')
    ax.set_ylim([10,1000])
    ax.set_yticks([10,100,1000])
    ax.set_yticklabels(['10','100','1000'])
    
    if do_lines:
        ax.axvline(0.1,linestyle='dashed',c='black',lw=2)
        ax.axvline(0.8,linestyle='dashed',c='black',lw=2)
    
    ax.set_ylabel('Number of exo-Earth candidates',fontsize=lfs)
    ax.set_xlabel('Fraction of exo-Earth candidates with life ($f_\mathrm{life}$)',ha='center',va='center',fontsize=lfs,labelpad=30)
     
    plt.subplots_adjust(left=0.13,bottom=0.14,right=0.88)
    
    if show:
        plt.show()
    elif save:
        init_outdir(outdir)
        plt.savefig(outdir+'/sample_selection.pdf')
        plt.close()
    else:
        return ax
Exemplo n.º 4
0
def test_comparison_plot(model='Model2',sample='Sample1',tests=['MannWhitney','Spearman','Student'],show=False,filtered=True,ax=None):
    save = ax is None
    if ax is None:
        fig,ax = plt.subplots(1,1,figsize=size1c)

    for i in range(len(tests)):
        filename = 'results/{:s}_{:s}_{:s}.pkl'.format(sample.replace(' ',''),model.replace(' ',''),tests[i])
        x,f_false,y,z,dz = load_result(filename)
        z,dz = z[:,0,:],dz[:,0,:]
        
        # Gaussian filter for smoother data
        if filtered: z,dz = filter_data(z,dz)

        ls = ['solid','dashed','dotted','dashdot']
        label = test_names[tests[i]]
    
        xs,ys = get_contour(x,y,z,np.log10(thresh))
        ax.plot(xs+(0.005 if i == 2 else 0),ys,c=cc[1],lw=lw,ls=ls[i])
        idx = np.argmin(np.abs(xs-0.5))
        
        
        if i == 0:
            # Shaded region marking detectable correlation
            ys = ys
            ax.fill_between(xs,ys,ys+1e4,color='grey',alpha=0.15,lw=0)
        
    for i in range(2):
        x0 = [0.75,0.45]
        y0 = [0.21,0.243]
        rots = [-18.,-24]
        labels = ['Mann-Whitney U test',"Spearman's / Student's tests"]
        ax.annotate(labels[i],xy=(x0[i],y0[i]),color=cc[1],xycoords='axes fraction',ha='center',va='center',rotation=rots[i])
    
    ax.set_xticks([0,0.25,0.5,0.75,1.0])
    ax.set_xticklabels(['{:d}%'.format(int(xt*100)) for xt in ax.get_xticks()],y=-0.01)
    ax.set_xlim([0,1])
    
    ax.grid(True,axis='y',which='major',lw=2)
    ax.grid(True,axis='y',which='minor',lw=0.3)
    
    ax.set_yscale('log')
    ax.set_ylim([10,1000])
    ax.set_yticks([10,100,1000])
    ax.set_yticklabels(['10','100','1000'])
    
    if do_lines:
        ax.axvline(0.1,linestyle='dashed',c='black',lw=2)
        ax.axvline(0.8,linestyle='dashed',c='black',lw=2)
    
    ax.set_ylabel('Number of exo-Earth candidates',fontsize=lfs)
    ax.set_xlabel('Fraction of exo-Earth candidates with life ($f_\mathrm{life}$)',ha='center',va='center',fontsize=lfs,labelpad=30)   

    plt.subplots_adjust(left=0.13,bottom=0.14,right=0.88)
    
    if show:
        plt.show()
    elif save:
        init_outdir(outdir)
        plt.savefig(outdir+'/test_comparison.pdf')
        plt.close()
    else:
        return ax