예제 #1
0
def gasFraction(path, db, label='Bolshoi', output='fgascentral', tpy='.pdf'):
    #get data
    query = '''select gal_id, halo_id, mbulge, mstar, mcold, mbh from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    gal_id = data[:, 0]
    halo_id = data[:, 1].astype(N.int)
    mbulge = data[:, 2]
    mstar = data[:, 3]
    mcold = data[:, 4]
    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]

    fgas = 10.0**mcold / (10.0**mcold + 10.0**mstar)
    wgal = weight[halo_id]
    btt = 10.0**(mbulge - mstar)

    #masking
    cdisk = (gal_id == 1) & (btt < 0.4)

    #output file
    output = output + label + tpy
    #call the gas
    gasfracHess(mstar[cdisk], fgas[cdisk], wgal[cdisk], label, output)
예제 #2
0
def mhb(path, db, type='.pdf'):
    #get data
    query = '''select halo_id, mstar, mbulge, mbh from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    halo_id = data[:, 0].astype(N.int)
    mstar = data[:, 1]
    mbulge = data[:, 2]
    mbh = data[:, 3]

    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]
    wgal = weight[halo_id]

    #fitting functions of ??
    mbin_fit = 8.0 + N.arange(40) * 0.1
    mbh_fit = 8.2 + 1.12 * (mbin_fit - 11.0)

    #central = p.gal_id == 1
    btt = 10.0 ** (mbulge - mstar)

    #These could be changed to 0.4 and 0.6...
    early = btt >= 0.5
    late = btt <= 0.5
    print 'Number of galaxies %i, early types %i and late %i' % (len(mstar), len(mstar[early]), len(mstar[late]))

    #mbin = 8.0 + ((11.8 - 8.0) / 19.0) * N.arange(19)
    #mbh_hr = 8.2 + 1.12 * (p.mbulge - 11.0)
    output = 'mbhBolshoi' + type

    mbhHess(mbulge, mbh, wgal, 4.85, 10.0, 40,
            mbin_fit, mbh_fit, output)
예제 #3
0
def gasFraction(path, db,
                label='Bolshoi',
                output='fgascentral',
                tpy='.pdf'):
    #get data
    query = '''select gal_id, halo_id, mbulge, mstar, mcold, mbh from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    gal_id = data[:, 0]
    halo_id = data[:, 1].astype(N.int)
    mbulge = data[:, 2]
    mstar = data[:, 3]
    mcold = data[:, 4]
    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]

    fgas = 10.0 ** mcold / (10.0 ** mcold + 10.0 ** mstar)
    wgal = weight[halo_id]
    btt = 10.0 ** (mbulge - mstar)

    #masking
    cdisk = (gal_id == 1) & (btt < 0.4)

    #output file
    output = output + label + tpy
    #call the gas
    gasfracHess(mstar[cdisk], fgas[cdisk], wgal[cdisk], label, output)
예제 #4
0
def mhb(path, db, type='.pdf'):
    #get data
    query = '''select halo_id, mstar, mbulge, mbh from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    halo_id = data[:, 0].astype(N.int)
    mstar = data[:, 1]
    mbulge = data[:, 2]
    mbh = data[:, 3]

    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]
    wgal = weight[halo_id]

    #fitting functions of ??
    mbin_fit = 8.0 + N.arange(40) * 0.1
    mbh_fit = 8.2 + 1.12 * (mbin_fit - 11.0)

    #central = p.gal_id == 1
    btt = 10.0**(mbulge - mstar)

    #These could be changed to 0.4 and 0.6...
    early = btt >= 0.5
    late = btt <= 0.5
    print 'Number of galaxies %i, early types %i and late %i' % (
        len(mstar), len(mstar[early]), len(mstar[late]))

    #mbin = 8.0 + ((11.8 - 8.0) / 19.0) * N.arange(19)
    #mbh_hr = 8.2 + 1.12 * (p.mbulge - 11.0)
    output = 'mbhBolshoi' + type

    mbhHess(mbulge, mbh, wgal, 4.85, 10.0, 40, mbin_fit, mbh_fit, output)
예제 #5
0
def ssfrWrapper(path, db):
    #get data
    query = '''select gal_id, mbulge, mstar from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    gal_id = data[:, 0]
    mbulge = data[:, 1]
    mstar = data[:, 2]

    #make masks for all, central, and satellite galaxies
    all = gal_id >= 0
    c = gal_id == 1
    s = gal_id != 1

    #early vs. late type galaxies
    btt = 10.0 ** (mbulge - mstar)
    early = btt >= 0.4
    late = btt < 0.4

    label = 'ssfrBolshoi'

    ssfr(path, db, all, label)
    ssfr(path, db, c, label + '_cent')
    ssfr(path, db, s, label + '_sat')
    ssfr(path, db, early, label + '_sph')
    ssfr(path, db, late, label + '_disk')
예제 #6
0
def plotColourProperties(query,
                         xlabel,
                         ylabel,
                         output,
                         out_folder,
                         ymin=-12,
                         ymax=2,
                         xmin=-6,
                         xmax=3.2,
                         title='',
                         clabel='$\mathrm{Redshift}$'):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x1 = data[:, 0]
    x2 = co.ABMagnitudeToJansky(data[:, 1])
    x = N.log10(x1 / x2)
    y = N.log10(data[:, 2] * 1e3)
    z = data[:, 3]
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.09, bottom=0.08, right=0.92, top=0.94)
    ax1 = fig.add_subplot(111)
    #plot scatters
    s1 = ax1.scatter(x,
                     y,
                     s=0.5,
                     marker='o',
                     c=z,
                     cmap=cm.get_cmap('jet'),
                     alpha=0.25,
                     edgecolor='none')
    s1 = ax1.scatter(x,
                     y,
                     s=0.1,
                     marker='o',
                     c=z,
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    c1 = fig.colorbar(s1, ax=ax1, shrink=0.7, fraction=0.05, pad=0.01)
    c1.set_label(clabel)
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    #add annotate
    P.text(0.5,
           1.03,
           title,
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    #P.legend(loc = 'upper left', scatterpoints = 1)
    P.savefig(out_folder + output)
예제 #7
0
def ssfrWrapper(path, db):
    #get data
    query = '''select gal_id, mbulge, mstar from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    gal_id = data[:, 0]
    mbulge = data[:, 1]
    mstar = data[:, 2]

    #make masks for all, central, and satellite galaxies
    all = gal_id >= 0
    c = gal_id == 1
    s = gal_id != 1

    #early vs. late type galaxies
    btt = 10.0**(mbulge - mstar)
    early = btt >= 0.4
    late = btt < 0.4

    label = 'ssfrBolshoi'

    ssfr(path, db, all, label)
    ssfr(path, db, c, label + '_cent')
    ssfr(path, db, s, label + '_sat')
    ssfr(path, db, early, label + '_sph')
    ssfr(path, db, late, label + '_disk')
예제 #8
0
def massMet(path, db, typ='.pdf'):
    #get data
    query = '''select halo_id, mstar, zstar from galprop where zstar > -50 and zstar < 50'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    halo_id = data[:, 0].astype(N.int)
    mstar = data[:, 1]
    zstar = N.log10(data[:, 2])

    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]
    wgal = weight[halo_id]

    output = 'massMetStarBolshoi' + typ
    #mbar = (10.0 ** mcold + 10.0 ** mstar)
    #fg = 10.0 ** p.mcold / mbar

    #massmet_hess
    massMetHess(mstar, zstar, wgal, output)
예제 #9
0
def massMet(path, db, typ='.pdf'):
    #get data
    query = '''select halo_id, mstar, zstar from galprop where zstar > -50 and zstar < 50'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    halo_id = data[:, 0].astype(N.int)
    mstar = data[:, 1]
    zstar = N.log10(data[:, 2])

    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]
    wgal = weight[halo_id]

    output = 'massMetStarBolshoi' + typ
    #mbar = (10.0 ** mcold + 10.0 ** mstar)
    #fg = 10.0 ** p.mcold / mbar

    #massmet_hess
    massMetHess(mstar, zstar, wgal, output)
예제 #10
0
def ssfr(path, db, mask, output, typ='.pdf'):
    '''
    Specific star formation rate plots.
    '''
    #get data
    query = '''select halo_id, mstar, sfr_ave from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    halo_id = data[:, 0].astype(N.int)
    mstar = data[:, 1]
    sfr_ave = data[:, 2]
    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]

    #set weighting
    wgal = weight[halo_id]

    log_ssfr = N.log10(sfr_ave / 10.0 ** mstar)
    log_ssfr[log_ssfr <= -14.0] = -13.8

    ssfrHess(mstar[mask], log_ssfr[mask], wgal[mask], output + typ)
예제 #11
0
def ssfr(path, db, mask, output, typ='.pdf'):
    '''
    Specific star formation rate plots.
    '''
    #get data
    query = '''select halo_id, mstar, sfr_ave from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    halo_id = data[:, 0].astype(N.int)
    mstar = data[:, 1]
    sfr_ave = data[:, 2]
    #get the weights from another table
    query = '''select weight from halos'''
    d = sq.get_data_sqliteSMNfunctions(path, db, query)
    weight = d[:, 0]

    #set weighting
    wgal = weight[halo_id]

    log_ssfr = N.log10(sfr_ave / 10.0**mstar)
    log_ssfr[log_ssfr <= -14.0] = -13.8

    ssfrHess(mstar[mask], log_ssfr[mask], wgal[mask], output + typ)
예제 #12
0
def plotSFRFractions(query,
                     xlabel,
                     ylabel,
                     output,
                     out_folder,
                     xmin=8.0,
                     xmax=11.5,
                     xbins=15,
                     ymin=-0.01,
                     ymax=1.01,
                     logscale=False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = data[:, 0]
    mstar = data[:, 1]
    burst = data[:, 2]

    mids, fract = dm.binAndReturnFractions(x,
                                           burst,
                                           mstar,
                                           xmin,
                                           xmax,
                                           xbins,
                                           logscale=False)
    print mids, fract
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.08, bottom=0.07, right=0.97, top=0.93)
    ax1 = fig.add_subplot(111)
    #draw lines
    ax1.plot(mids, fract, 'k-', lw=2.6, label='In Bursts')

    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    #add annotate
    P.text(0.5,
           0.93,
           'All galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    P.legend(loc='upper right')
    P.savefig(out_folder + output)
예제 #13
0
파일: plotsfr.py 프로젝트: eddienko/SamPy
def plotSFRFractions(query,
                     xlabel, ylabel,
                     output, out_folder,
                     xmin = 8.0,
                     xmax = 11.5,
                     xbins = 15,
                     ymin = -0.01,
                     ymax = 1.01,
                     logscale = False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = data[:,0]
    mstar = data[:,1]
    burst = data[:,2]

    mids, fract = dm.binAndReturnFractions(x,
                                           burst,
                                           mstar,
                                           xmin,
                                           xmax,
                                           xbins,
                                           logscale = False)
    print mids, fract
    #make the figure
#    fig = P.figure()
    fig = P.figure(figsize=(10,10))
    fig.subplots_adjust(left = 0.08, bottom = 0.07,
                        right = 0.97, top = 0.93)
    ax1 = fig.add_subplot(111)
    #draw lines
    ax1.plot(mids, fract, 'k-', lw = 2.6, label = 'In Bursts')


    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    #add annotate
    P.text(0.5, 0.93,'All galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform = ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    P.legend(loc = 'upper right')
    P.savefig(out_folder + output)
예제 #14
0
def plot_correlation(query, xlabel, ylabel, zmin, zmax, out_folder):
    #get data
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = data[:,0]
    y = data[:,1]*10**3
    #make the figure
    P.figure()
    P.title('$%.1f \leq z < %.1f$' % (zmin, zmax)) 
    P.scatter(x, y, c = 'k', marker = 'o', s = 9)
    #P.yscale('log')
#    if 'meanage' in xlabel:
#        P.xlim(0.0, 8.0)
#    if 'mstar' in xlabel:
#        P.xlim(7, 12)
#    if 'mstardot' in xlabel:
#        P.xlim(0, 800)
    if 'sfr_ave' in xlabel:
        P.xlim(0, 500)
    if 'sfr_bur' in xlabel:
        P.xlim(-1, 750)
    if 'tmerge' in xlabel:
        P.xlim(-0.1, 3)
    if 'pacs70' in ylabel:
        P.ylim(0, 3)
    if 'pacs100' in ylabel:
        P.ylim(0, 12)
    if 'pacs160' in ylabel:
        P.ylim(0, 37)
    if 'spire250' in ylabel:
        P.ylim(0, 50)
    if 'spire350' in ylabel:
        P.ylim(0, 45)
    if 'spire500' in ylabel:
        P.ylim(0, 26)
    if 'tmajmerge' in xlabel:
        P.xlim(0, 2)
    if 'r_disk' in xlabel:
        P.xlim(0, 23)
    if 'sigma_bul' in xlabel:
        P.xlim(0, 1000)

    P.xlabel(xlabel.replace('_', '\_'))
    P.ylabel(ylabel.replace('_', '\_'))
    P.savefig(out_folder + '%s_%s.png' % (xlabel, ylabel[:-7]))
    P.close()
    
    print '\nSpearmann R-test (rho, P) for %s and %s:' % (xlabel, ylabel[:-7])
    print SS.spearmanr(x, y)
예제 #15
0
def plotProperties(query,
                   xlabel,
                   ylabel,
                   output,
                   out_folder,
                   ymin=-12,
                   ymax=2,
                   xmin=-6,
                   xmax=3.2,
                   title='',
                   clabel='$\mathrm{Redshift}$'):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = N.log10(data[:, 0])
    y = N.log10(data[:, 1] * 1e3)
    z = data[:, 2]
    noMerge = z < 0.0
    merged = z > 0.0
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.09, bottom=0.08, right=0.92, top=0.94)
    ax1 = fig.add_subplot(111)
    #plot scatters
    s1 = ax1.scatter(x[noMerge],
                     y[noMerge],
                     s=1,
                     marker='o',
                     c='black',
                     edgecolor='none',
                     label='Never Merged')
    s1 = ax1.scatter(x[merged],
                     y[merged],
                     s=1,
                     marker='o',
                     c=z[merged],
                     cmap=cm.get_cmap('jet'),
                     alpha=0.1,
                     edgecolor='none',
                     label='Merged')
    s1 = ax1.scatter(x[merged],
                     y[merged],
                     s=0.1,
                     marker='o',
                     c=z[merged],
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    c1 = fig.colorbar(s1, ax=ax1, shrink=0.7, fraction=0.05, pad=0.01)
    c1.set_label(clabel)
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    #add annotate
    P.text(0.5,
           1.03,
           title,
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    P.legend(loc='upper left',
             scatterpoints=1,
             markerscale=10,
             shadow=True,
             fancybox=True)
    P.savefig(out_folder + output)
예제 #16
0
def plotColourFlux(query,
                   xlabel,
                   ylabel,
                   output,
                   out_folder,
                   ymin=-0.5,
                   ymax=2,
                   xmin=0.0,
                   xmax=60,
                   title='$S_{250} > 5 \ \mathrm{mJy}$',
                   clabel='$\mathrm{Redshift}$'):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = data[:, 0] * 1e3
    y = data[:, 1]
    z = data[:, 2]
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.09, bottom=0.08, right=0.92, top=0.94)
    ax1 = fig.add_subplot(111)
    #plot scatters
    s1 = ax1.scatter(x,
                     y,
                     s=15,
                     marker='o',
                     c=z,
                     cmap=cm.get_cmap('jet'),
                     alpha=0.5,
                     edgecolor='none')
    s1 = ax1.scatter(x,
                     y,
                     s=0.1,
                     marker='o',
                     c=z,
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    c1 = fig.colorbar(s1, ax=ax1, shrink=0.7, fraction=0.05, pad=0.01)

    #    axins = zoomed_inset_axes(ax1, 3.2, loc=1) # zoom = 3.2
    #    axins.scatter(x, y, s = 20, marker = 'o',
    #                     c=z, cmap = cm.get_cmap('jet'), alpha = 0.45,
    #                     edgecolor = 'none')
    #    #
    #    ax1.axvline(5, linestyle = ':', color = 'green', lw = 2)
    #    # sub region of the original image
    #    x1, x2, y1, y2 = 4.8, 15.2, -0.2, 0.18
    #    axins.set_xlim(x1, x2)
    #    axins.set_ylim(y1, y2)
    #    mark_inset(ax1, axins, loc1=2, loc2=4, fc="none", ec="0.5")
    #    P.xticks(visible=False)
    #    P.yticks(visible=False)

    c1.set_label(clabel)
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    #add annotate
    P.text(0.5,
           1.03,
           title,
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    #P.legend(loc = 'upper left', scatterpoints = 1)
    P.savefig(out_folder + output)
예제 #17
0
def plotColourProperties4(query, output, out_folder):
    #get data, all galaxies
    #FIR.spire250_obs, FIR.irac_ch4_obs, galprop.mstardot,
    #galprop.sfr_burst, galprop.sfr_ave, FIR.z, galprop.tmerge
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x1 = data[:, 0]
    x2 = data[:, 1]
    x = N.log10(x1 / x2)
    sfr = data[:, 2]
    burst = data[:, 3]
    avera = data[:, 4]
    z = data[:, 5]
    tmerge = data[:, 6]
    #masks
    noMerge = tmerge < 0.0
    recent = (tmerge < 0.25) & (tmerge > 0.0)
    mergers = tmerge > 0.0
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.085,
                        bottom=0.08,
                        right=0.99,
                        top=0.99,
                        wspace=0.21,
                        hspace=0.0)
    ax1 = fig.add_subplot(221)
    ax2 = fig.add_subplot(222)
    ax3 = fig.add_subplot(223)
    ax4 = fig.add_subplot(224)
    #plot scatters
    s1 = ax1.scatter(x[noMerge],
                     N.log10(sfr[noMerge]),
                     s=3.5,
                     marker='<',
                     c=z[noMerge],
                     cmap=cm.get_cmap('jet'),
                     alpha=0.15,
                     edgecolor='none',
                     label='Never Merged')
    s1 = ax1.scatter(x[noMerge],
                     N.log10(sfr[noMerge]),
                     s=1.0,
                     marker='<',
                     c=z[noMerge],
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    s2 = ax2.scatter(x[recent],
                     N.log10(sfr[recent]),
                     s=3.5,
                     marker='>',
                     c=z[recent],
                     cmap=cm.get_cmap('jet'),
                     alpha=0.15,
                     edgecolor='none',
                     label='Recent Mergers $T_{\mathrm{merge}} < 250$ Myr')
    s2 = ax2.scatter(x[recent],
                     N.log10(sfr[recent]),
                     s=1.0,
                     marker='>',
                     c=z[recent],
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    s3 = ax3.scatter(x[recent],
                     N.log10(burst[recent]),
                     s=3.5,
                     marker='>',
                     c=z[recent],
                     cmap=cm.get_cmap('jet'),
                     alpha=0.15,
                     edgecolor='none',
                     label='Recent Mergers $T_{\mathrm{merge}} < 250$ Myr')
    s3 = ax3.scatter(x[recent],
                     N.log10(burst[recent]),
                     s=1.0,
                     marker='>',
                     c=z[recent],
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    s6 = ax4.scatter(x[noMerge],
                     N.log10(avera[noMerge]),
                     s=0.5,
                     marker='o',
                     c='red',
                     alpha=0.1,
                     edgecolor='none',
                     label='Never Merged')
    s7 = ax4.scatter(x[recent],
                     N.log10(avera[recent]),
                     s=0.5,
                     marker='s',
                     c='blue',
                     alpha=0.1,
                     edgecolor='none',
                     label='Recent Mergers $T_{\mathrm{merge}} < 250$ Myr')
    s6 = ax4.scatter(x[noMerge],
                     N.log10(avera[noMerge]),
                     s=2.0,
                     marker='o',
                     c='red',
                     edgecolor='none',
                     visible=False)
    s7 = ax4.scatter(x[recent],
                     N.log10(avera[recent]),
                     s=2.0,
                     marker='s',
                     c='blue',
                     edgecolor='none',
                     visible=False)
    #colorbars
    cax1 = fig.add_axes([0.11, 0.93, 0.15,
                         0.15 / 12.])  #[left, bottom, width, height]
    c1 = fig.colorbar(s1,
                      cax=cax1,
                      orientation='horizontal',
                      ticks=[2, 2.6, 3.4, 4])
    c1.set_label('$\mathrm{Redshift}$', size=13)
    cax2 = fig.add_axes([0.6, 0.93, 0.15, 0.15 / 12.])
    c2 = fig.colorbar(s2,
                      cax=cax2,
                      orientation='horizontal',
                      ticks=[2, 2.6, 3.4, 4])
    c2.set_label('$\mathrm{Redshift}$', size=13)
    cax3 = fig.add_axes([0.11, 0.475, 0.15, 0.15 / 12.])
    c3 = fig.colorbar(s3,
                      cax=cax3,
                      orientation='horizontal',
                      ticks=[2, 2.6, 3.4, 4])
    c3.set_label('$\mathrm{Redshift}$', size=13)

    #labels
    xlabel = r'$\log_{10} \left ( \frac{S_{250}}{S_{8.0}} \right )$'
    ylabel1 = r'$\log_{10}(\dot{M}_{\star} \ [M_{\odot} \ \mathrm{yr}^{-1}])$'
    ylabel3 = r'$\log_{10}(\dot{M}_{\mathrm{BURST}} \ [M_{\odot} \ \mathrm{yr}^{-1}])$'
    ylabel4 = r'$\log_{10}(< \dot{M}_{\star} > \ [M_{\odot} \ \mathrm{yr}^{-1}])$'
    ax1.set_xticklabels([])
    ax1.set_ylabel(ylabel1)
    ax2.set_xticklabels([])
    ax2.set_ylabel(ylabel1)
    ax3.set_xlabel(xlabel)
    ax3.set_ylabel(ylabel3)
    ax4.set_xlabel(xlabel)
    ax4.set_ylabel(ylabel4)
    #limits
    xmin = -1.5
    xmax = 3.3
    ymin = -3.8
    ymax = 3.2
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    ax2.set_ylim(ymin, ymax)
    ax2.set_xlim(xmin, xmax)
    ax3.set_ylim(ymin, ymax)
    ax3.set_xlim(xmin, xmax)
    ax4.set_ylim(ymin, ymax)
    ax4.set_xlim(xmin, xmax)
    #make grid
    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()
    #legends and save
    ax1.legend(loc='upper left', scatterpoints=1, markerscale=7)
    ax2.legend(loc='upper left', scatterpoints=1, markerscale=7)
    ax2.legend(loc='upper left', scatterpoints=1, markerscale=7)
    ax3.legend(loc='upper left', scatterpoints=1, markerscale=7)
    ax4.legend(loc='upper left', scatterpoints=1, markerscale=18)
    P.savefig(out_folder + output)
예제 #18
0
def plotMergerFractions(query,
                        xlabel, ylabel,
                        output, out_folder,
                        mergetimelimit=0.25,
                        mstarmin=8.0,
                        mstarmax=11.5,
                        mbins=15,
                        ymin=-0.01,
                        ymax=1.01,
                        logscale=False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    if logscale:
        mstar = N.log10(data[:, 0])
        logscale = False
    else:
        mstar = data[:, 0]
    print N.min(mstar), N.max(mstar)
    tmerge = data[:, 1]
    tmajor = data[:, 2]
    #masks
    nomergeMask = tmerge < 0.0
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    mergersMask2 = (nomergeMask == False) & (majorsMask == False) &\
                   (mergersMask == False) & (majorsMask2 == False)
    #bin the data
    mids, numbs = dm.binAndReturnMergerFractions2(mstar,
                                                  nomergeMask,
                                                  mergersMask,
                                                  majorsMask,
                                                  mergersMask2,
                                                  majorsMask2,
                                                  mstarmin,
                                                  mstarmax,
                                                  mbins,
                                                  logscale)
    #the fraction of mergers
    noMergerFraction = N.array([float(x[1]) / x[0] for x in numbs])
    mergerFraction = N.array([float(x[2]) / x[0] for x in numbs])
    majorMergerFraction = N.array([float(x[3]) / x[0] for x in numbs])
    mergerFraction2 = N.array([float(x[4]) / x[0] for x in numbs])
    majorMergerFraction2 = N.array([float(x[5]) / x[0] for x in numbs])

    #sanity check
    for a, b, c, d, e in zip(noMergerFraction, mergerFraction, majorMergerFraction,
                             mergerFraction2, majorMergerFraction2):
        print a + b + c + d + e

        #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.08, bottom=0.07,
                        right=0.97, top=0.93)
    ax1 = fig.add_subplot(111)
    #draw lines
    ax1.plot(mids, noMergerFraction, 'k-', lw=2.6,
             label='Never Merged')
    ax1.plot(mids, mergerFraction, ls='--', lw=2.6,
             label='Minor Merger: $T \leq 250$ Myr')
    ax1.plot(mids, mergerFraction2, ls='-.', lw=2.6,
             label='Minor Merger: $T > 250$ Myr')
    ax1.plot(mids, majorMergerFraction, ls='--', lw=2.6,
             label='Major Merger: $T \leq 250$ Myr')
    ax1.plot(mids, majorMergerFraction2, ls='-.', lw=2.6,
             label='Major Merger: $T > 250$ Myr')
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    #add annotate
    P.text(0.5, 0.93, 'All galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    P.legend(loc='upper right')
    P.savefig(out_folder + output)
예제 #19
0
def plotMergerFractions(query,
                        xlabel,
                        ylabel,
                        output,
                        out_folder,
                        mergetimelimit=0.25,
                        ymin=-0.2,
                        ymax=1.0,
                        xmin=-8,
                        xmax=4.1,
                        xbins=70,
                        ybins=70,
                        title='All galaxies in $2 \leq z < 4$'):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = data[:, 0]
    f775w = data[:, 1]
    f850lp = data[:, 2]
    uvcolor = f775w - f850lp
    tmerge = data[:, 3]
    tmajor = data[:, 4]
    #masks
    nomergeMask = tmerge < 0.0
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    mergersMask2 = (nomergeMask == False) & (majorsMask == False) &\
                   (mergersMask == False) & (majorsMask2 == False)
    #KDE
    mu = M.AnaKDE([N.log10(x[nomergeMask]), uvcolor[nomergeMask]])
    x_vec, y_vec, zm, lvls, d0, d1 = mu.contour(N.linspace(xmin, xmax, xbins),
                                                N.linspace(ymin, ymax, ybins),
                                                return_data=True)
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.09, bottom=0.08, right=0.92, top=0.94)
    ax1 = fig.add_subplot(111)
    #make contours
    cont = ax1.contour(x_vec,
                       y_vec,
                       zm,
                       linewidths=1.3,
                       colors='black',
                       levels=N.linspace(0.2, N.max(zm), 5))
    #plot scatters
    ax1.scatter(N.log10(x[nomergeMask]),
                uvcolor[nomergeMask],
                s=1,
                c='k',
                marker='s',
                label='Never merged')
    s2 = ax1.scatter(N.log10(x[mergersMask]),
                     uvcolor[mergersMask],
                     s=18,
                     c=1000. * tmerge[mergersMask],
                     marker='^',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     label='Minor Merger: $T \leq %.0f$ Myr' %
                     (mergetimelimit * 1000.),
                     alpha=0.2)
    s1 = ax1.scatter(N.log10(x[majorsMask]),
                     uvcolor[majorsMask],
                     s=25,
                     c=1000. * tmajor[majorsMask],
                     marker='o',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     label='Major Merger: $T \leq %.0f$ Myr' %
                     (mergetimelimit * 1000.),
                     alpha=0.2)
    s1 = ax1.scatter(N.log10(x[majorsMask]),
                     uvcolor[majorsMask],
                     s=1,
                     c=1000. * tmajor[majorsMask],
                     marker='o',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     alpha=1.0,
                     visible=False)
    c1 = fig.colorbar(s1, shrink=0.8, fraction=0.03)
    c1.set_label('Time since merger [Myr]')
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    #add annotate
    P.text(0.5,
           1.03,
           title,
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    P.legend(loc='upper left',
             scatterpoints=1,
             shadow=True,
             fancybox=True,
             markerscale=2)
    P.savefig(out_folder + output)
예제 #20
0
파일: plotssfr.py 프로젝트: RainW7/SamPy
def plot_ssfr_paper(query1, query2, out_folder,
                    xmin1=7.7, xmax1=11.8, xbin1=16,
                    ymin1=-11, ymax1=-7.5, ybin1=16,
                    xmin2=9.8, xmax2=11.8, xbin2=15,
                    ymin2=-10, ymax2=-7.5, ybin2=15,
                    pmax=1.0, pmin=0.01):

    #get data, all galaxies
    data1 = sq.get_data_sqliteSMNfunctions(path, db, query1)
    ssfr1 = N.log10(data1[:, 0] / (10 ** data1[:, 1]))
    x1 = data1[:, 1]
    #get data, S_250 > 5mJy
    data2 = sq.get_data_sqliteSMNfunctions(path, db, query2)
    ssfr2 = N.log10(data2[:, 0] / (10 ** data2[:, 1]))
    x2 = data2[:, 1]
    #make hess data
    s1, smin1, smax1 = h.hess_plot(x1, ssfr1,
                                   N.ones(len(x1)),
                                   xmin1, xmax1, xbin1,
                                   ymin1, ymax1, ybin1,
                                   pmax, pmin)
    s2, smin2, smax2 = h.hess_plot(x2, ssfr2,
                                   N.ones(len(x2)),
                                   xmin2, xmax2, xbin2,
                                   ymin2, ymax2, ybin2,
                                   pmax, pmin)

    #make the figure
    fig = P.figure()
    fig.subplots_adjust(wspace=0.0, hspace=0.01,
                        bottom=0.07,
                        right=0.97, top=0.93)

    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122)

    ims = ax1.imshow(s1, vmin=smin1, vmax=smax1,
                     origin='lower', cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin1, xmax1, ymin1, ymax1],
                     aspect='auto', alpha=1)
    ims = ax2.imshow(s2, vmin=smin2, vmax=smax2,
                     origin='lower', cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin2, xmax2, ymin2, ymax2],
                     aspect='auto', alpha=1)

    #scatter plot
    ax2.scatter(x2, ssfr2, c='b', marker='o', s=5)

    #percentiles
    xbin_midd, y50d, y16d, y84d = dm.percentile_bins(x1, ssfr1,
                                                     xmin1, xmax1)
    md = (y50d > -99) | (y16d > -99) | (y84d > -99)
    xbin_mide, y50e, y16e, y84e = dm.percentile_bins(x2, ssfr2,
                                                     xmin2, xmax2)
    me = (y50e > -99) | (y16e > -99) | (y84e > -99)
    ax1.plot(xbin_midd[md], y50d[md], 'r-')
    ax1.plot(xbin_midd[md], y16d[md], 'r--')
    ax1.plot(xbin_midd[md], y84d[md], 'r--')
    ax2.plot(xbin_mide[me], y50e[me], 'r-')
    ax2.plot(xbin_mide[me], y16e[me], 'r--')
    ax2.plot(xbin_mide[me], y84e[me], 'r--')

    #labels
    ax1.set_xlabel(r'$\log_{10}(M_{\star} \ [M_{\odot}])$')
    ax2.set_xlabel(r'$\log_{10}(M_{\star} \ [M_{\odot}])$')
    ax1.set_ylabel(r'$\log_{10} \left (\frac{\dot{M}_{\star}}{M_{\star}} \ [\mathrm{yr}^{-1}] \right )$')

    #limits
    ax1.set_ylim(ymin1, ymax1)
    ax2.set_ylim(ymin1, ymax1)
    ax1.set_xlim(xmin1, xmax1)
    ax2.set_xlim(xmin2, xmax2)

    #add text
    P.text(0.5, 0.94, 'All galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    P.text(0.5, 0.97, '$S_{250} > 5$ mJy',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax2.transAxes)

    #yticks
    ax2.set_yticks(ax1.get_yticks()[1:-1])

    #make grid
    ax1.grid()
    ax2.grid()

    P.savefig(out_folder + 'ssfr.ps')
    P.close()
예제 #21
0
def plotMergerFractions3(query,
                         xlabel,
                         ylabel,
                         output,
                         out_folder,
                         mergetimelimit=0.25,
                         mstarmin=8.0,
                         mstarmax=11.5,
                         mbins=15,
                         ymin=0.0,
                         ymax=1.0,
                         logscale=False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    tmp = data[:, 1]
    mstar = data[:, 0]
    mstar = N.log10(mstar / 10**tmp)
    print N.min(mstar), N.max(mstar)
    tmerge = data[:, 2]
    tmajor = data[:, 3]
    #masks
    nomergeMask = tmerge < 0.0
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    mergersMask2 = (nomergeMask == False) & (majorsMask == False) &\
                   (mergersMask == False) & (majorsMask2 == False)
    #bin the data
    mids, numbs = dm.binAndReturnMergerFractions2(mstar, nomergeMask,
                                                  mergersMask, majorsMask,
                                                  mergersMask2, majorsMask2,
                                                  mstarmin, mstarmax, mbins,
                                                  logscale)
    #the fraction of mergers
    noMergerFraction = N.array([float(x[1]) / x[0] for x in numbs])
    mergerFraction = N.array([float(x[2]) / x[0] for x in numbs])
    majorMergerFraction = N.array([float(x[3]) / x[0] for x in numbs])
    mergerFraction2 = N.array([float(x[4]) / x[0] for x in numbs])
    majorMergerFraction2 = N.array([float(x[5]) / x[0] for x in numbs])

    #sanity check
    for a, b, c, d, e in zip(noMergerFraction, mergerFraction,
                             majorMergerFraction, mergerFraction2,
                             majorMergerFraction2):
        print a + b + c + d + e
        #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.08, bottom=0.07, right=0.97, top=0.93)
    ax1 = fig.add_subplot(111)
    #calculate widths
    wd = (mids[1] - mids[0]) * 1.0
    #draw bars
    ax1.bar(mids,
            noMergerFraction,
            label='Never Merged',
            align='center',
            color='grey',
            width=wd,
            hatch='.')
    ax1.bar(mids,
            mergerFraction,
            bottom=noMergerFraction,
            align='center',
            label='Minor Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.),
            color='red',
            width=wd,
            hatch='/')
    ax1.bar(mids,
            mergerFraction2,
            align='center',
            bottom=noMergerFraction + mergerFraction,
            label='Minor Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.),
            color='blue',
            width=wd,
            hatch='|')
    ax1.bar(mids,
            majorMergerFraction,
            align='center',
            bottom=noMergerFraction + mergerFraction + mergerFraction2,
            label='Major Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.),
            color='magenta',
            width=wd,
            hatch='x')
    ax1.bar(mids,
            majorMergerFraction2,
            align='center',
            bottom=noMergerFraction + mergerFraction + mergerFraction2 +
            majorMergerFraction,
            label='Major Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.),
            color='green',
            width=wd,
            hatch='-')
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(mids[0] - wd / 2., mids[-1] + wd / 2.)
    #add annotate
    P.text(0.5,
           1.05,
           'All galaxies in $2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #legend and save
    P.legend(loc='upper center')
    P.savefig(out_folder + output)
예제 #22
0
def plotMergerFractionsMultiplot(query,
                                 xlabel,
                                 ylabel,
                                 output,
                                 out_folder,
                                 mergetimelimit=0.25,
                                 ymin=-0.2,
                                 ymax=0.8,
                                 xmin=-9,
                                 xmax=4.1,
                                 xbins=50,
                                 ybins=50,
                                 title=''):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    x = data[:, 0]
    f775w = data[:, 1]
    f850lp = data[:, 2]
    uvcolor = f775w - f850lp
    tmerge = data[:, 3]
    tmajor = data[:, 4]
    #masks
    nomergeMask = tmerge < 0.0
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    mergersMask2 = (nomergeMask == False) & (majorsMask == False) &\
                   (mergersMask == False) & (majorsMask2 == False)

    #KDE
    mu = M.AnaKDE([N.log10(x[nomergeMask]), uvcolor[nomergeMask]])
    x_vec, y_vec, zm, lvls, d0, d1 = mu.contour(N.linspace(xmin, xmax, xbins),
                                                N.linspace(ymin, ymax, ybins),
                                                return_data=True)
    #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.09,
                        bottom=0.08,
                        right=0.93,
                        top=0.95,
                        wspace=0.0,
                        hspace=0.0)
    ax1 = fig.add_subplot(221)
    ax2 = fig.add_subplot(222)
    ax3 = fig.add_subplot(223)
    ax4 = fig.add_subplot(224)
    #make contours
    lv = N.linspace(0.2, N.max(zm), 4)
    cont = ax1.contour(x_vec,
                       y_vec,
                       zm,
                       linewidths=0.9,
                       levels=lv,
                       colors='black')
    cont = ax2.contour(x_vec,
                       y_vec,
                       zm,
                       linewidths=0.9,
                       levels=lv,
                       colors='black')
    cont = ax3.contour(x_vec,
                       y_vec,
                       zm,
                       linewidths=0.9,
                       levels=lv,
                       colors='black')
    cont = ax4.contour(x_vec,
                       y_vec,
                       zm,
                       linewidths=0.9,
                       levels=lv,
                       colors='black')
    #plot scatters
    s1 = ax1.scatter(N.log10(x[majorsMask]),
                     uvcolor[majorsMask],
                     s=4,
                     c=1000. * tmajor[majorsMask],
                     marker='o',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     label='Major Merger: $T \leq %.0f$ Myr' %
                     (mergetimelimit * 1000.),
                     alpha=0.25)
    s2 = ax2.scatter(N.log10(x[mergersMask]),
                     uvcolor[mergersMask],
                     s=6,
                     c=1000. * tmerge[mergersMask],
                     marker='^',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     label='Minor Merger: $T \leq %.0f$ Myr' %
                     (mergetimelimit * 1000.),
                     alpha=0.25)
    s2 = ax2.scatter(N.log10(x[mergersMask]),
                     uvcolor[mergersMask],
                     s=6,
                     c=1000. * tmerge[mergersMask],
                     marker='^',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)
    #masks
    mergetimelimit *= 2.
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    s3 = ax3.scatter(N.log10(x[majorsMask]),
                     uvcolor[majorsMask],
                     s=4,
                     c=1000. * tmajor[majorsMask],
                     marker='o',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     label='Major Merger: $T \leq %.0f$ Myr' %
                     (mergetimelimit * 1000.),
                     alpha=0.25)
    s4 = ax4.scatter(N.log10(x[mergersMask]),
                     uvcolor[mergersMask],
                     s=6,
                     c=1000. * tmerge[mergersMask],
                     marker='^',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     label='Minor Merger: $T \leq %.0f$ Myr' %
                     (mergetimelimit * 1000.),
                     alpha=0.25)
    s4 = ax4.scatter(N.log10(x[mergersMask]),
                     uvcolor[mergersMask],
                     s=6,
                     c=1000. * tmerge[mergersMask],
                     marker='^',
                     cmap=cm.get_cmap('jet'),
                     edgecolor='none',
                     visible=False)

    c1 = fig.colorbar(s2, ax=ax2, shrink=0.7, fraction=0.05)
    c2 = fig.colorbar(s4, ax=ax4, shrink=0.7, fraction=0.05)
    c1.set_label('Time since merger [Myr]')
    c2.set_label('Time since merger [Myr]')
    #add annotate
    P.text(1.0,
           1.04,
           title,
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #labels
    ax3.set_xlabel(xlabel)
    ax4.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    ax3.set_ylabel(ylabel)
    ax2.set_yticklabels([])
    ax4.set_yticklabels([])
    ax1.set_xticklabels([])
    ax2.set_xticklabels([])
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    ax2.set_ylim(ymin, ymax)
    ax2.set_xlim(xmin, xmax)
    ax3.set_ylim(ymin, ymax)
    ax3.set_xlim(xmin, xmax)
    ax4.set_ylim(ymin, ymax)
    ax4.set_xlim(xmin, xmax)
    #make grid
    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()
    #legend and save
    ax1.legend(loc='upper left',
               scatterpoints=1,
               shadow=True,
               fancybox=True,
               markerscale=3)
    ax2.legend(loc='upper left',
               scatterpoints=1,
               shadow=True,
               fancybox=True,
               markerscale=3)
    ax3.legend(loc='upper left',
               scatterpoints=1,
               shadow=True,
               fancybox=True,
               markerscale=3)
    ax4.legend(loc='upper left',
               scatterpoints=1,
               shadow=True,
               fancybox=True,
               markerscale=3)
    P.savefig(out_folder + output)
예제 #23
0
파일: plotmergers.py 프로젝트: RainW7/SamPy
def plot_tmerge(query1,
                query2,
                xlabel,
                ylabel,
                output,
                out_folder,
                pmin=0.05,
                pmax=1.0,
                xbin1=15,
                ybin1=15,
                xbin2=15,
                ybin2=15,
                y1ticks=[0, .4, .8, 1.2, 1.6, 2.0, 2.5, 3],
                y2ticks=[.4, .8, 1.2, 1.6, 2.0, 2.5],
                xmin1=7.9,
                xmax1=11.7,
                xmin2=7.9,
                xmax2=11.7,
                ymin=0.0,
                ymax=3.0,
                scatters=False,
                mean=False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query1)
    xd1 = data[:, 0]
    yd1 = data[:, 1]
    #get data, S_250 > 5 mJy
    data = sq.get_data_sqliteSMNfunctions(path, db, query2)
    xd2 = data[:, 0]
    yd2 = data[:, 1]

    #the fraction of no mergers?
    nm1 = len(yd1[yd1 < 0.0]) / float(len(yd1)) * 100.
    nm2 = len(yd2[yd2 < 0.0]) / float(len(yd2)) * 100.

    #print out some statistics
    print len(yd2)
    print 'Mean tmerge of all galaxies', N.mean(yd1[yd1 > 0.0])
    print 'Mean tmerge of SPIRE detected galaxies', N.mean(yd2[yd2 > 0.0])
    print
    print 'Max tmerge of all galaxies', N.max(yd1[yd1 > 0.0])
    print 'Max tmerge of SPIRE detected galaxies', N.max(yd2[yd2 > 0.0])
    print
    print 'Fraction of all galaxies that have experienced a merger', 100. - nm1
    print 'Fraction of SPIRE that have experienced a merger', 100. - nm2

    #calculate 2D probability fields
    sd1, sdmin1, sdmax1 = h.hess_plot(xd1,
                                      yd1,
                                      N.ones(len(xd1)),
                                      xmin1,
                                      xmax1,
                                      xbin1,
                                      ymin,
                                      ymax,
                                      ybin1,
                                      pmax=pmax,
                                      pmin=pmin)
    sd2, sdmin2, sdmax2 = h.hess_plot(xd2,
                                      yd2,
                                      N.ones(len(xd2)),
                                      xmin2,
                                      xmax2,
                                      xbin2,
                                      ymin,
                                      ymax,
                                      ybin2,
                                      pmax=pmax,
                                      pmin=pmin)

    #make the figure
    fig = P.figure()
    fig.subplots_adjust(wspace=0.0,
                        hspace=0.01,
                        left=0.08,
                        bottom=0.07,
                        right=0.97,
                        top=0.93)
    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122)

    ims = ax1.imshow(sd1,
                     vmin=sdmin1,
                     vmax=sdmax1,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin1, xmax1, ymin, ymax],
                     aspect='auto',
                     alpha=1)
    ims = ax2.imshow(sd2,
                     vmin=sdmin2,
                     vmax=sdmax2,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin2, xmax2, ymin, ymax],
                     aspect='auto',
                     alpha=1)

    ax2.scatter(xd2, yd2, s=7, marker='o', color='blue')

    #percentiles
    xbin_midd1, y50d1, y16d1, y84d1 = dm.percentile_bins(xd1,
                                                         yd1,
                                                         xmin1,
                                                         xmax1,
                                                         nxbins=xbin1)
    md1 = (y50d1 >= 0) & (y16d1 >= 0) & (y84d1 >= 0)
    xbin_midd2, y50d2, y16d2, y84d2 = dm.percentile_bins(xd2,
                                                         yd2,
                                                         xmin2,
                                                         xmax2,
                                                         nxbins=xbin2)
    md2 = (y50d2 >= 0) | (y16d2 >= 0) | (y84d2 >= 0)
    ax1.plot(xbin_midd1[md1], y50d1[md1], 'r-')
    ax1.plot(xbin_midd1[md1], y16d1[md1], 'r--')
    ax1.plot(xbin_midd1[md1], y84d1[md1], 'r--')
    ax2.plot(xbin_midd2[md2], y50d2[md2], 'r-')
    ax2.plot(xbin_midd2[md2], y16d2[md2], 'r--')
    ax2.plot(xbin_midd2[md2], y84d2[md2], 'r--')

    #add text
    P.text(0.5,
           0.93,
           'All galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    P.text(0.5,
           0.96,
           '$S_{250} > 5$ mJy',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax2.transAxes)

    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)

    #limits
    ax1.set_ylim(ymin, ymax)
    ax2.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin1, xmax1)
    ax2.set_xlim(xmin2, xmax2)

    #yticks
    ax2.set_yticks([])
    ax2.set_xticks(ax2.get_xticks()[1:])
    ax1.set_yticks(y1ticks)
    ax2.set_yticks(y2ticks)

    #make grid
    #ax1.grid()
    #ax2.grid()

    P.savefig(out_folder + output)
예제 #24
0
def plotMergerFractions(query,
                        xlabel,
                        ylabel,
                        output,
                        out_folder,
                        mergetimelimit=0.25,
                        mstarmin=8.0,
                        mstarmax=11.5,
                        mbins=15,
                        ymin=-0.01,
                        ymax=1.01,
                        logscale=False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    if logscale:
        mstar = N.log10(data[:, 0])
        logscale = False
    else:
        mstar = data[:, 0]
    print N.min(mstar), N.max(mstar)
    tmerge = data[:, 1]
    tmajor = data[:, 2]
    #masks
    nomergeMask = tmerge < 0.0
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    mergersMask2 = (nomergeMask == False) & (majorsMask == False) &\
                   (mergersMask == False) & (majorsMask2 == False)
    #bin the data
    mids, numbs = dm.binAndReturnMergerFractions2(mstar, nomergeMask,
                                                  mergersMask, majorsMask,
                                                  mergersMask2, majorsMask2,
                                                  mstarmin, mstarmax, mbins,
                                                  logscale)
    #the fraction of mergers
    noMergerFraction = N.array([float(x[1]) / x[0] for x in numbs])
    mergerFraction = N.array([float(x[2]) / x[0] for x in numbs])
    majorMergerFraction = N.array([float(x[3]) / x[0] for x in numbs])
    mergerFraction2 = N.array([float(x[4]) / x[0] for x in numbs])
    majorMergerFraction2 = N.array([float(x[5]) / x[0] for x in numbs])

    #sanity check
    for a, b, c, d, e in zip(noMergerFraction, mergerFraction,
                             majorMergerFraction, mergerFraction2,
                             majorMergerFraction2):
        print a + b + c + d + e

        #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.08, bottom=0.07, right=0.97, top=0.93)
    ax1 = fig.add_subplot(111)
    #draw lines
    ax1.plot(mids, noMergerFraction, 'k-', lw=2.6, label='Never Merged')
    ax1.plot(mids,
             mergerFraction,
             ls='--',
             lw=2.6,
             label='Minor Merger: $T \leq 250$ Myr')
    ax1.plot(mids,
             mergerFraction2,
             ls='-.',
             lw=2.6,
             label='Minor Merger: $T > 250$ Myr')
    ax1.plot(mids,
             majorMergerFraction,
             ls='--',
             lw=2.6,
             label='Major Merger: $T \leq 250$ Myr')
    ax1.plot(mids,
             majorMergerFraction2,
             ls='-.',
             lw=2.6,
             label='Major Merger: $T > 250$ Myr')
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    #add annotate
    P.text(0.5,
           0.93,
           'All galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #make grid
    ax1.grid()
    #legend and save
    P.legend(loc='upper right')
    P.savefig(out_folder + output)
예제 #25
0
def massfunctions(path, db,
                  mmax=12.5,
                  mmin=5.0,
                  nbins=30,
                  output='SMN',
                  nvolumes=15):
    '''
    Plots stellar mass functions, cold gas mass functions, & BH MF
    '''
    #get data
    query = '''select gal_id, halo_id, mbulge, mstar, mcold, mbh from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    gal_id = data[:, 0]
    halo_id = data[:, 1]
    mbulge = data[:, 2]
    mstar = data[:, 3]
    mcold = data[:, 4]
    mbh = data[:, 5]

    ngal = len(gal_id)
    print '%i galaxies found' % ngal

    #overrides weight for nvolumes Bolshoi sub-volumes
    weight = N.zeros(ngal) + 1. / (nvolumes * (50. / 0.7) ** 3)

    #mass bins
    dm = (mmax - mmin) / nbins
    mbin = mmin + (N.arange(nbins) + 0.5) * dm

    #mfit = mmin + N.arange(150) * 0.05

    mf_cold = N.zeros(nbins)
    mf_star = N.zeros(nbins)
    mf_star_central = N.zeros(nbins)
    mf_bar = N.zeros(nbins)
    mf_bh = N.zeros(nbins)

    mf_early = N.zeros(nbins)
    mf_late = N.zeros(nbins)
    mf_bulge = N.zeros(nbins)

    #TODO from IDL, should be done without looping
    btt = 10.0 ** (mbulge - mstar)
    for i in range(ngal):
        ihalo = halo_id[i]
        #cold gas
        ibin = int(N.floor((mcold[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_cold[ibin] += weight[ihalo]
            #stellar mass
        ibin = int(N.floor((mstar[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_star[ibin] += weight[ihalo]
            #stellar mass, by type
            if btt[i] >= 0.4:
                mf_early[ibin] += weight[ihalo]
            else:
                mf_late[ibin] += weight[ihalo]
                #stellar mass, centrals
            if gal_id[i] == 1:
                if ibin >= 0 and ibin < nbins:
                    mf_star_central[ibin] += weight[ihalo]
                    #bulge mass
        ibin = int(N.floor((mbulge[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_bulge[ibin] += weight[ihalo]
            #baryonic mass
        mbar = N.log10(10.0 ** mcold[i] + 10.0 ** mstar[i])
        ibin = int(N.floor((mbar - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_bar[ibin] += weight[ihalo]
            #black hole
        ibin = int(N.floor((mbh[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_bh[ibin] += weight[ihalo]

    mf_cold = N.log10(mf_cold / dm)
    mf_star = N.log10(mf_star / dm)
    #mf_early = N.log10(mf_early / dm)
    #mf_late = N.log10(mf_late / dm)
    #mf_bulge = N.log10(mf_bulge / dm)
    #mf_star_central = N.log10(mf_star_central / dm)
    mf_bar = N.log10(mf_bar / dm)
    mf_bh = N.log10(mf_bh / dm)

    #stellar mass function plot
    #obs constrains
    mg, phig, phi_lowg, phi_highg = stellarMFs.bellG()
    mk, phik, phi_lowk, phi_highk = stellarMFs.bellK()
    #ml, phil, phi_lowl, phi_hiugl = mstar_lin(obs + 'sdss_mf/SDSS_SMF.dat')
    m, n, nlow, nhigh = stellarMFs.panter()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_star, label='Stellar Mass Function')
    ax.errorbar(mg, phig, yerr=[phig - phi_highg, phi_lowg - phig], label='$G$-band from Bell et al.')
    ax.errorbar(mk, phik, yerr=[phik - phi_highk, phi_lowk - phik], label='$K$-band from Bell et al.')
    #ax.errorbar(ml, phil, yerr = [phi_lowl, phi_highl], label = 'Lin et al. K')
    ax.errorbar(m, n, yerr=[nlow - n, n - nhigh], label='$K$-band from Panter et al.')
    ax.set_xlim(8.0, 12.5)
    ax.set_ylim(-6.1, -1.0)
    ax.set_xlabel(r'$\log_{10} \left ( M_{\star} \ [M_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M_{\star}} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$')
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfstar_' + output + '.pdf')
    P.close()

    #cold gas mass function
    #obs constrains
    #mhi_bell_h70
    #mgas_bell_h70
    theta = gas.HIMassFunctionZwaan(mbin)
    m_hi, phi_hi, phi_low_hi, phi_high_hi = gas.HIMassFunctionBell()
    m_h2, phi_h2, phi_low_h2, phi_high_h2 = gas.H2MassFunctionBell()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_cold, label='Cold Gas Mass Function')
    ax.plot(mbin, theta, 'g-', lw=1.8, label='Zwaan et al.')
    ax.errorbar(m_hi, phi_hi, yerr=[phi_hi - phi_high_hi, phi_low_hi - phi_hi],
                c='cyan', ls='--', lw=1.5, label='Bell et al. $H_{I}$')
    ax.errorbar(m_h2, phi_h2, yerr=[phi_h2 - phi_high_h2, phi_low_h2 - phi_h2],
                c='magenta', ls=':', lw=1.5, label='Bell et al. $H_{2}$')
    ax.plot(m_hi, N.log10(10.0 ** phi_hi + 10 ** phi_h2), 'r-', label='$H_{I} + H_{2}$')
    ax.set_xlim(8.0, 11.5)
    ax.set_ylim(-5.5, -0.8)
    ax.set_xlabel(r'$\log_{10} \left ( M_{\mathrm{cold}} \ [M_{\odot}] \right )$')
    ax.set_ylabel(r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$')
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfcold_' + output + '.pdf')
    P.close()

    #total baryons
    #obs contstrains
    m_bar, phi_bar, phi_low_bar, phi_high_bar = baryons.BellBaryonicMassFunction()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_bar, label='Total Baryon Mass')
    ax.errorbar(m_bar, phi_bar, yerr=[phi_bar - phi_high_bar, phi_low_bar - phi_bar],
                c='g', ls='-', label='Bell et al.')
    ax.set_xlim(8.0, 12.5)
    ax.set_ylim(-4.9, -0.25)
    ax.set_xlabel(r'$\log_{10} \left ( M_{\mathrm{baryons}} \ [M_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M_{\mathrm{baryons}}} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$')
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfbar_' + output + '.pdf')
    P.close()

    #BH mass function
    #obs constrains
    m_bh, phi_low_bh, phi_med_bh, phi_high_bh = bh.MarconiMassFunction()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_bh, 'k-', label='Black Hole Mass Function')
    ax.plot(m_bh, phi_low_bh, 'g--')
    ax.plot(m_bh, phi_med_bh, 'g-', label='Marconi et al.')
    ax.plot(m_bh, phi_high_bh, 'g--')
    ax.set_xlim(6.0, 10.2)
    ax.set_ylim(-6.9, -1.5)
    ax.set_xlabel(r'$\log_{10} \left ( M_{BH} \ [M_{\odot}] \right )$')
    ax.set_ylabel(r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$')
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfBH_' + output + '.pdf')
    P.close()
예제 #26
0
def fstar(path, db, output='fstar.png'):
    '''
    Stellar mass to halo mass ratio as a function of halo mass.
    This plot differs slightly from the one in the Somerville 2008:
    the plot in the paper is the fraction of baryons in stars. 
    '''
    #get data
    query = '''select mstar, mhalo, gal_id from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    mstar = data[:, 0]
    mhalo = data[:, 1]
    gal_id = data[:, 2]

    mfit = 10. + N.arange(50) * 0.1
    mbin = 10.7 + N.arange(25) * 0.2

    f8 = 8. - mfit
    #f9 = 9. - mfit

    fs_halo = 10.0 ** (mstar - mhalo)

    #central and satellite galaxies
    central = gal_id == 1
    sat = gal_id != 1

    mbin_mid, fs_50, fs_10, fs_90 = perc_bin(mbin, mhalo, fs_halo)
    mbin_mid, fs_cen_50, fs_cen_10, fs_cen_90 = perc_bin(mbin, mhalo[central], fs_halo[central])
    mbin_mid, fs_sat_50, fs_sat_10, fs_sat_90 = perc_bin(mbin, mhalo[sat], fs_halo[sat])

    #begin figure
    fig = P.figure(figsize=(10, 10))
    ax = fig.add_subplot(111)

    ax.scatter(mhalo[central], N.log10(fs_halo[central]),
               edgecolor='r', s=2, facecolor='r', label='Central galaxies')

    ax.plot(mbin_mid, N.log10(fs_50), 'ko', ms=10, label='Median, all galaxies')
    ax.plot(mbin_mid, N.log10(fs_10), 'k--')
    ax.plot(mbin_mid, N.log10(fs_90), 'k--')

    ax.plot(mbin_mid, N.log10(fs_sat_50), 'cD', ms=8, label='Median, satellite galaxies')
    ax.plot(mbin_mid, N.log10(fs_cen_50), 'pm', ms=8, label='Median, central galaxies')

    #constrains from moster et al.
    fstar_med_ben = stellarMFs.fstarBen(mfit, 11.884, 0.0282, 1.057, 0.5560)
    fstar_med_ben_scat = stellarMFs.fstarBen(mfit, 11.866, 0.02891, 1.110, 0.648)
    ax.plot(mfit, N.log10(fstar_med_ben), 'g-', label='Moster et al.')
    ax.plot(mfit, N.log10(fstar_med_ben_scat), c='burlywood', label='Moster et al. (sc)')

    #get fstar_behroozi_log
    mh, sh = stellarMFs.fstarBehroozi()
    ax.plot(mh, sh, 'hg', label='Behroozi et al.')

    ax.plot(mfit, f8, 'k--', c='0.25')

    #axis scales
    ax.set_xlim(9.8, 15.0)
    ax.set_ylim(-4.0, -0.75)

    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)

    ax.set_ylabel(r'$\log_{10} \left ( \frac{M_{star}}{f_{b}M_{halo}} \right )$')
    ax.set_xlabel(r'$\log_{10} \left ( \frac{M_{(sub)halo}}{M_{\odot}} \right )$')

    P.legend(numpoints=1, scatterpoints=1)
    P.savefig(output)
    P.close()
예제 #27
0
def massfunctions(path,
                  db,
                  mmax=12.5,
                  mmin=5.0,
                  nbins=30,
                  output='SMN',
                  nvolumes=15):
    '''
    Plots stellar mass functions, cold gas mass functions, & BH MF
    '''
    #get data
    query = '''select gal_id, halo_id, mbulge, mstar, mcold, mbh from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    gal_id = data[:, 0]
    halo_id = data[:, 1]
    mbulge = data[:, 2]
    mstar = data[:, 3]
    mcold = data[:, 4]
    mbh = data[:, 5]

    ngal = len(gal_id)
    print '%i galaxies found' % ngal

    #overrides weight for nvolumes Bolshoi sub-volumes
    weight = N.zeros(ngal) + 1. / (nvolumes * (50. / 0.7)**3)

    #mass bins
    dm = (mmax - mmin) / nbins
    mbin = mmin + (N.arange(nbins) + 0.5) * dm

    #mfit = mmin + N.arange(150) * 0.05

    mf_cold = N.zeros(nbins)
    mf_star = N.zeros(nbins)
    mf_star_central = N.zeros(nbins)
    mf_bar = N.zeros(nbins)
    mf_bh = N.zeros(nbins)

    mf_early = N.zeros(nbins)
    mf_late = N.zeros(nbins)
    mf_bulge = N.zeros(nbins)

    #TODO from IDL, should be done without looping
    btt = 10.0**(mbulge - mstar)
    for i in range(ngal):
        ihalo = halo_id[i]
        #cold gas
        ibin = int(N.floor((mcold[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_cold[ibin] += weight[ihalo]
            #stellar mass
        ibin = int(N.floor((mstar[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_star[ibin] += weight[ihalo]
            #stellar mass, by type
            if btt[i] >= 0.4:
                mf_early[ibin] += weight[ihalo]
            else:
                mf_late[ibin] += weight[ihalo]
                #stellar mass, centrals
            if gal_id[i] == 1:
                if ibin >= 0 and ibin < nbins:
                    mf_star_central[ibin] += weight[ihalo]
                    #bulge mass
        ibin = int(N.floor((mbulge[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_bulge[ibin] += weight[ihalo]
            #baryonic mass
        mbar = N.log10(10.0**mcold[i] + 10.0**mstar[i])
        ibin = int(N.floor((mbar - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_bar[ibin] += weight[ihalo]
            #black hole
        ibin = int(N.floor((mbh[i] - mmin) / dm))
        if ibin >= 0 and ibin < nbins:
            mf_bh[ibin] += weight[ihalo]

    mf_cold = N.log10(mf_cold / dm)
    mf_star = N.log10(mf_star / dm)
    #mf_early = N.log10(mf_early / dm)
    #mf_late = N.log10(mf_late / dm)
    #mf_bulge = N.log10(mf_bulge / dm)
    #mf_star_central = N.log10(mf_star_central / dm)
    mf_bar = N.log10(mf_bar / dm)
    mf_bh = N.log10(mf_bh / dm)

    #stellar mass function plot
    #obs constrains
    mg, phig, phi_lowg, phi_highg = stellarMFs.bellG()
    mk, phik, phi_lowk, phi_highk = stellarMFs.bellK()
    #ml, phil, phi_lowl, phi_hiugl = mstar_lin(obs + 'sdss_mf/SDSS_SMF.dat')
    m, n, nlow, nhigh = stellarMFs.panter()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_star, label='Stellar Mass Function')
    ax.errorbar(mg,
                phig,
                yerr=[phig - phi_highg, phi_lowg - phig],
                label='$G$-band from Bell et al.')
    ax.errorbar(mk,
                phik,
                yerr=[phik - phi_highk, phi_lowk - phik],
                label='$K$-band from Bell et al.')
    #ax.errorbar(ml, phil, yerr = [phi_lowl, phi_highl], label = 'Lin et al. K')
    ax.errorbar(m,
                n,
                yerr=[nlow - n, n - nhigh],
                label='$K$-band from Panter et al.')
    ax.set_xlim(8.0, 12.5)
    ax.set_ylim(-6.1, -1.0)
    ax.set_xlabel(r'$\log_{10} \left ( M_{\star} \ [M_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M_{\star}} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$'
    )
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfstar_' + output + '.pdf')
    P.close()

    #cold gas mass function
    #obs constrains
    #mhi_bell_h70
    #mgas_bell_h70
    theta = gas.HIMassFunctionZwaan(mbin)
    m_hi, phi_hi, phi_low_hi, phi_high_hi = gas.HIMassFunctionBell()
    m_h2, phi_h2, phi_low_h2, phi_high_h2 = gas.H2MassFunctionBell()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_cold, label='Cold Gas Mass Function')
    ax.plot(mbin, theta, 'g-', lw=1.8, label='Zwaan et al.')
    ax.errorbar(m_hi,
                phi_hi,
                yerr=[phi_hi - phi_high_hi, phi_low_hi - phi_hi],
                c='cyan',
                ls='--',
                lw=1.5,
                label='Bell et al. $H_{I}$')
    ax.errorbar(m_h2,
                phi_h2,
                yerr=[phi_h2 - phi_high_h2, phi_low_h2 - phi_h2],
                c='magenta',
                ls=':',
                lw=1.5,
                label='Bell et al. $H_{2}$')
    ax.plot(m_hi,
            N.log10(10.0**phi_hi + 10**phi_h2),
            'r-',
            label='$H_{I} + H_{2}$')
    ax.set_xlim(8.0, 11.5)
    ax.set_ylim(-5.5, -0.8)
    ax.set_xlabel(
        r'$\log_{10} \left ( M_{\mathrm{cold}} \ [M_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$'
    )
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfcold_' + output + '.pdf')
    P.close()

    #total baryons
    #obs contstrains
    m_bar, phi_bar, phi_low_bar, phi_high_bar = baryons.BellBaryonicMassFunction(
    )

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_bar, label='Total Baryon Mass')
    ax.errorbar(m_bar,
                phi_bar,
                yerr=[phi_bar - phi_high_bar, phi_low_bar - phi_bar],
                c='g',
                ls='-',
                label='Bell et al.')
    ax.set_xlim(8.0, 12.5)
    ax.set_ylim(-4.9, -0.25)
    ax.set_xlabel(
        r'$\log_{10} \left ( M_{\mathrm{baryons}} \ [M_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M_{\mathrm{baryons}}} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$'
    )
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfbar_' + output + '.pdf')
    P.close()

    #BH mass function
    #obs constrains
    m_bh, phi_low_bh, phi_med_bh, phi_high_bh = bh.MarconiMassFunction()

    fig = P.figure()
    ax = fig.add_subplot(111)
    ax.plot(mbin, mf_bh, 'k-', label='Black Hole Mass Function')
    ax.plot(m_bh, phi_low_bh, 'g--')
    ax.plot(m_bh, phi_med_bh, 'g-', label='Marconi et al.')
    ax.plot(m_bh, phi_high_bh, 'g--')
    ax.set_xlim(6.0, 10.2)
    ax.set_ylim(-6.9, -1.5)
    ax.set_xlabel(r'$\log_{10} \left ( M_{BH} \ [M_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\frac{\log_{10} \mathrm{d}N}{\mathrm{d}\log_{10} M} \quad [\mathrm{Mpc}^{-3} \mathrm{dex}^{-1}]$'
    )
    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)
    P.legend()
    P.savefig('mfBH_' + output + '.pdf')
    P.close()
예제 #28
0
def plotMergerFractions3(query,
                         xlabel, ylabel,
                         output, out_folder,
                         mergetimelimit=0.25,
                         mstarmin=8.0,
                         mstarmax=11.5,
                         mbins=15,
                         ymin=0.0,
                         ymax=1.0,
                         logscale=False):
    #get data, all galaxies
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    tmp = data[:, 1]
    mstar = data[:, 0]
    mstar = N.log10(mstar / 10 ** tmp)
    print N.min(mstar), N.max(mstar)
    tmerge = data[:, 2]
    tmajor = data[:, 3]
    #masks
    nomergeMask = tmerge < 0.0
    majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit)
    majorsMask2 = (tmajor > mergetimelimit)
    mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\
                  (majorsMask == False) & (majorsMask2 == False)
    mergersMask2 = (nomergeMask == False) & (majorsMask == False) &\
                   (mergersMask == False) & (majorsMask2 == False)
    #bin the data
    mids, numbs = dm.binAndReturnMergerFractions2(mstar,
                                                  nomergeMask,
                                                  mergersMask,
                                                  majorsMask,
                                                  mergersMask2,
                                                  majorsMask2,
                                                  mstarmin,
                                                  mstarmax,
                                                  mbins,
                                                  logscale)
    #the fraction of mergers
    noMergerFraction = N.array([float(x[1]) / x[0] for x in numbs])
    mergerFraction = N.array([float(x[2]) / x[0] for x in numbs])
    majorMergerFraction = N.array([float(x[3]) / x[0] for x in numbs])
    mergerFraction2 = N.array([float(x[4]) / x[0] for x in numbs])
    majorMergerFraction2 = N.array([float(x[5]) / x[0] for x in numbs])

    #sanity check
    for a, b, c, d, e in zip(noMergerFraction, mergerFraction, majorMergerFraction,
                             mergerFraction2, majorMergerFraction2):
        print a + b + c + d + e
        #make the figure
    #    fig = P.figure()
    fig = P.figure(figsize=(10, 10))
    fig.subplots_adjust(left=0.08, bottom=0.07,
                        right=0.97, top=0.93)
    ax1 = fig.add_subplot(111)
    #calculate widths
    wd = (mids[1] - mids[0]) * 1.0
    #draw bars
    ax1.bar(mids, noMergerFraction,
            label='Never Merged', align='center',
            color='grey', width=wd, hatch='.')
    ax1.bar(mids, mergerFraction,
            bottom=noMergerFraction, align='center',
            label='Minor Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.),
            color='red', width=wd, hatch='/')
    ax1.bar(mids, mergerFraction2, align='center',
            bottom=noMergerFraction + mergerFraction,
            label='Minor Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.),
            color='blue', width=wd, hatch='|')
    ax1.bar(mids, majorMergerFraction, align='center',
            bottom=noMergerFraction + mergerFraction + mergerFraction2,
            label='Major Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.),
            color='magenta', width=wd, hatch='x')
    ax1.bar(mids, majorMergerFraction2, align='center',
            bottom=noMergerFraction + mergerFraction + mergerFraction2 + majorMergerFraction,
            label='Major Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.),
            color='green', width=wd, hatch='-')
    #labels
    ax1.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(mids[0] - wd / 2., mids[-1] + wd / 2.)
    #add annotate
    P.text(0.5, 1.05, 'All galaxies in $2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #legend and save
    P.legend(loc='upper center')
    P.savefig(out_folder + output)
예제 #29
0
def fstar(path, db, output='fstar.png'):
    '''
    Stellar mass to halo mass ratio as a function of halo mass.
    This plot differs slightly from the one in the Somerville 2008:
    the plot in the paper is the fraction of baryons in stars. 
    '''
    #get data
    query = '''select mstar, mhalo, gal_id from galprop'''
    data = sq.get_data_sqliteSMNfunctions(path, db, query)
    mstar = data[:, 0]
    mhalo = data[:, 1]
    gal_id = data[:, 2]

    mfit = 10. + N.arange(50) * 0.1
    mbin = 10.7 + N.arange(25) * 0.2

    f8 = 8. - mfit
    #f9 = 9. - mfit

    fs_halo = 10.0**(mstar - mhalo)

    #central and satellite galaxies
    central = gal_id == 1
    sat = gal_id != 1

    mbin_mid, fs_50, fs_10, fs_90 = perc_bin(mbin, mhalo, fs_halo)
    mbin_mid, fs_cen_50, fs_cen_10, fs_cen_90 = perc_bin(
        mbin, mhalo[central], fs_halo[central])
    mbin_mid, fs_sat_50, fs_sat_10, fs_sat_90 = perc_bin(
        mbin, mhalo[sat], fs_halo[sat])

    #begin figure
    fig = P.figure(figsize=(10, 10))
    ax = fig.add_subplot(111)

    ax.scatter(mhalo[central],
               N.log10(fs_halo[central]),
               edgecolor='r',
               s=2,
               facecolor='r',
               label='Central galaxies')

    ax.plot(mbin_mid,
            N.log10(fs_50),
            'ko',
            ms=10,
            label='Median, all galaxies')
    ax.plot(mbin_mid, N.log10(fs_10), 'k--')
    ax.plot(mbin_mid, N.log10(fs_90), 'k--')

    ax.plot(mbin_mid,
            N.log10(fs_sat_50),
            'cD',
            ms=8,
            label='Median, satellite galaxies')
    ax.plot(mbin_mid,
            N.log10(fs_cen_50),
            'pm',
            ms=8,
            label='Median, central galaxies')

    #constrains from moster et al.
    fstar_med_ben = stellarMFs.fstarBen(mfit, 11.884, 0.0282, 1.057, 0.5560)
    fstar_med_ben_scat = stellarMFs.fstarBen(mfit, 11.866, 0.02891, 1.110,
                                             0.648)
    ax.plot(mfit, N.log10(fstar_med_ben), 'g-', label='Moster et al.')
    ax.plot(mfit,
            N.log10(fstar_med_ben_scat),
            c='burlywood',
            label='Moster et al. (sc)')

    #get fstar_behroozi_log
    mh, sh = stellarMFs.fstarBehroozi()
    ax.plot(mh, sh, 'hg', label='Behroozi et al.')

    ax.plot(mfit, f8, 'k--', c='0.25')

    #axis scales
    ax.set_xlim(9.8, 15.0)
    ax.set_ylim(-4.0, -0.75)

    #small ticks
    m = ax.get_yticks()[1] - ax.get_yticks()[0]
    yminorLocator = MultipleLocator(m / 5)
    yminorFormattor = NullFormatter()
    ax.yaxis.set_minor_locator(yminorLocator)
    ax.yaxis.set_minor_formatter(yminorFormattor)
    m = ax.get_xticks()[1] - ax.get_xticks()[0]
    xminorLocator = MultipleLocator(m / 5)
    xminorFormattor = NullFormatter()
    ax.xaxis.set_minor_locator(xminorLocator)
    ax.xaxis.set_minor_formatter(xminorFormattor)

    ax.set_ylabel(
        r'$\log_{10} \left ( \frac{M_{star}}{f_{b}M_{halo}} \right )$')
    ax.set_xlabel(
        r'$\log_{10} \left ( \frac{M_{(sub)halo}}{M_{\odot}} \right )$')

    P.legend(numpoints=1, scatterpoints=1)
    P.savefig(output)
    P.close()