def plotMergerFractions(query, xlabel, ylabel, output, out_folder, mergetimelimit=0.25, mstarmin=8.0, mstarmax=11.5, mbins=15, ymin=-0.001, ymax=1.01, logscale=False): """ Plot merger fractions. """ #get data, all galaxies data = sq.get_data_sqliteSMNfunctions(path, db, query) #mstar = N.log10(data[:, 0]) mstar = data[:, 0] tmerge = data[:, 1] tmajor = data[:, 2] print N.min(mstar), N.max(mstar) #masks nomergeMask = tmerge < 0.0 majorsMask = (tmajor > 0.0) & (tmajor <= mergetimelimit) majorsMask2 = (tmajor > mergetimelimit) & (tmajor <= 0.5) mergersMask = (tmerge > 0.0) & (tmerge <= mergetimelimit) &\ (majorsMask == False) & (majorsMask2 == False) mergersMask2 = (tmerge > mergetimelimit) & (tmerge <= 0.5) &\ (majorsMask2 == False) #bin the data mids, numbs = dm.binAndReturnMergerFractions2(mstar, nomergeMask, mergersMask, majorsMask, mergersMask2, majorsMask2, mstarmin, mstarmax, mbins, logscale) #the fraction of mergers noMergerFraction = [float(x[1]) / x[0] for x in numbs] mergerFraction = [float(x[2]) / x[0] for x in numbs] majorMergerFraction = [float(x[3]) / x[0] for x in numbs] mergerFraction2 = [float(x[4]) / x[0] for x in numbs] majorMergerFraction2 = [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 if 'ps' in output: fig = P.figure() else: 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: $250 < T \leq 500$ 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: $250 < T \leq 500$ Myr') ax1.plot(mids, majorMergerFraction, ls='-', lw=2.6, c='0.3', label='Young Major Merger') ax1.plot(mids, mergerFraction, ls='-.', lw=2.6, c='0.2', label='Young Minor Merger') ax1.plot(mids, majorMergerFraction2, ls='--', lw=2.6, c='0.4', label='Old Major Merger') ax1.plot(mids, mergerFraction2, ls=':', lw=2.6, c='0.5', label='Old Minor Merger') #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) #legend and save P.legend(loc='upper left') P.savefig(out_folder + output)
def plotMergerFractions3(query, xlabel, ylabel, output, out_folder, mergetimelimit=0.4, 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) 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.1, 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='0.5', width=wd)#, hatch = '/') ax1.bar(mids, mergerFraction2, align='center', bottom=noMergerFraction, label='Minor Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.), color='0.7', width=wd)#, hatch = '|') ax1.bar(mids, majorMergerFraction2, align='center', bottom=noMergerFraction + mergerFraction2, label='Major Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.), color='0.9', width=wd)#, hatch = '-') ax1.bar(mids, majorMergerFraction, align='center', bottom=noMergerFraction + mergerFraction2 + majorMergerFraction2, label='Major Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.), color='green', width=wd)#, hatch = '.') ax1.bar(mids, mergerFraction, bottom=noMergerFraction + mergerFraction2 + majorMergerFraction2 + majorMergerFraction, align='center', label='Minor Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.), color='red', width=wd)#, hatch = 'x') #labels ax1.set_xlabel(xlabel) ax1.set_ylabel(ylabel) 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='lower left') P.savefig(out_folder + output)
def plot_mergerfraction(path, db, reshifts, out_folder, outname, xmin=-0.01, xmax=2.3, fluxlimit=5, png=True, mergetimelimit=0.25, xbin=[10, 8, 9, 7, 7, 5], neverMerged=False, obs=True): ''' Plots ''' #figure if png: fig = P.figure(figsize=(10, 10)) type = '.png' else: fig = P.figure() type = '.ps' 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) #loop over all the redshifts for i, reds in enumerate(redshifts): if obs: query = '''select FIR.pacs160_obs, galprop.tmerge, galprop.tmajmerge from FIR, galprop where %s and FIR.pacs160_obs > 5e-4 and FIR.pacs160_obs < 1e6 and FIR.gal_id = galprop.gal_id and FIR.halo_id = galprop.halo_id ''' % reds else: query = '''select FIR.pacs160, galprop.tmerge, galprop.tmajmerge from FIR, galprop where %s and FIR.pacs160 > 8.8 and FIR.pacs160 < 13.0 and FIR.gal_id = galprop.gal_id and FIR.halo_id = galprop.halo_id ''' % reds #tmp tmp = reds.split() zz = N.mean(N.array([float(tmp[2]), float(tmp[6])])) #get data data = sq.get_data_sqliteSMNfunctions(path, db, query) if obs: x = N.log10(data[:, 0] * 1e3) else: x = data[:, 0] tmerge = data[:, 1] tmajor = data[:, 2] print N.min(x), N.max(x) #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) print xbin[i] mids, numbs = dm.binAndReturnMergerFractions2(x, nomergeMask, mergersMask, majorsMask, mergersMask2, majorsMask2, N.min(x), N.max(x), xbin[i], False) #the fraction of mergers noMergerFraction = [float(x[1]) / x[0] for x in numbs] mergerFraction = [float(x[2]) / x[0] for x in numbs] majorMergerFraction = [float(x[3]) / x[0] for x in numbs] mergerFraction2 = [float(x[4]) / x[0] for x in numbs] majorMergerFraction2 = [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 #plots ax1.plot(mids, majorMergerFraction, label='$z = %.1f$' % zz) ax2.plot(mids, majorMergerFraction2, label='$z = %.1f$' % zz) ax3.plot(mids, mergerFraction, label='$z = %.1f$' % zz) if neverMerged: ax4.plot(mids, noMergerFraction, label='$z = %.1f$' % zz) else: ax4.plot(mids, mergerFraction2, label='$z = %.1f$' % zz) #set obs limit if obs: ax1.axvline(N.log10(fluxlimit), ls=':', color='green') ax2.axvline(N.log10(fluxlimit), ls=':', color='green') ax3.axvline(N.log10(fluxlimit), ls=':', color='green') ax4.axvline(N.log10(fluxlimit), ls=':', color='green') #labels if obs: ax3.set_xlabel('$\log_{10}(S_{160} \ [\mathrm{mJy}])$') ax4.set_xlabel('$\log_{10}(S_{160} \ [\mathrm{mJy}])$') else: ax3.set_xlabel('$\log_{10}(L_{160} \ [L_{\odot}])$') ax4.set_xlabel('$\log_{10}(L_{160} \ [L_{\odot}])$') ax1.set_ylabel('$\mathrm{Merger\ Fraction}$') ax3.set_ylabel('$\mathrm{Merger\ Fraction}$') ax2.set_yticklabels([]) ax4.set_yticklabels([]) ax1.set_xticklabels([]) ax2.set_xticklabels([]) #texts P.text( 0.5, 0.94, '$\mathrm{Major\ mergers:}\ T_{\mathrm{merge}} \leq %i \ \mathrm{Myr}$' % (mergetimelimit * 1000.), horizontalalignment='center', verticalalignment='center', transform=ax1.transAxes) P.text( 0.5, 0.94, '$\mathrm{Major\ mergers:}\ T_{\mathrm{merge}} > %i \ \mathrm{Myr}$' % (mergetimelimit * 1000.), horizontalalignment='center', verticalalignment='center', transform=ax2.transAxes) P.text( 0.5, 0.94, '$\mathrm{Minor\ mergers:}\ T_{\mathrm{merge}} \leq %i \ \mathrm{Myr}$' % (mergetimelimit * 1000.), horizontalalignment='center', verticalalignment='center', transform=ax3.transAxes) if neverMerged: P.text(0.5, 0.94, '$\mathrm{Never\ Merged}$', horizontalalignment='center', verticalalignment='center', transform=ax4.transAxes) else: P.text( 0.5, 0.94, '$\mathrm{Minor\ mergers:}\ T_{\mathrm{merge}} > %i \ \mathrm{Myr}$' % (mergetimelimit * 1000.), horizontalalignment='center', verticalalignment='center', transform=ax4.transAxes) #set limits ax1.set_xlim(xmin, xmax) ax1.set_ylim(-0.01, 0.95) ax2.set_xlim(xmin, xmax) ax2.set_ylim(-0.01, 0.95) ax3.set_xlim(xmin, xmax) ax3.set_ylim(-0.01, 0.95) ax4.set_xlim(xmin, xmax) ax4.set_ylim(-0.01, 0.95) #make legend and save the figure ax3.legend(loc='center left') P.savefig(out_folder + outname + type)
def plotMergerFractions3(query, xlabel, ylabel, output, out_folder, mergetimelimit=0.4, 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) 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.1, 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='0.5', width=wd) #, hatch = '/') ax1.bar(mids, mergerFraction2, align='center', bottom=noMergerFraction, label='Minor Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.), color='0.7', width=wd) #, hatch = '|') ax1.bar(mids, majorMergerFraction2, align='center', bottom=noMergerFraction + mergerFraction2, label='Major Merger: $T > %.0f$ Myr' % (mergetimelimit * 1000.), color='0.9', width=wd) #, hatch = '-') ax1.bar(mids, majorMergerFraction, align='center', bottom=noMergerFraction + mergerFraction2 + majorMergerFraction2, label='Major Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.), color='green', width=wd) #, hatch = '.') ax1.bar(mids, mergerFraction, bottom=noMergerFraction + mergerFraction2 + majorMergerFraction2 + majorMergerFraction, align='center', label='Minor Merger: $T \leq %.0f$ Myr' % (mergetimelimit * 1000.), color='red', width=wd) #, hatch = 'x') #labels ax1.set_xlabel(xlabel) ax1.set_ylabel(ylabel) 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='lower left') P.savefig(out_folder + output)