def CenSat_GroupCat(): ''' ''' # import centrals centrals = GroupCat(Mrcut=18, position='central') centrals.Read() # import satellites satellites = GroupCat(Mrcut=18, position='satellite') satellites.Read() N_cen = np.sum(centrals.mass >= 9.7) N_sat = np.sum(satellites.mass >= 9.7) print np.float(N_cen) / np.float(N_cen + N_sat)
def GroupCat_iSEDfitMatch(Mrcut=18, position='central'): ''' Test _iSEDfitMatch function of Group Catalog class object ''' grpcat = GroupCat(Mrcut=Mrcut, position=position) grpcat.Read() grpcat._iSEDfitMatch() return None
def PlotEvolvedSat(sg_obj): ''' Plot stuff for the evolved satellite population ''' #infall = np.where( # (sg_obj.first_infall_mass > 0.) & # (sg_obj.first_infall_sfr > -999.) & # (sg_obj.first_infall_t > 5.7)) infall = np.arange(len(sg_obj.first_infall_mass)) # SSFR plot ssfr_plot = PlotSSFR() ssfr_plot.plot(mass=sg_obj.mass[infall], ssfr=sg_obj.ssfr[infall], line_color=3) ssfr_plot.GroupCat(position='satellite') ssfr_plot.set_axes() ssfr_fig_name = ''.join([ 'figure/', 'SSFR.Satellite', '.ABC_posterior', '.', sg_obj.abcrun, '.', sg_obj.prior_name, '_prior', '.png' ]) ssfr_plot.save_fig(ssfr_fig_name) plt.close() # Quiescent fraction plot fq_plot = PlotFq() fq_plot.plot(mass=sg_obj.mass[infall], sfr=sg_obj.sfr[infall], z=sg_obj.zsnap, line_color='r', sfms_prop=sg_obj.sfms_prop, label='SHAM Sat. Simulation') grpcat = GroupCat(Mrcut=18, position='satellite') grpcat.Read() fq_plot.plot(mass=grpcat.mass, sfr=grpcat.sfr, z=np.median(grpcat.z), line_color='k', line_style='--', sfms_prop=sg_obj.sfms_prop, label='Satellite Group Catalog') fq_plot.set_axes() fq_fig_name = ''.join([ 'figure/', 'Fq.Satellite', '.ABC_posterior', '.', sg_obj.abcrun, '.', sg_obj.prior_name, '_prior', '.png' ]) fq_plot.save_fig(fq_fig_name) plt.close() return None
def CentralSFR(self): ''' Assign SFRs to central galaxies based on the SDSS DR7 observed central SFRs. ''' # central galaxy indices cen_index = np.where( (self.ilk >= 1.0) & (self.ilk < 2.01) ) self.cen_index = cen_index cen_mass = getattr(self, 'm.star')[cen_index] # import central SDSS DR7 galaxies sdss = GroupCat(Mrcut=18, position='central') sdss.Read() dlogm = 0.1 m_arr = np.arange(sdss.mass.min()-0.5*dlogm, 11.2+dlogm, dlogm) m_low = m_arr[:-1] m_high = m_arr[1:] self.sfr = np.repeat(-999., len(getattr(self, 'm.star'))) self.ssfr = np.repeat(-999., len(getattr(self, 'm.star'))) self.position = np.repeat(-1, len(getattr(self, 'm.star'))) self.position[cen_index] = 0 for im in range(len(m_low)): if im < len(m_low) - 1: sdss_bin = np.where((sdss.mass >= m_low[im]) & (sdss.mass < m_high[im])) subh_bin = np.where((cen_mass >= m_low[im]) & (cen_mass < m_high[im])) else: sdss_bin = np.where(sdss.mass >= m_low[im]) subh_bin = np.where(cen_mass >= m_low[im]) sdss_sfr = sdss.sfr[sdss_bin] dist, bin_edges = np.histogram( sdss_sfr, range=[-3., 3.], bins=50, normed=True) sfr_cdf = np.zeros(len(bin_edges)) sfr_cdf[1:] = np.cumsum(dist * np.diff(bin_edges)) cdf_interp = interp1d(sfr_cdf, bin_edges, kind='linear') rand_i = np.random.uniform(size=len(subh_bin[0])) cen_sfr = cdf_interp(rand_i) #print cen_sfr.min(), cen_sfr.max() self.sfr[cen_index[0][subh_bin]] = cen_sfr self.ssfr[cen_index[0][subh_bin]] = self.sfr[cen_index[0][subh_bin]] - getattr(self, 'm.star')[cen_index[0][subh_bin]] return None
def ABC(T, eps_input, Npart=1000, cen_tf=None, cen_prior_name=None, cen_abcrun=None): ''' ABC-PMC implementation. Parameters ---------- T : (int) Number of iterations eps_input : (float) Starting epsilon threshold value N_part : (int) Number of particles prior_name : (string) String that specifies what prior to use. abcrun : (string) String that specifies abc run information ''' abcinh = ABCInherit(cen_tf, abcrun=cen_abcrun, prior_name=cen_prior_name) # Data (Group Catalog Satellite fQ) grpcat = GroupCat(Mrcut=18, position='satellite') grpcat.Read() qfrac = Fq() m_bin = np.array([9.7, 10.1, 10.5, 10.9, 11.3]) M_mid = 0.5 * (m_bin[:-1] + m_bin[1:]) sfq = qfrac.Classify(grpcat.mass, grpcat.sfr, np.median(grpcat.z), sfms_prop=abcinh.sim_kwargs['sfr_prop']['sfms']) ngal, dum = np.histogram(grpcat.mass, bins=m_bin) ngal_q, dum = np.histogram(grpcat.mass[sfq == 'quiescent'], bins=m_bin) data_sum = [M_mid, ngal_q.astype('float') / ngal.astype('float')] # Simulator cen_assigned_sat_file = ''.join([ '/data1/hahn/pmc_abc/pickle/', 'satellite', '.cenassign', '.', cen_abcrun, '_ABC', '.', cen_prior_name, '_prior', '.p' ]) if not os.path.isfile(cen_assigned_sat_file): sat_cen = AssignCenSFR(cen_tf, abcrun=cen_abcrun, prior_name=cen_prior_name) pickle.dump(sat_cen, open(cen_assigned_sat_file, 'wb')) else: sat_cen = pickle.load(open(cen_assigned_sat_file, 'rb')) def Simz(tt): # Simulator (forward model) tqdel_dict = {'name': 'explin', 'm': tt[0], 'b': tt[1]} sat_evol = EvolveSatSFR(sat_cen, tqdelay_dict=tqdel_dict) sfq_sim = qfrac.Classify(sat_evol.mass, sat_evol.sfr, sat_evol.zsnap, sfms_prop=sat_evol.sfms_prop) ngal_sim, dum = np.histogram(sat_evol.mass, bins=m_bin) ngal_q_sim, dum = np.histogram(sat_evol.mass[sfq_sim == 'quiescent'], bins=m_bin) sim_sum = [ M_mid, ngal_q_sim.astype('float') / ngal_sim.astype('float') ] return sim_sum # Priors prior_min = [-11.75, 2.] prior_max = [-10.25, 4.] prior = abcpmc.TophatPrior(prior_min, prior_max) # ABCPMC prior object def rho(simum, datum): datum_dist = datum[1] simum_dist = simum[1] drho = np.sum((datum_dist - simum_dist)**2) return drho abcrun_flag = cen_abcrun + '_central' theta_file = lambda pewl: ''.join([ code_dir(), 'dat/pmc_abc/', 'Satellite.tQdelay.theta_t', str(pewl), '_', abcrun_flag, '.dat' ]) w_file = lambda pewl: ''.join([ code_dir(), 'dat/pmc_abc/', 'Satellite.tQdelay.w_t', str(pewl), '_', abcrun_flag, '.dat' ]) dist_file = lambda pewl: ''.join([ code_dir(), 'dat/pmc_abc/', 'Satellite.tQdelay.dist_t', str(pewl), '_', abcrun_flag, '.dat' ]) eps_file = ''.join([ code_dir(), 'dat/pmc_abc/Satellite.tQdelay.epsilon_', abcrun_flag, '.dat' ]) eps = abcpmc.ConstEps(T, eps_input) try: mpi_pool = mpi_util.MpiPool() abcpmc_sampler = abcpmc.Sampler( N=Npart, # N_particles Y=data_sum, # data postfn=Simz, # simulator dist=rho, # distance function pool=mpi_pool) except AttributeError: abcpmc_sampler = abcpmc.Sampler( N=Npart, # N_particles Y=data_sum, # data postfn=Simz, # simulator dist=rho) # distance function abcpmc_sampler.particle_proposal_cls = abcpmc.ParticleProposal pools = [] f = open(eps_file, "w") f.close() eps_str = '' for pool in abcpmc_sampler.sample(prior, eps, pool=None): print '----------------------------------------' print 'eps ', pool.eps new_eps_str = '\t' + str(pool.eps) + '\n' if eps_str != new_eps_str: # if eps is different, open fiel and append f = open(eps_file, "a") eps_str = new_eps_str f.write(eps_str) f.close() print("T:{0},ratio: {1:>.4f}".format(pool.t, pool.ratio)) print eps(pool.t) # write theta, weights, and distances to file np.savetxt(theta_file(pool.t), pool.thetas, header='tQdelay_slope, tQdelay_offset') np.savetxt(w_file(pool.t), pool.ws) np.savetxt(dist_file(pool.t), pool.dists) # update epsilon based on median thresholding eps.eps = np.median(pool.dists) pools.append(pool) return pools
def PlotABC_EvolvedSat(tf, cen_tf=7, cen_abcrun=None, cen_prior_name=None): ''' Plot stuff for the evolved satellite population ''' # Simulator cen_assigned_sat_file = ''.join([ '/data1/hahn/pmc_abc/pickle/', 'satellite', '.cenassign', '.', cen_abcrun, '_ABC', '.', cen_prior_name, '_prior', '.p' ]) if not os.path.isfile(cen_assigned_sat_file): sat_cen = AssignCenSFR(cen_tf, abcrun=cen_abcrun, prior_name=cen_prior_name) pickle.dump(sat_cen, open(cen_assigned_sat_file, 'wb')) else: sat_cen = pickle.load(open(cen_assigned_sat_file, 'rb')) abcrun_flag = cen_abcrun + '_central' theta_file = lambda pewl: ''.join([ code_dir(), 'dat/pmc_abc/', 'Satellite.tQdelay.theta_t', str(pewl), '_', abcrun_flag, '.dat' ]) theta = np.loadtxt(theta_file(tf)) med_theta = [np.median(theta[:, i]) for i in range(len(theta[0]))] abc_tqdelay_dict = {'name': 'explin', 'm': med_theta[0], 'b': med_theta[1]} sg_obj = EvolveSatSFR(sat_cen, tqdelay_dict=abc_tqdelay_dict) #infall = np.arange(len(sg_obj.first_infall_mass)) infall = np.where( (sg_obj.first_infall_mass > 0.) & (sg_obj.first_infall_sfr > -999.)) # & (sg_obj.first_infall_t > 5.7)) print len(sg_obj.first_infall_mass) print len(infall[0]) # SSFR plot ssfr_plot = PlotSSFR() ssfr_plot.plot(mass=sg_obj.mass[infall], ssfr=sg_obj.ssfr[infall], line_color=3) ssfr_plot.GroupCat(position='satellite') ssfr_plot.set_axes() ssfr_fig_name = ''.join([ 'figure/', 'SSFR.Satellite', '.tQdelayABC', '.', sg_obj.abcrun, '.', sg_obj.prior_name, '_prior', '.png' ]) ssfr_plot.save_fig(ssfr_fig_name) plt.close() # Quiescent fraction plot fq_plot = PlotFq() fq_plot.plot(mass=sg_obj.mass[infall], sfr=sg_obj.sfr[infall], z=sg_obj.zsnap, line_color='r', sfms_prop=sg_obj.sfms_prop, label='SHAM Sat. Simulation') grpcat = GroupCat(Mrcut=18, position='satellite') grpcat.Read() fq_plot.plot(mass=grpcat.mass, sfr=grpcat.sfr, z=np.median(grpcat.z), line_color='k', line_style='--', sfms_prop=sg_obj.sfms_prop, label='Satellite Group Catalog') fq_plot.set_axes() fq_fig_name = ''.join([ 'figure/', 'Fq.Satellite', '.tQdelayABC', '.', sg_obj.abcrun, '.', sg_obj.prior_name, '_prior', '.png' ]) fq_plot.save_fig(fq_fig_name) plt.close() return None
def DescendantQAplot(nsnap_descendants, **sfinh_kwargs): ''' The ultimate QAplot t rule them all. 4 panels showing all the properties. ''' sfinherit_file = InheritSF_file(nsnap_descendants, **sfinh_kwargs) bloodline = Lineage(nsnap_ancestor=sfinh_kwargs['nsnap_ancestor'], subhalo_prop=sfinh_kwargs['subhalo_prop']) if not isinstance(nsnap_descendants, list): nsnap_descendants = [nsnap_descendants] bloodline.Read(nsnap_descendants, filename=sfinherit_file) for nsnap_descendant in nsnap_descendants: descendant = getattr(bloodline, 'descendant_snapshot' + str(nsnap_descendant)) descendant.sfr_prop = sfinh_kwargs['sfr_prop'] started_here = np.where( descendant.nsnap_genesis == sfinh_kwargs['nsnap_ancestor']) start_mass = descendant.mass_genesis[started_here] # Mass bins mass_bins = np.arange(7., 12.5, 0.5) mass_bin_low = mass_bins[:-1] mass_bin_high = mass_bins[1:] plt.close() prettyplot() fig = plt.figure(1, figsize=[25, 6]) for i_sub in range(1, 5): sub_i = fig.add_subplot(1, 4, i_sub) if i_sub == 1: # SMF mf = SMF() mass, phi = mf.Obj(descendant) sub_i.plot(mass, phi, lw=4, c=pretty_colors[descendant.nsnap], label=r'Simulated') censub = CentralSubhalos() censub.Read(descendant.nsnap, scatter=sfinh_kwargs['subhalo_prop']['scatter'], source=sfinh_kwargs['subhalo_prop']['source'], nsnap_ancestor=sfinh_kwargs['nsnap_ancestor']) mass, phi = mf._smf(censub.mass) sub_i.plot(mass, phi, c='k', lw=4, ls='--', label='Central Subhalos') sub_i.set_ylim([10**-5, 10**-1]) sub_i.set_xlim([7.5, 12.0]) plt.xticks([8., 9., 10., 11., 12.]) sub_i.set_yscale('log') # x,y labels sub_i.set_xlabel(r'Mass $\mathtt{M_*}$', fontsize=25) sub_i.set_ylabel(r'Stellar Mass Function $\mathtt{\Phi}$', fontsize=25) sub_i.legend(loc='upper right', frameon=False) elif i_sub == 2: # SFMS # SMF composition based on their initial mass at nsnap_ancestor for i_m in range(len(mass_bin_low)): mbin = np.where((start_mass > mass_bin_low[i_m]) & (start_mass <= mass_bin_high[i_m])) sub_i.scatter(descendant.mass[started_here[0][mbin]], descendant.sfr[started_here[0][mbin]], color=pretty_colors[i_m], label=r"$\mathtt{M_{*,i}=}$" + str(round(mass_bin_low[i_m], 2)) + "-" + str(round(mass_bin_high[i_m], 2))) qfrac = Fq() m_arr = np.arange(9.0, 12.5, 0.5) sub_i.plot(m_arr, qfrac.SFRcut( m_arr, descendant.zsnap, sfms_prop=(sfinh_kwargs['sfr_prop'])['sfms']), c='k', ls='--', lw=4) sub_i.set_xlim([9.0, 12.0]) sub_i.set_ylim([-5.0, 2.0]) sub_i.set_xlabel(r'$\mathtt{log\;M_*}$', fontsize=25) sub_i.set_ylabel(r'$\mathtt{log\;SFR}$', fontsize=25) elif i_sub == 3: #SMHM for i_m in range(len(mass_bin_low)): mbin = np.where((start_mass > mass_bin_low[i_m]) & (start_mass <= mass_bin_high[i_m])) sub_i.scatter(descendant.halo_mass[started_here[0][mbin]], descendant.mass[started_here[0][mbin]], color=pretty_colors[i_m], label=r"$\mathtt{M_{*,i}=}$" + str(round(mass_bin_low[i_m], 2)) + "-" + str(round(mass_bin_high[i_m], 2))) stellarmass = descendant.mass[started_here] halomass = descendant.halo_mass[started_here] mbin = np.arange(halomass.min(), halomass.max(), 0.25) mlow = mbin[:-1] mhigh = mbin[1:] muMstar = np.zeros(len(mlow)) sigMstar = np.zeros(len(mlow)) for im in range(len(mlow)): mbin = np.where((halomass > mlow[im]) & (halomass <= mhigh[im])) muMstar[im] = np.mean(stellarmass[mbin]) sigMstar[im] = np.std(stellarmass[mbin]) sub_i.errorbar(0.5 * (mlow + mhigh), muMstar, yerr=sigMstar, color='k', lw=3, fmt='o', capthick=2) sub_i.set_ylim([9.0, 12.0]) sub_i.set_xlim([10.0, 15.0]) sub_i.set_ylabel(r'Stellar Mass $\mathtt{M_*}$', fontsize=25) sub_i.set_xlabel(r'Halo Mass $\mathtt{M_{Halo}}$', fontsize=25) #sub_i.legend(loc='upper left', frameon=False, scatterpoints=1) elif i_sub == 4: # Fq #mass, fq = descendant.Fq() sfq = qfrac.Classify(descendant.mass, descendant.sfr, descendant.zsnap, sfms_prop=descendant.sfr_prop['sfms']) gc = GroupCat(Mrcut=18, position='central') gc.Read() gc_sfq = qfrac.Classify(gc.mass, gc.sfr, np.mean(gc.z), sfms_prop=descendant.sfr_prop['sfms']) #sub_i.plot(mass, fq, color=pretty_colors[descendant.nsnap], lw=3, ls='--', # label=r'$\mathtt{z =} '+str(descendant.zsnap)+'$') M_bin = np.array([9.7, 10.1, 10.5, 10.9, 11.3]) M_low = M_bin[:-1] M_high = M_bin[1:] M_mid = 0.5 * (M_low + M_high) fq = np.zeros(len(M_low)) gc_fq = np.zeros(len(M_low)) for i_m in xrange(len(M_low)): mlim = np.where((descendant.mass > M_low[i_m]) & (descendant.mass <= M_high[i_m])) gc_mlim = np.where((gc.mass > M_low[i_m]) & (gc.mass <= M_high[i_m])) ngal = np.float(len(mlim[0])) gc_ngal = np.float(len(gc_mlim[0])) if ngal != 0: # no galaxy in mass bin ngal_q = np.float( len(np.where(sfq[mlim] == 'quiescent')[0])) fq[i_m] = ngal_q / ngal if gc_ngal != 0: gc_ngal_q = np.float( len(np.where(gc_sfq[gc_mlim] == 'quiescent')[0])) gc_fq[i_m] = gc_ngal_q / gc_ngal sub_i.plot(M_mid, fq, color=pretty_colors[descendant.nsnap], lw=3, label=r'$\mathtt{z =} ' + str(descendant.zsnap) + '$') fq_model = qfrac.model( M_bin, descendant.zsnap, lit=sfinh_kwargs['sfr_prop']['fq']['name']) sub_i.plot(M_bin, fq_model, color='k', lw=4, ls='--', label=sfinh_kwargs['sfr_prop']['fq']['name']) sub_i.scatter(M_mid, gc_fq, color='k', s=100, lw=0, label='Group Catalog') sub_i.set_xlim([9.0, 12.0]) sub_i.set_ylim([0.0, 1.0]) sub_i.set_xlabel(r'Mass $\mathtt{M_*}$') sub_i.set_ylabel(r'Quiescent Fraction $\mathtt{f_Q}$', fontsize=20) sub_i.legend(loc='upper left', frameon=False, scatterpoints=1, markerscale=0.75) plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0) fig_name = ''.join([ 'figure/test/', 'QAplot.', '.nsnap', str(nsnap_descendant), '.'.join( (sfinherit_file.rsplit('/')[-1]).rsplit('.')[:-1]), '.png' ]) fig.savefig(fig_name, bbox_inches='tight') plt.close() return None
def GroupCat_SalimMatch(galprop, lit='uv', Mrcut=18, position='central'): ''' ''' grpcat = GroupCat(Mrcut=Mrcut, position=position) grpcat.Read() grpcat._Match_OtherSFR(lit=lit) hasmatch = np.where(getattr(grpcat, lit + '_match') >= 0)[0] prettyplot() pretty_colors = prettycolors() fig = plt.figure(figsize=(10, 10)) bkgd = fig.add_subplot(111, frameon=False) bkgd.tick_params(labelcolor='none', top='off', bottom='off', left='off', right='off') fig.subplots_adjust(hspace=0., wspace=0.) if galprop == 'mass': subs = [fig.add_subplot(2, 2, i_mass + 1) for i_mass in xrange(4)] mass_bins = [[9.7, 10.1], [10.1, 10.5], [10.5, 10.9], [10.9, 11.3]] for i_mass, mbin in enumerate(mass_bins): mbin = np.where((grpcat.mass[hasmatch] > mass_bins[i_mass][0]) & (grpcat.mass[hasmatch] < mass_bins[i_mass][-1])) subs[i_mass].scatter(grpcat.mass[hasmatch[mbin]], getattr(grpcat, lit + '_mass')[hasmatch[mbin]], color=pretty_colors[3], s=4) subs[i_mass].plot([9., 12.], [9., 12.], color='k', lw=4, ls='--') subs[i_mass].set_xlim([9., 12.]) subs[i_mass].set_ylim([9., 12.]) subs[i_mass].set_xticks([9., 10., 11., 12.]) subs[i_mass].set_yticks([9., 10., 11., 12.]) massbin_str = ''.join([ r'$\mathtt{log \; M^{VAGC}_{*} = [', str(mass_bins[i_mass][0]), ',\;', str(mass_bins[i_mass][1]), ']}$' ]) subs[i_mass].text(9.2, 11.6, massbin_str, fontsize=15) if i_mass == 0: subs[i_mass].set_xticklabels([]) elif i_mass == 1: subs[i_mass].set_xticklabels([]) subs[i_mass].set_yticklabels([]) elif i_mass == 3: subs[i_mass].set_yticklabels([]) bkgd.set_ylabel(lit + ' $\mathcal{M}_*$', fontsize=30) bkgd.set_xlabel('VAGC $\mathcal{M}_*$', fontsize=30) elif galprop == 'ssfr': subs = [fig.add_subplot(2, 2, i_mass + 1) for i_mass in xrange(4)] mass_bins = [[9.7, 10.1], [10.1, 10.5], [10.5, 10.9], [10.9, 11.3]] for i_mass, mbin in enumerate(mass_bins): mbin = np.where((grpcat.mass[hasmatch] > mass_bins[i_mass][0]) & (grpcat.mass[hasmatch] < mass_bins[i_mass][-1])) subs[i_mass].scatter(grpcat.ssfr[hasmatch[mbin]], getattr(grpcat, lit + '_ssfr')[hasmatch[mbin]], color=pretty_colors[3], s=4) subs[i_mass].plot([-13., -9.], [-13., -9.], color='k', lw=4, ls='--') subs[i_mass].set_xlim([-13., -9.]) subs[i_mass].set_ylim([-13., -9.]) massbin_str = ''.join([ r'$\mathtt{log \; M^{VAGC}_{*} = [', str(mass_bins[i_mass][0]), ',\;', str(mass_bins[i_mass][1]), ']}$' ]) subs[i_mass].text(-12.8, -9.5, massbin_str, fontsize=15) subs[i_mass].set_xticks([-13, -12, -11, -10, -9]) subs[i_mass].set_yticks([-13, -12, -11, -10, -9]) if i_mass == 0: subs[i_mass].set_xticklabels([]) elif i_mass == 1: subs[i_mass].set_xticklabels([]) subs[i_mass].set_yticklabels([]) elif i_mass == 3: subs[i_mass].set_yticklabels([]) bkgd.set_ylabel(lit + ' SSFR', fontsize=30) bkgd.set_xlabel('VAGC SSFR ', fontsize=30) elif galprop == 'sfr': subs = [fig.add_subplot(2, 2, i_mass + 1) for i_mass in xrange(4)] mass_bins = [[9.7, 10.1], [10.1, 10.5], [10.5, 10.9], [10.9, 11.3]] for i_mass, mbin in enumerate(mass_bins): mbin = np.where((grpcat.mass[hasmatch] > mass_bins[i_mass][0]) & (grpcat.mass[hasmatch] < mass_bins[i_mass][-1])) subs[i_mass].scatter(grpcat.sfr[hasmatch[mbin]], getattr(grpcat, lit + '_sfr')[hasmatch[mbin]], color=pretty_colors[3], s=4) subs[i_mass].plot([-3., 2.], [-3., 2.], color='k', lw=4, ls='--') subs[i_mass].set_xlim([-3., 3.]) subs[i_mass].set_ylim([-3., 3.]) massbin_str = ''.join([ r'$\mathtt{log \; M^{VAGC}_{*} = [', str(mass_bins[i_mass][0]), ',\;', str(mass_bins[i_mass][1]), ']}$' ]) subs[i_mass].text(-12.8, -9.5, massbin_str, fontsize=15) subs[i_mass].set_xticks([-3, -2, -1, 0, 1, 2, 3]) subs[i_mass].set_yticks([-3, -2, -1, 0, 1, 2, 3]) if i_mass == 0: subs[i_mass].set_xticklabels([]) elif i_mass == 1: subs[i_mass].set_xticklabels([]) subs[i_mass].set_yticklabels([]) elif i_mass == 3: subs[i_mass].set_yticklabels([]) bkgd.set_ylabel(lit + ' SFR', fontsize=30) bkgd.set_xlabel('VAGC SFR ', fontsize=30) fig_file = ''.join([ 'figure/test/', 'Salim_Comparison', '.Mr', str(Mrcut), '.', position, '.', galprop, '.', lit, '.png' ]) fig.savefig(fig_file, bbox_inches='tight', dpi=150) return None
def GroupCat_SalimMatch_SFR(Mrcut=18, position='central'): ''' Compare the SSFr distribution ''' grpcat = GroupCat(Mrcut=Mrcut, position=position) grpcat.Read() grpcat._Match_OtherSFR(lit='salim2016') grpcat._Match_OtherSFR(lit='uv') print len(np.where(grpcat.uv_match != -999)[0]) prettyplot() pretty_colors = prettycolors() fig = plt.figure(figsize=(16, 16)) fig.subplots_adjust(hspace=0., wspace=0.) subs = [fig.add_subplot(2, 2, i_mass + 1) for i_mass in xrange(4)] mass_bins = [[9.7, 10.1], [10.1, 10.5], [10.5, 10.9], [10.9, 11.3]] for i_mass, mbin in enumerate(mass_bins): in_massbin = np.where((grpcat.mass > mass_bins[i_mass][0]) & (grpcat.mass <= mass_bins[i_mass][1]) & (grpcat.salim2016_match != -999) & (grpcat.uv_match != -999)) vagc_dist, bin_edges = np.histogram(grpcat.sfr[in_massbin], range=[-3., 3.], bins=40, normed=True) salim_dist, bin_edges = np.histogram(grpcat.salim2016_sfr[in_massbin], range=[-3., 3.], bins=40, normed=True) uv_dist, bin_edges = np.histogram(grpcat.uv_sfr[in_massbin], range=[-3., 3.], bins=40, normed=True) subs[i_mass].plot(0.5 * (bin_edges[:-1] + bin_edges[1:]), vagc_dist, color='k', lw=4, ls='-') subs[i_mass].plot(0.5 * (bin_edges[:-1] + bin_edges[1:]), salim_dist, color=pretty_colors[3], lw=4, ls='--') subs[i_mass].plot(0.5 * (bin_edges[:-1] + bin_edges[1:]), uv_dist, color=pretty_colors[5], lw=4, ls=':') #subs[i_mass].plot(salim_bin[i_mass], salim_ssfr[i_mass], color='r', lw=4, ls='--') subs[i_mass].set_xlim([-3., 3.]) subs[i_mass].set_ylim([0.0, 1.6]) massbin_str = ''.join([ r'$\mathtt{log \; M_{*} = [', str(mass_bins[i_mass][0]), ',\;', str(mass_bins[i_mass][1]), ']}$' ]) subs[i_mass].text(-1.5, 1.4, massbin_str, fontsize=24) if i_mass == 0: subs[i_mass].set_ylabel(r'$\mathtt{P(log \; SFR)}$', fontsize=20) subs[i_mass].set_xticklabels([]) elif i_mass == 1: subs[i_mass].set_xticklabels([]) subs[i_mass].set_yticklabels([]) elif i_mass == 2: #sub.set_yticklabels([]) subs[i_mass].set_ylabel(r'$\mathtt{P(log \; SFR)}$', fontsize=20) subs[i_mass].set_xlabel(r'$\mathtt{log \; SFR \;[yr^{-1}]}$', fontsize=20) else: subs[i_mass].set_yticklabels([]) subs[i_mass].set_xlabel(r'$\mathtt{log \; SFR \;[yr^{-1}]}$', fontsize=20) fig_file = ''.join([ 'figure/test/', 'SFR_comparison', '.Mr', str(Mrcut), '.', position, '.png' ]) fig.savefig(fig_file, bbox_inches='tight', dpi=150) #plt.show() return None
def QAplot(descendant, sfinh_kwargs, fig_name=None, **kwargs): ''' Given galpop object and the SF Inheritance parametes, plot its SMF, ''' # Mass bins mass_bins = np.arange(7., 12.5, 0.5) mass_bin_low = mass_bins[:-1] mass_bin_high = mass_bins[1:] plt.close() prettyplot() fig = plt.figure(1, figsize=[20,12]) for i_sub in range(1,6): sub_i = fig.add_subplot(2,3,i_sub) if i_sub == 1: # SMF mf = SMF() mass, phi = mf.Obj(descendant) sub_i.plot(mass, phi, lw=4, c='r', label=r'Simulated') censub = CentralSubhalos() censub.Read(descendant.nsnap, scatter=sfinh_kwargs['subhalo_prop']['scatter'], source=sfinh_kwargs['subhalo_prop']['source'], nsnap_ancestor=sfinh_kwargs['nsnap_ancestor']) mass, phi = mf._smf(censub.mass) sub_i.plot(mass, phi, c='k', lw=4, ls='--', label='Central Subhalos') sub_i.set_ylim([10**-5, 10**-1]) sub_i.set_xlim([7.5, 12.0]) plt.xticks([8., 9., 10., 11., 12.]) sub_i.set_yscale('log') # x,y labels sub_i.set_ylabel(r'Stellar Mass ($\mathtt{log\; M_*}$)', fontsize=20) sub_i.set_ylabel(r'Stellar Mass Function $\mathtt{\Phi}$', fontsize=20) sub_i.legend(loc='upper right', frameon=False) elif i_sub == 2: # SFMS # SMF composition based on their initial mass at nsnap_ancestor # random subsample n_tot = len(descendant.mass) r_subsample = np.random.choice(n_tot, size=100000) sub_i.scatter(descendant.mass[r_subsample], descendant.sfr[r_subsample], color='b', s=0.5) qfrac = Fq() m_arr = np.arange(9.0, 12.5, 0.5) sub_i.plot( m_arr, qfrac.SFRcut(m_arr, descendant.zsnap, sfms_prop=(sfinh_kwargs['sfr_prop'])['sfms']), c='k', ls='--', lw=4) sub_i.text(10.5, -4., r'$\mathtt{z='+str(descendant.zsnap)+'}$', fontsize=25) sub_i.set_xlim([9.0, 12.0]) sub_i.set_ylim([-5.0, 2.0]) sub_i.set_ylabel(r'Stellar Mass ($\mathtt{log\; M_*}$)', fontsize=20) sub_i.set_ylabel(r'$\mathtt{log\;SFR}$', fontsize=20) elif i_sub == 3: #SMHM #corner.hist2d(descendant.halo_mass, descendant.mass, ax=sub_i, c='b', fill_contours=True, smooth=1.0) n_tot = len(descendant.mass) r_subsample = np.random.choice(n_tot, size=100000) sub_i.scatter(descendant.halo_mass[r_subsample], descendant.mass[r_subsample], color='b', s=0.5) stellarmass = descendant.mass halomass = descendant.halo_mass mbin = np.arange(halomass.min(), halomass.max(), 0.25) mlow = mbin[:-1] mhigh = mbin[1:] muMstar = np.zeros(len(mlow)) sigMstar = np.zeros(len(mlow)) for im in range(len(mlow)): mbin = np.where((halomass > mlow[im]) & (halomass <= mhigh[im])) muMstar[im] = np.mean(stellarmass[mbin]) sigMstar[im] = np.std(stellarmass[mbin]) sub_i.errorbar(0.5*(mlow+mhigh), muMstar, yerr=sigMstar, color='k', lw=3, fmt='o', capthick=2) sub_i.set_ylim([9.0, 12.0]) sub_i.set_xlim([10.0, 15.0]) sub_i.set_ylabel(r'Stellar Mass ($\mathtt{log\; M_*}$)', fontsize=20) sub_i.set_xlabel(r'Halo Mass ($\mathtt{log\;M_{Halo}}$)', fontsize=20) elif i_sub == 4: # Fq sfq = qfrac.Classify(descendant.mass, descendant.sfr, descendant.zsnap, sfms_prop=descendant.sfr_prop['sfms']) gc = GroupCat(Mrcut=18, position='central') gc.Read() gc_sfq = qfrac.Classify(gc.mass, gc.sfr, np.mean(gc.z), sfms_prop=descendant.sfr_prop['sfms']) #sub_i.plot(mass, fq, color=pretty_colors[descendant.nsnap], lw=3, ls='--', # label=r'$\mathtt{z =} '+str(descendant.zsnap)+'$') M_bin = np.array([9.7, 10.1, 10.5, 10.9, 11.3]) M_low = M_bin[:-1] M_high = M_bin[1:] M_mid = 0.5 * (M_low + M_high) fq = np.zeros(len(M_low)) gc_fq = np.zeros(len(M_low)) for i_m in xrange(len(M_low)): mlim = np.where((descendant.mass > M_low[i_m]) & (descendant.mass <= M_high[i_m])) gc_mlim = np.where((gc.mass > M_low[i_m]) & (gc.mass <= M_high[i_m])) ngal = np.float(len(mlim[0])) gc_ngal = np.float(len(gc_mlim[0])) if ngal != 0: # no galaxy in mass bin ngal_q = np.float(len(np.where(sfq[mlim] == 'quiescent')[0])) fq[i_m] = ngal_q/ngal if gc_ngal != 0: gc_ngal_q = np.float(len(np.where(gc_sfq[gc_mlim] == 'quiescent')[0])) gc_fq[i_m] = gc_ngal_q/gc_ngal sub_i.plot(M_mid, fq, color='r', lw=3, label=r'Simulated') # fQ of the Group Catalog sub_i.scatter(M_mid, gc_fq, color='k', s=100, lw=0, label='Group Catalog') # fQ of the model (input) fQ fq_model = qfrac.model(M_bin, descendant.zsnap, lit=sfinh_kwargs['sfr_prop']['fq']['name']) sub_i.plot(M_bin, fq_model, color='k', lw=4, ls='--', label=sfinh_kwargs['sfr_prop']['fq']['name'].replace('_', ' ').title() ) sub_i.set_xlim([9.0, 12.0]) sub_i.set_ylim([0.0, 1.0]) sub_i.set_ylabel(r'Stellar Mass ($\mathtt{log\; M_*}$)', fontsize=20) sub_i.set_ylabel(r'Quiescent Fraction $\mathtt{f_Q}$', fontsize=20) sub_i.legend(loc='upper left', frameon=False, scatterpoints=1, markerscale=0.75) elif i_sub == 5: # Tau_Q(M*) mass_bin = np.arange(9.0, 12.0, 0.1) tau_m = getTauQ(mass_bin, tau_prop=sfinh_kwargs['evol_prop']['tau']) sub_i.plot(10**mass_bin, tau_m, color='r', lw=4, label='Simulated') if 'taus' in kwargs: tau_slopes, tau_offsets = kwargs['taus'] i_tau_ms = np.zeros((len(mass_bin), len(tau_slopes))) for i_tau in range(len(tau_slopes)): i_tau_prop = sfinh_kwargs['evol_prop']['tau'].copy() i_tau_prop['slope'] = tau_slopes[i_tau] i_tau_prop['yint'] = tau_offsets[i_tau] i_tau_m = getTauQ(mass_bin, tau_prop=i_tau_prop) #sub_i.plot(10**mass_bin, i_tau_m, color='r', alpha=0.1, lw=2) i_tau_ms[:,i_tau] = i_tau_m sig_tau = np.zeros(len(mass_bin)) for im in range(len(mass_bin)): sig_tau[im] = np.std(i_tau_ms[im,:]) sub_i.errorbar(10**mass_bin, tau_m, yerr=sig_tau, color='r', lw=4) # satellite quenching fraction for comparison tau_sat = getTauQ(mass_bin, tau_prop={'name': 'satellite'}) sub_i.plot(10**mass_bin, tau_sat, color='black', lw=4, ls='--', label=r'Satellite (Wetzel+ 2013)') sub_i.set_xlim([10**9.5, 10**11.75]) sub_i.set_ylim([0.0, 2.0]) sub_i.set_xscale('log') sub_i.set_xlabel(r'Stellar Mass $[\mathtt{M_\odot}]$',fontsize=20) sub_i.legend(loc='upper right') sub_i.set_ylabel(r'Quenching Timescales $(\tau_\mathtt{Q})$ [Gyr]',fontsize=20) plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0) if fig_name is None: plt.show() plt.close() else: fig.savefig(fig_name, bbox_inches='tight') plt.close() return None