Example #1
0
def plot_powerspectra(fr,data,title,i):
    fig,axes=plt.subplots(1,1,figsize=(10,6))
    print "plotting"
    if i!='null':
        plt.plot(np.log10(fr),np.log10(data))
        fig.text(0.2,0.85,"z = "+str(redshifts[i]),fontsize=fontsize,color='red')
    else:
        print "plotting redshifts:"
        for z in range(0,len(redshifts),10):
            print redshifts[z]
            plt.plot(np.log10(fr),np.log10(data[z,:]),label="z = " +str(redshifts[z]))
            lg=plt.legend(loc=2,prop={'size':fontsize-1},ncol=2)
            lg.draw_frame(False)
    plt.ylim(0,2.0)
    m0=MultipleLocator(0.5)
    axes.xaxis.set_major_locator(m0)

    m0=MultipleLocator(0.1)
    axes.xaxis.set_minor_locator(m0)

    #plt.ylim(0,1e6)
#    plt.title(title)
    plt.ylabel("log$_{10}$($\Delta_{21cm}$)  [mK] ",size=fontsize)
    plt.xlabel("log$_{10}$(k) [h Mpc$^{-1}$]",size=fontsize)
    plt.tight_layout()
    print "saing as: "+setup_dirs.plotsdir()+title+".png" 
    plt.savefig(setup_dirs.plotsdir()+title+".png")
    plt.close()
Example #2
0
def plot_3_log_histograms(dataHI,dataHeI,dataHeII,title,name,xlabel,nobins=5000,type='log'):
    fig = plt.figure()
    #print np.amin(data3)
    dataHI = dataHI.flatten()
    dataHeI = dataHeI.flatten()
    dataHeII = dataHeII.flatten()
    ax = fig.add_subplot(111)
    ax.set_yscale('log',basey=10)
    if (type=='log'):
        weights = np.ones_like(dataHI)/len(dataHI)
        ax.hist(np.log10(dataHI),weights=weights,bins=np.linspace(-16, 0, nobins),histtype='stepfilled',edgecolor='none',alpha=0.4,color='red',label='HII')
        ax.hist(np.log10(dataHeI),weights=weights,bins=np.linspace(-16, 0, nobins),histtype='stepfilled',alpha=0.4,color='yellow',edgecolor='none',label='HeII')
        ax.hist(np.log10(dataHeII),weights=weights,bins=np.linspace(-16, 0, nobins),histtype='stepfilled',alpha=0.4,color='blue',edgecolor='none',label='HeIII')
        
    else:
        ax.hist(data,nobins,color='red',alpha=0.01)
        ax.hist(data,nobins,color='green',alpha=0.01)
    plt.title(title)
    plt.legend(loc=2)
    if type=='log':
        plt.xlabel('log10('+xlabel+')')
        plt.yscale=('log')
    else:
        plt.xlabel(xlabel)
    plt.ylabel("Frequency")
    plt.savefig(setup_dirs.plotsdir()+name+".png")
    plt.close()
    print "histogram complete"
Example #3
0
def plot_log_histogram(data,name,xlabel,label1='Stellar Sources',label2='Stellar sources and X-Rays',type='log',filedir='',nobins=90):
    fig = plt.figure()
    ax=plt.gca()
    ax = fig.add_subplot(111)
    ax.set_yscale('log',basey=10)
    if(data.shape==(250**3,)):
        weights = np.ones_like(data)/float(len(data))
        ax.hist(np.log10(data),weights=weights,bins=10**np.linspace(-1, 0.6, nobins),histtype='stepfilled',color='red',edgecolor='red')
    elif(data.shape==(250**3,2)):
        print "Plotting 2 data sets..."+label1+" and "+label2
        weights = np.ones_like(data[:,0])/float(len(data))
        ax.hist(np.log10(data[:,0]),weights=weights,bins=10**np.linspace(-1, 0.6, nobins),histtype='stepfilled',color='red',edgecolor='none',alpha=0.5,label=label1)
        ax.hist(np.log10(data[:,1]),weights=weights,bins=10**np.linspace(-1, 0.6, nobins),histtype='stepfilled',color='blue',edgecolor='none',alpha=0.5,label=label2)
        lg = plt.legend(loc=2,prop={'size':fontsize})
        lg.draw_frame(False)

#    lg=plt.legend(loc=2,prop={'size':14})
#    lg.draw_frame(False)
    plt.xlabel('log$_{10}$('+xlabel+')',size=fontsize)
    plt.ylabel("Probability",size=fontsize)
    plt.tight_layout()
    if filedir=='':filedir=setup_dirs.plotsdir()
    plt.savefig(filedir+name+".png")
    plt.close()
    print "histogram complete, saving as "+filedir+name+".png"
Example #4
0
def plot_dbt_histogram(data,title,name,xlabel,nobins=500,type='log'):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.set_yscale('log',basey=10)
    weights = np.ones_like(data)/float(len(data))
    #logbins = np.zeros(nobins)
    #logbins[nobins/2:nobins] = np.logspace(-10,np.log10(100),nobins/2)
    #temp = -1*np.logspace(-10,np.log10(100),nobins/2)
    #logbins[0:nobins/2] = temp[::-1]
    #print logbins
    #print logbins

    #if(data.shape==(len(redshifts1),))
    ax.hist(data,weights=weights,bins=500,histtype='stepfilled',color='blue',edgecolor='blue')

#    elif(data.shape==(len(redshifts1),2)):
#        if legend1 == '' or legend2 =='':
#            print "WARNING: Specify legend for plotting two data sets"
#        ax.hist(data[:,0],weights=weights,bins=logbins,histtype='stepfilled',color='blue',edgecolor='red')
#        ax.hist(data[:,1],weights=weights,bins=logbins,histtype='stepfilled',color='red',edgecolor='red')
#

    plt.xlabel(xlabel,size=30)
    plt.xlim(-457,83)
    plt.ylabel("Probability",size=30)
    plt.savefig(setup_dirs.plotsdir()+name+".png")
    plt.close()
    print "histogram complete"
Example #5
0
def plot_scatter_contour(x,y,name,ylabel,xlabel,it,nbins=200):
    #plt.figure()
    fig=plt.figure(figsize=(9, 7.25), dpi= 300)
    plt.subplot('111', axisbg='black')
    ax = plt.gca()
    #general tick parameters
    ax.tick_params(axis='both', which='major', labelsize=numberfontsize, width = tickwidth, length = 11, direction='out',pad=14.0,top='off',right='off')
    ax.tick_params(axis='both', which='minor', width = tickwidth, length = 5.5,direction='out',top='off',right='off')

    #y-axis

    #ax.get_yaxis().get_major_formatter().set_useOffset(False)
    ax.ticklabel_format(axis='y', style='sci', scilimits=(-2,2),useOffset=False)
    m0 = MultipleLocator(5000)
    ax.yaxis.set_major_locator(m0)
    m0 = MultipleLocator(1000)
    ax.yaxis.set_minor_locator(m0)
    #x-axis
    m0 = MultipleLocator(1)
    ax.xaxis.set_major_locator(m0)
    m0 = MultipleLocator(0.2)
    ax.xaxis.set_minor_locator(m0)

    norm = 1.0
    if name =="equation_of_state":
        h =0.7
        omega_m = 0.27
        omega_delta = 0.73
        z =  redshifts[it]
        G = 6.67408e-11
        Mpc_in_metres=3.086e+22

        H0 = h/Mpc_in_metres*1e5
        pcrit = 3.0*H0**2/(8*np.pi*G)#*(omega_m*(0.0+z)**3+omega_delta)
        pcrit = pcrit/1.0e4
        norm = pcrit


    #plot data
    cax =plt.hist2d(x/norm, y, bins=nbins,norm=LogNorm(),normed=True,cmap='Blues_r')
    cbar = plt.colorbar(orientation='vertical')
    #cbar.set_ticks([maxi,maxi/10.0,maxi/100.0,maxi/1000.0,maxi/10000.0,maxi/1000000.0])
    #cbar.set_ticklabels(['$10**0$','$10**{-1}$','$10**{-2}$','$10**{-3}$','$10**{-4}$','$10**{-5}$'])
    plt.ylabel(ylabel,size=fontsize)
    plt.ylim(0,25100)
    plt.xlabel(xlabel,size=fontsize)
    plt.tight_layout()   
    plt.savefig(setup_dirs.plotsdir()+name+"_"+str(it+10)+"_"+str(redshifts[it])+".png")
    plt.close()
Example #6
0
def plot(dataslice,it,label,name,mini,maxi,cmap='hot',type='lin'):
    
    if name=='dbt':
        cmapdbt = {'red':   ((0.0, 0.0, 0.0),
                            (0.846, 0.0, 1.0),
                            (1.0, 0.0, 0.0)),
                   
                   #'green':   ((0.1, 0.1, 0.1),
                   #         (0.846, 0.1, 0.0),
                   #         (0.0, 0.0, 0.0)),
    
                   'green': ((0.0, 0.0, 0.0),
                            (1.0, 0.0, 0.0)),

                   'blue':  ((0.0, 0.0, 0.0),
                            (0.846, 1.0, 0.0),
                            (1.0, 0.0, 0.0))

                   #'white': ((0.0, 0.0, 0.0),
                   #         (0.846, 1.0, 0.0),
                   #         (1.0, 0.1, 1.0)),

                  }


        plt.register_cmap(name='dbtmap',data=cmapdbt)
        cmap = plt.get_cmap('dbtmap')

    plt.figure()
    print mini,maxi
#    plt.title(str(title) + ", Redshift: " + str(redshifts[it]))
    if (type=='lin'):
        plt.imshow(dataslice,cmap=cmap,vmin=mini,vmax=maxi,origin='lower')
    else:
        plt.imshow(dataslice,cmap=cmap,norm=LogNorm(),vmin=mini,vmax=maxi,origin='lower')
    cbar = plt.colorbar(orientation='vertical')
    cbar.set_label(label,size=19)

    cnv=250.0/244.0
    tick_locs=[0,50*cnv,100*cnv,150*cnv,200*cnv,250*cnv]
    tick_lbls=[0,50,100,150,200,250]
    plt.xlabel("Distance (Mpc/h)",size=18)
    plt.ylabel("Distance (Mpc/h)",size=18)
    #plt.title(title+", Redshift: "+str(redshifts[it]))
    plt.savefig(setup_dirs.plotsdir()+name+"_"+str(it+10)+"_"+str(redshifts[it])+".png")
    plt.close()
Example #7
0
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib.ticker import MultipleLocator
mpl.rc('xtick', labelsize=25)
mpl.rc('ytick', labelsize=25)
mpl.rc('font',family='serif')
fontsize=26
numberfontsize=25
tickwidth=1.5
start=0

#print plotsdir()
redshifts = setup_dirs.read_redshifts()
path_data = setup_dirs.resultsdir()
path_plots = setup_dirs.plotsdir()

def mean(name,pathd = path_data,redshifts1=redshifts):
    mean = np.zeros(len(redshifts1))
    print 'Reading mean from ../generate_data/'+pathd+'mean_'+name+'.dat'
    file = open('../generate_data/'+pathd+'mean_'+name+'.dat', 'r')
    i=0
    for line in file:
        mean[i] = float(line)
        i=i+1
    return mean

def plot_mean(data,title,ylabel,pathp = path_plots, redshifts1=redshifts, redshifts2=redshifts,legend1='',legend2='',legend3='',legend4=''):
    #plt.figure()
    fig=plt.figure(figsize=(10.25, 10.25), dpi= 300)
#    plt.subplot('111')
Example #8
0
def plot(dataslice,it,label,name,mini,maxi,cmap='hot',type='lin'):
    
    if name=='dbt' or name=='dbt_lightcone_' or name=='smoothed_dbt':
        print dataslice
        print "using dbt colourmap"
        cmapdbt = {'red':   ((0.0, 0.0, 0.0),
                            (0.84629629629, 0.0, 1.0),
                            (1.0, 1.0, 1.0)),
                   
                   #'green':   ((0.1, 0.1, 0.1),
                   #         (0.846, 0.1, 0.0),
                   #         (0.0, 0.0, 0.0)),
    
                   'green': ((0.0, 0.0, 0.0),
                            (0.84629629629,0.0, 0.0),
                            (1.0, 1.0, 1.0)),

                   'blue':  ((0.0, 0.0, 0.0),
                            (0.84629629629, 1.0, 0.0),
                            (1.0, 1.0, 1.0))

                   #'white': ((0.0, 0.0, 0.0),
                   #         (0.846, 1.0, 0.0),
                   #         (1.0, 0.1, 1.0)),

                  }


        plt.register_cmap(name='dbtmap',data=cmapdbt)
        cmap = plt.get_cmap('dbtmap')

    #plt.figure()
    plt.figure(figsize=(9,7.25),dpi=300)
    #plt.subplots_adjust(right=0.3)
    #plt.subplots_adjust(bottom=1.3)

    print mini,maxi
#    plt.title(str(title) + ", Redshift: " + str(redshifts[it]))
    if (type=='lin'):
        print "linear"
        im = plt.imshow(dataslice,cmap=cmap,vmin=mini,vmax=maxi,origin='lower')
    else:
        im = plt.imshow(dataslice,cmap=cmap,norm=LogNorm(),vmin=mini,vmax=maxi,origin='lower')
    font = FontProperties()
    font.set_weight('bold')
    if name == "xfrac" : 
        plt.text(20,220,"HII",fontsize=fontsize,color='white')
    if name == "xfracHe1" : 
        plt.text(20,220,"HeII",fontsize=fontsize,color='white')
    if name == "xfracHe2" : 
        plt.text(20,220,"HeIII",fontsize=fontsize,color='white')
        plt.text(150,20,"z = "+str(redshifts[it]),fontsize=fontsize,color='red')
#    if name == "Temperature":
        #plt.text(20,220, "Temperature",fontsize=fontsize,color='white')    

    if name!='dbt':
        print "not dbt..."
        cbar = plt.colorbar(im,orientation='vertical',fraction=0.046,pad=0.04)
        cbar.set_label(label,size=fontsize)
    #cbar.ax.set_yticklabels
        if name!="Temperature" :
            cbar.set_ticks([1.,1./10.0,1./100.0,1./1000.0,1./10000.0,1./1000000.0])
            cbar.set_ticklabels(['$ \ 10 ^0 $  ','$ \ 10  ^{-1}  $  ','$ \ 10  ^{-2}  $  ','$ \ 10  ^{-3}  $  ','$ \ 10  ^{-4}  $  ','$ \ 10 ^{-5}  $  '])
        else:
            cbar.set_ticks([2000,4000,6000,8000,10000,12000,14000])
            cbar.set_ticklabels(['  2  ','  4  ','  6  ','  8  ','  10  $ \ $','  12  ' , '  14   '])

    if FLAG=='TEST':
        print "Adding resolution to plot"
        res=10./float(ss)
        plt.text(0.08*ss,ss-0.15*ss,"Resolution: "+str('%.2f' % res)+ " Mpc/cell",fontsize=fontsize,color="white")

    cnv=250.0/244.0
    tick_locs=[0,50*cnv,100*cnv,150*cnv,200*cnv,250*cnv]
    tick_lbls=[0,50,100,150,200,250]
    #plt.xlabel("Distance (Mpc/h)",size=18)
    #plt.ylabel("Distance (Mpc/h)",size=18)
    #plt.title(title+", Redshift: "+str(redshifts[it]))i

    #plt.tight_layout()
#    if name == "Temperature":
    #plt.gcf().subplots_adjust(left=0.5)
    print "saving as..." + setup_dirs.plotsdir()+name+"_"+str(it+10)+"_"+str(redshifts[it])+".png"
    plt.savefig(setup_dirs.plotsdir()+name+"_"+str(it+10)+"_"+str(redshifts[it])+".png")
    plt.close()
Example #9
0
def plot_lightcone(dataslice,it,label,name,mini,maxi,redshifts,cmap='hot',type='lin'):
    if name=='dbt' or name=='dbt_lightcone' or name=='smoothed_dbt':
        print "using dbt colourmap"
        cmapdbt = {'red':   ((0.0, 0.0, 0.0),
                            (0.846, 0.0, 1.0),
                            (1.0, 1.0, 1.0)),

                   'green': ((0.0, 0.0, 0.0),
                            (0.846,0.0, 0.0),
                            (1.0, 1.0, 1.0)),

                   'blue':  ((0.0, 0.0, 0.0),
                            (0.846, 1.0, 0.0),
                            (1.0, 1.0, 1.0))
                  }
        plt.register_cmap(name='dbtmap',data=cmapdbt)
        cmap = plt.get_cmap('dbtmap')

    if name=='temp_lightcone':
        maxi =12000#400#13000
        mini= 0.00

        tcmap = {'green':   ((0.0, 1.0, 1.0),
                        (0.00, 0.0, 0.0),
                       (1.0, 0.0, 0.0)),
    
                   'blue': ((0.0, 1.0, 1.0),
                            (0.00,0.0, 0.0),
                            (1.0, 0.0, 0.0)),
    
                   'red':  ((0.0, 1.0, 1.0),
                            (0.1, 0.1, 0.1),
    #                        (0.05, 0.0, 0.0),
                             (1.0, 0.0, 0.0))
                }


        plt.register_cmap(name='cmapt',data=tcmap)
        cmap = plt.get_cmap('cmapt')
    if name=='xfrac_lightcone':
        mini = 0
        maxi = 1.0
        #type='log'

    fig,axes =plt.subplots(1,1,figsize=(26,6))
    if (type=='lin'):
        im = plt.imshow(dataslice,cmap=cmap,vmin=mini,vmax=maxi,origin='lower')
    else:
        im = plt.imshow(dataslice,cmap=cmap,norm=LogNorm(),vmin=mini,vmax=maxi,origin='lower')
    font = FontProperties()
    font.set_weight('bold')

    cnv=250.0/244.0
    ytick_locs=[0,50*cnv,100*cnv,150*cnv,200*cnv,250*cnv]
    ytick_lbls=[0,50,100,150,200,250]
    
    axes.tick_params(axis='both', which='major', labelsize=numberfontsize, width = tickwidth, length = 11, direction='out',pad=14.0,top='off',right='off')
    m0=MultipleLocator(200)
    axes.xaxis.set_major_locator(m0)

    m0=MultipleLocator(100)
    axes.xaxis.set_minor_locator(m0)

    labels = np.zeros(len(redshifts)/200+2)
    print len(labels-1)
    for i in range(len(dataslice[1,:])):
        if (i+1)%200==0: 
            if i<len(redshifts) and i/100<len(labels):
                labels[i/100] = str('%.2f'%redshifts[i])
    labels[len(labels)-2]=str('%.2f'%redshifts[len(redshifts)-2])
    print labels
    #axes.set_xticklabels(labels[::-1])
    plt.xlabel("z",size=fontsize)
    plt.ylabel("Distance (Mpc)",size=fontsize) 
    fig.subplots_adjust(right=0.85)
    cbar_ax = fig.add_axes([0.87, 0.25, 0.02, 0.5])
    cbar = fig.colorbar(im, cax=cbar_ax,ticks=[-400,-300,-200,-100,0,100,200,300])
    cbar.ax.set_yticklabels
    cbar.set_label("$\delta T_b \ (mK)$",size=fontsize)

#    plt.tight_layout()
    print "saving as..." + setup_dirs.plotsdir()+name+"_stepcell.png"
    plt.savefig(setup_dirs.plotsdir()+name+"_stepcell.png")
    plt.close()