Exemple #1
0
def stellarHaloMFRatio(path,
                       database,
                       redshifts,
                       output_folder,
                       outfile,
                       xmin=10.0,
                       xmax=14.4,
                       ymin=-3,
                       ymax=-1,
                       nbins=15,
                       h=0.7):
    '''
    Plots stellar to dark matter halo mass ratios as a function of redshift.
    '''
    #get Behroozi et al. fits
    BFits = g.glob(
        '/Users/niemi/Dropbox/Research/Observations/behroozi/results/*.dat')

    #get a colour scheme
    cols = pt.give_colours()

    #scale the SAM's output masses with this factor
    multiply = 1e9

    #make the figure and axes instance
    fig = P.figure()
    ax = fig.add_subplot(111)

    #plot the different redshifts
    for ii, redshift in enumerate(redshifts):
        #get redshift, add 0.1 so that int/floor returns the closest int
        tmp = redshift.split()
        rd = int(float(tmp[2]) + 0.1)

        #generate the SQL query
        query = '''select mstar_disk, mbulge, mhalo from galpropz where ''' + redshift
        query += ' and mstar_disk >= 0.0 and mbulge >= 0.0'
        query += ' and mstar_disk + mbulge > 0.0'
        query += ' and gal_id = 1'

        #load Behroozi et al fit data
        BF = N.loadtxt(BFits[ii + 1])
        ax.plot(
            BF[:, 0],  # - N.log10(h),
            BF[:, 1],
            color=cols[ii],
            ls='--',
            label='Behroozi et al.: $z \sim %s$' %
            (BFits[ii + 1].split('z')[2][:4]))

        logging.debug(BFits[ii + 1])

        #get data from the SQLite3 db
        dat = db.sqlite.get_data_sqlite(path, database, query)

        #rename data and calculate the ratio
        mstar = dat[:, 0] + dat[:, 1]
        mhalo = dat[:, 2]
        ratio = N.log10(mstar / mhalo)
        mhalo = N.log10(mhalo * multiply)
        #print ratio, N.min(ratio), N.max(ratio)

        #debug output
        ngal = len(mstar)
        logging.debug('%i galaxies found at z = %i\n' % (ngal, rd))

        #bin the data
        xbin_mid, y50, y16, y84 = dm.percentile_bins(mhalo,
                                                     ratio,
                                                     xmin,
                                                     xmax,
                                                     nxbins=nbins)
        msk = y50 > -10
        #plot the binned data
        #        ax.errorbar(xbin_mid[msk],
        #                    y50[msk],
        #                    yerr = [y50[msk]-y16[msk], y84[msk]-y50[msk]],
        #                    color = cols[ii],
        #                    label = 'Bolshoi+SAM: $z \sim %i$' % rd)
        ax.plot(xbin_mid[msk],
                y50[msk],
                color=cols[ii],
                ms='o',
                ls='-',
                label='Bolshoi+SAM: $z \sim %i$' % rd)

    #set axes scales and labels
    ax.set_xlim(xmin, xmax)
    ax.set_ylim(ymin, ymax)
    ax.set_xlabel(
        r'$\log_{10} \left ( M_{\mathrm{dm}} \ [\mathrm{M}_{\odot}] \right )$')
    ax.set_ylabel(
        r'$\log_{10} \left (\frac{M_{\star}}{M_{\mathrm{dm}}} \right )$')
    #set 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(shadow=True, fancybox=True, numpoints=1)
    P.savefig(output_folder + outfile + '.pdf')
    P.close()
Exemple #2
0
def plot_properties(query,
                    xlabel,
                    ylabel,
                    output,
                    out_folder,
                    flux=5,
                    band=250,
                    pmin=0.1,
                    pmax=1.0,
                    xbin=15,
                    ybin=11,
                    xmin=7.9,
                    xmax=11.7,
                    ymin=0,
                    ymax=50):
    '''
    Plots 
    '''

    #get data
    data = sq.get_data_sqlitePowerTen(path, db, query)

    #set 1: all galaxies
    xd = data[:, 0]
    yd = data[:, 1]

    #set 2
    mask = data[:, 1] > flux
    xe = data[:, 0][mask]
    ye = data[:, 1][mask]
    #x limits for the right hand (scatter) plot
    secxmin, secxmax = 0.99 * N.min(xe), 1.005 * N.max(xe)
    if 'mstardot' in query:
        secxmax = 1200.
    if 'burst' in query:
        secxmax = 1500.

    #hess
    sd, sdmin, sdmax = h.hess_plot(xd,
                                   yd,
                                   N.ones(len(xd)),
                                   xmin,
                                   xmax,
                                   xbin,
                                   ymin,
                                   ymax,
                                   ybin,
                                   pmax=pmax,
                                   pmin=pmin)
    se, semin, semax = h.hess_plot(xe,
                                   ye,
                                   N.ones(len(xe)),
                                   secxmin,
                                   secxmax,
                                   xbin - 4,
                                   flux,
                                   ymax,
                                   ybin - 1,
                                   pmax=pmax,
                                   pmin=pmin)

    #figure
    #    f, (ax1, ax2) = P.subplots(1, 2, sharey=True)
    #    f, (ax1, ax2) = P.subplots(1, 2, figsize=(10,10))
    f, (ax1, ax2) = P.subplots(1, 2)
    f.subplots_adjust(wspace=0.0,
                      hspace=0.01,
                      left=0.08,
                      bottom=0.07,
                      right=0.97,
                      top=0.93)

    #hess plots
    ims = ax1.imshow(sd,
                     vmin=sdmin,
                     vmax=sdmax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin, xmax, ymin, ymax],
                     aspect='auto',
                     alpha=1)
    ims = ax2.imshow(se,
                     vmin=semin,
                     vmax=semax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[secxmin, secxmax, flux, ymax],
                     aspect='auto',
                     alpha=1)
    #flux limit lines
    ax1.axhline(flux, color='green', ls='--')
    ax2.axhline(flux, color='green', ls='--')
    #scatter to the second plot
    ax2.scatter(xe, ye, s=6, color='b')
    #percentiles
    xbin_midd, y50d, y16d, y84d = dm.percentile_bins(xd, yd, xmin, xmax)
    md = (y50d > 0) | (y16d > 0) | (y84d > 0)
    xbin_mide, y50e, y16e, y84e = dm.percentile_bins(xe, ye, secxmin, secxmax)
    me = (y50e > 0) | (y16e > 0) | (y84e > 0)
    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--')

    #add text
    P.text(0.5,
           0.95,
           'All galaxies',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    P.text(0.5,
           0.95,
           r'%s > %.1f $ mJy' % (ylabel.split()[0], flux),
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax2.transAxes)

    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #y tick positions
    #    ax1.set_yticks(yticks)
    #ax2.set_yticks(yticks[1:-2])

    #limits
    ax1.set_xlim(xmin, xmax)
    ax2.set_xlim(secxmin, secxmax)

    ax1.set_ylim(ymin, ymax)
    ax2.set_ylim(ymin, ymax)

    ax2.set_yticks(ax2.get_yticks()[1:-1])
    #    ax2.set_xticks(ax2.get_xticks()[1:])

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

    P.savefig(out_folder + output)
Exemple #3
0
def plot_ages(query,
              xlabel,
              ylabel,
              output,
              out_folder,
              flux=5,
              band=250,
              title='$2.0 < z < 4.0$',
              pmin=0.05,
              pmax=1.0,
              xbin=10,
              ybin=15,
              xmin=7.9,
              xmax=11.7,
              ymin=-1.5,
              ymax=1.8,
              scatters=False,
              mean=False):
    '''
    Plots age versus a given quantity.
    '''
    #get data
    data = N.array(sq.get_data_sqlitePowerTen(path, db, query))

    #observable galaxies
    mask = data[:, 1] > flux
    xe = data[:, 0][mask]
    ye = N.log10(data[:, 1][mask])
    #all galaxies
    xd = data[:, 0]
    yd = N.log10(data[:, 1])
    mask = yd != N.nan
    xd = xd[mask]
    yd = yd[mask]

    #hess
    sd, sdmin, sdmax = h.hess_plot(xd,
                                   yd,
                                   N.ones(len(xd)),
                                   xmin,
                                   xmax,
                                   xbin,
                                   ymin,
                                   ymax,
                                   ybin,
                                   pmax=pmax,
                                   pmin=pmin)
    se, semin, semax = h.hess_plot(xe,
                                   ye,
                                   N.ones(len(xe)),
                                   xmin,
                                   xmax,
                                   xbin,
                                   N.log10(flux),
                                   ymax,
                                   ybin,
                                   pmax=pmax,
                                   pmin=pmin)

    #figure
    fig = P.figure()
    fig.suptitle(title)
    f, (ax1, ax2) = P.subplots(1, 2, sharey=True)
    f.subplots_adjust(wspace=0.0,
                      hspace=0.01,
                      left=0.08,
                      bottom=0.07,
                      right=0.97,
                      top=0.93)

    #contours
    ims = ax1.imshow(sd,
                     vmin=sdmin,
                     vmax=sdmax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin, xmax, ymin, ymax],
                     aspect='auto',
                     alpha=1)
    ims = ax2.imshow(se,
                     vmin=semin,
                     vmax=semax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin, xmax, N.log10(flux), ymax],
                     aspect='auto',
                     alpha=1)

    #percentiles
    xbin_midd, y50d, y16d, y84d = dm.percentile_bins(xd, yd, xmin, xmax)
    md = (y50d > 0) & (y16d > 0) & (y84d > 0)
    xbin_mide, y50e, y16e, y84e = dm.percentile_bins(xe, ye, xmin, xmax)
    me = (y50e > 0) & (y16e > 0) & (y84e > 0)
    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--')

    #dots
    if scatters:
        ax1.scatter(xd, yd, c='b', s=10, marker='h', label='All galaxies')
        ax2.scatter(xe,
                    ye,
                    c='r',
                    s=10,
                    marker='o',
                    label=r'$S_{%i} > %.1f$ mJy' % (band, flux))

    #hlines
    if mean:
        #mean size
        mean_disk = N.mean(yd)
        mean_early = N.mean(ye)
        ax1.axhline(mean_disk, c='b', label='Mean')
        ax2.axhline(mean_early, c='r', label='Mean')

    #add text
    P.text(0.5,
           0.95,
           'All galaxies',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    P.text(0.5,
           0.95,
           r'$S_{%i} > %.1f$ mJy' % (band, flux),
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax2.transAxes)

    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #ax2.set_yticks([])

    #limits
    #ax1.set_ylim(ymin, ymax)
    #ax2.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    ax2.set_xlim(xmin, xmax)

    #yticks
    #ax1.set_yticks(y1ticks)
    #ax2.set_yticks(y2ticks)

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

    #write a legend
    ax1.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1)
    ax2.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1)
    P.savefig(out_folder + output)
Exemple #4
0
def stellarHaloMFRatioMultiPanel(path,
                                 database,
                                 redshifts,
                                 output_folder,
                                 outfile,
                                 xmin=10.0,
                                 xmax=14.4,
                                 ymin=-3,
                                 ymax=-1,
                                 nbins=15):
    '''
    Plots stellar to dark matter halo mass ratios as a function of redshift.
    '''
    #get Behroozi et al. fits
    BFits = g.glob(hm +
                   '/Dropbox/Research/Observations/behroozi/results/*.dat')

    #get a colour scheme
    cols = pt.give_colours()

    #scale the SAM's output masses with this factor
    multiply = 1e9

    #make the figure and axes instance
    fig = P.figure()
    P.subplots_adjust(left=0.13, bottom=0.1, wspace=0.0, hspace=0.0)

    #plot the different redshifts
    for ii, redshift in enumerate(redshifts):
        #get redshift, add 0.1 so that int/floor returns the closest int
        tmp = redshift.split()
        rd = int(float(tmp[2]) + 0.1)

        #generate the SQL query
        query = '''select mstar_disk, mbulge, mhalo from galpropz where ''' + redshift
        query += ' and mstar_disk >= 0.0 and mbulge >= 0.0'
        query += ' and mstar_disk + mbulge > 0.0'
        query += ' and gal_id = 1'

        if ii < 6:
            ax = fig.add_subplot(2, 3, ii + 1)

        #get data from the SQLite3 db
        dat = db.sqlite.get_data_sqlite(path, database, query)

        #rename data and calculate the ratio
        mstar = dat[:, 0] + dat[:, 1]
        mhalo = dat[:, 2]
        ratio = N.log10(mstar / mhalo)
        mhalo = N.log10(mhalo * multiply)
        #print ratio, N.min(ratio), N.max(ratio)

        #debug output
        ngal = len(mstar)
        logging.debug('%i galaxies found at z = %i\n' % (ngal, rd))

        #bin the data
        xbin_mid, y50, y16, y84 = dm.percentile_bins(mhalo,
                                                     ratio,
                                                     xmin,
                                                     xmax,
                                                     nxbins=nbins)
        msk = y50 > -10
        #plot the binned data
        if ii == 6:
            ax.plot(xbin_mid[msk], y50[msk], 'k--', label='Bolshoi+SAM')
        else:
            ax.errorbar(xbin_mid[msk],
                        y50[msk],
                        yerr=[y50[msk] - y16[msk], y84[msk] - y50[msk]],
                        color='k',
                        label='Bolshoi+SAM')

        #load Behroozi et al fit data
        BF = N.loadtxt(BFits[ii + 1])
        #plot Behroozi data
        if ii == 6:
            ax.plot(BF[:, 0],
                    BF[:, 1],
                    color='r',
                    ls='--',
                    label='Behroozi et al.')
        else:
            ax.plot(BF[:, 0],
                    BF[:, 1],
                    color='r',
                    ls='-',
                    label='Behroozi et al.')

        #output some information
        logging.debug(BFits[ii + 1])

        #mark the redshift
        if ii < 5:
            P.text(0.5,
                   0.93,
                   r'$ z \sim %.1f $' % (rd),
                   horizontalalignment='center',
                   verticalalignment='center',
                   transform=ax.transAxes,
                   fontsize=12)
        elif ii == 5:
            P.text(0.5,
                   0.93,
                   r'$z \sim %.1f (s)\ \& \ %.1f (d)$' % (rd, rd + 1),
                   horizontalalignment='center',
                   verticalalignment='center',
                   transform=ax.transAxes,
                   fontsize=12)

        #set axes scales and labels
        ax.set_xlim(xmin - 0.1, xmax)
        ax.set_ylim(ymin, ymax)

        #set 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)

        #set legend
        if ii == 4:
            ax.legend(shadow=True,
                      fancybox=True,
                      numpoints=1,
                      loc='lower right')

        #set ylabel
        if ii == 0 or ii == 3:
            ax.set_ylabel(
                r'$\log_{10} \left (\frac{M_{\star}}{M_{\mathrm{dm}}} \right )$'
            )

        #set xlabel
        if ii == 4:  # or ii == 3 or ii == 5:
            ax.set_xlabel(
                r'$\log_{10} \left ( M_{\mathrm{dm}} \ [\mathrm{M}_{\odot}] \right )$'
            )

        #remove some y ticks
        if ii == 0 or ii == 3:
            ax.set_yticks(ax.get_yticks()[:-1])
        else:
            ax.set_yticklabels([])

        #remove some x ticks
        if ii == 3 or ii == 4 or ii == 5:
            #ax.set_xticks(ax.get_xticks()[:-1])
            continue
        elif ii == 6:
            continue
        else:
            ax.set_xticklabels([])

    P.savefig(output_folder + outfile + 'Multi.pdf')
    P.close()
Exemple #5
0
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)
Exemple #6
0
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()
Exemple #7
0
def plot_size_paper(xd1,
                    xd2,
                    yd1,
                    yd2,
                    xlabel,
                    ylabel,
                    output,
                    out_folder,
                    pmin=0.05,
                    pmax=1.0,
                    xbin1=15,
                    ybin1=15,
                    xbin2=15,
                    ybin2=15,
                    y1ticks=[1, 3, 5, 7, 9, 12],
                    y2ticks=[1, 3, 5, 7, 9],
                    xmin1=7.9,
                    xmax1=11.7,
                    xmin2=7.9,
                    xmax2=11.7,
                    ymin=0.1,
                    ymax=12,
                    scatters=False,
                    mean=False):
    #calculate hess
    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)

    #load obs data
    file = os.getenv(
        'HOME') + '/Dropbox/Research/Herschel/obs_data/CavaSizesValues.txt'
    data = N.loadtxt(file, comments='#', usecols=(0, 1))

    #figure
    fig = P.figure()
    #fig.suptitle('Late-type Galaxies')
    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=1,
                marker='o',
                color='blue',
                label='$S_{250} > 5$ mJy')

    ax1.scatter(data[:, 0], data[:, 1], s=45, marker='s', color='green')
    ax2.scatter(data[:, 0],
                data[:, 1],
                s=45,
                marker='s',
                color='green',
                label='Cava et al 2010')

    #percentiles
    xbin_midd1, y50d1, y16d1, y84d1 = dm.percentile_bins(xd1,
                                                         yd1,
                                                         xmin1,
                                                         xmax1,
                                                         nxbins=2 * xbin1,
                                                         limit=25)
    md1 = (y50d1 > 0) & (y16d1 > 0) & (y84d1 > 0)
    xbin_midd2, y50d2, y16d2, y84d2 = dm.percentile_bins(xd2,
                                                         yd2,
                                                         xmin2,
                                                         xmax2,
                                                         nxbins=xbin2,
                                                         limit=12)
    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.95,
           'Late-type galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    #    P.text(0.5, 0.95,'$S_{250} > 5$ mJy',
    #           horizontalalignment='center',
    #           verticalalignment='center',
    #           transform = ax2.transAxes)

    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #yticks
    ax2.set_yticks([])
    ax1.set_xticks(ax1.get_xticks()[:-1])
    ax2.set_xticks(ax2.get_xticks()[1:])
    ax1.set_yticks(y1ticks)
    ax2.set_yticks(y2ticks)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax2.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin1, xmax1)
    ax2.set_xlim(xmin2, xmax2)
    #make grid
    #ax1.grid()
    #ax2.grid()
    #write a legend
    #ax1.legend(shadow = True, fancybox = True,
    #           numpoints = 1, loc = 'upper left',
    #           scatterpoints = 1)
    ax2.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1,
               markerscale=1.5)
    P.savefig(out_folder + output)
Exemple #8
0
def plot_size_paperKDE(xd1,
                       xd2,
                       yd1,
                       yd2,
                       xlabel,
                       ylabel,
                       output,
                       out_folder,
                       xbin1=15,
                       ybin1=15,
                       xbin2=15,
                       ybin2=15,
                       y1ticks=[1, 3, 5, 7, 9, 12],
                       y2ticks=[1, 3, 5, 7, 9],
                       xmin1=7.9,
                       xmax1=11.7,
                       xmin2=7.9,
                       xmax2=11.7,
                       ymin=0.1,
                       ymax=12,
                       scatters=False,
                       mean=False,
                       lvls=None):
    #calclate KDEs
    mu1 = M.AnaKDE([xd1, yd1])
    x_vec1, y_vec1, zm1, lvls1, d01, d11 = mu1.contour(
        N.linspace(xmin1, xmax1, xbin1),
        N.linspace(ymin, ymax, ybin1),
        return_data=True)
    mu2 = M.AnaKDE([xd2, yd2])
    x_vec2, y_vec2, zm2, lvls2, d02, d12 = mu2.contour(
        N.linspace(xmin2, xmax2, xbin2),
        N.linspace(ymin, ymax, ybin2),
        return_data=True)
    #load obs data
    file = os.getenv(
        'HOME') + '/Dropbox/Research/Herschel/obs_data/CavaSizesValues.txt'
    data = N.loadtxt(file, comments='#', usecols=(0, 1))

    #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)
    #make filled contours
    if lvls == None:
        cont = ax1.contourf(x_vec1, y_vec1, zm1, cmap=cm.get_cmap('gist_yarg'))
        cont = ax2.contourf(x_vec2, y_vec2, zm2, cmap=cm.get_cmap('gist_yarg'))
    else:
        cont = ax1.contourf(x_vec1,
                            y_vec1,
                            zm1,
                            cmap=cm.get_cmap('gist_yarg'),
                            levels=lvls)
        cont = ax2.contourf(x_vec2,
                            y_vec2,
                            zm2,
                            cmap=cm.get_cmap('gist_yarg'),
                            levels=lvls)

    #plot scatter
    ax2.scatter(xd2,
                yd2,
                s=0.5,
                marker='o',
                color='blue',
                label='$S_{250} > 5$ mJy')
    #plot observed data
    ax1.scatter(data[:, 0], data[:, 1], s=45, marker='s', color='green')
    ax2.scatter(data[:, 0],
                data[:, 1],
                s=45,
                marker='s',
                color='green',
                label='Cava et al 2010')
    #calculate and plot percentiles
    xbin_midd1, y50d1, y16d1, y84d1 = dm.percentile_bins(xd1,
                                                         yd1,
                                                         xmin1,
                                                         xmax1,
                                                         nxbins=30,
                                                         limit=20)
    md1 = (y50d1 > 0) & (y16d1 > 0) & (y84d1 > 0)
    xbin_midd2, y50d2, y16d2, y84d2 = dm.percentile_bins(xd2,
                                                         yd2,
                                                         xmin2,
                                                         xmax2,
                                                         nxbins=15,
                                                         limit=10)
    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.95,
           'Late-type galaxies\n$2 \leq z < 4$',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)

    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #yticks
    ax2.set_yticks([])
    ax1.set_xticks(ax1.get_xticks()[:-1])
    ax2.set_xticks(ax2.get_xticks()[1:])
    ax1.set_yticks(y1ticks)
    ax2.set_yticks(y2ticks)
    #limits
    ax1.set_ylim(ymin, ymax)
    ax2.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin1, xmax1)
    ax2.set_xlim(xmin2, xmax2)
    #make grid
    #ax1.grid()
    #ax2.grid()
    #write a legend
    ax2.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1,
               markerscale=1.5)
    P.savefig(out_folder + output)
Exemple #9
0
def plot_size(query,
              xlabel,
              ylabel,
              output,
              out_folder,
              bulge=0.4,
              title='$2.0 < z < 4.0$',
              pmin=0.05,
              pmax=1.0,
              xbin=15,
              ybin=15,
              y1ticks=[1, 3, 5, 7, 10],
              y2ticks=[1, 3, 5, 7],
              xmin=7.9,
              xmax=11.7,
              ymin=0.1,
              ymax=10,
              scatters=False,
              mean=False):
    '''
    Plots size versus a given quantity.
    '''
    #get data
    data = sq.get_data_sqlitePowerTen(path, db, query)

    #sphericals
    mask = data[:, 2] > bulge
    xe = data[:, 0][mask]
    ye = data[:, 1][mask]
    # disks
    disks = data[:, 2] <= bulge
    xd = data[:, 0][disks]
    yd = data[:, 1][disks]

    #hess
    sd, sdmin, sdmax = h.hess_plot(xd,
                                   yd,
                                   N.ones(len(xd)),
                                   xmin,
                                   xmax,
                                   xbin,
                                   ymin,
                                   ymax,
                                   ybin,
                                   pmax=pmax,
                                   pmin=pmin)
    se, semin, semax = h.hess_plot(xe,
                                   ye,
                                   N.ones(len(xe)),
                                   xmin,
                                   xmax,
                                   xbin,
                                   ymin,
                                   ymax,
                                   ybin,
                                   pmax=pmax,
                                   pmin=pmin)

    #figure
    #    fig = P.figure(figsize = (12, 12))
    fig = P.figure()
    fig.suptitle(title)
    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)

    #contours
    #    ax1.contourf(sd, origin = 'lower', colors = 'b',
    #                 linewidths = 0.8, linestyles = '-',
    #                 extent = [xmin, xmax, ymin, ymax],
    #                 rightside_up = True, alpha = 0.7)#,
    #                 #levels = [0.01, 0.3, 0.6, 0.9])
    #    ax2.contourf(se, origin = 'lower', colors = 'r',
    #                 linewidths = 0.8, linestyles = '-',
    #                 extent = [xmin, xmax, ymin, ymax],
    #                 rightside_up = True, alpha = 0.7)
    ims = ax1.imshow(sd,
                     vmin=sdmin,
                     vmax=sdmax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin, xmax, ymin, ymax],
                     aspect='auto',
                     alpha=1)
    ims = ax2.imshow(se,
                     vmin=semin,
                     vmax=semax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin, xmax, ymin, ymax],
                     aspect='auto',
                     alpha=1)

    #percentiles
    xbin_midd, y50d, y16d, y84d = dm.percentile_bins(xd, yd, xmin, xmax)
    md = (y50d > 0) & (y16d > 0) & (y84d > 0)
    xbin_mide, y50e, y16e, y84e = dm.percentile_bins(xe, ye, xmin, xmax)
    me = (y50e > 0) & (y16e > 0) & (y84e > 0)
    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--')

    #dots
    if scatters:
        ax1.scatter(xd, yd, c='b', s=10, marker='h', label='Late-type')
        ax2.scatter(xe, ye, c='r', s=10, marker='o', label='Early-type')

    #hlines
    if mean:
        #mean size
        mean_disk = N.mean(yd)
        mean_early = N.mean(ye)
        ax1.axhline(mean_disk, c='b', label='Mean')
        ax2.axhline(mean_early, c='r', label='Mean')

    #add text
    P.text(0.5,
           0.95,
           'Late-type galaxies',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)
    P.text(0.5,
           0.95,
           'Early-type galaxies',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax2.transAxes)

    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    ax2.set_yticks([])

    #limits
    ax1.set_ylim(ymin, ymax)
    ax2.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    ax2.set_xlim(xmin, xmax)

    #yticks
    ax1.set_yticks(y1ticks)
    ax2.set_yticks(y2ticks)

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

    #write a legend
    ax1.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1)
    ax2.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1)
    P.savefig(out_folder + output)
Exemple #10
0
def plot_size2(query,
               xlabel,
               ylabel,
               output,
               out_folder,
               bulge=0.4,
               title='$2.0 < z < 4.0$',
               pmin=0.05,
               pmax=1.0,
               xbin=15,
               ybin=15,
               xmin=7.9,
               xmax=11.7,
               ymin=0.1,
               ymax=10):
    '''
    Plots size versus a given quantity.
    '''
    #get data
    data = N.array(sq.get_data_sqlitePowerTen(path, db, query))

    # disks
    disks = data[:, 2] <= bulge
    xd = data[:, 0][disks]
    yd = data[:, 1][disks]

    #hess
    sd, sdmin, sdmax = h.hess_plot(xd,
                                   yd,
                                   N.ones(len(xd)),
                                   xmin,
                                   xmax,
                                   xbin,
                                   ymin,
                                   ymax,
                                   ybin,
                                   pmax=pmax,
                                   pmin=pmin)

    #figure
    fig = P.figure()
    fig.suptitle(title)
    ax1 = fig.add_subplot(111)

    ims = ax1.imshow(sd,
                     vmin=sdmin,
                     vmax=sdmax,
                     origin='lower',
                     cmap=cm.gray,
                     interpolation=None,
                     extent=[xmin, xmax, ymin, ymax],
                     aspect='auto',
                     alpha=1)

    #percentiles
    xbin_midd, y50d, y16d, y84d = dm.percentile_bins(xd, yd, xmin, xmax)
    md = (y50d > 0) & (y16d > 0) & (y84d > 0)
    ax1.plot(xbin_midd[md], y50d[md], 'r-')
    ax1.plot(xbin_midd[md], y16d[md], 'r--')
    ax1.plot(xbin_midd[md], y84d[md], 'r--')

    #add text
    P.text(0.5,
           0.95,
           'Late-type galaxies',
           horizontalalignment='center',
           verticalalignment='center',
           transform=ax1.transAxes)

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

    #limits
    ax1.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)

    #yticks
    #ax1.set_yticks(y1ticks)

    #make grid
    #ax1.grid()

    #write a legend
    ax1.legend(shadow=True,
               fancybox=True,
               numpoints=1,
               loc='upper left',
               scatterpoints=1)
    P.savefig(out_folder + output)
Exemple #11
0
def stellarHaloMFRatio(path, database, redshifts,
                       output_folder, outfile,
                       xmin=10.0, xmax=14.4,
                       ymin=-3, ymax=-1,
                       nbins=15, h=0.7):
    '''
    Plots stellar to dark matter halo mass ratios as a function of redshift.
    '''
    #get Behroozi et al. fits
    BFits = g.glob('/Users/niemi/Dropbox/Research/Observations/behroozi/results/*.dat')

    #get a colour scheme
    cols = pt.give_colours()

    #scale the SAM's output masses with this factor
    multiply = 1e9

    #make the figure and axes instance
    fig = P.figure()
    ax = fig.add_subplot(111)

    #plot the different redshifts
    for ii, redshift in enumerate(redshifts):
        #get redshift, add 0.1 so that int/floor returns the closest int
        tmp = redshift.split()
        rd = int(float(tmp[2]) + 0.1)

        #generate the SQL query
        query = '''select mstar_disk, mbulge, mhalo from galpropz where ''' + redshift
        query += ' and mstar_disk >= 0.0 and mbulge >= 0.0'
        query += ' and mstar_disk + mbulge > 0.0'
        query += ' and gal_id = 1'

        #load Behroozi et al fit data
        BF = N.loadtxt(BFits[ii + 1])
        ax.plot(BF[:, 0], # - N.log10(h),
                BF[:, 1],
                color=cols[ii],
                ls='--',
                label='Behroozi et al.: $z \sim %s$' % (BFits[ii + 1].split('z')[2][:4]))

        logging.debug(BFits[ii + 1])

        #get data from the SQLite3 db
        dat = db.sqlite.get_data_sqlite(path, database, query)

        #rename data and calculate the ratio
        mstar = dat[:, 0] + dat[:, 1]
        mhalo = dat[:, 2]
        ratio = N.log10(mstar / mhalo)
        mhalo = N.log10(mhalo * multiply)
        #print ratio, N.min(ratio), N.max(ratio)

        #debug output
        ngal = len(mstar)
        logging.debug('%i galaxies found at z = %i\n' % (ngal, rd))

        #bin the data
        xbin_mid, y50, y16, y84 = dm.percentile_bins(mhalo,
                                                     ratio,
                                                     xmin,
                                                     xmax,
                                                     nxbins=nbins)
        msk = y50 > -10
        #plot the binned data
        #        ax.errorbar(xbin_mid[msk],
        #                    y50[msk],
        #                    yerr = [y50[msk]-y16[msk], y84[msk]-y50[msk]],
        #                    color = cols[ii],
        #                    label = 'Bolshoi+SAM: $z \sim %i$' % rd)
        ax.plot(xbin_mid[msk],
                y50[msk],
                color=cols[ii],
                ms='o',
                ls='-',
                label='Bolshoi+SAM: $z \sim %i$' % rd)



    #set axes scales and labels
    ax.set_xlim(xmin, xmax)
    ax.set_ylim(ymin, ymax)
    ax.set_xlabel(r'$\log_{10} \left ( M_{\mathrm{dm}} \ [\mathrm{M}_{\odot}] \right )$')
    ax.set_ylabel(r'$\log_{10} \left (\frac{M_{\star}}{M_{\mathrm{dm}}} \right )$')
    #set 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(shadow=True, fancybox=True, numpoints=1)
    P.savefig(output_folder + outfile + '.pdf')
    P.close()
Exemple #12
0
def stellarHaloMFRatioMultiPanel(path, database, redshifts,
                                 output_folder, outfile,
                                 xmin=10.0, xmax=14.4,
                                 ymin=-3, ymax=-1,
                                 nbins=15):
    '''
    Plots stellar to dark matter halo mass ratios as a function of redshift.
    '''
    #get Behroozi et al. fits
    BFits = g.glob(hm + '/Dropbox/Research/Observations/behroozi/results/*.dat')

    #get a colour scheme
    cols = pt.give_colours()

    #scale the SAM's output masses with this factor
    multiply = 1e9

    #make the figure and axes instance
    fig = P.figure()
    P.subplots_adjust(left=0.13,
                      bottom=0.1,
                      wspace=0.0,
                      hspace=0.0)

    #plot the different redshifts
    for ii, redshift in enumerate(redshifts):
        #get redshift, add 0.1 so that int/floor returns the closest int
        tmp = redshift.split()
        rd = int(float(tmp[2]) + 0.1)

        #generate the SQL query
        query = '''select mstar_disk, mbulge, mhalo from galpropz where ''' + redshift
        query += ' and mstar_disk >= 0.0 and mbulge >= 0.0'
        query += ' and mstar_disk + mbulge > 0.0'
        query += ' and gal_id = 1'

        if ii < 6:
            ax = fig.add_subplot(2, 3, ii + 1)

        #get data from the SQLite3 db
        dat = db.sqlite.get_data_sqlite(path, database, query)

        #rename data and calculate the ratio
        mstar = dat[:, 0] + dat[:, 1]
        mhalo = dat[:, 2]
        ratio = N.log10(mstar / mhalo)
        mhalo = N.log10(mhalo * multiply)
        #print ratio, N.min(ratio), N.max(ratio)

        #debug output
        ngal = len(mstar)
        logging.debug('%i galaxies found at z = %i\n' % (ngal, rd))

        #bin the data
        xbin_mid, y50, y16, y84 = dm.percentile_bins(mhalo,
                                                     ratio,
                                                     xmin,
                                                     xmax,
                                                     nxbins=nbins)
        msk = y50 > -10
        #plot the binned data
        if ii == 6:
            ax.plot(xbin_mid[msk],
                    y50[msk],
                    'k--',
                    label='Bolshoi+SAM')
        else:
            ax.errorbar(xbin_mid[msk],
                        y50[msk],
                        yerr=[y50[msk] - y16[msk], y84[msk] - y50[msk]],
                        color='k',
                        label='Bolshoi+SAM')

        #load Behroozi et al fit data
        BF = N.loadtxt(BFits[ii + 1])
        #plot Behroozi data
        if ii == 6:
            ax.plot(BF[:, 0],
                    BF[:, 1],
                    color='r',
                    ls='--',
                    label='Behroozi et al.')
        else:
            ax.plot(BF[:, 0],
                    BF[:, 1],
                    color='r',
                    ls='-',
                    label='Behroozi et al.')

        #output some information
        logging.debug(BFits[ii + 1])

        #mark the redshift
        if ii < 5:
            P.text(0.5, 0.93,
                   r'$ z \sim %.1f $' % (rd),
                   horizontalalignment='center',
                   verticalalignment='center',
                   transform=ax.transAxes,
                   fontsize=12)
        elif ii == 5:
            P.text(0.5, 0.93,
                   r'$z \sim %.1f (s)\ \& \ %.1f (d)$' % (rd, rd + 1),
                   horizontalalignment='center',
                   verticalalignment='center',
                   transform=ax.transAxes,
                   fontsize=12)

        #set axes scales and labels
        ax.set_xlim(xmin - 0.1, xmax)
        ax.set_ylim(ymin, ymax)

        #set 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)

        #set legend
        if ii == 4:
            ax.legend(shadow=True,
                      fancybox=True,
                      numpoints=1,
                      loc='lower right')

        #set ylabel
        if ii == 0 or ii == 3:
            ax.set_ylabel(r'$\log_{10} \left (\frac{M_{\star}}{M_{\mathrm{dm}}} \right )$')

        #set xlabel
        if ii == 4: # or ii == 3 or ii == 5:
            ax.set_xlabel(r'$\log_{10} \left ( M_{\mathrm{dm}} \ [\mathrm{M}_{\odot}] \right )$')

        #remove some y ticks
        if ii == 0 or ii == 3:
            ax.set_yticks(ax.get_yticks()[:-1])
        else:
            ax.set_yticklabels([])

        #remove some x ticks
        if ii == 3 or ii == 4 or ii == 5:
            #ax.set_xticks(ax.get_xticks()[:-1])
            continue
        elif ii == 6:
            continue
        else:
            ax.set_xticklabels([])

    P.savefig(output_folder + outfile + 'Multi.pdf')
    P.close()
Exemple #13
0
def plot_ages(query, xlabel, ylabel, output, out_folder,
              flux = 5, band = 250, title = '$2.0 < z < 4.0$',
              pmin = 0.05, pmax = 1.0,
              xbin = 10, ybin = 15,
              xmin = 7.9, xmax = 11.7, ymin = -1.5, ymax = 1.8,
              scatters = False, mean = False):
    '''
    Plots age versus a given quantity.
    '''
    #get data
    data = N.array(sq.get_data_sqlitePowerTen(path, db, query))

    #observable galaxies
    mask = data[:,1] > flux
    xe = data[:,0][mask]
    ye = N.log10(data[:,1][mask])
    #all galaxies
    xd = data[:,0]
    yd = N.log10(data[:,1])
    mask = yd != N.nan
    xd = xd[mask]
    yd = yd[mask]

    #hess
    sd, sdmin, sdmax = h.hess_plot(xd, yd, N.ones(len(xd)), 
                                   xmin, xmax, xbin, 
                                   ymin, ymax, ybin,
                                   pmax = pmax, pmin = pmin)
    se, semin, semax = h.hess_plot(xe, ye, N.ones(len(xe)), 
                                   xmin, xmax, xbin, 
                                   N.log10(flux), ymax, ybin,
                                   pmax = pmax, pmin = pmin)
    
    #figure
    fig = P.figure()
    fig.suptitle(title)
    f, (ax1, ax2) = P.subplots(1, 2, sharey=True) 
    f.subplots_adjust(wspace = 0.0, hspace = 0.01, left = 0.08, bottom = 0.07,
                      right = 0.97, top = 0.93)

    #contours
    ims = ax1.imshow(sd, vmin = sdmin, vmax = sdmax,
                     origin = 'lower', cmap = cm.gray,
                     interpolation = None,
                     extent = [xmin, xmax, ymin, ymax],
                     aspect = 'auto', alpha = 1)
    ims = ax2.imshow(se, vmin = semin, vmax = semax,
                     origin = 'lower', cmap = cm.gray,
                     interpolation = None,
                     extent = [xmin, xmax, N.log10(flux), ymax],
                     aspect = 'auto', alpha = 1)

    #percentiles
    xbin_midd, y50d, y16d, y84d = dm.percentile_bins(xd, yd, xmin, xmax)
    md = (y50d > 0) & (y16d > 0) & (y84d > 0)
    xbin_mide, y50e, y16e, y84e = dm.percentile_bins(xe, ye, xmin, xmax)
    me = (y50e > 0) & (y16e > 0) & (y84e > 0)
    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--')

    #dots
    if scatters:
        ax1.scatter(xd, yd, c='b', s = 10,
                    marker = 'h', label = 'All galaxies')
        ax2.scatter(xe, ye, c='r', s = 10,
                    marker = 'o', label = r'$S_{%i} > %.1f$ mJy' % (band, flux))

    #hlines
    if mean:
        #mean size
        mean_disk = N.mean(yd)
        mean_early = N.mean(ye)
        ax1.axhline(mean_disk, c = 'b', label = 'Mean')
        ax2.axhline(mean_early, c = 'r', label = 'Mean')

    #add text
    P.text(0.5, 0.95, 'All galaxies',
           horizontalalignment='center',
           verticalalignment='center',
           transform = ax1.transAxes)
    P.text(0.5, 0.95, r'$S_{%i} > %.1f$ mJy' % (band, flux),
           horizontalalignment='center',
           verticalalignment='center',
           transform = ax2.transAxes)


    #labels
    ax1.set_xlabel(xlabel)
    ax2.set_xlabel(xlabel)
    ax1.set_ylabel(ylabel)
    #ax2.set_yticks([])

    #limits
    #ax1.set_ylim(ymin, ymax)
    #ax2.set_ylim(ymin, ymax)
    ax1.set_xlim(xmin, xmax)
    ax2.set_xlim(xmin, xmax)

    #yticks
    #ax1.set_yticks(y1ticks)
    #ax2.set_yticks(y2ticks)

    #make grid
    ax1.grid()
    ax2.grid()
    
    #write a legend
    ax1.legend(shadow = True, fancybox = True, 
               numpoints = 1, loc = 'upper left',
               scatterpoints = 1)
    ax2.legend(shadow = True, fancybox = True, 
               numpoints = 1, loc = 'upper left',
               scatterpoints = 1)
    P.savefig(out_folder + output)