def main(): import numpy as np import h5py import matplotlib.pyplot as plt import custom_utilities as cu import sys group_cat = sys.argv[1] # tinker_mocks, berlind_mocks, yang_mocks catalogue = sys.argv[ 2] # Mr19_age_distribution_matching_mock, Mr19_age_distribution_matching_mock_sys_empty_shuffle_satrel_shuffle filename = catalogue + '_HTP' if group_cat == 'tinker_mocks': filepath = cu.get_output_path( ) + 'processed_data/tinker_groupcat/mock_runs/4th_run/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/tinker_groupcat/' plotpath = cu.get_plot_path() + 'analysis/tinker_groupcat/' catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind_mocks': filepath = cu.get_output_path( ) + 'processed_data/berlind_groupcat/mock_runs/4th_run/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/berlind_groupcat/' plotpath = cu.get_plot_path() + 'analysis/berlind_groupcat/' catalogue = catalogue + '_groups' if group_cat == 'yang_mocks': filepath = cu.get_output_path( ) + 'processed_data/yang_groupcat/mock_runs/4th_run/version_2/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/yang_groupcat/' plotpath = cu.get_plot_path() + 'analysis/yang_groupcat/' catalogue = catalogue + '_groups' print 'opening group catalogue:', catalogue #open catalogue f = h5py.File(filepath + catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue) #determine central/satellite designation group_centrals = np.where(GC['RANK'] == 1)[0] group_satellites = np.where(GC['RANK'] != 1)[0] halo_centrals = np.where(GC['HALO_RANK'] == 1)[0] halo_satellites = np.where(GC['HALO_RANK'] != 1)[0] #define group/halo mass bins mass_bins = np.arange(11, 15.2, 0.2) bin_width = mass_bins[1] - mass_bins[0] bin_centers = (mass_bins[:-1] - mass_bins[1:]) / 2.0 #calculate the HTP H_cc, H_sc, H_ss, H_cs = htp(GC['MGROUP'], GC['HALO_M'], group_centrals, group_satellites, halo_centrals, halo_satellites, mass_bins) #plot the results fig = plot_htp(H_cc, H_sc, H_ss, H_cs, mass_bins) plt.show() print plotpath + filename + '.eps' fig.savefig(plotpath + filename + '.eps')
def main(): catalogue = 'sm_9.49_s0.2_sfr_c0.0_250' filepath_mock = cu.get_output_path() + 'processed_data/campbell_mocks/' f = h5py.File(filepath_mock+catalogue+'.hdf5', 'r') #open catalogue file mock = f.get(catalogue) mock = np.array(mock) #get slice in z show = (mock['z']<10.0) fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.82, bottom=0.2, top=0.9) p = plt.scatter(mock['x'][show],mock['y'][show],c=mock['SSFR'][show],\ cmap='jet_r',vmax=-9.5, vmin=-12.5, marker='.',\ lw=0, s=6, rasterized=False) plt.xlim([0,250]) plt.ylim([0,250]) plt.xlabel(r'$h^{-1} {\rm Mpc}$') plt.ylabel(r'$h^{-1} {\rm Mpc}$') cbar_ax = fig.add_axes([0.83, 0.2, 0.02, 0.7]) #xmin, ymin, +dx, +dy cbar = fig.colorbar(p, cax=cbar_ax) plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = catalogue+'_slice' fig.savefig(savepath+filename+'.png',dpi=400)
def main(): catalogues = ['sm_9.5_s0.2_sfr_c-1.0_250','sm_9.5_s0.2_sfr_c-0.75_250',\ 'sm_9.5_s0.2_sfr_c-0.5_250','sm_9.5_s0.2_sfr_c-0.25_250',\ 'sm_9.5_s0.2_sfr_c0.0_250'] rhos = [-1.0,-0.75,-0.5,-0.25,0.0] fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.85, bottom=0.2, top=0.9) alphas = [1.0,0.8,0.6,0.4,0.2] p1s =[] p2s =[] for i, catalogue in enumerate(catalogues): #open mock filepath_mock = cu.get_output_path() + 'processed_data/campbell_mocks/' print('opening mock catalogue:', catalogue+'.hdf5') #open catalogue f = h5py.File(filepath_mock+catalogue+'.hdf5', 'r') #open catalogue file mock = f.get(catalogue) mock = np.array(mock) print(mock.dtype.names) #define host haloes and subhaloes hosts = (mock['upid']==-1) subs = (mock['upid']!=-1) #define SF and quenched subsamples LHS = -11.0 blue = np.where(mock['SSFR']>LHS)[0] red = np.where(mock['SSFR']<LHS)[0] #calculate satellite fraction bins = np.arange(9.5,12,0.1) bin_centers = (bins[:-1]+bins[1:])/2.0 f_cen_red = cu.f_prop(mock['Mstar'],bins,red,blue,hosts) f_sat_red = cu.f_prop(mock['Mstar'],bins,red,blue,subs) p1, = plt.plot(bin_centers,f_sat_red, color='orange', alpha=alphas[i]) p2, = plt.plot(bin_centers,f_cen_red, color='green', alpha=alphas[i]) p1s.append(p1) p2s.append(p2) rhos = (r'$\rho=-1.0$',r'$\rho=-0.75$',r'$\rho=-0.5$',r'$\rho=-0.25$',r'$\rho=0.0$') plt.legend(tuple(p1s),rhos, frameon=False, fontsize=10.0, loc=4, title='satellites',labelspacing=0.01) plt.xlim([9.5,11.5]) plt.ylim([0,1]) plt.xlabel(r'$M_{\rm *} [h^{-2}M_{\odot}]$') plt.ylabel(r'$f_{\rm q}$') plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'sat_quenching_rho_effect' fig.savefig(savepath+filename+'.pdf')
def main(): if len(sys.argv)==2: rho = 'NA' sigma = 'NA' catalogue = sys.argv[1] elif len(sys.argv)>2: rho = sys.argv[1] sigma = sys.argv[2] catalogue = 'sm_9.5_s'+str(sigma)+'_sfr_c'+str(rho)+'_250' else: catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250_cen_shuffle' #catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250' #catalogue = 'age_matching' #catalogue = 'sm_9.5_s0.2_sfr_c1.0_Halfmass_Scale_250' rho = -1.0 sigma = 0.2 #open mock filepath = cu.get_output_path() + 'processed_data/campbell_mocks/' f = h5py.File(filepath+catalogue+'.hdf5', 'r') #open catalogue file mock = f.get(catalogue) mock = np.array(mock) print(catalogue) print(mock.dtype.names) host = (mock['upid']==-1) sub = (mock['upid']!=-1) #plot stellar mass halo mass relation for the mock fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.78, bottom=0.2, top=0.9) p = plt.scatter(mock['mvir'][host],10.0**mock['Mstar'][host],c=mock['SSFR'][host],\ cmap='jet_r',vmax=-9.5, vmin=-12.5, marker='.', lw=0, s=2, rasterized=True) plt.text(10.0**10.0,5*10**11.0,r'$\rho_{\rm SSFR}=$'+str(rho)) plt.text(10.0**10.0,5*10**10.8,r'$\sigma_{\rm SMHM}=$'+str(sigma)) plt.xlabel(r'$M_{\rm vir}~[h^{-1}M_{\odot}]$') plt.ylabel(r'$M_{*} ~[h^{-2}M_{\odot}]$') plt.xlim([10.0**9.5,10.0**15.0]) plt.ylim([10.0**9.0,10.0**12.0]) plt.yscale('log') plt.xscale('log') plt.title("Mpeak-Vpeak mock") cbar_ax = fig.add_axes([0.79, 0.2, 0.02, 0.7]) #xmin, ymin, +dx, +dy cbar = fig.colorbar(p, cax=cbar_ax) cbar.set_label(r'$\log({\rm SSFR}/{\rm yr}^{-1})$') plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'SMHM' fig.savefig(savepath+filename+'.pdf')
def main(): #open SDSS results #read in SDSS projected two-point correlation function names = ['r','sm9.8','sm9.8err','sm10.2','sm10.2err','sm10.6','sm10.6err'] sdss_delta_sigma_sf= ascii.read("./Watson_2015_delta_sigma_sf.txt",names=names) sdss_delta_sigma_q= ascii.read("./Watson_2015_delta_sigma_q.txt",names=names) sdss_delta_sigma_all= ascii.read("./Hearin_2014_delta_sigma_all.txt",names=names) h=0.7 #for the SDSS measurements, make sure to scale correctly when plotting catalogues = ['sm_9.49_s0.2_sfr_c-1.0_250','sm_9.49_s0.2_sfr_c-0.75_250',\ 'sm_9.49_s0.2_sfr_c-0.5_250','sm_9.49_s0.2_sfr_c-0.25_250',\ 'sm_9.49_s0.2_sfr_c0.0_250'] samples = ['all','q','sf'] sm_thresholds = ['9.49','9.89','10.29'] fig1, axes = plt.subplots(nrows=1,ncols=3,sharex=True,sharey=True,figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05, left=0.1, right=0.95, bottom=0.2, top=0.9) r_all = sdss_delta_sigma_all['r']*h/1000.0 r_q = sdss_delta_sigma_q['r']*h/1000.0 r_sf = sdss_delta_sigma_sf['r']*h/1000.0 ax = axes[0] #ax.errorbar(r_all,sdss_delta_sigma_all['sm9.8']/h,\ # yerr=sdss_delta_sigma_all['sm9.8err']/h,\ # ms=3, fmt='o', color='black', mec='none') #ax.errorbar(r_q,sdss_delta_sigma_q['sm9.8']/h,\ # yerr=sdss_delta_sigma_q['sm9.8err']/h,\ # ms=3, fmt='o',color='red', mec='none') #ax.errorbar(r_sf,sdss_delta_sigma_sf['sm9.8']/h,\ # yerr=sdss_delta_sigma_sf['sm9.8err']/h,\ # ms=3, fmt='o',color='blue', mec='none') ax.set_xlim([0.1,2]) ax.set_ylim([1,100]) ax.set_yscale('log') ax.set_xscale('log') ax.set_ylabel(r'$\Delta\Sigma(r_p)~[M_{\odot}{\rm pc}^{-2}h]$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$\log(M_{*}~M_{\odot}h^{-2})>9.49$') ax = axes[1] #ax.errorbar(r_all,sdss_delta_sigma_all['sm10.2']/h,\ # yerr=sdss_delta_sigma_all['sm10.2err']/h,\ # ms=3, fmt='o', color='black', mec='none') #ax.errorbar(r_q,sdss_delta_sigma_q['sm10.2']/h,\ # yerr=sdss_delta_sigma_q['sm10.2err']/h,\ # ms=3, fmt='o',color='red', mec='none') #ax.errorbar(r_sf,sdss_delta_sigma_sf['sm10.2']/h,\ # yerr=sdss_delta_sigma_sf['sm10.2err']/h,\ # ms=3, fmt='o',color='blue', mec='none') ax.set_xlim([0.1,2]) ax.set_ylim([1,100]) ax.set_yscale('log') ax.set_xscale('log') #ax.set_ylabel(r'$\omega_p(r_p)$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$\log(M_{*}~M_{\odot}h^{-2})>9.89$') ax = axes[2] #ax.errorbar(r_all,sdss_delta_sigma_all['sm10.6']/h,\ # yerr=sdss_delta_sigma_all['sm10.6err']/h,\ # ms=3, fmt='o', color='black', mec='none') #ax.errorbar(r_q,sdss_delta_sigma_q['sm10.6']/h,\ # yerr=sdss_delta_sigma_q['sm10.6err']/h,\ # ms=3, fmt='o',color='red', mec='none') #ax.errorbar(r_sf,sdss_delta_sigma_sf['sm10.6']/h,\ # yerr=sdss_delta_sigma_sf['sm10.6err']/h,\ # ms=3, fmt='o',color='blue', mec='none') ax.set_xlim([0.1,2]) ax.set_ylim([1,100]) ax.set_yscale('log') ax.set_xscale('log') #ax.set_ylabel(r'$\omega_p(r_p)$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$\log(M_{*}~M_{\odot}h^{-2})>10.29$') for i in range(0,len(sm_thresholds)): filepath = cu.get_output_path() + 'analysis/central_quenching/observables/' names = ['r','delta_sigma'] filename = catalogues[0]+'_DeltaSigma_'+samples[0]+'_'+sm_thresholds[i]+'.dat' result_1a = ascii.read(filepath+filename,names=names) filename = catalogues[0]+'_DeltaSigma_'+samples[1]+'_'+sm_thresholds[i]+'.dat' result_1b = ascii.read(filepath+filename,names=names) filename = catalogues[0]+'_DeltaSigma_'+samples[2]+'_'+sm_thresholds[i]+'.dat' result_1c = ascii.read(filepath+filename,names=names) filename = catalogues[1]+'_DeltaSigma_'+samples[0]+'_'+sm_thresholds[i]+'.dat' result_2a = ascii.read(filepath+filename,names=names) filename = catalogues[1]+'_DeltaSigma_'+samples[1]+'_'+sm_thresholds[i]+'.dat' result_2b = ascii.read(filepath+filename,names=names) filename = catalogues[1]+'_DeltaSigma_'+samples[2]+'_'+sm_thresholds[i]+'.dat' result_2c = ascii.read(filepath+filename,names=names) filename = catalogues[2]+'_DeltaSigma_'+samples[0]+'_'+sm_thresholds[i]+'.dat' result_3a = ascii.read(filepath+filename,names=names) filename = catalogues[2]+'_DeltaSigma_'+samples[1]+'_'+sm_thresholds[i]+'.dat' result_3b = ascii.read(filepath+filename,names=names) filename = catalogues[2]+'_DeltaSigma_'+samples[2]+'_'+sm_thresholds[i]+'.dat' result_3c = ascii.read(filepath+filename,names=names) filename = catalogues[3]+'_DeltaSigma_'+samples[0]+'_'+sm_thresholds[i]+'.dat' result_4a = ascii.read(filepath+filename,names=names) filename = catalogues[3]+'_DeltaSigma_'+samples[1]+'_'+sm_thresholds[i]+'.dat' result_4b = ascii.read(filepath+filename,names=names) filename = catalogues[3]+'_DeltaSigma_'+samples[2]+'_'+sm_thresholds[i]+'.dat' result_4c = ascii.read(filepath+filename,names=names) filename = catalogues[4]+'_DeltaSigma_'+samples[0]+'_'+sm_thresholds[i]+'.dat' result_5a = ascii.read(filepath+filename,names=names) filename = catalogues[4]+'_DeltaSigma_'+samples[1]+'_'+sm_thresholds[i]+'.dat' result_5b = ascii.read(filepath+filename,names=names) filename = catalogues[4]+'_DeltaSigma_'+samples[2]+'_'+sm_thresholds[i]+'.dat' result_5c = ascii.read(filepath+filename,names=names) ax = axes[i] p1a, = ax.plot(result_1a['r'],result_1a['delta_sigma'],'-',color='black', alpha=1) p1b, = ax.plot(result_1b['r'],result_1b['delta_sigma'],'-',color='red', alpha=1) p1c, = ax.plot(result_1c['r'],result_1c['delta_sigma'],'-',color='blue', alpha=1) p2a, = ax.plot(result_2a['r'],result_2a['delta_sigma'],'-',color='black', alpha=0.8) p2b, = ax.plot(result_2b['r'],result_2b['delta_sigma'],'-',color='red', alpha=0.8) p2c, = ax.plot(result_2c['r'],result_2c['delta_sigma'],'-',color='blue', alpha=0.8) p3a, = ax.plot(result_3a['r'],result_3a['delta_sigma'],'-',color='black', alpha=0.6) p3b, = ax.plot(result_3b['r'],result_3b['delta_sigma'],'-',color='red', alpha=0.6) p3c, = ax.plot(result_3c['r'],result_3c['delta_sigma'],'-',color='blue', alpha=0.6) p4a, = ax.plot(result_4a['r'],result_4a['delta_sigma'],'-',color='black', alpha=0.4) p4b, = ax.plot(result_4b['r'],result_4b['delta_sigma'],'-',color='red', alpha=0.4) p4c, = ax.plot(result_4c['r'],result_4c['delta_sigma'],'-',color='blue', alpha=0.4) p5a, = ax.plot(result_5a['r'],result_5a['delta_sigma'],'-',color='black', alpha=0.2) p5b, = ax.plot(result_5b['r'],result_5b['delta_sigma'],'-',color='red', alpha=0.2) p5c, = ax.plot(result_5c['r'],result_5c['delta_sigma'],'-',color='blue', alpha=0.2) if i==0: ax.legend((p1a,p2a,p3a,p4a,p5a),\ (r"$\rho=-1.0$",r"$\rho=-0.75$",r"$\rho=-0.5$",r"$\rho=-0.25$",r"$\rho=0.0$"),\ loc=1, fontsize=10, frameon=False, labelspacing=0.01, title='all') if i==1: ax.legend((p1b,p2b,p3b,p4b,p5b),\ (r"$\rho=-1.0$",r"$\rho=-0.75$",r"$\rho=-0.5$",r"$\rho=-0.25$",r"$\rho=0.0$"),\ loc=1, fontsize=10, frameon=False, labelspacing=0.01, title='quenched') if i==2: ax.legend((p1c,p2c,p3c,p4c,p5c),\ (r"$\rho=-1.0$",r"$\rho=-0.75$",r"$\rho=-0.5$",r"$\rho=-0.25$",r"$\rho=0.0$"),\ loc=1, fontsize=10, frameon=False, labelspacing=0.01, title='star-forming') plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'delta_sigma' fig1.savefig(savepath+filename+'.pdf')
def main(): if len(sys.argv)>1: group_cat = sys.argv[1] else: group_cat = 'yang' if len(sys.argv)>2: sample = sys.argv[2] else: sample = 'sample3_L_model.mr19' if group_cat == 'yang': filepath_cat = cu.get_output_path() + 'processed_data/yang_groupcat/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/yang_groupcat/' plotpath = cu.get_plot_path() + 'analysis/yang_groupcat/' if group_cat == 'wetzel': filepath_cat = cu.get_output_path() + 'processed_data/wetzel_groupcat/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/wetzel_groupcat/' plotpath = cu.get_plot_path() + 'analysis/wetzel_groupcat/' if group_cat == 'berlind': filepath_cat = cu.get_output_path() + 'processed_data/berlind_groupcat/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/berlind_groupcat/' plotpath = cu.get_plot_path() + 'analysis/berlind_groupcat/' if group_cat == 'tinker_mocks': filepath_cat = cu.get_output_path() + 'processed_data/tinker_groupcat/mock_runs/3rd_run/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/tinker_groupcat/' plotpath = cu.get_plot_path() + 'analysis/tinker_groupcat/' if group_cat == 'berlind_mocks': filepath_cat = cu.get_output_path() + 'processed_data/berlind_groupcat/mock_runs/2nd_run/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/berlind_groupcat/' plotpath = cu.get_plot_path() + 'analysis/berlind_groupcat/' catalogue = sample N_boots = 50 mass_bins = np.arange(10,15.2,0.2) #log mass bins f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', catalogue #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = catalogue+'_'+str(boot) print catalogue_1 f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print len(GC) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) ''' #plot results #fig.add_subplot(224) plt.figure() for boot in range(0,N_boots): selection = np.where( N_cen_blue[boot] > 50)[0] plt.plot(mass_bins[0:-1][selection],f_cen_blue[boot,selection], color='blue', alpha=0.5) selection = np.where( N_cen_red[boot] > 50)[0] plt.plot(mass_bins[0:-1][selection],f_cen_red[boot,selection], color='red', alpha=0.5) plt.xlim([10,15]) plt.ylim([0,1]) plt.xlabel('$\log(M) [{h}^{-1}{M}_{\odot}]$') plt.ylabel('${f}_{late}$') plt.show(block=True) #fig.savefig(plotpath+catalogue+'_conformity.png') ''' f_blue = np.mean(f_cen_blue, axis=0) f_red = np.mean(f_cen_red, axis=0) N_blue = np.mean(N_cen_blue, axis=0) N_red = np.mean(N_cen_red, axis=0) err_blue = np.std(f_cen_blue, axis=0) err_red = np.std(f_cen_red, axis=0) print f_blue print err_blue print N_blue fig = plt.figure(figsize=(3.3,3.3)) ax = fig.add_subplot(1,1,1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) selection = np.where( N_blue > 50)[0] p1 = ax.errorbar(mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], color='blue') selection = np.where( N_red > 50)[0] p2 = ax.errorbar(mass_bins[0:-1][selection],f_red[selection], yerr=err_red[selection], color='red') ax.set_xlim([11.5,15]) ax.set_ylim([0,1]) ax.set_xlabel(r'$\log(M)$ $[{M}_{\odot}/h]$') ax.set_ylabel(r'${f}_{\rm blue}$') ax.legend((p1,p2),('w/ blue central','w/ red central'), loc='upper right', fontsize=10, numpoints=1, frameon=False) plt.show(block=True) filename = 'conformity_'+catalogue fig.savefig(plotpath+filename+'.png', dpi=400)
def main(): catalogue = sys.argv[1] plotpath = cu.get_plot_path() + 'analysis/groupcats/' bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 plt.figure() ################################################### groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) catalogue_1 = group_catalogue f = h5py.File(filepath_cat + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] result = np.histogram(GC['MGROUP'][satellites_ind], bins=bins)[0] p1, = plt.plot(bin_centers, np.log10(result), '-o', color='orange') ################################################### groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) catalogue_1 = group_catalogue f = h5py.File(filepath_cat + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] result = np.histogram(GC['MGROUP'][satellites_ind], bins=bins)[0] p2, = plt.plot(bin_centers, np.log10(result), '-o', color='green') ################################################### groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) catalogue_1 = group_catalogue f = h5py.File(filepath_cat + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] result = np.histogram(GC['MGROUP'][satellites_ind], bins=bins)[0] p3, = plt.plot(bin_centers + np.log10(0.7), np.log10(result), '-o', color='cyan') plt.xlabel(r'$log(M)$') plt.ylabel(r'$log(N)$') plt.legend((p1, p2, p3), ('berlind', 'tinker', 'yang'), loc='lower right') plt.show() bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 plt.figure() ################################################### groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) catalogue_1 = group_catalogue f = h5py.File(filepath_cat + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] result = np.histogram(GC['MGROUP'][centrals_ind], bins=bins)[0] p1, = plt.plot(bin_centers, np.log10(result), '-o', color='orange') ################################################### groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) catalogue_1 = group_catalogue f = h5py.File(filepath_cat + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] result = np.histogram(GC['MGROUP'][centrals_ind], bins=bins)[0] p2, = plt.plot(bin_centers, np.log10(result), 'o', color='green') ################################################### groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) catalogue_1 = group_catalogue f = h5py.File(filepath_cat + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print GC.dtype.names centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] halo_centrals_ind = np.where(GC['HALO_RANK'] == 1)[0] result = np.histogram(GC['MGROUP'][centrals_ind], bins=bins)[0] p3, = plt.plot(bin_centers, np.log10(result), 'o', color='cyan') result = np.histogram(GC['HALO_M'][halo_centrals_ind], bins=bins)[0] p4, = plt.plot(bin_centers, np.log10(result), '-', color='red') plt.xlabel(r'$log(M)$') plt.ylabel(r'$log(N)$') plt.legend((p1, p2, p3, p4), ('berlind FoF groups', 'tinker SO groups', 'yang SO groups', 'Bolshoi mock haloes'), loc='upper right') plt.show()
def main(): catalogues_0 = ['sm_8.5_s0.0_sfr_c-1.0_250','sm_8.5_s0.1_sfr_c-1.0_250',\ 'sm_8.5_s0.2_sfr_c-1.0_250','sm_8.5_s0.3_sfr_c-1.0_250'] catalogues_1 = ['sm_9.5_s0.0_sfr_c-1.0_250','sm_9.5_s0.1_sfr_c-1.0_250',\ 'sm_9.5_s0.2_sfr_c-1.0_250','sm_9.5_s0.3_sfr_c-1.0_250'] samples = ['all','q','sf'] sm_bins = ['9.0_9.5', '9.5_10.0', '10.0_10.5', '10.5_11.0', '11.0_11.5'] ###################################################################################### #set up plot ###################################################################################### fig1, axes = plt.subplots(nrows=1,ncols=1,sharex=True,sharey=True,figsize=(3.3, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.0, left=0.2, right=0.9, bottom=0.2, top=0.9) ax = axes ax.set_xlim([0.1,20]) ax.set_ylim([10,200]) ax.set_yscale('log') ax.set_xscale('log') ax.set_ylabel(r'$\omega_p(r_p)\times r_p$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$10.0<\log(M_{*}/M_{\odot}h^{-2})<10.5$') ###################################################################################### #read in results and plot ###################################################################################### sm_bin = sm_bins[2] filepath = cu.get_output_path() + 'analysis/central_quenching/observables/' names = ['r','wp'] filename = catalogues_1[0]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_1a = ascii.read(filepath+filename,names=names) filename = catalogues_1[0]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_1b = ascii.read(filepath+filename,names=names) filename = catalogues_1[0]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_1c = ascii.read(filepath+filename,names=names) filename = catalogues_1[1]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_2a = ascii.read(filepath+filename,names=names) filename = catalogues_1[1]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_2b = ascii.read(filepath+filename,names=names) filename = catalogues_1[1]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_2c = ascii.read(filepath+filename,names=names) filename = catalogues_1[2]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_3a = ascii.read(filepath+filename,names=names) filename = catalogues_1[2]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_3b = ascii.read(filepath+filename,names=names) filename = catalogues_1[2]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_3c = ascii.read(filepath+filename,names=names) filename = catalogues_1[3]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_4a = ascii.read(filepath+filename,names=names) filename = catalogues_1[3]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_4b = ascii.read(filepath+filename,names=names) filename = catalogues_1[3]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_4c = ascii.read(filepath+filename,names=names) ax = axes p1a, = ax.plot(result_1a['r'],result_1a['wp']*result_1a['r'],'-',color='black', alpha=1) p1b, = ax.plot(result_1b['r'],result_1b['wp']*result_1a['r'],'-',color='red', alpha=1) p1c, = ax.plot(result_1c['r'],result_1c['wp']*result_1a['r'],'-',color='blue', alpha=1) p2a, = ax.plot(result_2a['r'],result_2a['wp']*result_1a['r'],'-',color='black', alpha=0.75) p2b, = ax.plot(result_2b['r'],result_2b['wp']*result_1a['r'],'-',color='red',alpha=0.75) p2c, = ax.plot(result_2c['r'],result_2c['wp']*result_1a['r'],'-',color='blue',alpha=0.75) p3a, = ax.plot(result_3a['r'],result_3a['wp']*result_1a['r'],'-',color='black',alpha=0.5) p3b, = ax.plot(result_3b['r'],result_3b['wp']*result_1a['r'],'-',color='red', alpha=0.5) p3c, = ax.plot(result_3c['r'],result_3c['wp']*result_1a['r'],'-',color='blue', alpha=0.5) p4a, = ax.plot(result_4a['r'],result_4a['wp']*result_1a['r'],'-',color='black',alpha=0.25) p4b, = ax.plot(result_4b['r'],result_4b['wp']*result_1a['r'],'-',color='red', alpha=0.25) p4c, = ax.plot(result_4c['r'],result_4c['wp']*result_1a['r'],'-',color='blue', alpha=0.25) ax.legend((p1b,p2b,p3b,p4b),\ (r"$\sigma_{\rm SMHM}=0.0$",r"$\sigma_{\rm SMHM}=0.1$",r"$\sigma_{\rm SMHM}=0.2$",r"$\sigma_{\rm SMHM}=0.3$"),\ loc=4,fontsize=10, frameon=False, labelspacing=0.01, title='quenched galaxies') plt.show(block=True) savepath = cu.get_plot_path()+'/analysis/central_quenching/' savepath = '/Users/duncan/Desktop/' filename = 'w_p_cross_r_single_panel_compare_sigma' fig1.savefig(savepath+filename+'.pdf')
def main(): catalogue = 'Mr19_age_distribution_matching_mock' if len(sys.argv)>1: catalogue = sys.argv[1] plotpath = cu.get_plot_path() + 'analysis/groupcats/' bins = np.arange(11,15,0.2) bin_centers = (bins[:-1]+bins[1:])/2.0 #open mock catalogue filepath_mock = cu.get_output_path() + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue+'.hdf5' f1 = h5py.File(filepath_mock+catalogue+'.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.array(mock['ID_host']==-1) satellites = np.array(mock['ID_host']!=-1) #galaxy color color = mock['g-r'] LHS = 0.7 - 0.032*(mock['M_r,0.1']+16.5) #Weinmann 2006 blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies blue_bool = np.array(color<LHS) #indices of blue galaxies red_bool = np.array(color>LHS) #indicies of red galaxies lumbins = np.arange(9.6,11.0,0.2) lumbin_centers = (lumbins[:-1]+lumbins[1:])/2.0 print len(lumbin_centers) print lumbin_centers inds = np.digitize(solar_lum(mock['M_r,0.1'],4.64),bins=lumbins) bininds=np.array(inds==0) result1 = np.histogram(mock['M_host'][(centrals & bininds)],bins=bins)[0] central_mean_mass_0 = np.mean(mock['M_host'][(centrals & bininds)]) f_red_cen_0 = float(len(mock['M_host'][red_bool&(centrals & bininds)]))/float(len(mock['M_host'][(centrals & bininds)])) f_red_sat_0 = f_prop(mock['M_host'],bins,red,blue,(satellites & bininds)) bininds=np.array(inds==2) result1 = np.histogram(mock['M_host'][(centrals & bininds)],bins=bins)[0] central_mean_mass_2 = np.mean(mock['M_host'][(centrals & bininds)]) f_red_cen_2 = float(len(mock['M_host'][red_bool&(centrals & bininds)]))/float(len(mock['M_host'][(centrals & bininds)])) f_red_sat_2 = f_prop(mock['M_host'],bins,red,blue,(satellites & bininds)) bininds=np.array(inds==4) result1 = np.histogram(mock['M_host'][(centrals & bininds)],bins=bins)[0] central_mean_mass_4 = np.mean(mock['M_host'][(centrals & bininds)]) f_red_cen_4 = float(len(mock['M_host'][red_bool&(centrals & bininds)]))/float(len(mock['M_host'][(centrals & bininds)])) f_red_sat_4 = f_prop(mock['M_host'],bins,red,blue,(satellites & bininds)) bininds=np.array(inds==6) result1 = np.histogram(mock['M_host'][(centrals & bininds)],bins=bins)[0] central_mean_mass_6 = np.mean(mock['M_host'][(centrals & bininds)]) f_red_cen_6 = float(len(mock['M_host'][red_bool&(centrals & bininds)]))/float(len(mock['M_host'][(centrals & bininds)])) f_red_sat_6 = f_prop(mock['M_host'],bins,red,blue,(satellites & bininds)) plt.figure() plt.plot(central_mean_mass_0,f_red_cen_0,'o',color='blue') p0,=plt.plot(bin_centers[bin_centers>central_mean_mass_0],f_red_sat_0[bin_centers>central_mean_mass_0],color='blue') plt.plot(central_mean_mass_2,f_red_cen_2,'o',color='green') p2,=plt.plot(bin_centers[bin_centers>central_mean_mass_2],f_red_sat_2[bin_centers>central_mean_mass_2],color='green') plt.plot(central_mean_mass_4,f_red_cen_4,'o',color='red') p4,=plt.plot(bin_centers[bin_centers>central_mean_mass_4],f_red_sat_4[bin_centers>central_mean_mass_4],color='red') plt.plot(central_mean_mass_6,f_red_cen_6,'o',color='black') p6,=plt.plot(bin_centers[bin_centers>central_mean_mass_6],f_red_sat_6[bin_centers>central_mean_mass_6],color='black') plt.legend((p0,p2,p4,p6),(lumbin_centers[0],lumbin_centers[2],lumbin_centers[4],lumbin_centers[6]),loc='lower right') plt.xlabel(r'$\log(M)$') plt.ylabel(r'$f_{red}$') ################################################### N_boots=50 groupcat='yang' filepath_cat=get_gc_path(groupcat) group_catalogue=get_gc_name(groupcat,catalogue) f_red_cen_0 = np.zeros((N_boots,)) f_red_sat_0 = np.zeros((N_boots,len(bin_centers))) f_red_cen_2 = np.zeros((N_boots,)) f_red_sat_2 = np.zeros((N_boots,len(bin_centers))) f_red_cen_4 = np.zeros((N_boots,)) f_red_sat_4 = np.zeros((N_boots,len(bin_centers))) f_red_cen_6 = np.zeros((N_boots,)) f_red_sat_6 = np.zeros((N_boots,len(bin_centers))) central_mean_mass_0 = np.zeros((N_boots,)) central_mean_mass_2 = np.zeros((N_boots,)) central_mean_mass_4 = np.zeros((N_boots,)) central_mean_mass_6 = np.zeros((N_boots,)) for boot in range(0,N_boots): #open catalogue catalogue_1 = group_catalogue+'_'+str(boot) f = h5py.File(filepath_cat+'bootstraps/'+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK']==1)[0] satellites_ind = np.where(GC['RANK']!=1)[0] centrals = np.array(GC['RANK']==1) satellites = np.array(GC['RANK']!=1) #galaxy color color = GC['M_g,0.1']-GC['M_r,0.1'] LHS = 0.7 - 0.032*(GC['M_r,0.1']+16.5) #Weinmann 2006 blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies blue_bool = (color<LHS) #indices of blue galaxies red_bool = (color>LHS) #indicies of red galaxies inds = np.digitize(solar_lum(GC['M_r,0.1'],4.64),bins=lumbins) bininds=np.array(inds==0) result1 = np.histogram(GC['MGROUP'][(centrals & bininds)],bins=bins)[0] central_mean_mass_0[boot] = np.mean(GC['MGROUP'][(centrals & bininds)]) f_red_cen_0[boot] = float(len(GC['MGROUP'][red_bool&(centrals & bininds)]))/float(len(GC['MGROUP'][(centrals & bininds)])) f_red_sat_0[boot,:] = f_prop(GC['MGROUP'],bins,red,blue,(satellites & bininds)) bininds=np.array(inds==2) result1 = np.histogram(GC['MGROUP'][(centrals & bininds)],bins=bins)[0] central_mean_mass_2[boot] = np.mean(GC['MGROUP'][(centrals & bininds)]) f_red_cen_2[boot] = float(len(GC['MGROUP'][red_bool&(centrals & bininds)]))/float(len(GC['MGROUP'][(centrals & bininds)])) f_red_sat_2[boot:,] = f_prop(GC['MGROUP'],bins,red,blue,(satellites & bininds)) bininds=np.array(inds==4) result1 = np.histogram(GC['MGROUP'][(centrals & bininds)],bins=bins)[0] central_mean_mass_4[boot] = np.mean(GC['MGROUP'][(centrals & bininds)]) f_red_cen_4[boot] = float(len(GC['MGROUP'][red_bool&(centrals & bininds)]))/float(len(GC['MGROUP'][(centrals & bininds)])) f_red_sat_4[boot,:] = f_prop(GC['MGROUP'],bins,red,blue,(satellites & bininds)) bininds=np.array(inds==6) result1 = np.histogram(GC['MGROUP'][(centrals & bininds)],bins=bins)[0] central_mean_mass_6[boot] = np.mean(GC['MGROUP'][(centrals & bininds)]) f_red_cen_6[boot] = float(len(GC['MGROUP'][red_bool&(centrals & bininds)]))/float(len(GC['MGROUP'][(centrals & bininds)])) f_red_sat_6[boot,:] = f_prop(GC['MGROUP'],bins,red,blue,(satellites & bininds)) err_cen_0 = np.nanstd(f_red_cen_0, axis=0) err_sat_0 = np.nanstd(f_red_sat_0, axis=0) f_red_cen_0 = np.nanmean(f_red_cen_0, axis=0) f_red_sat_0 = np.nanmean(f_red_sat_0, axis=0) central_mean_mass_err_0 = np.nanstd(central_mean_mass_0, axis=0) central_mean_mass_0 = np.nanmean(central_mean_mass_0, axis=0) err_cen_2 = np.nanstd(f_red_cen_2, axis=0) err_sat_2 = np.nanstd(f_red_sat_2, axis=0) f_red_cen_2 = np.nanmean(f_red_cen_2, axis=0) f_red_sat_2 = np.nanmean(f_red_sat_2, axis=0) central_mean_mass_err_2 = np.nanstd(central_mean_mass_2, axis=0) central_mean_mass_2 = np.nanmean(central_mean_mass_2, axis=0) err_cen_4 = np.nanstd(f_red_cen_4, axis=0) err_sat_4 = np.nanstd(f_red_sat_4, axis=0) f_red_cen_4 = np.nanmean(f_red_cen_4, axis=0) f_red_sat_4 = np.nanmean(f_red_sat_4, axis=0) central_mean_mass_err_4 = np.nanstd(central_mean_mass_4, axis=0) central_mean_mass_4 = np.nanmean(central_mean_mass_4, axis=0) err_cen_6 = np.nanstd(f_red_cen_6, axis=0) err_sat_6 = np.nanstd(f_red_sat_6, axis=0) f_red_cen_6 = np.nanmean(f_red_cen_6, axis=0) f_red_sat_6 = np.nanmean(f_red_sat_6, axis=0) central_mean_mass_err_6 = np.nanstd(central_mean_mass_6, axis=0) central_mean_mass_6 = np.nanmean(central_mean_mass_6, axis=0) plt.errorbar(central_mean_mass_0,f_red_cen_0,yerr=err_cen_0,fmt='o',color='blue') p0=plt.errorbar(bin_centers[bin_centers>central_mean_mass_0],f_red_sat_0[bin_centers>central_mean_mass_0],yerr=err_sat_0[bin_centers>central_mean_mass_0],\ fmt='o',color='blue', alpha=0.5) plt.errorbar(central_mean_mass_2,f_red_cen_2,yerr=err_cen_2,fmt='o',color='green') p2=plt.errorbar(bin_centers[bin_centers>central_mean_mass_2],f_red_sat_2[bin_centers>central_mean_mass_2],yerr=err_sat_2[bin_centers>central_mean_mass_2],\ fmt='o',color='green',alpha=0.5) plt.errorbar(central_mean_mass_4,f_red_cen_4,yerr=err_cen_4,fmt='o',color='red') p4=plt.errorbar(bin_centers[bin_centers>central_mean_mass_4],f_red_sat_4[bin_centers>central_mean_mass_4],yerr=err_sat_4[bin_centers>central_mean_mass_4],\ fmt='o',color='red',alpha=0.5) plt.errorbar(central_mean_mass_6,f_red_cen_6,yerr=err_cen_6,fmt='o',color='black') p6=plt.errorbar(bin_centers[bin_centers>central_mean_mass_6],f_red_sat_6[bin_centers>central_mean_mass_6],yerr=err_sat_6[bin_centers>central_mean_mass_6],\ fmt='o',color='black',alpha=0.5) plt.ylim([0.2,1]) plt.show()
def main(): if len(sys.argv) > 1: group_cat = sys.argv[1] else: group_cat = 'yang' if len(sys.argv) > 2: sample = sys.argv[2] else: sample = 'sample3_L_model.mr19' if group_cat == 'yang': filepath_cat = cu.get_output_path( ) + 'processed_data/yang_groupcat/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/yang_groupcat/' plotpath = cu.get_plot_path() + 'analysis/yang_groupcat/' if group_cat == 'wetzel': filepath_cat = cu.get_output_path( ) + 'processed_data/wetzel_groupcat/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/wetzel_groupcat/' plotpath = cu.get_plot_path() + 'analysis/wetzel_groupcat/' if group_cat == 'berlind': filepath_cat = cu.get_output_path( ) + 'processed_data/berlind_groupcat/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/berlind_groupcat/' plotpath = cu.get_plot_path() + 'analysis/berlind_groupcat/' if group_cat == 'tinker_mocks': filepath_cat = cu.get_output_path( ) + 'processed_data/tinker_groupcat/mock_runs/3rd_run/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/tinker_groupcat/' plotpath = cu.get_plot_path() + 'analysis/tinker_groupcat/' if group_cat == 'berlind_mocks': filepath_cat = cu.get_output_path( ) + 'processed_data/berlind_groupcat/mock_runs/2nd_run/custom_catalogues/' savepath = cu.get_output_path() + 'analysis/berlind_groupcat/' plotpath = cu.get_plot_path() + 'analysis/berlind_groupcat/' catalogue = sample N_boots = 50 mass_bins = np.arange(10, 15.2, 0.2) #log mass bins f_cen_blue = np.zeros( (N_boots, len(mass_bins) - 1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros( (N_boots, len(mass_bins) - 1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros( (N_boots, len(mass_bins) - 1)) #number of satellites for blue centrals N_cen_red = np.zeros( (N_boots, len(mass_bins) - 1)) #number of satellites for red centrals N_groups_blue = np.zeros( (N_boots, len(mass_bins) - 1)) #number of satellites for red centrals N_groups_red = np.zeros( (N_boots, len(mass_bins) - 1)) #number of satellites for red centrals for boot in range(0, N_boots): print 'opening group catalogue:', catalogue #open catalogue filepath = filepath_cat + 'bootstraps/' catalogue_1 = catalogue + '_' + str(boot) print catalogue_1 f = h5py.File(filepath + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print len(GC) #do we have a measure of M_u? good = np.where(GC['M_g,0.1'] != -99.9)[0] bad = np.where(GC['M_g,0.1'] == -99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h = 1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies lookup = color < LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where( GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals) + len(bad_centrals) mass_hist, bins = np.histogram( GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize( GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup == True)[0] selection = np.intersect1d(selection, centrals) mass_hist_blue, bins = np.histogram( GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize( GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup == False)[0] selection = np.intersect1d(selection, centrals) mass_hist_red, bins = np.histogram( GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize( GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram( GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals) > 0: mass_bin_ind_grey = np.digitize( GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey / float(N_groups) mass_hist_red = mass_hist_red / float(N_groups) mass_hist_blue = mass_hist_blue / float(N_groups) for i in range(0, len(mass_bins) - 1): print i, mass_bins[i], mass_bins[i + 1] ind = np.where(mass_bin_ind == i + 1)[0] if len(ind) > 0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'], ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[ 0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where( GC['RPROJ'][galaxy_members] > 0)[0] #satellites satellite_members = galaxy_members[ satellite_members] #indices of satellites central_members = np.where( GC['RPROJ'][galaxy_members] == 0)[0] #centrals central_members = galaxy_members[ central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len( satellite_members) == len(galaxy_members) blue_central_members = np.where( lookup[central_members] == True)[0] #blue centrals blue_central_members = central_members[ blue_central_members] #indicies of blue centrals red_central_members = np.where( lookup[central_members] == False)[0] #red centrals red_central_members = central_members[ red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members) + len( red_central_members) == len(central_members) blue_central_satellites = np.in1d( GC['GROUP_ID'][satellite_members], GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[ blue_central_satellites] red_central_satellites = np.in1d( GC['GROUP_ID'][satellite_members], GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[ red_central_satellites] print 'number of blue central satellites:', len( blue_central_satellites) print 'number of red central satellites:', len( red_central_satellites) print 'check:', len(blue_central_satellites) + len( red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where( lookup[blue_central_satellites] == True)[0] blue_central_blue_satellites = blue_central_satellites[ blue_central_blue_satellites] blue_central_red_satellites = np.where( lookup[blue_central_satellites] == False)[0] blue_central_red_satellites = blue_central_satellites[ blue_central_red_satellites] red_central_blue_satellites = np.where( lookup[red_central_satellites] == True)[0] red_central_blue_satellites = red_central_satellites[ red_central_blue_satellites] red_central_red_satellites = np.where( lookup[red_central_satellites] == False)[0] red_central_red_satellites = red_central_satellites[ red_central_red_satellites] N_blue_central_blue_satellites = float( len(blue_central_blue_satellites)) N_blue_central_red_satellites = float( len(blue_central_red_satellites)) N_red_central_blue_satellites = float( len(red_central_blue_satellites)) N_red_central_red_satellites = float( len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites + N_blue_central_red_satellites == len( blue_central_satellites) print 'check:', N_red_central_blue_satellites + N_red_central_red_satellites == len( red_central_satellites) if len(blue_central_satellites) > 0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot, i] if len(red_central_satellites) > 0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot, i] #number satellites in the bin N_cen_blue[boot, i] = float(len(blue_central_satellites)) N_cen_red[boot, i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot, i] = float(len(blue_central_members)) N_groups_red[boot, i] = float(len(red_central_members)) ''' #plot results #fig.add_subplot(224) plt.figure() for boot in range(0,N_boots): selection = np.where( N_cen_blue[boot] > 50)[0] plt.plot(mass_bins[0:-1][selection],f_cen_blue[boot,selection], color='blue', alpha=0.5) selection = np.where( N_cen_red[boot] > 50)[0] plt.plot(mass_bins[0:-1][selection],f_cen_red[boot,selection], color='red', alpha=0.5) plt.xlim([10,15]) plt.ylim([0,1]) plt.xlabel('$\log(M) [{h}^{-1}{M}_{\odot}]$') plt.ylabel('${f}_{late}$') plt.show(block=True) #fig.savefig(plotpath+catalogue+'_conformity.png') ''' f_blue = np.mean(f_cen_blue, axis=0) f_red = np.mean(f_cen_red, axis=0) N_blue = np.mean(N_cen_blue, axis=0) N_red = np.mean(N_cen_red, axis=0) err_blue = np.std(f_cen_blue, axis=0) err_red = np.std(f_cen_red, axis=0) print f_blue print err_blue print N_blue fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) selection = np.where(N_blue > 50)[0] p1 = ax.errorbar(mass_bins[0:-1][selection], f_blue[selection], yerr=err_blue[selection], color='blue') selection = np.where(N_red > 50)[0] p2 = ax.errorbar(mass_bins[0:-1][selection], f_red[selection], yerr=err_red[selection], color='red') ax.set_xlim([11.5, 15]) ax.set_ylim([0, 1]) ax.set_xlabel(r'$\log(M)$ $[{M}_{\odot}/h]$') ax.set_ylabel(r'${f}_{\rm blue}$') ax.legend((p1, p2), ('w/ blue central', 'w/ red central'), loc='upper right', fontsize=10, numpoints=1, frameon=False) plt.show(block=True) filename = 'conformity_' + catalogue fig.savefig(plotpath + filename + '.png', dpi=400)
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock' #define outputs plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_f_L' #set up plot fig1, axes = plt.subplots(nrows=2, ncols=3, sharex=True, sharey=True, figsize=(6.95, 6.6 - 1.5)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.125, top=0.95) axes = axes.flatten() ax = axes[0] ax.set_xlim([9.5, 10.8]) ax.set_ylim([0, 1]) ax.set_ylabel(r'$f_{red}$') ax.set_title(r'Berlind FoF groups') ax.set_yticks([0, 0.2, 0.4, 0.6, 0.8]) ax = axes[3] ax.set_xlabel(r'$\log(L/[L_{\odot}h^{-2}])$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_xlim([9.5, 10.7]) ax.set_ylabel(r'$f_{sat}$') ax.set_yticks([0, 0.2, 0.4, 0.6, 0.8]) ax = axes[1] ax.set_xlim([9.5, 10.8]) ax.set_ylim([0, 1]) ax.set_title(r'Tinker SO groups') ax = axes[4] ax.set_xlabel(r'$\log(L/[L_{\odot}h^{-2}])$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_xlim([9.5, 10.7]) ax.set_yticks([0, 0.2, 0.4, 0.6, 0.8]) ax = axes[2] ax.set_xlim([9.5, 10.8]) ax.set_ylim([0, 1]) ax.set_title(r'Yang SO groups') ax = axes[5] ax.set_xlabel(r'$\log(L/[L_{\odot}h^{-2}])$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_xlim([9.5, 10.7]) #define luminosity bins bins = np.arange(9.5, 10.8, 0.1) bin_centers = (bins[:-1] + bins[1:]) / 2.0 #define constants S_r = 4.64 N_boots = 50 #number of group cat bootstraps #open mock catalogue filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) #central/satellites centrals_ind = np.where(mock['ID_host'] == -1)[0] satellites_ind = np.where(mock['ID_host'] != -1)[0] centrals_bool = (mock['ID_host'] == -1) satellites_bool = (mock['ID_host'] != -1) f_sat_mock = float( len(satellites_ind)) / (len(satellites_ind) + len(centrals_ind)) print f_sat_mock #galaxy color color = mock['g-r'] LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies L = solar_lum(mock['M_r,0.1'], S_r) f_red_cen = f_prop(L, bins, red_ind, blue_ind, centrals_bool) f_red_sat = f_prop(L, bins, red_ind, blue_ind, satellites_bool) f_sat_red = f_prop(L, bins, satellites_ind, centrals_ind, red_bool) f_sat_blue = f_prop(L, bins, satellites_ind, centrals_ind, blue_bool) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax.legend((p1a, p2a), ('halo central', 'halo satellite'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[3] p1b, = ax.plot(bin_centers, f_sat_red, color='red') p2b, = ax.plot(bin_centers, f_sat_blue, color='blue') ax.legend((p1b, p2b), ('halo red sat/cen', 'halo blue sat/cen'), loc='upper right', fontsize=10, numpoints=1, frameon=False) ax = axes[4] p1b, = ax.plot(bin_centers, f_sat_red, color='red') p2b, = ax.plot(bin_centers, f_sat_blue, color='blue') ax = axes[5] p1b, = ax.plot(bin_centers, f_sat_red, color='red') p2b, = ax.plot(bin_centers, f_sat_blue, color='blue') f_red_cen_mock = f_red_cen f_red_sat_mock = f_red_sat f_sat_red_mock = f_sat_red f_sat_blue_mock = f_sat_blue ################################################### # Ideal Groups ################################################### filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/ideal_groups/' print 'opening mock catalogue:', catalogue + '_groups.hdf5' f1 = h5py.File(filepath_mock + catalogue + '_groups.hdf5', 'r') #open catalogue file GC = f1.get(catalogue + '_groups') f_red_cen = np.zeros((len(bin_centers))) f_red_sat = np.zeros((len(bin_centers))) f_sat_red = np.zeros((len(bin_centers))) f_sat_blue = np.zeros((len(bin_centers))) centrals_ind = np.where(GC['RANK'] == 0)[0] satellites_ind = np.where(GC['RANK'] != 0)[0] centrals_bool = (GC['RANK'] == 0) satellites_bool = (GC['RANK'] != 0) Nsat = float(len(satellites_ind)) Ncen = float(len(centrals_ind)) N_orphan = len(np.where(GC['CEN_IND'] == -99)[0]) centrals_mock_ind = np.where(GC['HALO_RANK'] == 0)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) f_red_cen = f_prop(L, bins, red_ind, blue_ind, centrals_bool) f_red_sat = f_prop(L, bins, red_ind, blue_ind, satellites_bool) f_sat_red = f_prop(L, bins, satellites_ind, centrals_ind, red_bool) f_sat_blue = f_prop(L, bins, satellites_ind, centrals_ind, blue_bool) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen, color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, color='green', alpha=0.5) ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen, color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, color='green', alpha=0.5) ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen, color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, color='green', alpha=0.5) ax = axes[3] p1b, = ax.plot(bin_centers, f_sat_red, color='red', alpha=0.5) p2b, = ax.plot(bin_centers, f_sat_blue, color='blue', alpha=0.5) ax = axes[4] p1b, = ax.plot(bin_centers, f_sat_red, color='red', alpha=0.5) p2b, = ax.plot(bin_centers, f_sat_blue, color='blue', alpha=0.5) ax = axes[5] p1b, = ax.plot(bin_centers, f_sat_red, color='red', alpha=0.5) p2b, = ax.plot(bin_centers, f_sat_blue, color='blue', alpha=0.5) ################################################### groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) f_red_cen[boot, :] = f_prop(L, bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(L, bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(L, bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(L, bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[0] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax = axes[3] p3b = ax.errorbar(bin_centers, f_sat_red, yerr=err_sat_red, fmt='o', color='red', mec='none', ms=3) p4b = ax.errorbar(bin_centers + 0.01, f_sat_blue, yerr=err_sat_blue, fmt='o', color='blue', mec='none', ms=3) ''' #calculate with correction catalogue_1 = group_catalogue f = h5py.File(filepath_cat+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK']==1)[0] satellites_ind = np.where(GC['RANK']!=1)[0] centrals_bool = (GC['RANK']==1) satellites_bool = (GC['RANK']!=1) centrals_mock_ind = np.where(GC['HALO_RANK']==1)[0] satellites_mock_ind = np.where(GC['HALO_RANK']!=1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) N_sat = float(len(satellites_ind)) N_cen = float(len(centrals_ind)) b_sat=sat_bias(GC) Ps=sat_purity(GC) Pc=cen_purity(GC) Cs=sat_comp(GC) Cc=cen_comp(GC) print Ps, Cs, Pc, Cc, b_sat print 'test:',(1-Ps)*N_sat_mock*Cs*Pc==(1-Pc)*N_cen_mock*b_sat*Cc*Ps print 'test:',N_sat*Ps/Cs==N_sat_mock print 'test:',N_cen*Pc/Cc==N_cen_mock print 'test:',N_cen+N_sat==N_cen_mock+N_sat_mock f_red_sat_1 = (f_red_sat-f_red_cen*(((1-Ps)*(1-Cc))/((1-Pc)*Cc*b_sat)))/(1-(((1-Cs)*(1-Cc))/(Ps*Pc)))/Ps f_red_cen_1 = (f_red_cen-f_red_sat_1*(((1-Cs)*(1-Pc)*Ps*b_sat)/((1-Ps)*Cs)))/Pc ax=axes[0] p4a_1, = ax.plot(bin_centers,f_red_sat_1,'o',color='green', mfc='none', mec='green', ms=3) p4a_1, = ax.plot(bin_centers,f_red_cen_1,'o',color='orange', mfc='none', mec='orange', ms=3) f_sat_red_1 =f_sat_red*b_sat f_sat_blue_1 =f_sat_blue*b_sat ax=axes[3] N_red_sat = f_red_sat_1 * N_sat*Ps/Cs N_red_cen = f_red_cen_1 * N_cen*Pc/Cc N_blue_sat = (1-f_red_sat_1) * N_sat*Ps/Cs N_blue_cen = (1-f_red_cen_1) * N_cen*Pc/Cc f_sat_red_1 = N_red_sat/(N_red_cen+N_red_sat) f_sat_blue_1 = N_blue_sat/(N_blue_cen+N_blue_sat) p4b_1, = ax.plot(bin_centers,f_sat_red_1,'o',color='red', mfc='none', mec='red', ms=3) p4b_1, = ax.plot(bin_centers,f_sat_blue_1,'o',color='blue', mfc='none', mec='blue', ms=3) ''' ################################################### groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) f_red_cen[boot, :] = f_prop(L, bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(L, bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(L, bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(L, bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[1] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p3a, p4a), ('group central', 'group satellite'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ax = axes[4] p3b = ax.errorbar(bin_centers, f_sat_red, yerr=err_sat_red, fmt='o', color='red', mec='none', ms=3) p4b = ax.errorbar(bin_centers + 0.01, f_sat_blue, yerr=err_sat_blue, fmt='o', color='blue', mec='none', ms=3) ax.legend((p3b, p4b), ('group red cen/sat', 'group blue cen/sat'), loc='upper right', fontsize=10, numpoints=1, frameon=False) ''' #calculate with correction catalogue_1 = group_catalogue f = h5py.File(filepath_cat+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK']==1)[0] satellites_ind = np.where(GC['RANK']!=1)[0] centrals_bool = (GC['RANK']==1) satellites_bool = (GC['RANK']!=1) centrals_mock_ind = np.where(GC['HALO_RANK']==1)[0] satellites_mock_ind = np.where(GC['HALO_RANK']!=1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) N_sat = float(len(satellites_ind)) N_cen = float(len(centrals_ind)) x=0.8 y=0.93 f_sat = (1-y)/((1-x)+(1-y)) f_red_sat_1 = (y*f_red_sat+(x-1)*f_red_cen)/(x*y+(x-1)*(1-y)) f_red_cen_1 = (f_red_cen-(1-y)*f_red_sat_1)/y ax=axes[1] p4a_1, = ax.plot(bin_centers,f_red_sat_1,'x',color='green', mfc='none', mec='green', ms=3) p4a_1, = ax.plot(bin_centers,f_red_cen_1,'x',color='orange', mfc='none', mec='orange', ms=3) N_red_sat = f_red_sat_1 * N_sat N_red_cen = f_red_cen_1 * N_cen N_blue_sat = (1-f_red_sat_1) * N_sat N_blue_cen = (1-f_red_cen_1) * N_cen f_sat_red_1 = N_red_sat/(N_red_cen+N_red_sat) f_sat_blue_1 = N_blue_sat/(N_blue_cen+N_blue_sat) ax=axes[4] p4b_1, = ax.plot(bin_centers,f_sat_red_1,'x',color='red', mfc='none', mec='red', ms=3) p4b_1, = ax.plot(bin_centers,f_sat_blue_1,'x',color='blue', mfc='none', mec='blue', ms=3) #calculate with correction b_sat=sat_bias(GC) Ps=sat_purity(GC) Pc=cen_purity(GC) Cs=sat_comp(GC) Cc=cen_comp(GC) print Ps, Cs, Pc, Cc, b_sat print 'test:',(1-Ps)*N_sat_mock*Cs*Pc==(1-Pc)*N_cen_mock*b_sat*Cc*Ps print 'test:',N_sat*Ps/Cs==N_sat_mock print 'test:',N_cen*Pc/Cc==N_cen_mock print 'test:',N_cen+N_sat==N_cen_mock+N_sat_mock f_red_sat_1 = (f_red_sat-f_red_cen*(((1-Ps)*(1-Cc))/((1-Pc)*Cc*b_sat)))/(1-(((1-Cs)*(1-Cc))/(Ps*Pc)))/Ps f_red_cen_1 = (f_red_cen-f_red_sat_1*(((1-Cs)*(1-Pc)*Ps*b_sat)/((1-Ps)*Cs)))/Pc ax=axes[1] p4a_1, = ax.plot(bin_centers,f_red_sat_1,'o',color='green', mfc='none', mec='green', ms=3) p4a_1, = ax.plot(bin_centers,f_red_cen_1,'o',color='orange', mfc='none', mec='orange', ms=3) f_sat_red_1 =f_sat_red*b_sat f_sat_blue_1 =f_sat_blue*b_sat ax=axes[4] N_red_sat = f_red_sat_1 * N_sat*Ps/Cs N_red_cen = f_red_cen_1 * N_cen*Pc/Cc N_blue_sat = (1-f_red_sat_1) * N_sat*Ps/Cs N_blue_cen = (1-f_red_cen_1) * N_cen*Pc/Cc f_sat_red_1 = N_red_sat/(N_red_cen+N_red_sat) f_sat_blue_1 = N_blue_sat/(N_blue_cen+N_blue_sat) p4b_1, = ax.plot(bin_centers,f_sat_red_1,'o',color='red', mfc='none', mec='red', ms=3) p4b_1, = ax.plot(bin_centers,f_sat_blue_1,'o',color='blue', mfc='none', mec='blue', ms=3) ''' ################################################### groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) f_red_cen[boot, :] = f_prop(L, bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(L, bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(L, bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(L, bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[2] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax = axes[5] p3b = ax.errorbar(bin_centers, f_sat_red, yerr=err_sat_red, fmt='o', color='red', mec='none', ms=3) p4b = ax.errorbar(bin_centers + 0.01, f_sat_blue, yerr=err_sat_blue, fmt='o', color='blue', mec='none', ms=3) ''' #calculate with correction catalogue_1 = group_catalogue f = h5py.File(filepath_cat+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK']==1)[0] satellites_ind = np.where(GC['RANK']!=1)[0] centrals_bool = (GC['RANK']==1) satellites_bool = (GC['RANK']!=1) centrals_mock_ind = np.where(GC['HALO_RANK']==1)[0] satellites_mock_ind = np.where(GC['HALO_RANK']!=1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) N_sat = float(len(satellites_ind)) N_cen = float(len(centrals_ind)) b_sat=sat_bias(GC) Ps=sat_purity(GC) Pc=cen_purity(GC) Cs=sat_comp(GC) Cc=cen_comp(GC) print Ps, Cs, Pc, Cc, b_sat print 'test:',(1-Ps)*N_sat_mock*Cs*Pc==(1-Pc)*N_cen_mock*b_sat*Cc*Ps print 'test:',N_sat*Ps/Cs==N_sat_mock print 'test:',N_cen*Pc/Cc==N_cen_mock print 'test:',N_cen+N_sat==N_cen_mock+N_sat_mock f_red_sat_1 = (f_red_sat-f_red_cen*(((1-Ps)*(1-Cc))/((1-Pc)*Cc*b_sat)))/(1-(((1-Cs)*(1-Cc))/(Ps*Pc)))/Ps f_red_cen_1 = (f_red_cen-f_red_sat_1*(((1-Cs)*(1-Pc)*Ps*b_sat)/((1-Ps)*Cs)))/Pc ax=axes[2] p4a_1, = ax.plot(bin_centers,f_red_sat_1,'o',color='green', mfc='none', mec='green', ms=3) p4a_1, = ax.plot(bin_centers,f_red_cen_1,'o',color='orange', mfc='none', mec='orange', ms=3) f_sat_red_1 =f_sat_red*b_sat f_sat_blue_1 =f_sat_blue*b_sat ax=axes[5] N_red_sat = f_red_sat_1 * N_sat*Ps/Cs N_red_cen = f_red_cen_1 * N_cen*Pc/Cc N_blue_sat = (1-f_red_sat_1) * N_sat*Ps/Cs N_blue_cen = (1-f_red_cen_1) * N_cen*Pc/Cc f_sat_red_1 = N_red_sat/(N_red_cen+N_red_sat) f_sat_blue_1 = N_blue_sat/(N_blue_cen+N_blue_sat) p4b_1, = ax.plot(bin_centers,f_sat_red_1,'o',color='red', mfc='none', mec='red', ms=3) p4b_1, = ax.plot(bin_centers,f_sat_blue_1,'o',color='blue', mfc='none', mec='blue', ms=3) ''' plt.show(block=False) print plotpath + filename + '.pdf' fig1.savefig(plotpath + filename + '.pdf')
def main(): catalogue = sys.argv[1] plotpath = cu.get_plot_path() + 'analysis/groupcats/' fig1, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() filename = catalogue + '_mock_group_f_red_sat_M.eps' N_boots = 50 ################################################################################################################################### group_cat = 'berlind' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' filepath_cat = cu.get_output_path( ) + 'processed_data/' + group_cat + '_groupcat/mock_runs/4th_run/custom_catalogues/' if group_cat == 'tinker': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind': group_catalogue = catalogue + '_groups' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.where(mock['ID_host'] == -1) satellites = np.where(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] LHS = 0.21 - 0.03 * mock['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #bins = np.arange(9.5,10.8,0.1) bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 result = np.digitize(mock['M_host'], bins=bins) f_red_cen = np.zeros(len(bin_centers)) f_red_sat = np.zeros(len(bin_centers)) f_sat_red = np.zeros(len(bin_centers)) f_sat_blue = np.zeros(len(bin_centers)) for i in range(0, len(bins) - 1): print i ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[i] = float( len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[i] = float(len(red_satellites)) / (len(red_satellites) + len(blue_satellites)) if (len(centrals_in_bin)) > 0: #f_sat_red[i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[i] = float(len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) ax = axes[0] ax.set_xlim([11, 15]) ax.set_ylim([0, 1]) ax.set_ylabel(r'$f_{red}$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) print 'opening group catalogue:', group_catalogue f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals = np.where(GC['RPROJ'] == 0) satellites = np.where(GC['RPROJ'] > 0) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #S_r = 4.64 #L = solar_lum(GC['M_r,0.1'],S_r) result = np.digitize(GC['MGROUP'], bins=bins) for i in range(0, len(bins) - 1): print i ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[boot, i] = float(len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[boot, i] = float(len(red_satellites)) / ( len(red_satellites) + len(blue_satellites)) if (len(centrals_in_bin)) > 0: #f_sat_red[boot,i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[boot,i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[boot, i] = float(len(red_satellites)) / ( len(red_centrals) + len(red_satellites)) f_sat_blue[boot, i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) f_sat_red_111 = f_sat_red f_sat_blue_111 = f_sat_blue f_cen = np.nanmean(f_red_cen, axis=0) f_sat = np.nanmean(f_red_sat, axis=0) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) err_sat_red = np.nanstd(f_sat_red_111, axis=0) err_sat_blue = np.nanstd(f_sat_blue_111, axis=0) ax = axes[0] p3a = ax.errorbar(bin_centers, f_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p1a, p2a), ('halo cen', 'halo sat'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_title(r'Berlind FoF groups') ####################################################################################################################### group_cat = 'tinker' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' filepath_cat = cu.get_output_path( ) + 'processed_data/' + group_cat + '_groupcat/mock_runs/4th_run/custom_catalogues/' if group_cat == 'tinker': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind': group_catalogue = catalogue + '_groups' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.where(mock['ID_host'] == -1) satellites = np.where(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] LHS = 0.21 - 0.03 * mock['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #bins = np.arange(9.5,10.8,0.1) bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 result = np.digitize(mock['M_host'], bins=bins) f_red_cen = np.zeros(len(bin_centers)) f_red_sat = np.zeros(len(bin_centers)) f_sat_red = np.zeros(len(bin_centers)) f_sat_blue = np.zeros(len(bin_centers)) for i in range(0, len(bins) - 1): print i ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[i] = float( len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[i] = float(len(red_satellites)) / (len(red_satellites) + len(blue_satellites)) if (len(centrals_in_bin)) > 0: #f_sat_red[i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[i] = float(len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) ax = axes[1] ax.set_xlim([11, 15]) ax.set_ylim([0, 1]) #ax.set_xticks([9.6,9.8,10.0,10.2,10.4,10.6]) #ax.set_ylabel(r'$f_{red}$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) print 'opening group catalogue:', group_catalogue f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals = np.where(GC['RPROJ'] == 0) satellites = np.where(GC['RPROJ'] > 0) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #S_r = 4.64 #L = solar_lum(GC['M_r,0.1'],S_r) result = np.digitize(GC['MGROUP'], bins=bins) for i in range(0, len(bins) - 1): print i ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[boot, i] = float(len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[boot, i] = float(len(red_satellites)) / ( len(red_satellites) + len(blue_satellites)) if (len(centrals_in_bin)) > 0: #f_sat_red[boot,i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[boot,i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[boot, i] = float(len(red_satellites)) / ( len(red_centrals) + len(red_satellites)) f_sat_blue[boot, i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) f_sat_red_111 = f_sat_red f_sat_blue_111 = f_sat_blue f_cen = np.nanmean(f_red_cen, axis=0) f_sat = np.nanmean(f_red_sat, axis=0) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) err_sat_red = np.nanstd(f_sat_red_111, axis=0) err_sat_blue = np.nanstd(f_sat_blue_111, axis=0) ax = axes[1] p3a = ax.errorbar(bin_centers, f_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.set_xticks([12.5, 13, 13.5, 14, 14.5]) ax.set_xlim([12, 15]) ax.set_title(r'Tinker SO groups') ax.legend((p3a, p4a), ('groups cen', 'groups sat'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ''' #calculate with correction x=0.8 y=0.93 f_sat_1 = (y*f_sat+(x-1)*f_cen)/(x*y+(x-1)*(1-y)) f_cen_1 = (f_cen-(1-y)*f_sat_1)/y p4a_1, = ax.plot(bin_centers,f_sat_1,'o',color='green', mfc='none', mec='green') p4a_1, = ax.plot(bin_centers,f_cen_1,'o',color='orange', mfc='none', mec='orange') ''' ####################################################################################################################### group_cat = 'yang' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' filepath_cat = cu.get_output_path( ) + 'processed_data/' + group_cat + '_groupcat/mock_runs/4th_run/custom_catalogues/' if group_cat == 'tinker': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind': group_catalogue = catalogue + '_groups' if group_cat == 'yang': group_catalogue = catalogue + '_groups' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.where(mock['ID_host'] == -1) satellites = np.where(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] LHS = 0.21 - 0.03 * mock['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #bins = np.arange(9.5,10.8,0.1) bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 result = np.digitize(mock['M_host'], bins=bins) f_red_cen = np.zeros(len(bin_centers)) f_red_sat = np.zeros(len(bin_centers)) f_sat_red = np.zeros(len(bin_centers)) f_sat_blue = np.zeros(len(bin_centers)) for i in range(0, len(bins) - 1): print i ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[i] = float( len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[i] = float(len(red_satellites)) / (len(red_satellites) + len(blue_satellites)) if (len(centrals_in_bin)) > 0: #f_sat_red[i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[i] = float(len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) ax = axes[2] ax.set_xlim([11, 15]) ax.set_ylim([0, 1]) #ax.set_xticks([9.6,9.8,10.0,10.2,10.4,10.6]) #ax.set_ylabel(r'$f_{red}$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) print 'opening group catalogue:', group_catalogue f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals = np.where(GC['RPROJ'] == 0) satellites = np.where(GC['RPROJ'] > 0) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #S_r = 4.64 #L = solar_lum(GC['M_r,0.1'],S_r) result = np.digitize(GC['MGROUP'], bins=bins) for i in range(0, len(bins) - 1): print i ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[boot, i] = float(len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[boot, i] = float(len(red_satellites)) / ( len(red_satellites) + len(blue_satellites)) if (len(centrals_in_bin)) > 0: #f_sat_red[boot,i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[boot,i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[boot, i] = float(len(red_satellites)) / ( len(red_centrals) + len(red_satellites)) f_sat_blue[boot, i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) f_sat_red_111 = f_sat_red f_sat_blue_111 = f_sat_blue f_cen = np.nanmean(f_red_cen, axis=0) f_sat = np.nanmean(f_red_sat, axis=0) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) err_sat_red = np.nanstd(f_sat_red_111, axis=0) err_sat_blue = np.nanstd(f_sat_blue_111, axis=0) ax = axes[2] p3a = ax.errorbar(bin_centers, f_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.set_xticks([12.5, 13, 13.5, 14, 14.5]) ax.set_xlim([12, 15]) ax.set_title(r'Yang SO groups') plt.show() fig1.savefig(plotpath + filename)
def main(): catalogue = 'Mr19_age_distribution_matching_mock' if len(sys.argv) > 1: catalogue = sys.argv[1] plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_mock_group_f_red_sat_M.eps' fig1, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() ax = axes[0] ax.set_xlim([0, 1.5]) ax.set_ylim([0, 1]) ax.set_ylabel(r'$f_{red}$') ax.set_xlabel(r'$R_{\rm proj} [{\rm Mpc}]$') ax.set_title(r'$13<log(M)<13.5$') ax = axes[1] ax.set_xlim([0, 1.5]) ax.set_ylim([0, 1]) ax.set_xlabel(r'$R_{\rm proj} [{\rm Mpc}]$') ax.set_title(r'$13.5<log(M)<14$') ax = axes[2] ax.set_xlim([0, 1.5]) ax.set_ylim([0, 1]) ax.set_xlabel(r'$R_{\rm proj} [{\rm Mpc}]$') ax.set_title(r'$14<log(M)<14.5$') N_boots = 50 bins = np.arange(0, 1.5, 0.1) bin_centers = (bins[:-1] + bins[1:]) / 2.0 #open mock catalogue filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) print mock.dtype.names centrals = np.array(mock['ID_host'] == -1) satellites = np.array(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] LHS = 0.21 - 0.03 * mock['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies selection = ((mock['M_host'] > 13.0) & (mock['M_host'] < 13.5)) selection = satellites & selection f_red_1 = f_prop(mock['R_proj'][selection], bins, red, blue, selection) selection = ((mock['M_host'] > 13.5) & (mock['M_host'] < 14.0)) selection = satellites & selection f_red_2 = f_prop(mock['R_proj'][selection], bins, red, blue, selection) selection = ((mock['M_host'] > 14.0) & (mock['M_host'] < 14.5)) selection = satellites & selection f_red_3 = f_prop(mock['R_proj'][selection], bins, red, blue, selection) ax = axes[0] p1, = ax.plot(bin_centers, f_red_1, color='orange') ax = axes[1] p2, = ax.plot(bin_centers, f_red_2, color='orange') ax = axes[2] p3, = ax.plot(bin_centers, f_red_3, color='orange') ################################################### groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_1 = np.zeros((N_boots, len(bin_centers))) f_red_2 = np.zeros((N_boots, len(bin_centers))) f_red_3 = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies selection = ((GC['MGROUP'] > 13.0) & (GC['MGROUP'] < 13.5)) selection = satellites_bool & selection f_red_1[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) selection = ((GC['MGROUP'] > 13.5) & (GC['MGROUP'] < 14.0)) selection = satellites_bool & selection f_red_2[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) selection = ((GC['MGROUP'] > 14.0) & (GC['MGROUP'] < 14.5)) selection = satellites_bool & selection f_red_3[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) err_1 = np.nanstd(f_red_1, axis=0) f_red_1 = np.nanmean(f_red_1, axis=0) err_2 = np.nanstd(f_red_2, axis=0) f_red_2 = np.nanmean(f_red_2, axis=0) err_3 = np.nanstd(f_red_3, axis=0) f_red_3 = np.nanmean(f_red_3, axis=0) ax = axes[0] p0a = ax.errorbar(bin_centers, f_red_1, yerr=err_1, fmt='o', color='red', mec='none', ms=3) ax = axes[1] p1a = ax.errorbar(bin_centers, f_red_2, yerr=err_2, fmt='o', color='red', mec='none', ms=3) ax = axes[2] p2a = ax.errorbar(bin_centers, f_red_3, yerr=err_3, fmt='o', color='red', mec='none', ms=3) ################################################### groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_1 = np.zeros((N_boots, len(bin_centers))) f_red_2 = np.zeros((N_boots, len(bin_centers))) f_red_3 = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies selection = ((GC['MGROUP'] > 13.0) & (GC['MGROUP'] < 13.5)) selection = satellites_bool & selection f_red_1[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) selection = ((GC['MGROUP'] > 13.5) & (GC['MGROUP'] < 14.0)) selection = satellites_bool & selection f_red_2[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) selection = ((GC['MGROUP'] > 14.0) & (GC['MGROUP'] < 14.5)) selection = satellites_bool & selection f_red_3[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) err_1 = np.nanstd(f_red_1, axis=0) f_red_1 = np.nanmean(f_red_1, axis=0) err_2 = np.nanstd(f_red_2, axis=0) f_red_2 = np.nanmean(f_red_2, axis=0) err_3 = np.nanstd(f_red_3, axis=0) f_red_3 = np.nanmean(f_red_3, axis=0) ax = axes[0] p0b = ax.errorbar(bin_centers, f_red_1, yerr=err_1, fmt='o', color='green', mec='none', ms=3) ax = axes[1] p1b = ax.errorbar(bin_centers, f_red_2, yerr=err_2, fmt='o', color='green', mec='none', ms=3) ax = axes[2] p2b = ax.errorbar(bin_centers, f_red_3, yerr=err_3, fmt='o', color='green', mec='none', ms=3) ################################################### groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_1 = np.zeros((N_boots, len(bin_centers))) f_red_2 = np.zeros((N_boots, len(bin_centers))) f_red_3 = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies selection = ((GC['MGROUP'] > 13.0) & (GC['MGROUP'] < 13.5)) selection = satellites_bool & selection f_red_1[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) selection = ((GC['MGROUP'] > 13.5) & (GC['MGROUP'] < 14.0)) selection = satellites_bool & selection f_red_2[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) selection = ((GC['MGROUP'] > 14.0) & (GC['MGROUP'] < 14.5)) selection = satellites_bool & selection f_red_3[boot, :] = f_prop(GC['RPROJ'] / 1000.0, bins, red_ind, blue_ind, selection) err_1 = np.nanstd(f_red_1, axis=0) f_red_1 = np.nanmean(f_red_1, axis=0) err_2 = np.nanstd(f_red_2, axis=0) f_red_2 = np.nanmean(f_red_2, axis=0) err_3 = np.nanstd(f_red_3, axis=0) f_red_3 = np.nanmean(f_red_3, axis=0) ax = axes[0] p0c = ax.errorbar(bin_centers, f_red_1, yerr=err_1, fmt='o', color='blue', mec='none', ms=3) ax = axes[1] p1c = ax.errorbar(bin_centers, f_red_2, yerr=err_2, fmt='o', color='blue', mec='none', ms=3) ax = axes[2] p2c = ax.errorbar(bin_centers, f_red_3, yerr=err_3, fmt='o', color='blue', mec='none', ms=3) plt.show()
def main(): comm = MPI.COMM_WORLD rank = comm.rank if len(sys.argv)>1: field = sys.argv[1] else: field = 'W3' if len(sys.argv)>2: catalogue = sys.argv[2] else: catalogue = 'sample3_L_model' savepath = cu.get_plot_path()+'/analysis/sdss.cfhtlens/cross_correlations/' #define cosmology cosmo = FlatLambdaCDM(H0=70, Om0=0.3) #down sample the number of points? Use this for testing purposes... DS = True fw = 100 fr = 1000 #import cfhtlens catalogues filepath = cu.get_output_path()+'processed_data/CFHTLens/' f = h5py.File(filepath+'catalogues/'+field+'_abbreviated.hdf5', 'r') W = f.get(field) filepath = cu.get_output_path()+'processed_data/CFHTLens/' R = np.load(filepath+'random_catalogues/'+field+'_randoms'+'.npy') print(W.dtype.names) #print(R.dtype.names) #import sdss group catalogue filepath = cu.get_output_path()+'processed_data/yang_groupcat/' f = h5py.File(filepath+'catalogues/'+catalogue+'.hdf5', 'r') GC = f.get(catalogue) #print(GC.dtype.names) #choose group sample to cross correlate with #choose galaxies in the field filepath = cu.get_output_path()+'processed_data/CFHTLens/' field_boundary = np.load(filepath+'field_boundaries/'+field +'.npy') condition_1 = cu.inside(GC['RAgal'],GC['DECgal'],field_boundary) #choose central galaxies condition_2 = (GC['Rproj_L'] == 0) #cut off low redshift(for now) condition_3 = (GC['GROUP_Z'] >= 0.02) #combine conditionals condition = (condition_1 & condition_2 & condition_3) GC = GC[condition] if rank==0: print("N1: {0}".format(len(GC))) #choose cfhtlens sample condition_1 = ((W['MAG_y']<24.5) & (W['MAG_y']!=-99)) condition_2 = ((W['MAG_i']<24.5) & (W['MAG_i']!=-99)) condition_12 = (condition_1 | condition_2) condition_3 = (W['Z_B']<0.2) condition_4 = (W['MASK']==0) condition = ((condition_12 & condition_3) & condition_4) W = W[condition] if DS==True: N = len(W) np.random.seed(0) inds = np.random.permutation(np.arange(0,N)) inds = inds[0:N//fw] W = W[inds] if rank==0: print("N2: {0}".format(len(W))) #choose random sample condition_1 = (R['flag']==0) condition = condition_1 R = R[condition] if DS==True: N = len(R) np.random.seed(0) inds = np.random.permutation(np.arange(0,N)) inds = inds[0:N//fr] R = R[inds] if rank==0: print("Nran: {0}".format(len(R))) #get the data into the appropriate form data_1 = np.column_stack((GC['RAgal'],GC['DECgal'])) z_gal = GC['ZGAL'] data_2 = np.column_stack((W['ALPHA_J2000'],W['DELTA_J2000'])) randoms = np.column_stack((R['ra'],R['dec'])) """ if rank==0: #plot the field and randoms as a sanity check fig = plt.figure(figsize=plt.figaspect(1)) #fig = plt.figure(figsize=plt.figaspect(0.5)) ax = fig.add_subplot(2, 2, 1) #ax.plot(R['ra'],R['dec'],'.',color='black', ms=2) ax.plot(GC['RAgal'],GC['DECgal'],'.',color='blue', ms=2) ax.plot(W['ALPHA_J2000'],W['DELTA_J2000'],'.',color='red', ms=2, alpha=0.25) ax.set_xlabel('ra') ax.set_ylabel('dec') ax.set_xlim([206,222]) ax.set_ylim([50,59]) #ax.legend(('randoms','sdss centrals','cfhtlens')) ax = fig.add_subplot(2, 2, 2) ax.plot(W['ALPHA_J2000'],W['DELTA_J2000'],'.',color='red', ms=2, alpha=0.25) ax.set_xlabel('ra') ax.set_ylabel('dec') ax.set_xlim([206,222]) ax.set_ylim([50,59]) ax = fig.add_subplot(2, 2, 3) ax.plot(R['ra'],R['dec'],'.',color='black', ms=2, alpha=0.25) ax.set_xlabel('ra') ax.set_ylabel('dec') ax.set_xlim([206,222]) ax.set_ylim([50,59]) #place on surface of a unit sphere to plot for sanity check from halotools.utils.spherical_geometry import spherical_to_cartesian, chord_to_cartesian from mpl_toolkits.mplot3d import Axes3D xyz_1 = np.empty((len(data_1),3)) xyz_1[:,0],xyz_1[:,1],xyz_1[:,2] = spherical_to_cartesian(data_1[:,0], data_1[:,1]) xyz_2 = np.empty((len(data_2),3)) xyz_2[:,0],xyz_2[:,1],xyz_2[:,2] = spherical_to_cartesian(data_2[:,0], data_2[:,1]) xyz_randoms = np.empty((len(randoms),3)) xyz_randoms[:,0],xyz_randoms[:,1],xyz_randoms[:,2] = spherical_to_cartesian(randoms[:,0], randoms[:,1]) ax = fig.add_subplot(2, 2, 4, projection='3d') #plot a spherical surface u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x = 1.0 * np.outer(np.cos(u), np.sin(v)) y = 1.0 * np.outer(np.sin(u), np.sin(v)) z = 1.0 * np.outer(np.ones(np.size(u)), np.cos(v)) #plot points on surface ax.plot_surface(x, y, z, rstride=4, cstride=4, color='grey',alpha=0.2) ax.plot(xyz_randoms[:,0],xyz_randoms[:,1],xyz_randoms[:,2],'.',color='black',ms=2) ax.plot(xyz_1[:,0],xyz_1[:,1],xyz_1[:,2],'.',color='blue',ms=2) ax.plot(xyz_2[:,0],xyz_2[:,1],xyz_2[:,2],'.',color='red',ms=2) #ax.set_xlim([min(xyz_1[:,0]),max(xyz_1[:,0])]) #ax.set_ylim([min(xyz_1[:,1]),max(xyz_1[:,1])]) #ax.set_zlim([min(xyz_1[:,2]),max(xyz_1[:,2])]) plt.show(block=False) """ #define angular bins r_bins = np.logspace(-2,0,25) bin_centers = (r_bins[:-1]+r_bins[1:])/2.0 if rank==0: print("radial bins:",r_bins) result = projected_cross_two_point_correlation_function(data_1, z_gal, data_2, r_bins,\ cosmo=cosmo, N_theta_bins=5,\ randoms=randoms, N_threads=1,\ estimator='Davis-Peebles',\ comm=comm, max_sample_size=int(1e8)) if rank==0: print(result) print(bin_centers) fig1 = plt.figure() plt.plot(bin_centers,result,'o-') plt.yscale('log') plt.xscale('log') plt.xlabel(r'$r_{\rm proj} [Mpc]$') plt.ylabel(r'$\omega(r_{\rm proj})$') filename = 'projected_correlation_'+field+'.pdf' plt.savefig(savepath+filename) plt.show()
def main(): catalogue_1 = 'sm_9.5_s0.2_sfr_c0.0_250' catalogue_2 = 'sm_8.5_s0.2_sfr_c-1.0_125' filepath_mock = cu.get_output_path() + 'processed_data/campbell_mocks/' #open catalogue f_1 = h5py.File(filepath_mock+catalogue_1+'.hdf5', 'r') #open catalogue file mock_1 = f_1.get(catalogue_1) f_2 = h5py.File(filepath_mock+catalogue_2+'.hdf5', 'r') #open catalogue file mock_2 = f_2.get(catalogue_2) data_1 = np.array(mock_1) data_2 = np.array(mock_2) GC = get_sdss_sample() mock = np.concatenate((data_1,data_2),axis=1) sm_bins = np.arange(9.5,11.5,0.4) sm_bin_centers = (sm_bins[:-1]+sm_bins[1:])/2.0 binned_gc_inds = np.digitize(mock['Mstar'],bins=sm_bins) p = [] fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.85, bottom=0.2, top=0.9) ax = fig.add_subplot(1, 1, 1) for i in range(0,len(sm_bins)-1): gc_inds = np.where(binned_gc_inds==i+1)[0] sub_sfr = mock['SSFR'][gc_inds] N = len(gc_inds) sorted_sfr = np.sort(sub_sfr) count = np.ones(N) counts = np.cumsum(count)-1 normalized_counts = counts/float(counts[-1]) line, = ax.plot(sorted_sfr,normalized_counts,color='black',alpha=(i+1.0)/(len(sm_bins))) p.append(line) binned_gc_inds = np.digitize(np.log10(10.0**GC['sm_MEDIAN']),bins=sm_bins) for i in range(0,len(sm_bins)-1): gc_inds = np.where(binned_gc_inds==i+1)[0] sub_sfr = GC['sfr_MEDIAN'][gc_inds] N = len(gc_inds) sorted_sfr = np.sort(sub_sfr) count = np.ones(N) counts = np.cumsum(count)-1 normalized_counts = counts/float(counts[-1]) ax.plot(sorted_sfr,normalized_counts,'--',color='black',alpha=(i+1.0)/(len(sm_bins))) ax.legend(p,sm_bin_centers,loc=4,title=r'$M_{*}$',fontsize=10, frameon=False, labelspacing=0.01) ax.set_ylim([0,1]) ax.set_xlim([-12.5,-8.5]) ax.set_xlabel(r'$\log({\rm SSFR}/{\rm yr^{-1}})$') ax.set_ylabel(r'$f(<{\rm SSFR})$') ax.set_xticklabels(['-12.5','','-11.5','','-10.5','','-9.5','','-8.5']) plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'mstar_ssfr_dist' fig.savefig(savepath+filename+'.pdf')
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock' savepath = cu.get_output_path() + 'analysis/groupcats/' plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_HOD' N_boots = 50 #set up ploting parameters fig, axes = plt.subplots(nrows=3, ncols=3, sharex=True, sharey=True, figsize=(6.95, 7.92)) fig.subplots_adjust(hspace=0.05, wspace=0) fig.subplots_adjust(right=0.95, bottom=0.083, left=0.1, top=0.958) axes = axes.flatten() #plot 1 axes[0].set_ylabel(r'$\langle N(M)\rangle$') axes[0].text(10**11.5, 50, 'all galaxies\n' r'$M_r<-19+5\log(h)$') axes[0].set_yscale('log', nonposy='clip') axes[0].set_xscale('log', nonposy='clip') axes[0].set_ylim([0.1, 200]) axes[0].set_xlim([10**11, 10**15]) #plot 2 axes[1].text(10**11.5, 50, 'red galaxies\n' r'$M_r<-19+5\log(h)$') axes[1].set_yscale('log', nonposy='clip') axes[1].set_xscale('log', nonposy='clip') axes[1].set_ylim([0.1, 200]) axes[1].set_xlim([10**11, 10**15]) #plot 3 axes[2].text(10**11.5, 50, 'blue galaxies\n' r'$M_r<-19+5\log(h)$') axes[2].text(10**15.15, 25, 'Berlind FoF groups', rotation=90) axes[2].set_yscale('log', nonposy='clip') axes[2].set_xscale('log', nonposy='clip') axes[2].set_ylim([0.1, 200]) axes[2].set_xlim([10**11, 10**15]) #plot 4 axes[3].set_ylabel(r'$\langle N(M)\rangle$') axes[3].set_yscale('log', nonposy='clip') axes[3].set_xscale('log', nonposy='clip') axes[3].set_ylim([0.1, 200]) axes[3].set_xlim([10**11, 10**15]) #plot 5 axes[4].set_yscale('log', nonposy='clip') axes[4].set_xscale('log', nonposy='clip') axes[4].set_ylim([0.1, 200]) axes[4].set_xlim([10**11, 10**15]) #plot 6 axes[5].text(10**15.15, 25, 'Tinker SO groups', rotation=90) axes[5].set_yscale('log', nonposy='clip') axes[5].set_xscale('log', nonposy='clip') axes[5].set_ylim([0.1, 200]) axes[5].set_xlim([10**11, 10**15]) #plot 7 axes[6].set_ylabel(r'$\langle N(M)\rangle$') axes[6].set_xlabel(r'$M$ $[M_{\odot}/h]$') axes[6].set_yscale('log', nonposy='clip') axes[6].set_xscale('log', nonposy='clip') axes[6].set_ylim([0.1, 200]) axes[6].set_xlim([10**11, 10**15]) #plot 8 axes[7].set_xlabel(r'$M$ $[M_{\odot}/h]$') axes[7].set_yscale('log', nonposy='clip') axes[7].set_xscale('log', nonposy='clip') axes[7].set_ylim([0.1, 200]) axes[7].set_xlim([10**11, 10**15]) #plot 9 axes[8].set_xlabel(r'$M$ $[M_{\odot}/h]$') axes[8].text(10**15.15, 25, 'Yang SO groups', rotation=90) axes[8].set_yscale('log', nonposy='clip') axes[8].set_xscale('log', nonposy='clip') axes[8].set_ylim([0.1, 200]) axes[8].set_xlim([10**11, 10**15]) axes[8].set_xticks([10**11, 10**12, 10**13, 10**14, 10**15]) axes[8].set_xticklabels( [r' ', r'$10^{12}$', r'$10^{13}$', r'$10^{14}$', r' ']) axes[0].set_yticks([0.1, 1.0, 10.0, 100.0]) axes[0].set_yticklabels([r' ', r'$1$', r'$10$', r'$100$']) bins = np.arange(10, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 ########################## #calculate for mock HOD ########################## filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '_extended.hdf5', 'r') #open catalogue file mock = f1.get(catalogue + '_extended') mock = np.array(mock) #print 'length:', len(mock) #for name in mock.dtype.names: print ' ', name bins = np.arange(10, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 occupied = np.where(mock['M_r,0.1'] != -99) empty = np.where(mock['M_r,0.1'] == -99) host = np.where(mock['ID_host'] == -1)[0] color = mock['g-r'] LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where((color < LHS) & (mock['M_r,0.1'] != -99))[0] red = np.where((color > LHS) & (mock['M_r,0.1'] != -99))[0] Ngal = np.zeros(len(mock)) Ngal[occupied] = 1 host_ID = mock['ID_host'] host_ID[host] = mock['ID_halo'][host] #All galaxies mask = np.zeros(len(mock)) mask[:] = 1 avg_N = hod(host_ID, mock['M_host'], Ngal, bins, mask) #Red Galaxies mask = np.zeros(len(mock)) mask[red] = 1 avg_N_red = hod(host_ID, mock['M_host'], Ngal, bins, mask) #Blue Galaxies mask = np.zeros(len(mock)) mask[blue] = 1 avg_N_blue = hod(host_ID, mock['M_host'], Ngal, bins, mask) #plot the results ax = axes[0] p1a, = ax.plot(10**bin_centers, avg_N, color='black') ax = axes[1] p2a, = ax.plot(10**bin_centers, avg_N_red, color='red') ax = axes[2] p3a, = ax.plot(10**bin_centers, avg_N_blue, color='blue') ax = axes[3] ax.plot(10**bin_centers, avg_N, color='black') ax = axes[4] ax.plot(10**bin_centers, avg_N_red, color='red') ax = axes[5] ax.plot(10**bin_centers, avg_N_blue, color='blue') ax = axes[6] ax.plot(10**bin_centers, avg_N, color='black') ax = axes[7] ax.plot(10**bin_centers, avg_N_red, color='red') ax = axes[8] ax.plot(10**bin_centers, avg_N_blue, color='blue') ########################## #calculate ideal groups HOD ########################## filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/ideal_groups/' print 'opening mock catalogue:', catalogue + '_groups.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '_groups.hdf5', 'r') #open catalogue file GC = f1.get(catalogue + '_groups') GC = np.array(GC) #print 'length:', len(GC) #for name in GC.dtype.names: print ' ', name bins = np.arange(10, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 centrals = np.where(GC['HALO_RANK'] == 1)[0] satellites = np.where(GC['HALO_RANK'] == 0)[0] color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where(color < LHS)[0] red = np.where(color > LHS)[0] Ngal = np.zeros(len(GC)) Ngal[:] = 1 host_ID = GC['GROUP_ID'] #mfactor=-1.0*np.log10(1.0/0.7) mfactor = 0.0 #All galaxies mask = np.zeros(len(GC)) mask[:] = 1 avg_N_all = hod(host_ID, GC['MGROUP'] + mfactor, Ngal, bins, mask) #Red Galaxies mask = np.zeros(len(GC)) mask[red] = 1 avg_N_red = hod(host_ID, GC['MGROUP'] + mfactor, Ngal, bins, mask) #Blue Galaxies mask = np.zeros(len(GC)) mask[blue] = 1 avg_N_blue = hod(host_ID, GC['MGROUP'] + mfactor, Ngal, bins, mask) #plot the results alpha = 1 ax = axes[0] pppp, = ax.plot(10**bin_centers, avg_N_all, ':', color='black', alpha=alpha, fillstyle='none') ax = axes[1] p2c, = ax.plot(10**bin_centers, avg_N_red, ':', color='red', alpha=alpha, fillstyle='none') ax = axes[2] p3a, = ax.plot(10**bin_centers, avg_N_blue, ':', color='blue', alpha=alpha, fillstyle='none') ax = axes[3] ax.plot(10**bin_centers, avg_N_all, ':', color='black', alpha=alpha, fillstyle='none') ax = axes[4] ax.plot(10**bin_centers, avg_N_red, ':', color='red', alpha=alpha, fillstyle='none') ax = axes[5] ax.plot(10**bin_centers, avg_N_blue, ':', color='blue', alpha=alpha, fillstyle='none') ax = axes[6] ax.plot(10**bin_centers, avg_N_all, ':', color='black', alpha=alpha, fillstyle='none') ax = axes[7] ax.plot(10**bin_centers, avg_N_red, ':', color='red', alpha=alpha, fillstyle='none') ax = axes[8] ax.plot(10**bin_centers, avg_N_blue, ':', color='blue', alpha=alpha, fillstyle='none') ########################## #calculate mock groups HOD ########################## group_cat = 'berlind_groupcat' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' filepath_GC = cu.get_output_path( ) + 'processed_data/' + group_cat + '/mock_runs/4th_run/custom_catalogues/' if group_cat == 'tinker_groupcat': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind_groupcat': group_catalogue = catalogue + '_groups' if group_cat == 'yang_groupcat': group_catalogue = catalogue + '_groups' #set up arrays to store results avg_N_all = np.zeros((N_boots, len(bins) - 1)) avg_N_red = np.zeros((N_boots, len(bins) - 1)) avg_N_blue = np.zeros((N_boots, len(bins) - 1)) for boot in range(0, N_boots): #print 'opening mock group catalogue:', filepath_GC+'bootstraps/'+group_catalogue+'_'+str(boot)+'.hdf5' f2 = h5py.File(filepath_GC + 'bootstraps/' + group_catalogue + '_' + str(boot) + '.hdf5', 'r') #open catalogue file GC = f2.get(group_catalogue + '_' + str(boot)) GC = np.array(GC) #print len(GC) #for name in GC.dtype.names: print ' ', name centrals = np.where(GC['RANK'] == 1)[0] satellites = np.where(GC['RANK'] == 0)[0] color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where(color < LHS)[0] red = np.where(color > LHS)[0] Ngal = np.zeros(len(GC)) Ngal[:] = 1 host_ID = GC['GROUP_ID'] #All galaxies mask = np.zeros(len(GC)) mask[:] = 1 avg_N_all[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #Red Galaxies mask = np.zeros(len(GC)) mask[red] = 1 avg_N_red[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #Blue Galaxies mask = np.zeros(len(GC)) mask[blue] = 1 avg_N_blue[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #calculate the error bars avg_N_all_err = np.std(avg_N_all, axis=0) avg_N_red_err = np.std(avg_N_red, axis=0) avg_N_blue_err = np.std(avg_N_blue, axis=0) avg_N_all = np.mean(avg_N_all, axis=0) avg_N_red = np.mean(avg_N_red, axis=0) avg_N_blue = np.mean(avg_N_blue, axis=0) #plot the results with error bars ontop of the mock result ax = axes[0] p1b = ax.errorbar(10**bin_centers, avg_N_all, yerr=avg_N_all_err, fmt='o', color='black', ms=3, mec='none') ax.legend((p1a, p1b), ('mock', 'group catalogue'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ax = axes[1] p2b = ax.errorbar(10**bin_centers, avg_N_red, yerr=avg_N_red_err, fmt='o', color='red', ms=3, mec='none') ax = axes[2] p3b = ax.errorbar(10**bin_centers, avg_N_blue, yerr=avg_N_blue_err, fmt='o', color='blue', ms=3, mec='none') ########################## #calculate mock groups HOD ########################## group_cat = 'tinker_groupcat' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' filepath_GC = cu.get_output_path( ) + 'processed_data/' + group_cat + '/mock_runs/4th_run/custom_catalogues/' if group_cat == 'tinker_groupcat': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind_groupcat': group_catalogue = catalogue + '_groups' if group_cat == 'yang_groupcat': group_catalogue = catalogue + '_groups' #set up arrays to store results avg_N_all = np.zeros((N_boots, len(bins) - 1)) avg_N_red = np.zeros((N_boots, len(bins) - 1)) avg_N_blue = np.zeros((N_boots, len(bins) - 1)) for boot in range(0, N_boots): #print 'opening mock group catalogue:', filepath_GC+'bootstraps/'+group_catalogue+'_'+str(boot)+'.hdf5' f2 = h5py.File(filepath_GC + 'bootstraps/' + group_catalogue + '_' + str(boot) + '.hdf5', 'r') #open catalogue file GC = f2.get(group_catalogue + '_' + str(boot)) GC = np.array(GC) #print len(GC) #for name in GC.dtype.names: print ' ', name centrals = np.where(GC['RANK'] == 1)[0] satellites = np.where(GC['RANK'] == 0)[0] color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where(color < LHS)[0] red = np.where(color > LHS)[0] Ngal = np.zeros(len(GC)) Ngal[:] = 1 host_ID = GC['GROUP_ID'] #All galaxies mask = np.zeros(len(GC)) mask[:] = 1 avg_N_all[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #Red Galaxies mask = np.zeros(len(GC)) mask[red] = 1 avg_N_red[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #Blue Galaxies mask = np.zeros(len(GC)) mask[blue] = 1 avg_N_blue[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #calculate the error bars avg_N_all_err = np.std(avg_N_all, axis=0) avg_N_red_err = np.std(avg_N_red, axis=0) avg_N_blue_err = np.std(avg_N_blue, axis=0) avg_N_all = np.mean(avg_N_all, axis=0) avg_N_red = np.mean(avg_N_red, axis=0) avg_N_blue = np.mean(avg_N_blue, axis=0) #plot the results with error bars ontop of the mock result ax = axes[3] p1b = ax.errorbar(10**bin_centers, avg_N_all, yerr=avg_N_all_err, fmt='o', color='black', ms=3, mec='none') ax.legend([pppp], ['limit of ``perfect" \n group membership'], loc='lower right', fontsize=10, numpoints=1, frameon=False) ax = axes[4] p2b = ax.errorbar(10**bin_centers, avg_N_red, yerr=avg_N_red_err, fmt='o', color='red', ms=3, mec='none') ax = axes[5] p3b = ax.errorbar(10**bin_centers, avg_N_blue, yerr=avg_N_blue_err, fmt='o', color='blue', ms=3, mec='none') ########################## #calculate mock groups HOD ########################## group_cat = 'yang_groupcat' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' filepath_GC = cu.get_output_path( ) + 'processed_data/' + group_cat + '/mock_runs/4th_run/version_2/custom_catalogues/' if group_cat == 'tinker_groupcat': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind_groupcat': group_catalogue = catalogue + '_groups' if group_cat == 'yang_groupcat': group_catalogue = catalogue + '_groups' #set up arrays to store results avg_N_all = np.zeros((N_boots, len(bins) - 1)) avg_N_red = np.zeros((N_boots, len(bins) - 1)) avg_N_blue = np.zeros((N_boots, len(bins) - 1)) for boot in range(0, N_boots): #print 'opening mock group catalogue:', filepath_GC+'bootstraps/'+group_catalogue+'_'+str(boot)+'.hdf5' f2 = h5py.File(filepath_GC + 'bootstraps/' + group_catalogue + '_' + str(boot) + '.hdf5', 'r') #open catalogue file GC = f2.get(group_catalogue + '_' + str(boot)) GC = np.array(GC) #print len(GC) #for name in GC.dtype.names: print ' ', name centrals = np.where(GC['RANK'] == 1)[0] satellites = np.where(GC['RANK'] == 0)[0] color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where(color < LHS)[0] red = np.where(color > LHS)[0] Ngal = np.zeros(len(GC)) Ngal[:] = 1 host_ID = GC['GROUP_ID'] #All galaxies mask = np.zeros(len(GC)) mask[:] = 1 avg_N_all[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #Red Galaxies mask = np.zeros(len(GC)) mask[red] = 1 avg_N_red[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #Blue Galaxies mask = np.zeros(len(GC)) mask[blue] = 1 avg_N_blue[boot, :] = hod(host_ID, GC['MGROUP'], Ngal, bins, mask) #calculate the error bars avg_N_all_err = np.std(avg_N_all, axis=0) avg_N_red_err = np.std(avg_N_red, axis=0) avg_N_blue_err = np.std(avg_N_blue, axis=0) avg_N_all = np.mean(avg_N_all, axis=0) avg_N_red = np.mean(avg_N_red, axis=0) avg_N_blue = np.mean(avg_N_blue, axis=0) #plot the results with error bars ontop of the mock result ax = axes[6] p1b = ax.errorbar(10**(bin_centers), avg_N_all, yerr=avg_N_all_err, fmt='o', color='black', ms=3, mec='none') ax = axes[7] p2b = ax.errorbar(10**(bin_centers), avg_N_red, yerr=avg_N_red_err, fmt='o', color='red', ms=3, mec='none') ax = axes[8] p3b = ax.errorbar(10**(bin_centers), avg_N_blue, yerr=avg_N_blue_err, fmt='o', color='blue', ms=3, mec='none') plt.show(block=True) print plotpath + filename + '.pdf' fig.savefig(plotpath + filename + '.pdf')
def main(): catalogues_0 = [ "sm_8.5_s0.2_sfr_c-1.0_250", "sm_8.5_s0.2_sfr_c-0.75_250", "sm_8.5_s0.2_sfr_c-0.5_250", "sm_8.5_s0.2_sfr_c-0.25_250", "sm_8.5_s0.2_sfr_c0.0_250", ] catalogues_1 = [ "sm_9.5_s0.2_sfr_c-1.0_250", "sm_9.5_s0.2_sfr_c-0.75_250", "sm_9.5_s0.2_sfr_c-0.5_250", "sm_9.5_s0.2_sfr_c-0.25_250", "sm_9.5_s0.2_sfr_c0.0_250", ] samples = ["central_all", "central_q", "central_sf"] sm_bins = ["9.0_9.5", "9.5_10.0", "10.0_10.5", "10.5_11.0", "11.0_11.5"] ###################################################################################### # set up plot ###################################################################################### fig1, axes = plt.subplots(nrows=1, ncols=1, sharex=True, sharey=True, figsize=(3.3, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.0, left=0.2, right=0.9, bottom=0.2, top=0.9) ax = axes ax.set_xlim([0.1, 20]) ax.set_ylim([10, 200]) ax.set_yscale("log") ax.set_xscale("log") ax.set_ylabel(r"$\omega_p(r_p)\times r_p$") ax.set_xlabel(r"$r_p~[{\rm Mpc}~h^{-1}]$") ax.set_title(r"$10.0<\log(M_{*}/M_{\odot}h^{-2})<10.5$") ###################################################################################### # read in results and plot ###################################################################################### sm_bin = sm_bins[2] filepath = cu.get_output_path() + "analysis/central_quenching/observables/" names = ["r", "wp"] filename = catalogues_1[0] + "_wp_" + samples[0] + "_" + sm_bin + ".dat" result_1a = ascii.read(filepath + filename, names=names) filename = catalogues_1[0] + "_wp_" + samples[1] + "_" + sm_bin + ".dat" result_1b = ascii.read(filepath + filename, names=names) filename = catalogues_1[0] + "_wp_" + samples[2] + "_" + sm_bin + ".dat" result_1c = ascii.read(filepath + filename, names=names) filename = catalogues_1[1] + "_wp_" + samples[0] + "_" + sm_bin + ".dat" result_2a = ascii.read(filepath + filename, names=names) filename = catalogues_1[1] + "_wp_" + samples[1] + "_" + sm_bin + ".dat" result_2b = ascii.read(filepath + filename, names=names) filename = catalogues_1[1] + "_wp_" + samples[2] + "_" + sm_bin + ".dat" result_2c = ascii.read(filepath + filename, names=names) filename = catalogues_1[2] + "_wp_" + samples[0] + "_" + sm_bin + ".dat" result_3a = ascii.read(filepath + filename, names=names) filename = catalogues_1[2] + "_wp_" + samples[1] + "_" + sm_bin + ".dat" result_3b = ascii.read(filepath + filename, names=names) filename = catalogues_1[2] + "_wp_" + samples[2] + "_" + sm_bin + ".dat" result_3c = ascii.read(filepath + filename, names=names) filename = catalogues_1[3] + "_wp_" + samples[0] + "_" + sm_bin + ".dat" result_4a = ascii.read(filepath + filename, names=names) filename = catalogues_1[3] + "_wp_" + samples[1] + "_" + sm_bin + ".dat" result_4b = ascii.read(filepath + filename, names=names) filename = catalogues_1[3] + "_wp_" + samples[2] + "_" + sm_bin + ".dat" result_4c = ascii.read(filepath + filename, names=names) filename = catalogues_1[4] + "_wp_" + samples[0] + "_" + sm_bin + ".dat" result_5a = ascii.read(filepath + filename, names=names) filename = catalogues_1[4] + "_wp_" + samples[1] + "_" + sm_bin + ".dat" result_5b = ascii.read(filepath + filename, names=names) filename = catalogues_1[4] + "_wp_" + samples[2] + "_" + sm_bin + ".dat" result_5c = ascii.read(filepath + filename, names=names) ax = axes p1a, = ax.plot(result_1a["r"], result_1a["wp"] * result_1a["r"], "-", color="black", alpha=1) p1b, = ax.plot(result_1b["r"], result_1b["wp"] * result_1a["r"], "-", color="red", alpha=1) p1c, = ax.plot(result_1c["r"], result_1c["wp"] * result_1a["r"], "-", color="blue", alpha=1) p2a, = ax.plot(result_2a["r"], result_2a["wp"] * result_1a["r"], "-", color="black", alpha=0.8) p2b, = ax.plot(result_2b["r"], result_2b["wp"] * result_1a["r"], "-", color="red", alpha=0.8) p2c, = ax.plot(result_2c["r"], result_2c["wp"] * result_1a["r"], "-", color="blue", alpha=0.8) p3a, = ax.plot(result_3a["r"], result_3a["wp"] * result_1a["r"], "-", color="black", alpha=0.6) p3b, = ax.plot(result_3b["r"], result_3b["wp"] * result_1a["r"], "-", color="red", alpha=0.6) p3c, = ax.plot(result_3c["r"], result_3c["wp"] * result_1a["r"], "-", color="blue", alpha=0.6) p4a, = ax.plot(result_4a["r"], result_4a["wp"] * result_1a["r"], "-", color="black", alpha=0.4) p4b, = ax.plot(result_4b["r"], result_4b["wp"] * result_1a["r"], "-", color="red", alpha=0.4) p4c, = ax.plot(result_4c["r"], result_4c["wp"] * result_1a["r"], "-", color="blue", alpha=0.4) p5a, = ax.plot(result_5a["r"], result_5a["wp"] * result_1a["r"], "-", color="black", alpha=0.2) p5b, = ax.plot(result_5b["r"], result_5b["wp"] * result_1a["r"], "-", color="red", alpha=0.2) p5c, = ax.plot(result_5c["r"], result_5c["wp"] * result_1a["r"], "-", color="blue", alpha=0.2) ax.legend( (p1c, p2c, p3c, p4c, p5c), (r"$\rho=-1.0$", r"$\rho=-0.75$", r"$\rho=-0.5$", r"$\rho=-0.25$", r"$\rho=0.0$"), loc=4, fontsize=10, frameon=False, labelspacing=0.01, title="SF galaxies", ) plt.show(block=True) savepath = cu.get_plot_path() + "/analysis/central_quenching/" filename = "w_p_cross_r_single_panel" fig1.savefig(savepath + filename + ".pdf")
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock' savepath = cu.get_output_path() + 'analysis/groupcats/' plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_CLF_expanded' N_boots = 50 #set up ploting parameters fig, axes = plt.subplots(nrows=3, ncols=3, sharex=True, sharey=True, figsize=(6.95, 7.92)) fig.subplots_adjust(hspace=0.05, wspace=0) fig.subplots_adjust(right=0.95, bottom=0.083, left=0.1, top=0.958) axes = axes.flatten() #plot 1 axes[0].set_ylabel(r'$\phi(L){\rm dlog}L/{\rm group}$') axes[0].set_title(r'$12.5<\log(M/[M_{\odot}h^{-1}])<13.0$', fontsize=8) axes[0].set_yscale('log', nonposy='clip') axes[0].set_ylim(0.01, 50) axes[0].set_xlim([9, 11.5]) #plot 2 axes[1].set_title(r'$13.0<\log(M/[M_{\odot}h^{-1}])<13.5$', fontsize=8) axes[1].set_yscale('log', nonposy='clip') axes[1].set_ylim(0.01, 50) axes[1].set_xlim([9, 11.5]) #plot 3 axes[2].set_title(r'$13.5<\log(M/[M_{\odot}h^{-1}])<14.0$', fontsize=8) axes[2].set_yscale('log', nonposy='clip') axes[2].set_ylim(0.01, 50) axes[2].set_xlim([9, 11.5]) #axes[2].text(11.05,8,'Berlind FoF groups', rotation=90) #plot 4 axes[3].set_ylabel(r'$\phi(L){\rm dlog}L/{\rm group}$') axes[3].set_yscale('log', nonposy='clip') axes[3].set_ylim(0.01, 50) axes[3].set_xlim([9, 11.5]) #plot 5 axes[4].set_yscale('log', nonposy='clip') axes[4].set_ylim(0.01, 50) axes[4].set_xlim([9, 11.5]) #plot 6 axes[5].set_yscale('log', nonposy='clip') axes[5].set_ylim(0.01, 50) axes[5].set_xlim([9, 11.5]) #axes[5].text(11.05,8,'Tinker SO groups', rotation=90) #plot 7 axes[6].set_ylabel(r'$\phi(L){\rm dlog}L/{\rm group}$') axes[6].set_xlabel(r'$\log(L/[L_{\odot}h^{-2}])$') axes[6].set_yscale('log', nonposy='clip') axes[6].set_ylim(0.01, 50) axes[6].set_xlim([9, 11.5]) #plot 8 axes[7].set_xlabel(r'$\log(L/[L_{\odot}h^{-2}])$') axes[7].set_yscale('log', nonposy='clip') axes[7].set_ylim(0.01, 50) axes[7].set_xlim([9, 11.5]) #plot 9 axes[8].set_xlabel(r'$\log(L/[L_{\odot}h^{-2}])$') axes[8].set_yscale('log', nonposy='clip') axes[8].set_ylim(0.01, 50) axes[8].set_xlim([9.5, 11.0]) #axes[8].text(11.05,6,'Yang SO groups', rotation=90) axes[8].set_xticks([9.4, 9.6, 9.8, 10.0, 10.2, 10.4, 10.6, 10.8, 11.0]) axes[8].set_xticklabels( ["", "9.6", "", "10.0", "", "10.4", "", "10.8", ""]) #axes[8].set_yticklabels(["", "$0.1$", "$1$","$10$"]) bins = np.arange(9.45, 12.0, 0.15) bin_centers = (bins[:-1] + bins[1:]) / 2.0 S_r = 4.64 ########################## #calculate for mock HOD ########################## filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '_extended.hdf5', 'r') #open catalogue file mock = f1.get(catalogue + '_extended') mock = np.array(mock) print 'length:', len(mock) for name in mock.dtype.names: print ' ', name occupied = np.where(mock['M_r,0.1'] != -99) empty = np.where(mock['M_r,0.1'] == -99) host = np.where(mock['ID_host'] == -1)[0] color = mock['g-r'] LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.array((color < LHS) & (mock['M_r,0.1'] != -99)) red = np.array((color > LHS) & (mock['M_r,0.1'] != -99)) centrals = np.array(mock['ID_host'] == -1) satellites = np.array(mock['ID_host'] != -1) host_ID = mock['ID_host'] host_ID[host] = mock['ID_halo'][host] L = solar_lum(mock['M_r,0.1'], S_r) mass_bin = [12.5, 13.0] phi = clf(host_ID, L, bins, mock['M_host'], mass_bin) mask = red & centrals phi_red_cen = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = blue & centrals phi_blue_cen = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = red & satellites phi_red_sat = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = blue & satellites phi_blue_sat = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) print phi_blue_sat #plot the results ax = axes[0] p1a, = ax.plot(bin_centers, phi, color='black') ax = axes[3] p2a, = ax.plot(bin_centers, phi_red_cen, '-', color='red') ax = axes[3] p3a, = ax.plot(bin_centers, phi_blue_cen, '-', color='blue') ax = axes[6] p4a, = ax.plot(bin_centers, phi_red_sat, color='red') ax = axes[6] p5a, = ax.plot(bin_centers, phi_blue_sat, color='blue') mass_bin = [13.0, 13.5] phi = clf(host_ID, L, bins, mock['M_host'], mass_bin) mask = red & centrals phi_red_cen = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = blue & centrals phi_blue_cen = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = red & satellites phi_red_sat = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = blue & satellites phi_blue_sat = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) print phi_blue_sat #plot the results ax = axes[1] p1b, = ax.plot(bin_centers, phi, color='black') ax = axes[4] p2b, = ax.plot(bin_centers, phi_red_cen, '-', color='red') ax = axes[4] p3b, = ax.plot(bin_centers, phi_blue_cen, '-', color='blue') ax = axes[7] p4b, = ax.plot(bin_centers, phi_red_sat, color='red') ax = axes[7] p5b, = ax.plot(bin_centers, phi_blue_sat, color='blue') mass_bin = [13.5, 14.0] phi = clf(host_ID, L, bins, mock['M_host'], mass_bin) mask = red & centrals phi_red_cen = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = blue & centrals phi_blue_cen = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = red & satellites phi_red_sat = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) mask = blue & satellites phi_blue_sat = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask) print phi_blue_sat #plot the results ax = axes[2] p1c, = ax.plot(bin_centers, phi, color='black') ax = axes[5] p2c, = ax.plot(bin_centers, phi_red_cen, '-', color='red') ax = axes[5] p3c, = ax.plot(bin_centers, phi_blue_cen, '-', color='blue') ax = axes[8] p4c, = ax.plot(bin_centers, phi_red_sat, color='red') ax = axes[8] p5c, = ax.plot(bin_centers, phi_blue_sat, color='blue') ''' ########################## #calculate for ideal groups ########################## filepath_mock = cu.get_output_path() + 'processed_data/hearin_mocks/ideal_groups/' print 'opening mock catalogue:', catalogue+'_groups.hdf5' f1 = h5py.File(filepath_mock+catalogue+'_groups.hdf5', 'r') #open catalogue file GC = f1.get(catalogue+'_groups') #centrals = np.array(GC['HALO_RANK']==0) #satellites = np.array(GC['HALO_RANK']>0) centrals = np.array(GC['RANK']==0) satellites = np.array(GC['RANK']>0) color = GC['M_g,0.1']-GC['M_r,0.1'] LHS = 0.7 - 0.032*(GC['M_r,0.1']+16.5) #Weinmann 2006 blue = np.array(color<LHS) red = np.array(color>LHS) host_ID = GC['GROUP_ID'] L = solar_lum(GC['M_r,0.1'],S_r) #halo_mass = GC['HALO_M'] halo_mass = GC['MGROUP'] mass_bin = [12.5,13.0] phi_1 = clf(host_ID,L,bins,halo_mass,mass_bin) mask=red¢rals phi_red_cen_1 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=blue¢rals phi_blue_cen_1 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=red&satellites phi_red_sat_1 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=blue&satellites phi_blue_sat_1 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mass_bin = [13.0,13.5] phi_2 = clf(host_ID,L,bins,halo_mass,mass_bin) mask=red¢rals phi_red_cen_2 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=blue¢rals phi_blue_cen_2 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=red&satellites phi_red_sat_2 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=blue&satellites phi_blue_sat_2= clf(host_ID,L,bins,halo_mass,mass_bin,mask) mass_bin = [13.5,14.0] phi_3 = clf(host_ID,L,bins,halo_mass,mass_bin) mask=red¢rals phi_red_cen_3 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=blue¢rals phi_blue_cen_3 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=red&satellites phi_red_sat_3 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) mask=blue&satellites phi_blue_sat_3 = clf(host_ID,L,bins,halo_mass,mass_bin,mask) #plot the results ax=axes[0] p1a,=ax.plot(bin_centers, phi_1, color='black', alpha=0.5) ax=axes[0] p2a,=ax.plot(bin_centers, phi_red_cen_1, '--', color='red', alpha=0.5) ax=axes[0] p3a,=ax.plot(bin_centers, phi_blue_cen_1, '--', color='blue', alpha=0.5) ax=axes[3] p1a,=ax.plot(bin_centers, phi_1, color='black', alpha=0.5) ax=axes[3] p2a,=ax.plot(bin_centers, phi_red_cen_1, '--', color='red', alpha=0.5) ax=axes[3] p3a,=ax.plot(bin_centers, phi_blue_cen_1, '--', color='blue', alpha=0.5) ax=axes[6] p1a,=ax.plot(bin_centers, phi_1, color='black', alpha=0.5) ax=axes[6] p2a,=ax.plot(bin_centers, phi_red_cen_1, '--', color='red', alpha=0.5) ax=axes[6] p3a,=ax.plot(bin_centers, phi_blue_cen_1, '--', color='blue', alpha=0.5) ax=axes[0] p2a,=ax.plot(bin_centers, phi_red_sat_1, color='red', alpha=0.5) ax=axes[0] p3a,=ax.plot(bin_centers, phi_blue_sat_1, color='blue', alpha=0.5) ax=axes[3] p2a,=ax.plot(bin_centers, phi_red_sat_1, color='red', alpha=0.5) ax=axes[3] p3a,=ax.plot(bin_centers, phi_blue_sat_1, color='blue', alpha=0.5) ax=axes[6] p2a,=ax.plot(bin_centers, phi_red_sat_1, color='red', alpha=0.5) ax=axes[6] p3a,=ax.plot(bin_centers, phi_blue_sat_1, color='blue', alpha=0.5) ax=axes[1] p1a,=ax.plot(bin_centers, phi_2, color='black', alpha=0.5) ax=axes[1] p2a,=ax.plot(bin_centers, phi_red_cen_2, '--', color='red', alpha=0.5) ax=axes[1] p3a,=ax.plot(bin_centers, phi_blue_cen_2, '--', color='blue', alpha=0.5) ax=axes[4] p1a,=ax.plot(bin_centers, phi_2, color='black', alpha=0.5) ax=axes[4] p2a,=ax.plot(bin_centers, phi_red_cen_2, '--', color='red', alpha=0.5) ax=axes[4] p3a,=ax.plot(bin_centers, phi_blue_cen_2, '--', color='blue', alpha=0.5) ax=axes[7] p1a,=ax.plot(bin_centers, phi_2, color='black', alpha=0.5) ax=axes[7] p2a,=ax.plot(bin_centers, phi_red_cen_2, '--', color='red', alpha=0.5) ax=axes[7] p3a,=ax.plot(bin_centers, phi_blue_cen_2, '--', color='blue', alpha=0.5) ax=axes[1] p2a,=ax.plot(bin_centers, phi_red_sat_2, color='red', alpha=0.5) ax=axes[1] p3a,=ax.plot(bin_centers, phi_blue_sat_2, color='blue', alpha=0.5) ax=axes[4] p2a,=ax.plot(bin_centers, phi_red_sat_2, color='red', alpha=0.5) ax=axes[4] p3a,=ax.plot(bin_centers, phi_blue_sat_2, color='blue', alpha=0.5) ax=axes[7] p2a,=ax.plot(bin_centers, phi_red_sat_2, color='red', alpha=0.5) ax=axes[7] p3a,=ax.plot(bin_centers, phi_blue_sat_2, color='blue', alpha=0.5) ax=axes[2] p1a,=ax.plot(bin_centers, phi_3, color='black', alpha=0.5) ax=axes[2] p2a,=ax.plot(bin_centers, phi_red_cen_3, '--', color='red', alpha=0.5) ax=axes[2] p3a,=ax.plot(bin_centers, phi_blue_cen_3, '--', color='blue', alpha=0.5) ax=axes[5] p1a,=ax.plot(bin_centers, phi_3, color='black', alpha=0.5) ax=axes[5] p2a,=ax.plot(bin_centers, phi_red_cen_3, '--', color='red', alpha=0.5) ax=axes[5] p3a,=ax.plot(bin_centers, phi_blue_cen_3, '--', color='blue', alpha=0.5) ax=axes[8] p1a,=ax.plot(bin_centers, phi_3, color='black', alpha=0.5) ax=axes[8] p2a,=ax.plot(bin_centers, phi_red_cen_3, '--', color='red', alpha=0.5) ax=axes[8] p3a,=ax.plot(bin_centers, phi_blue_cen_3, '--', color='blue', alpha=0.5) ax=axes[2] p2a,=ax.plot(bin_centers, phi_red_sat_3, color='red', alpha=0.5) ax=axes[2] p3a,=ax.plot(bin_centers, phi_blue_sat_3, color='blue', alpha=0.5) ax=axes[5] p2a,=ax.plot(bin_centers, phi_red_sat_3, color='red', alpha=0.5) ax=axes[5] p3a,=ax.plot(bin_centers, phi_blue_sat_3, color='blue', alpha=0.5) ax=axes[8] p2a,=ax.plot(bin_centers, phi_red_sat_3, color='red', alpha=0.5) ax=axes[8] p3a,=ax.plot(bin_centers, phi_blue_sat_3, color='blue', alpha=0.5) ''' ########################## #calculate mock groups CLF ########################## group_cat = 'yang_groupcat' filepath_GC = cu.get_output_path( ) + 'processed_data/' + group_cat + '/mock_runs/4th_run/version_2/custom_catalogues/' if group_cat == 'tinker_groupcat': group_catalogue = catalogue + '_clf_groups_M19' if group_cat == 'berlind_groupcat': group_catalogue = catalogue + '_groups' if group_cat == 'yang_groupcat': group_catalogue = catalogue + '_groups' #set up arrays to store results phi_1 = np.zeros((N_boots, len(bins) - 1)) phi_red_cen_1 = np.zeros((N_boots, len(bins) - 1)) phi_blue_cen_1 = np.zeros((N_boots, len(bins) - 1)) phi_red_sat_1 = np.zeros((N_boots, len(bins) - 1)) phi_blue_sat_1 = np.zeros((N_boots, len(bins) - 1)) phi_2 = np.zeros((N_boots, len(bins) - 1)) phi_red_cen_2 = np.zeros((N_boots, len(bins) - 1)) phi_blue_cen_2 = np.zeros((N_boots, len(bins) - 1)) phi_red_sat_2 = np.zeros((N_boots, len(bins) - 1)) phi_blue_sat_2 = np.zeros((N_boots, len(bins) - 1)) phi_3 = np.zeros((N_boots, len(bins) - 1)) phi_red_cen_3 = np.zeros((N_boots, len(bins) - 1)) phi_blue_cen_3 = np.zeros((N_boots, len(bins) - 1)) phi_red_sat_3 = np.zeros((N_boots, len(bins) - 1)) phi_blue_sat_3 = np.zeros((N_boots, len(bins) - 1)) for boot in range(0, N_boots): print boot f2 = h5py.File( filepath_GC + 'bootstraps/' + group_catalogue + '_' + str(boot) + '.hdf5', 'r') GC = f2.get(group_catalogue + '_' + str(boot)) GC = np.array(GC) centrals = np.array(GC['RANK'] == 1) satellites = np.array(GC['RANK'] == 0) color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.array(color < LHS) red = np.array(color > LHS) host_ID = GC['GROUP_ID'] L = solar_lum(GC['M_r,0.1'], S_r) mass_bin = [12.5, 13.0] phi_1[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin) mask = red & centrals phi_red_cen_1[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = blue & centrals phi_blue_cen_1[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = red & satellites phi_red_sat_1[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = blue & satellites phi_blue_sat_1[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mass_bin = [13.0, 13.5] phi_2[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin) mask = red & centrals phi_red_cen_2[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = blue & centrals phi_blue_cen_2[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = red & satellites phi_red_sat_2[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = blue & satellites phi_blue_sat_2[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mass_bin = [13.5, 14.0] phi_3[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin) mask = red & centrals phi_red_cen_3[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = blue & centrals phi_blue_cen_3[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = red & satellites phi_red_sat_3[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) mask = blue & satellites phi_blue_sat_3[boot, :] = clf(host_ID, L, bins, GC['MGROUP'], mass_bin, mask) phi_err_1 = np.std(phi_1, axis=0) phi_1 = np.mean(phi_1, axis=0) phi_red_cen_err_1 = np.std(phi_red_cen_1, axis=0) phi_red_cen_1 = np.mean(phi_red_cen_1, axis=0) phi_blue_cen_err_1 = np.std(phi_blue_cen_1, axis=0) phi_blue_cen_1 = np.mean(phi_blue_cen_1, axis=0) phi_red_sat_err_1 = np.std(phi_red_sat_1, axis=0) phi_red_sat_1 = np.mean(phi_red_sat_1, axis=0) phi_blue_sat_err_1 = np.std(phi_blue_sat_1, axis=0) phi_blue_sat_1 = np.mean(phi_blue_sat_1, axis=0) phi_err_2 = np.std(phi_2, axis=0) phi_2 = np.mean(phi_2, axis=0) phi_red_cen_err_2 = np.std(phi_red_cen_2, axis=0) phi_red_cen_2 = np.mean(phi_red_cen_2, axis=0) phi_blue_cen_err_2 = np.std(phi_blue_cen_2, axis=0) phi_blue_cen_2 = np.mean(phi_blue_cen_2, axis=0) phi_red_sat_err_2 = np.std(phi_red_sat_2, axis=0) phi_red_sat_2 = np.mean(phi_red_sat_2, axis=0) phi_blue_sat_err_2 = np.std(phi_blue_sat_2, axis=0) phi_blue_sat_2 = np.mean(phi_blue_sat_2, axis=0) phi_err_3 = np.std(phi_3, axis=0) phi_3 = np.mean(phi_3, axis=0) phi_red_cen_err_3 = np.std(phi_red_cen_3, axis=0) phi_red_cen_3 = np.mean(phi_red_cen_3, axis=0) phi_blue_cen_err_3 = np.std(phi_blue_cen_3, axis=0) phi_blue_cen_3 = np.mean(phi_blue_cen_3, axis=0) phi_red_sat_err_3 = np.std(phi_red_sat_3, axis=0) phi_red_sat_3 = np.mean(phi_red_sat_3, axis=0) phi_blue_sat_err_3 = np.std(phi_blue_sat_3, axis=0) phi_blue_sat_3 = np.mean(phi_blue_sat_3, axis=0) #full sample ax = axes[0] p1 = ax.errorbar(bin_centers, phi_1, yerr=phi_err_1, fmt='o', color='black', ms=4, mec='none') ax.legend([p1], ['group catalogue'], frameon=False, fontsize=10, numpoints=1) ax = axes[1] p1 = ax.errorbar(bin_centers, phi_2, yerr=phi_err_2, fmt='o', color='black', ms=4, mec='none') ax.legend([p1a], ['mock'], frameon=False, fontsize=10, numpoints=1) ax = axes[2] p1 = ax.errorbar(bin_centers, phi_3, yerr=phi_err_3, fmt='o', color='black', ms=4, mec='none') #centrals ax = axes[3] p2 = ax.errorbar(bin_centers, phi_red_cen_1, yerr=phi_red_cen_err_1, fmt='o', color='red', ms=4, mec='none') p3 = ax.errorbar(bin_centers, phi_blue_cen_1, yerr=phi_blue_cen_err_1, fmt='o', color='blue', ms=4, mec='none') ax.legend([p2, p3], ['red group centrals', 'blue group centrals'], frameon=False, fontsize=10, numpoints=1) ax = axes[4] ax.errorbar(bin_centers, phi_red_cen_2, yerr=phi_red_cen_err_2, fmt='o', color='red', ms=4, mec='none') ax.errorbar(bin_centers, phi_blue_cen_2, yerr=phi_blue_cen_err_2, fmt='o', color='blue', ms=4, mec='none') ax.legend([p2a, p3a], ['red mock centrals', 'blue mock centrals'], frameon=False, fontsize=10, numpoints=1) ax = axes[5] ax.errorbar(bin_centers, phi_red_cen_3, yerr=phi_red_cen_err_3, fmt='o', color='red', ms=4, mec='none') ax.errorbar(bin_centers, phi_blue_cen_3, yerr=phi_blue_cen_err_3, fmt='o', color='blue', ms=4, mec='none') #satellites ax = axes[6] p4 = ax.errorbar(bin_centers, phi_red_sat_1, yerr=phi_red_sat_err_1, fmt='o', color='red', ms=4, mec='none') p5 = ax.errorbar(bin_centers, phi_blue_sat_1, yerr=phi_blue_sat_err_1, fmt='o', color='blue', ms=4, mec='none') ax.legend([p4, p5], ['red group satellites', 'blue group satellites'], frameon=False, fontsize=10, numpoints=1) ax = axes[7] ax.errorbar(bin_centers, phi_red_sat_2, yerr=phi_red_sat_err_2, fmt='o', color='red', ms=4, mec='none') ax.errorbar(bin_centers, phi_blue_sat_2, yerr=phi_blue_sat_err_2, fmt='o', color='blue', ms=4, mec='none') ax.legend([p4a, p5a], ['red mock satellites', 'blue mock satellites'], frameon=False, fontsize=10, numpoints=1) ax = axes[8] ax.errorbar(bin_centers, phi_red_sat_3, yerr=phi_red_sat_err_3, fmt='o', color='red', ms=4, mec='none') ax.errorbar(bin_centers, phi_blue_sat_3, yerr=phi_blue_sat_err_3, fmt='o', color='blue', ms=4, mec='none') plt.show(block=True) print plotpath + filename + '.pdf' fig.savefig(plotpath + filename + '.pdf')
def main(): catalogue = sys.argv[1] filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' plotpath = cu.get_plot_path() + 'analysis/hearin_mocks/' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) mock = np.array(mock) print 'length:', len(mock) for name in mock.dtype.names: print ' ', name color = mock['g-r'] LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies #create subsample for plotting purposes N = 10000.0 N_red = float(len(red)) N_blue = float(len(blue)) N_red_1 = int(N_red / (N_red + N_blue) * N) N_blue_1 = int(N_blue / (N_red + N_blue) * N) red_sub = np.random.random_integers(0, len(red) - 1, N_red_1) blue_sub = np.random.random_integers(0, len(blue) - 1, N_blue_1) x = np.arange(-25, -15, 0.1) y = 0.7 - 0.032 * (x + 16.5) #Weinmann 2006 #make density plot H, xedges, yedges = np.histogram2d(mock['M_r,0.1'], mock['g-r'], bins=50) xbins = (xedges[:-1] + xedges[1:]) / 2.0 ybins = (yedges[:-1] + yedges[1:]) / 2.0 fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) ax.scatter(mock['M_r,0.1'][red[red_sub]], mock['g-r'][red[red_sub]], s=1, marker='o', color='red', edgecolor='none') #, rasterized=True) ax.scatter(mock['M_r,0.1'][blue[blue_sub]], mock['g-r'][blue[blue_sub]], s=1, marker='o', color='blue', edgecolor='none') #, rasterized=True) #ax.contour(xbins,ybins,H.T, colors='0.75', linewidths=1) ax.plot(x, y, '-', color='black', linewidth=1) ax.set_xlabel(r'$M_r-5log(h)$') ax.set_ylabel(r'$(g-r)$') ax.set_xlim([-18.5, -22.5]) ax.set_ylim([0, 1.5]) ax.set_yticks([0, 0.5, 1, 1.5]) ax.set_yticks(np.arange(0, 1.5, 0.1), minor=True) ax.set_xticks(np.arange(-22, -18, 1)) ax.set_xticks(np.arange(-22.5, -18.5, 0.5), minor=True) plt.show(block=False) filename = catalogue + '_Mr_colors' fig.savefig(plotpath + filename + '.pdf', dpi=400) fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) ax.plot(mock['M_host'][red], mock['V_peak'][red], '.', color='red', ms=0.2) ax.plot(mock['M_host'][blue], mock['V_peak'][blue], '.', color='blue', ms=0.2) ax.set_yscale('log') ax.set_ylim([90, 1500]) ax.set_xlim([10, 15]) ax.set_xlabel(r'$log(M_{\rm halo})$ $[M_{\odot}/h]$') ax.set_ylabel(r'$V_{\rm peak}$ $[{\rm km/s}]$') plt.show(block=False) filename = catalogue + '_Mhost_Vmax_color'
def main(): catalogues = ['sm_9.49_s0.2_sfr_c-1.0_250','sm_9.49_s0.2_sfr_c-0.75_250',\ 'sm_9.49_s0.2_sfr_c-0.5_250','sm_9.49_s0.2_sfr_c-0.25_250',\ 'sm_9.49_s0.2_sfr_c0.0_250'] catalogues = ['sm_9.49_s0.0_sfr_c-1.0_250','sm_9.49_s0.0_sfr_c-1.0_250',\ 'sm_9.49_s0.0_sfr_c-1.0_250','sm_9.49_s0.0_sfr_c-1.0_250',\ 'sm_9.49_s0.0_sfr_c-1.0_250'] samples = ['sm_all','sm_q','sm_sf'] sm_bins = ['10.0_10.5','10.5_11.0','11.0_11.5'] fig1, axes = plt.subplots(nrows=1,ncols=3,sharex=True,sharey=True,figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05, left=0.1, right=0.95, bottom=0.2, top=0.9) ax = axes[0] ax.set_xlim([0.1,2]) ax.set_ylim([1,200]) ax.set_yscale('log') ax.set_xscale('log') ax.set_ylabel(r'$\Delta\Sigma(r_p)~[M_{\odot}{\rm pc}^{-2}h]$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$\log(M_{*}~M_{\odot}h^{-2})>9.49$') ax = axes[1] ax.set_xlim([0.1,2]) ax.set_ylim([1,200]) ax.set_yscale('log') ax.set_xscale('log') #ax.set_ylabel(r'$\omega_p(r_p)$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$\log(M_{*}~M_{\odot}h^{-2})>9.89$') ax = axes[2] ax.set_xlim([0.1,2]) ax.set_ylim([1,200]) ax.set_yscale('log') ax.set_xscale('log') #ax.set_ylabel(r'$\omega_p(r_p)$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$\log(M_{*}~M_{\odot}h^{-2})>10.29$') for i,sm_bin in enumerate(sm_bins): filepath = cu.get_output_path() + 'analysis/central_quenching/observables/' names = ['r','delta_sigma'] filename = catalogues[0]+'_DeltaSigma_'+samples[0]+'_'+sm_bin+'.dat' result_1a = ascii.read(filepath+filename,names=names) filename = catalogues[0]+'_DeltaSigma_'+samples[1]+'_'+sm_bin+'.dat' result_1b = ascii.read(filepath+filename,names=names) filename = catalogues[0]+'_DeltaSigma_'+samples[2]+'_'+sm_bin+'.dat' result_1c = ascii.read(filepath+filename,names=names) filename = catalogues[1]+'_DeltaSigma_'+samples[0]+'_'+sm_bin+'.dat' result_2a = ascii.read(filepath+filename,names=names) filename = catalogues[1]+'_DeltaSigma_'+samples[1]+'_'+sm_bin+'.dat' result_2b = ascii.read(filepath+filename,names=names) filename = catalogues[1]+'_DeltaSigma_'+samples[2]+'_'+sm_bin+'.dat' result_2c = ascii.read(filepath+filename,names=names) filename = catalogues[2]+'_DeltaSigma_'+samples[0]+'_'+sm_bin+'.dat' result_3a = ascii.read(filepath+filename,names=names) filename = catalogues[2]+'_DeltaSigma_'+samples[1]+'_'+sm_bin+'.dat' result_3b = ascii.read(filepath+filename,names=names) filename = catalogues[2]+'_DeltaSigma_'+samples[2]+'_'+sm_bin+'.dat' result_3c = ascii.read(filepath+filename,names=names) filename = catalogues[3]+'_DeltaSigma_'+samples[0]+'_'+sm_bin+'.dat' result_4a = ascii.read(filepath+filename,names=names) filename = catalogues[3]+'_DeltaSigma_'+samples[1]+'_'+sm_bin+'.dat' result_4b = ascii.read(filepath+filename,names=names) filename = catalogues[3]+'_DeltaSigma_'+samples[2]+'_'+sm_bin+'.dat' result_4c = ascii.read(filepath+filename,names=names) filename = catalogues[4]+'_DeltaSigma_'+samples[0]+'_'+sm_bin+'.dat' result_5a = ascii.read(filepath+filename,names=names) filename = catalogues[4]+'_DeltaSigma_'+samples[1]+'_'+sm_bin+'.dat' result_5b = ascii.read(filepath+filename,names=names) filename = catalogues[4]+'_DeltaSigma_'+samples[2]+'_'+sm_bin+'.dat' result_5c = ascii.read(filepath+filename,names=names) ax = axes[i] p1a, = ax.plot(result_1a['r'],result_1a['delta_sigma'],'-',color='black', alpha=1) p1b, = ax.plot(result_1b['r'],result_1b['delta_sigma'],'-',color='red', alpha=1) p1c, = ax.plot(result_1c['r'],result_1c['delta_sigma'],'-',color='blue', alpha=1) p2a, = ax.plot(result_2a['r'],result_2a['delta_sigma'],'-',color='black', alpha=0.8) p2b, = ax.plot(result_2b['r'],result_2b['delta_sigma'],'-',color='red', alpha=0.8) p2c, = ax.plot(result_2c['r'],result_2c['delta_sigma'],'-',color='blue', alpha=0.8) p3a, = ax.plot(result_3a['r'],result_3a['delta_sigma'],'-',color='black', alpha=0.6) p3b, = ax.plot(result_3b['r'],result_3b['delta_sigma'],'-',color='red', alpha=0.6) p3c, = ax.plot(result_3c['r'],result_3c['delta_sigma'],'-',color='blue', alpha=0.6) p4a, = ax.plot(result_4a['r'],result_4a['delta_sigma'],'-',color='black', alpha=0.4) p4b, = ax.plot(result_4b['r'],result_4b['delta_sigma'],'-',color='red', alpha=0.4) p4c, = ax.plot(result_4c['r'],result_4c['delta_sigma'],'-',color='blue', alpha=0.4) p5a, = ax.plot(result_5a['r'],result_5a['delta_sigma'],'-',color='black', alpha=0.2) p5b, = ax.plot(result_5b['r'],result_5b['delta_sigma'],'-',color='red', alpha=0.2) p5c, = ax.plot(result_5c['r'],result_5c['delta_sigma'],'-',color='blue', alpha=0.2) if i==0: ax.legend((p1a,p2a,p3a,p4a,p5a),\ (r"$\rho=-1.0$",r"$\rho=-0.75$",r"$\rho=-0.5$",r"$\rho=-0.25$",r"$\rho=0.0$"),\ loc=1, fontsize=10, frameon=False, labelspacing=0.01, title='all') if i==1: ax.legend((p1b,p2b,p3b,p4b,p5b),\ (r"$\rho=-1.0$",r"$\rho=-0.75$",r"$\rho=-0.5$",r"$\rho=-0.25$",r"$\rho=0.0$"),\ loc=1, fontsize=10, frameon=False, labelspacing=0.01, title='quenched') if i==2: ax.legend((p1c,p2c,p3c,p4c,p5c),\ (r"$\rho=-1.0$",r"$\rho=-0.75$",r"$\rho=-0.5$",r"$\rho=-0.25$",r"$\rho=0.0$"),\ loc=3, fontsize=10, frameon=False, labelspacing=0.01, title='star-forming') plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'delta_sigma' fig1.savefig(savepath+filename+'.pdf')
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock' plotpath = cu.get_plot_path() + 'analysis/groupcats/' ###################################################################################### #Satellite and central purity and completeness ###################################################################################### #define outputs filename1 = catalogue + '_performance_M' filename2 = catalogue + '_performance_L' filename3 = catalogue + '_performance_Tsat' #First make plots as a function of galaxy Mgroup and Mhalo #set up plots fig1, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() axes[0].set_xlim(10**12, 10**15) axes[0].set_ylim(0.0, 1.0) axes[0].set_xscale('log') axes[0].set_xlabel(r'$M$ $[M_{\odot}h^{-1}]$') axes[0].set_ylabel(r'$C,P$') axes[0].set_title('Berlind et al. groups') axes[1].set_title('Tinker et al. groups') axes[1].set_xlabel(r'$M$ $[M_{\odot}h^{-1}]$') axes[1].set_xscale('log') axes[2].set_title('Yang et al. groups') axes[2].set_xlabel(r'$M$ $[M_{\odot}h^{-1}]$') axes[2].set_xscale('log') axes[2].set_xticks([10**12, 10**13, 10**14, 10**15]) axes[2].set_xticklabels([r'$10^{12}$', r'$10^{13}$', r'$10^{14}$', r' ']) #define mass bins bins = np.arange(12, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 #open the Berlind group catalogue groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) #open catalogue f = h5py.File(filepath_cat + group_catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(group_catalogue) result1 = sp_in_mass_bins(GC, bins) result2 = sc_in_mass_bins(GC, bins) result3 = cp_in_mass_bins(GC, bins) result4 = cc_in_mass_bins(GC, bins) result5_berlind = Tsat_in_mass_bins(GC, bins) result5_berlind_global = sat_bias(GC) ax = axes[0] p1, = ax.plot(10**bin_centers, result1, color='green', ls='-') p2, = ax.plot(10**bin_centers, result2, color='green', ls='--') p3, = ax.plot(10**bin_centers, result3, color='orange', ls='-') p4, = ax.plot(10**bin_centers, result4, color='orange', ls='--') ax.legend((p1, p2), ('satellite purity', 'satellite \ncompleteness'), loc='lower right', fontsize=10, numpoints=1, frameon=False) #open the Tinker group catalogue groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) #open catalogue f = h5py.File(filepath_cat + group_catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(group_catalogue) result1 = sp_in_mass_bins(GC, bins) result2 = sc_in_mass_bins(GC, bins) result3 = cp_in_mass_bins(GC, bins) result4 = cc_in_mass_bins(GC, bins) result5_tinker = Tsat_in_mass_bins(GC, bins) result5_tinker_global = sat_bias(GC) ax = axes[1] p1, = ax.plot(10**bin_centers, result1, color='green', ls='-') p2, = ax.plot(10**bin_centers, result2, color='green', ls='--') p3, = ax.plot(10**bin_centers, result3, color='orange', ls='-') p4, = ax.plot(10**bin_centers, result4, color='orange', ls='--') ax.legend((p3, p4), ('central purity', 'central \ncompleteness'), loc='lower right', fontsize=10, numpoints=1, frameon=False) #open the Yang group catalogue groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) #open catalogue f = h5py.File(filepath_cat + group_catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(group_catalogue) result1 = sp_in_mass_bins(GC, bins) result2 = sc_in_mass_bins(GC, bins) result3 = cp_in_mass_bins(GC, bins) result4 = cc_in_mass_bins(GC, bins) result5_yang = Tsat_in_mass_bins(GC, bins) result5_yang_global = sat_bias(GC) ax = axes[2] ax.plot(10**bin_centers, result1, color='green', ls='-') ax.plot(10**bin_centers, result2, color='green', ls='--') ax.plot(10**bin_centers, result3, color='orange', ls='-') ax.plot(10**bin_centers, result4, color='orange', ls='--') ''' #open ideal group catalogue filepath_mock = cu.get_output_path() + 'processed_data/hearin_mocks/ideal_groups/' print 'opening mock catalogue:', catalogue+'_groups.hdf5' #open catalogue f1 = h5py.File(filepath_mock+catalogue+'_groups.hdf5', 'r') #open catalogue file GC = f1.get(catalogue+'_groups') GC = np.array(GC) #look at purity and completeness for perfect groups satellites = (GC['RANK']>0) GC['RANK'][satellites]=2 centrals = (GC['RANK']==0) GC['RANK'][centrals]=1 satellites = (GC['HALO_RANK']!=0) GC['HALO_RANK'][satellites]=2 centrals = (GC['HALO_RANK']==0) GC['HALO_RANK'][centrals]=1 #define mass bins bins = np.arange(12,15,0.2) bin_centers = (bins[:-1]+bins[1:])/2.0 result1 = sp_in_mass_bins(GC,bins) result2 = sc_in_mass_bins(GC,bins) result3 = cp_in_mass_bins(GC,bins) result4 = cc_in_mass_bins(GC,bins) result5 = Tsat_in_mass_bins(GC,bins) ax=axes[0] ax.plot(10**bin_centers,result2, color='green', ls='-') ax.plot(10**bin_centers,result4, color='orange',ls='-') ''' plt.show() #save plot print plotpath + filename1 + '.pdf' fig1.savefig(plotpath + filename1 + '.pdf') #purity and completeness as a function of galaxy Luminosity #set up plots fig2, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 3.3)) fig2.subplots_adjust(hspace=0, wspace=0.05) fig2.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() axes[0].set_xlim(9, 11) axes[0].set_ylim(0.0, 1) axes[0].set_xticks([9.5, 10, 10.5]) axes[0].set_xlabel(r'$log(L/L_{\odot})$') axes[0].set_ylabel(r'$C,P$') axes[0].set_title('Berlind et al. groups') axes[1].set_title('Tinker et al. groups') axes[1].set_xlabel(r'$log(L/L_{\odot})$') axes[2].set_title('Yang et al. groups') axes[2].set_xlabel(r'$log(L/L_{\odot})$') #define luminosity bins bins = np.arange(9.4, 10.8, 0.1) bin_centers = (bins[:-1] + bins[1:]) / 2.0 #open the Berlind group catalogue groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) #open catalogue f = h5py.File(filepath_cat + group_catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(group_catalogue) result1 = sp_in_L_bins(GC, bins) result2 = sc_in_L_bins(GC, bins) result3 = cp_in_L_bins(GC, bins) result4 = cc_in_L_bins(GC, bins) ax = axes[0] p1, = ax.plot(bin_centers, result1, color='green', ls='-') p2, = ax.plot(bin_centers, result2, color='green', ls='--') p3, = ax.plot(bin_centers, result3, color='orange', ls='-') p4, = ax.plot(bin_centers, result4, color='orange', ls='--') ax.legend((p1, p2), ('satellite purity', 'satellite \ncompleteness'), loc='lower left', fontsize=10, numpoints=1, frameon=False) #open the Tinker group catalogue groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) #open catalogue f = h5py.File(filepath_cat + group_catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(group_catalogue) result1 = sp_in_L_bins(GC, bins) result2 = sc_in_L_bins(GC, bins) result3 = cp_in_L_bins(GC, bins) result4 = cc_in_L_bins(GC, bins) ax = axes[1] p1, = ax.plot(bin_centers, result1, color='green', ls='-') p2, = ax.plot(bin_centers, result2, color='green', ls='--') p3, = ax.plot(bin_centers, result3, color='orange', ls='-') p4, = ax.plot(bin_centers, result4, color='orange', ls='--') ax.legend((p3, p4), ('central purity', 'central \ncompleteness'), loc='lower left', fontsize=10, numpoints=1, frameon=False) #open the Yang group catalogue groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) #open catalogue f = h5py.File(filepath_cat + group_catalogue + '.hdf5', 'r') #open catalogue file GC = f.get(group_catalogue) result1 = sp_in_L_bins(GC, bins) result2 = sc_in_L_bins(GC, bins) result3 = cp_in_L_bins(GC, bins) result4 = cc_in_L_bins(GC, bins) ax = axes[2] ax.plot(bin_centers, result1, color='green', ls='-') ax.plot(bin_centers, result2, color='green', ls='--') ax.plot(bin_centers, result3, color='orange', ls='-') ax.plot(bin_centers, result4, color='orange', ls='--') plt.show(block=False) #save plots print plotpath + filename2 + '.pdf' fig2.savefig(plotpath + filename2 + '.pdf') #plot the satellite transition factor as a function of Mgroup and Mhalo #define mass bins bins = np.arange(12, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) p1, = ax.plot(10.0**bin_centers, result5_berlind, '--', color='cyan') ax.plot([1.2 * 10.0**bin_centers[-1]], [result5_berlind_global], 'o', color='cyan', mec='none') p2, = ax.plot(10.0**bin_centers, result5_tinker, '-', color='grey') ax.plot([1.2 * 10.0**bin_centers[-1]], [result5_tinker_global], 'o', color='grey', mec='none') p3, = ax.plot(10.0**bin_centers, result5_yang, ':', color='purple') ax.plot([1.2 * 10.0**bin_centers[-1]], [result5_yang_global], 'o', color='purple', mec='none') ax.legend((p1, p2, p3), ('Berlind et al. groups', 'Tinker et al. groups', 'Yang et al. groups'), frameon=False, fontsize=8) ax.plot([10.0**11, 10**16], [1, 1], '--', color='black') ax.set_xlabel(r'$M$ $[M_{\odot}h^{-1}]$') ax.set_ylabel(r'$T_{\rm sat}$') ax.set_xscale('log') ax.set_ylim([0.5, 4]) ax.set_xlim([10**12, 10**15]) plt.show() fig.savefig(plotpath + filename3 + '.pdf') ###################################################################################### ##### look at fraction of satellites that are more luminous than the central ###################################################################################### filename1 = catalogue + '_performance_fu_censat_Mh' filename2 = catalogue + '_performance_fu_censat_Mg' filename3 = catalogue + '_performance_fuMg' filename4 = catalogue + '_performance_fuMh' filename5 = catalogue + '_performance_fuMhMg' #open ideal group catalogue filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/ideal_groups/' print 'opening mock catalogue:', catalogue + '_groups.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '_groups.hdf5', 'r') #open catalogue file GC = f1.get(catalogue + '_groups') GC = np.array(GC) #define mass bins bins = np.arange(10, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 #which are true centrals and satellites? true_centrals = np.where(GC['HALO_RANK'] == 0)[0] true_satellites = np.where(GC['HALO_RANK'] == 1)[0] true_centrals_bool = (GC['HALO_RANK'] == 0) true_satellites_bool = (GC['HALO_RANK'] == 1) #which are identified centrals and satellites? identified_centrals = np.where(GC['RANK'] == 0)[0] identified_satellites = np.where(GC['RANK'] != 0)[0] identified_centrals_bool = (GC['RANK'] == 0) identified_satellites_bool = (GC['RANK'] != 0) #which identified centrals are not true centrals? fu_cen = (np.in1d(true_centrals, identified_centrals) == False) nfu_cen = (np.in1d(true_centrals, identified_centrals)) fu_cen = true_centrals[fu_cen] #which identified centrals are not true centrals? fu_icen = (np.in1d(identified_centrals, true_satellites)) nfu_icen = (np.in1d(identified_centrals, true_centrals)) fu_icen = identified_centrals[fu_icen] #which identified centrals are actually satellites? fu_sat = (np.in1d(true_satellites, identified_satellites) == False) nfu_sat = (np.in1d(true_satellites, identified_satellites)) fu_sat = true_satellites[fu_sat] #which identified centrals are actually satellites? fu_isat = (np.in1d(identified_satellites, true_centrals)) nfu_isat = (np.in1d(identified_satellites, true_satellites)) fu_isat = identified_satellites[fu_isat] f_fu_icen = f_prop(GC['HALO_M'], bins, fu_icen, identified_centrals[nfu_icen], identified_centrals_bool) f_fu_isat = f_prop(GC['HALO_M'], bins, fu_isat, identified_satellites[nfu_isat], identified_satellites_bool) f_fu_cen = f_prop(GC['HALO_M'], bins, fu_cen, true_centrals[nfu_cen], true_centrals_bool) f_fu_sat = f_prop(GC['HALO_M'], bins, fu_sat, true_satellites[nfu_sat], true_satellites_bool) f_fu_icen_im = f_prop(GC['MGROUP'], bins, fu_icen, identified_centrals[nfu_icen], identified_centrals_bool) f_fu_isat_im = f_prop(GC['MGROUP'], bins, fu_isat, identified_satellites[nfu_isat], identified_satellites_bool) f_fu_cen_im = f_prop(GC['MGROUP'], bins, fu_cen, true_centrals[nfu_cen], true_centrals_bool) f_fu_sat_im = f_prop(GC['MGROUP'], bins, fu_sat, true_satellites[nfu_sat], true_satellites_bool) fig1 = plt.figure(figsize=(3.3, 3.3)) l1, = plt.plot(bin_centers, f_fu_icen, '--', color='black') l2, = plt.plot(bin_centers, f_fu_cen, '-', color='black') l3, = plt.plot(bin_centers, f_fu_isat, '--', color='green') l4, = plt.plot(bin_centers, f_fu_sat, '-', color='green') plt.ylim([0, 1]) plt.xlim([11, 15]) plt.xlabel(r'$M_{\rm halo}$') plt.ylabel(r'$f_{fu}$') plt.legend([l1, l2, l3, l4], [ 'inferred centrals', 'true centrals', 'inferred satellites', 'true satellites' ]) plt.show(block=False) fig1.savefig(plotpath + filename1 + '.pdf') fig2 = plt.figure(figsize=(3.3, 3.3)) l5, = plt.plot(bin_centers, f_fu_icen_im, '--', color='black') l6, = plt.plot(bin_centers, f_fu_cen_im, '-', color='black', alpha=0.5) l7, = plt.plot(bin_centers, f_fu_isat_im, '--', color='green') l8, = plt.plot(bin_centers, f_fu_sat_im, '-', color='green', alpha=0.5) plt.ylim([0, 1]) plt.xlim([11, 15]) plt.xlabel(r'$M_{\rm group}$') plt.ylabel(r'$f_{fu}$') plt.legend([l1, l2, l3, l4], [ 'inferred centrals', 'true centrals', 'inferred satellites', 'true satellites' ]) plt.show(block=False) fig2.savefig(plotpath + filename2 + '.pdf') inds = np.digitize(GC['MGROUP'][identified_centrals], bins=bins) - 1 f_fu = np.zeros((len(bins) - 1, )) for i in range(0, len(bins) - 1): selection = (inds == i) selection = identified_centrals[selection] N_bad = np.not_equal(GC['RANK'][selection], GC['HALO_RANK'][selection]) N_bad = np.sum(N_bad) N_good = np.equal(GC['RANK'][selection], GC['HALO_RANK'][selection]) N_good = np.sum(N_good) N_tot = len(selection) print N_tot, N_good + N_bad f_fu[i] = N_bad / float(N_good + N_bad) fig3 = plt.figure(figsize=(3.3, 3.3)) ax = fig3.add_subplot(1, 1, 1) fig3.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) p1, = ax.plot(10.0**bin_centers, f_fu) ax.set_ylim([0, 1]) ax.set_xlim([10.0**11, 10.0**15]) ax.set_xscale('log') ax.set_xlabel(r'$M_{\rm group}$ $[M_{\odot}/h]$') ax.set_ylabel(r'$f_{fu}$') plt.show(block=False) fig3.savefig(plotpath + filename3 + '.pdf') inds = np.digitize(GC['HALO_M'][identified_centrals], bins=bins) - 1 f_fu = np.zeros((len(bins) - 1, )) for i in range(0, len(bins) - 1): selection = (inds == i) selection = identified_centrals[selection] bad = np.not_equal(GC['RANK'][selection], GC['HALO_RANK'][selection]) N_bad = np.sum(bad) good = np.equal(GC['RANK'][selection], GC['HALO_RANK'][selection]) N_good = np.sum(good) N_tot = len(selection) print N_tot, N_good + N_bad f_fu[i] = N_bad / float(N_good + N_bad) fig4 = plt.figure(figsize=(3.3, 3.3)) ax = fig4.add_subplot(1, 1, 1) fig4.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) p2, = ax.plot(10.0**bin_centers, f_fu) ax.set_ylim([0, 1]) ax.set_xlim([10.0**11, 10.0**15]) ax.set_xscale('log') ax.set_xlabel(r'$M_{\rm halo}$ $[M_{\odot}/h]$') ax.set_ylabel(r'$f_{inversion}$') plt.show(block=False) fig4.savefig(plotpath + filename4 + '.pdf') #look at purity and completeness for perfect groups satellites = (GC['RANK'] > 0) GC['RANK'][satellites] = 2 centrals = (GC['RANK'] == 0) GC['RANK'][centrals] = 1 satellites = (GC['HALO_RANK'] != 0) GC['HALO_RANK'][satellites] = 2 centrals = (GC['HALO_RANK'] == 0) GC['HALO_RANK'][centrals] = 1 #define mass bins bins = np.arange(12, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 result1 = sp_in_mass_bins(GC, bins) result2 = sc_in_mass_bins(GC, bins) result3 = cp_in_mass_bins(GC, bins) result4 = cc_in_mass_bins(GC, bins) result5 = Tsat_in_mass_bins(GC, bins) fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) p1, = ax.plot(10**bin_centers, result1, color='green', ls='-') p2, = ax.plot(10**bin_centers, result2, color='green', ls='--') p3, = ax.plot(10**bin_centers, result3, color='orange', ls='-') p4, = ax.plot(10**bin_centers, result4, color='orange', ls='--') ax.set_ylim([0, 1]) ax.set_xscale('log') ax.legend((p1, p2, p3, p4), ('satellite purity', 'satellite \ncompleteness', 'central purity', 'central \ncompleteness'), loc='lower right', fontsize=10, numpoints=1, frameon=False) plt.show() fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) p1, = ax.plot(10**bin_centers, result5, '--', color='black') ax.set_xscale('log') ax.set_yscale('log') ax.set_ylim([0.1, 100]) plt.show()
def main(): filepath_mock = cu.get_output_path() + 'processed_data/campbell_mocks/' catalogues = ['sm_9.5_s0.0_sfr_c-1.0_250','sm_9.5_s0.1_sfr_c-1.0_250',\ 'sm_9.5_s0.2_sfr_c-1.0_250','sm_9.5_s0.3_sfr_c-1.0_250'] sigmas = [0.0,0.1,0.2,0.3] fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.85, bottom=0.2, top=0.9) plt.xlabel(r'$r~(h^{-1}\rm Mpc)$') plt.ylabel(r'$f_{\rm quenched}$') plt.title(r'$10.0<\log(M_{*, \rm host}/M_{\odot}h^{-2})<10.5$') plt.ylim([0,1]) plt.xlim([0.1,10]) plt.xscale('log') a = [1.0,0.8,0.6,0.4,0.2] #red_colors=['#FF0000','#FF2900','#FF5C00','#FF8F00','#FFCC00'] #blue_colors=['#0000FF','#0040FF','#0080FF','#00BFFF','#00FFFF'] p1 = [None]*5 p2 = [None]*5 for i, catalogue in enumerate(catalogues): #open catalogue print(i,catalogue) f = h5py.File(filepath_mock+catalogue+'.hdf5', 'r') #open catalogue file mock = f.get(catalogue) Lbox = np.array([250.0,250.0,250.0]) #define centrals and satellites host = (mock['upid']==-1) sub = (mock['upid']!=-1) #define quenched and star-forming LHS = -11.0 blue = (mock['SSFR']>LHS) #indices of blue galaxies red = (mock['SSFR']<LHS) #indicies of red galaxies #define samples red_host = host & red blue_host = host & blue #host mass selection bin = (mock['Mstar']>10.0) & (mock['Mstar']<10.5) red_host = red_host & bin blue_host = blue_host & bin #count pairs rbins = np.linspace(-1,1,20) rbin_centers = (rbins[1:]+rbins[:-1])/2.0 rbins = 10**rbins data1 = np.vstack((mock['x'], mock['y'], mock['z'])).T[red_host] data2 = np.vstack((mock['x'], mock['y'], mock['z'])).T[red] data3 = np.vstack((mock['x'], mock['y'], mock['z'])).T[blue] print(len(data1), len(data2), len(data3)) red_pairs = rect_cuboid_pairs.npairs(data1, data2, rbins, period=Lbox) red_pairs = np.diff(red_pairs) blue_pairs = rect_cuboid_pairs.npairs(data1, data3, rbins, period=Lbox) blue_pairs = np.diff(blue_pairs) all_pairs = red_pairs+blue_pairs red_quenched_frac = red_pairs/all_pairs data1 = np.vstack((mock['x'], mock['y'], mock['z'])).T[blue_host] data2 = np.vstack((mock['x'], mock['y'], mock['z'])).T[red] data3 = np.vstack((mock['x'], mock['y'], mock['z'])).T[blue] print(len(data1), len(data2), len(data3)) red_pairs = rect_cuboid_pairs.npairs(data1, data2, rbins, period=Lbox) red_pairs = np.diff(red_pairs) blue_pairs = rect_cuboid_pairs.npairs(data1, data3, rbins, period=Lbox) blue_pairs = np.diff(blue_pairs) all_pairs = red_pairs+blue_pairs blue_quenched_frac = red_pairs/all_pairs p1[i], = plt.plot(10**rbin_centers,red_quenched_frac, color='red', alpha=a[i], lw=1) p2[i], =plt.plot(10**rbin_centers,blue_quenched_frac, color='blue', alpha=a[i], lw=1) p1 = tuple(p1) p2 = tuple(p2) plt.legend(p1, (r"$\sigma=0.0$",r"$\sigma=0.1$",r"$\sigma=0.2$",r"$\sigma=0.3$"),\ loc=4, fontsize=10, frameon=False, labelspacing=0.01, title='quenched centrals') fig.savefig('/Users/duncan/Desktop/conformity.pdf') plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'conformity_rho_effect' fig.savefig(savepath+filename+'.pdf')
def main(): #open mock Lbox = 250.0 if len(sys.argv)>1: catalogue = sys.argv[1] else: catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250' filepath = cu.get_output_path() + 'processed_data/campbell_mocks/' f = h5py.File(filepath+catalogue+'.hdf5', 'r') #open catalogue file mock = f.get(catalogue) mock = np.array(mock) print(mock.dtype.names) #measure stellar mass function bins = np.arange(9.5,12,0.1) dn, dm, err = raw_abundance(mock['Mstar'], 1.0/Lbox**3.0, bins, xlog=False) """ #define fit to mass function, Baldry 2008. M0 = 10.648 + np.log10(0.7**2) phi1 = 4.26 * 10**(-3) / 0.7**3 phi2 = 0.58 * 10**(-3) / 0.7**3 alpha1 = -0.46 alpha2 = -1.58 dndm_gal = cu.schechter_function.Log_Double_Schechter(M0,M0,phi1,phi2,alpha1,alpha2) """ #define stellar mass function #phi_1 = 7.97407978*10**(-3) #phi_2 = 1.10507295*10**(-3) #m_1 = 10.5040374 #m_2 = 10.9083632 #alpha_1 = -0.956108368 #alpha_2 = -1.48157281 phi_1 = 6.94559219e-03 phi_2 = 2.76601643e-04 m_1 = 1.05518723e+01 m_2 = 1.08818830e+01 alpha_1 = -1.20094175e+00 alpha_2 = -7.40886755e-01 dndm_gal = cu.schechter_function.Log_Double_Schechter(m_1, m_2, phi_1, phi_2, alpha_1, alpha_2) #plot stellar mass function msample=np.linspace(9,12,100) fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.85, bottom=0.2, top=0.9) p1 = plt.errorbar(10**dm,dn,yerr=err,fmt='.',color='black') p2, = plt.plot(10**msample, dndm_gal(msample),color='black') plt.xlabel(r'$h^{-2}M_{*}~[M_{\odot}]$') plt.ylabel(r'$h^{3}\phi~[{\rm Mpc^{-3}}\log(M_{*})]$') plt.yscale('log') plt.xscale('log') plt.ylim([10**(-7),0.1]) plt.legend((p1,p2),('mock','SDSS'), loc=3, fontsize=10, frameon=False, numpoints=1) plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'mock_stellar_mass_function' fig.savefig(savepath+filename+'.pdf', dpi=250)
def main(): catalogue = sys.argv[1] plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_mock_group_f_red_sat_M.eps' fig1, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() ax = axes[0] ax.set_xlim([11, 15]) ax.set_ylim([0, 1]) ax.set_ylabel(r'$f_{red}$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_title(r'Berlind FoF groups') ax = axes[1] ax.set_xlim([11, 15]) ax.set_ylim([0, 1]) ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') ax.set_xticks([12.5, 13, 13.5, 14, 14.5]) ax.set_xlim([12, 15]) ax.set_title(r'Tinker SO groups') ax = axes[2] ax.set_xlim([11, 15]) ax.set_ylim([0, 1]) ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') ax.set_xticks([12.5, 13, 13.5, 14, 14.5]) ax.set_xlim([12, 15]) ax.set_title(r'Yang SO groups') N_boots = 1 bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 #open mock catalogue filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.array(mock['ID_host'] == -1) satellites = np.array(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] LHS = 0.21 - 0.03 * mock['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies lumbins = np.arange(9.6, 10.8, 0.25) lumbin_centers = (lumbins[:-1] + lumbins[1:]) / 2.0 inds = np.digitize(solar_lum(mock['M_r,0.1'], 4.64), bins=lumbins) bininds = (inds == 0) f_red_cen_0 = f_prop(mock['M_host'], bins, red, blue, centrals & bininds) f_red_sat_0 = f_prop(mock['M_host'], bins, red, blue, satellites & bininds) bininds = (inds == 1) f_red_cen_1 = f_prop(mock['M_host'], bins, red, blue, centrals & bininds) f_red_sat_1 = f_prop(mock['M_host'], bins, red, blue, satellites & bininds) bininds = (inds == 2) f_red_cen_2 = f_prop(mock['M_host'], bins, red, blue, centrals & bininds) f_red_sat_2 = f_prop(mock['M_host'], bins, red, blue, satellites & bininds) bininds = (inds == 3) f_red_cen_3 = f_prop(mock['M_host'], bins, red, blue, centrals & bininds) f_red_sat_3 = f_prop(mock['M_host'], bins, red, blue, satellites & bininds) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen_0, color='orange') p2a, = ax.plot(bin_centers, f_red_sat_0, color='green') p3a, = ax.plot(bin_centers, f_red_cen_1, color='orange') p4a, = ax.plot(bin_centers, f_red_sat_1, color='green') p5a, = ax.plot(bin_centers, f_red_cen_2, color='orange') p6a, = ax.plot(bin_centers, f_red_sat_2, color='green') p7a, = ax.plot(bin_centers, f_red_cen_3, color='orange') p8a, = ax.plot(bin_centers, f_red_sat_3, color='green') ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen_0, color='orange') p2a, = ax.plot(bin_centers, f_red_sat_0, color='green') ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen_0, color='orange') p2a, = ax.plot(bin_centers, f_red_sat_0, color='green') ################################################### groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[0] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p1a, p2a), ('halo cen', 'halo sat'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ################################################### groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[1] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p3a, p4a), ('groups cen', 'groups sat'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ################################################### groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[2] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) plt.show() fig1.savefig(plotpath + filename)
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] esle: catalogue = 'sample3_L_model.mr19' plotpath = cu.get_plot_path() + 'analysis/groupcats/' filepath_cat = cu.get_output_path() + 'analysis/yang_groupcat/' filename = catalogue + '_blue_central_conformity.npy' arr1_1 = np.load(filepath_cat + filename) filename = catalogue + '_red_central_conformity.npy' arr2_1 = np.load(filepath_cat + filename) filepath_cat = cu.get_output_path() + 'analysis/berlind_groupcat/' filename = catalogue + '_blue_central_conformity.npy' arr1_2 = np.load(filepath_cat + filename) filename = catalogue + '_red_central_conformity.npy' arr2_2 = np.load(filepath_cat + filename) filepath_cat = cu.get_output_path() + 'analysis/berlind_groupcat/' filename = catalogue + '_blue_central_conformity.npy' arr1_3 = np.load(filepath_cat + filename) filename = catalogue + '_red_central_conformity.npy' arr2_3 = np.load(filepath_cat + filename) catalogue_mock = 'Mr19_age_distribution_matching_mock' filepath_cat = cu.get_output_path() + 'analysis/hearin_mocks/' filename = catalogue_mock + '_blue_central_conformity.npy' arr1_mock = np.load(filepath_cat + filename) filename = catalogue_mock + '_red_central_conformity.npy' arr2_mock = np.load(filepath_cat + filename) mass_bins = np.arange(10, 15.2, 0.2) #log mass bins fig = plt.figure() #Yang f_cen_blue = arr1_1[0] N_cen_blue = arr1_1[2] f_cen_red = arr2_1[0] N_cen_red = arr2_1[2] selection = np.where(N_cen_blue > 50)[0] p1a, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='blue', linewidth=2) selection = np.where(N_cen_red > 50)[0] p2a, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='red', linewidth=2) p3a, = plt.plot([0, 1], [-1, -1], color='black', linewidth=2) #Berlind f_cen_blue = arr1_2[0] N_cen_blue = arr1_2[2] f_cen_red = arr2_2[0] N_cen_red = arr2_2[2] selection = np.where(N_cen_blue > 50)[0] p1b, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='blue', alpha=0.5, linewidth=2) selection = np.where(N_cen_red > 50)[0] p2b, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='red', alpha=0.5, linewidth=2) p3b, = plt.plot([0, 1], [-1, -1], color='black', alpha=0.5, linewidth=2) #Wetzel f_cen_blue = arr1_3[0] N_cen_blue = arr1_3[2] f_cen_red = arr2_3[0] N_cen_red = arr2_3[2] selection = np.where(N_cen_blue > 50)[0] p1c, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='blue', ls='--', linewidth=2) selection = np.where(N_cen_red > 50)[0] p2c, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='red', ls='--', linewidth=2) p3c, = plt.plot([0, 1], [-1, -1], color='black', ls='--', linewidth=2) #Hearin Mock ''' f_cen_blue = arr1_mock[0] N_cen_blue = arr1_mock[2] f_cen_red = arr2_mock[0] N_cen_red = arr2_mock[2] selection = np.where( N_cen_blue > 50)[0] p1d, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='green', lw=3) selection = np.where( N_cen_red > 50)[0] p2d, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='magenta', lw=3) ''' font = {'size': 19} matplotlib.rc('font', **font) plt.ylim([0, 0.8]) plt.xlim([11, 15]) plt.xlabel(r'$\mathrm{log}(M)$ $[{h}^{-1}{M}_{\odot}]$') plt.ylabel(r'$f_{\mathrm{late}}$', fontsize=25) #plt.title(catalogue) #plt.legend([p1a, p1b, p1c, p1d], ["Yang blue centrals", "Berlind blue centrals", "Tinker blue centrals", "mock blue centrals"]) #plt.legend([p1a, p1b, p1c], ["Yang et al. blue centrals", "Berlind et al. blue centrals", "Tinker et al. blue centrals"]) plt.legend([p3a, p3b, p3c], ["Yang et al.", "Berlind et al.", "Tinker et al."], prop={'size': 20}) filename = catalogue + '_compare_conformity' fig.savefig(plotpath + filename + '.eps') plt.show(block=True)
def main(): rhos = np.array([-1.0,-0.75,-0.5,-0.25,0.0]) sigma = 0.2 #fig = plt.figure(figsize=(3.3,3.3)) #fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) #ax = fig.add_subplot(1,1,1) fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=False, figsize=(3.3,5.5)) fig.subplots_adjust(hspace=0, wspace=0, left=0.2, right=0.9, bottom=0.1, top=0.95) axes = axes.flatten() colors = [0.8,0.6,0.4,0.2,0.0] colors = colors[::-1] pa = [] pb = [] for i,rho in enumerate(rhos): catalogue_1 = 'sm_9.5_s'+str(sigma)+'_sfr_c'+str(rho)+'_250' catalogue_2 = 'sm_8.5_s'+str(sigma)+'_sfr_c'+str(rho)+'_125' filepath_mock = cu.get_output_path() + 'processed_data/campbell_mocks/' print('opening mock catalogue:', catalogue_1+'.hdf5') #open catalogue f = h5py.File(filepath_mock+catalogue_1+'.hdf5', 'r') #open catalogue file mock_1 = f.get(catalogue_1) print(mock_1.dtype.names) print('opening mock catalogue:', catalogue_2+'.hdf5') #open catalogue f = h5py.File(filepath_mock+catalogue_2+'.hdf5', 'r') #open catalogue file mock_2 = f.get(catalogue_2) am_1 = abundance_match(mock_1) am_2 = abundance_match(mock_2) am = np.hstack((am_1,am_2)) mock = np.hstack((mock_1,mock_2)) bins = np.arange(10,15,0.1) bin_centers = (bins[:-1]+bins[1:])/2.0 mass = np.log10(mock['mvir']) f_red_cen_halo, N_halo = quenched_fraction(mock,mass,bins) mass = np.log10(am) f_red_cen_am, N_am = quenched_fraction(mock,mass,bins,use_rank=False) #pa_1, = axes[0].plot(10**bin_centers,f_red_cen_halo,'-',color=str(colors[i])) pa_1 = cu.plotting.colorline(10**bin_centers, f_red_cen_halo, rho, axes[0],\ vmin=np.min(rhos), vmax=np.max(rhos), cmap='winter') #pb_1, = axes[1].plot(10**bin_centers,f_red_cen_am,'-',color=str(colors[i])) pb_1 = cu.plotting.colorline(10**bin_centers, f_red_cen_am, rho, axes[1],\ vmin=np.min(rhos), vmax=np.max(rhos), cmap='winter') pa.append(pa_1) pb.append(pb_1) axes[0].set_xlabel(r'$M_{\rm vir}$ $[h^{-1}M_{\odot}]$') axes[0].set_ylabel(r'$f_{\rm q}(M)$') axes[0].set_xlim([10.0**11,10.0**14.0]) axes[0].set_xscale('log') #axes[0].set_xticklabels([' ',r'$10^{11}$',r'$10^{12}$',r'$10^{13}$',' ']) axes[0].legend(pa,rhos,loc=4,fontsize=10,frameon=False,labelspacing=0.01,title=r'$\rho_{\rm SSFR}$') axes[0].text(10.0**11.2,0.9,"intrinisic") axes[0].text(10.0**11.2,0.84,r'$\sigma_{\rm SMHM}=$'+str(sigma)) axes[1].set_xlabel(r'$M_{\rm vir}$ $[h^{-1}M_{\odot}]$') axes[1].set_ylabel(r'$f_{\rm q}(M)$') axes[1].set_xlim([10.0**11,10.0**14.0]) axes[1].set_xscale('log') #axes[1].set_xticklabels([' ',r'$10^{11}$',r'$10^{12}$',r'$10^{13}$','$10^{14}$']) axes[1].set_yticklabels(['0',r'$0.2$',r'$0.4$',r'$0.6$','$0.8$',' ']) axes[1].legend(pb,rhos,loc=4,fontsize=10,frameon=False,labelspacing=0.01,title=r'$\rho_{\rm SSFR}$') axes[1].text(10.0**11.2,0.85,"inverse abundance \n matching") axes[1].text(10.0**11.2,0.78,r'$\sigma_{\rm SMHM}=$'+str(sigma)) plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'f_q_cen_compare_rho' fig.savefig(savepath+filename+'.pdf')
def main(): if len(sys.argv)>1: mock_1 = sys.argv[1] else: mock_1 = 'Mr19_age_distribution_matching_mock' if len(sys.argv)>2: group_cat = sys.argv[2] else: group_cat = 'yang_groupcat' #set up plotting space fig, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 2.66)) fig.subplots_adjust(hspace=0, wspace=0.05) fig.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() #plot 1, left ax = axes[0] ax.set_ylim([0,1]) ax.set_xlim([12,15]) ax.set_ylabel(r'$f_{\rm blue}$') # ax.set_xlabel(r'$M~M_{\odot}h^{-1}$') #plot 2, middle ax = axes[1] ax.set_ylim([0,1]) ax.set_xlim([10**12,10**15]) ax.set_xlabel(r'$\log[M/(h^{-1}M_{\odot})]$') #plot 3, right ax = axes[2] ax.set_ylim([0,1]) ax.set_xlim([12,15]) #ax.set_xlabel(r'$M~M_{\odot}h^{-1}$') ax.set_xticks([12,13,14,15]) ax.set_xticklabels([r'$12$', r'$13$', r'$14$',r' ']) mass_bins = np.arange(10,15.2,0.2) #log mass bins #open age-matching mock filepath = cu.get_output_path() + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', mock_1+'.hdf5' f1 = h5py.File(filepath+mock_1+'.hdf5', 'r') #open catalogue file GC = f1.get(mock_1) #galaxy color h=1.0 color = GC['g-r'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) centrals = np.where(GC['ID_host'] == -1)[0] #central galaxies N_groups = len(centrals) mass_hist, bins = np.histogram(GC['M_host'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['M_host'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['M_host'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['M_host'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['M_host'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['M_host'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) f_cen_blue = np.zeros(len(mass_bins)-1) #fraction of blue satellites for blue centrals f_cen_red = np.zeros(len(mass_bins)-1) #fraction of blue satellites for red centrals err_cen_blue = np.zeros(len(mass_bins)-1) #poisson error on blue fraction for blue centrals err_cen_red = np.zeros(len(mass_bins)-1) #poisson error on blue fraction for red centrals N_cen_blue = np.zeros(len(mass_bins)-1) #number of satellites for blue centrals N_cen_red = np.zeros(len(mass_bins)-1) #number of satellites for red centrals N_groups_blue= np.zeros(len(mass_bins)-1) #number of satellites for red centrals N_groups_red = np.zeros(len(mass_bins)-1) #number of satellites for red centrals for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['ID_halo'][centrals[ind]] sat_galaxy_members = np.in1d(GC['ID_host'],ids) #satellite galaxies in the mass bin sat_galaxy_members = np.where(sat_galaxy_members)[0] #indicies of galaxies cen_galaxy_members = np.in1d(GC['ID_halo'],ids) #central galaxies in the mass bin cen_galaxy_members = np.where(cen_galaxy_members)[0] #indicies of galaxies galaxy_members = np.hstack((sat_galaxy_members,cen_galaxy_members)) print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['ID_host'][galaxy_members]!=-1)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['ID_host'][galaxy_members]==-1)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['ID_host'][satellite_members],GC['ID_halo'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['ID_host'][satellite_members],GC['ID_halo'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[i] if len(red_central_satellites)>0: f_cen_red[i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[i] #number satellites in the bin N_cen_blue[i] = float(len(blue_central_satellites)) N_cen_red[i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[i] = float(len(blue_central_members)) N_groups_red[i] = float(len(red_central_members)) ax=axes[0] selection = np.where( N_cen_blue > 50)[0] p0a_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_blue[selection], '-', color='blue', alpha=1, ms=4, mec='blue', mfc='none') p0a_mock_fake, = ax.plot(10*mass_bins[0:-1][selection],f_cen_blue[selection], '-', color='black', alpha=1, ms=4, mec='black', mfc='none') selection = np.where( N_cen_red > 50)[0] p0b_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_red[selection], '-', color='red', alpha=1, ms=4, mec='red', mfc='none') p0b_mock_fake, = ax.plot(10**mass_bins[0:-1][selection],f_cen_red[selection], '-', color='black', alpha=1, ms=4, mec='black', mfc='none') ax=axes[1] selection = np.where( N_cen_blue > 50)[0] p0a_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_blue[selection], '-', color='blue', alpha=1, ms=4, mec='blue', mfc='none') p0a_mock_fake, = ax.plot(10*mass_bins[0:-1][selection],f_cen_blue[selection], '-', color='black', alpha=1, ms=4, mec='black', mfc='none') selection = np.where( N_cen_red > 50)[0] p0b_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_red[selection], '-', color='red', alpha=1, ms=4, mec='red', mfc='none') p0b_mock_fake, = ax.plot(10**mass_bins[0:-1][selection],f_cen_red[selection], '-', color='black', alpha=1, ms=4, mec='black', mfc='none') ax=axes[2] selection = np.where( N_cen_blue > 50)[0] p2a, = ax.plot(mass_bins[0:-1][selection],f_cen_blue[selection], '-', color='blue', alpha=1, ms=4, mec='blue', mfc='none') p2a_mock_fake, = ax.plot(10*mass_bins[0:-1][selection],f_cen_blue[selection], '-', color='black', alpha=1, ms=4, mec='black', mfc='none') selection = np.where( N_cen_red > 50)[0] p2b_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_red[selection], '-', color='red', alpha=1, ms=4, mec='red', mfc='none') p2b_mock_fake, = ax.plot(10**mass_bins[0:-1][selection],f_cen_red[selection], '-', color='black', alpha=1, ms=4, mec='black', mfc='none') group_cat = 'yang' sample = 'sample3_L_model.mr19' filepath_cat = cu.get_output_path() + 'processed_data/yang_groupcat/custom_catalogues/' catalogue = sample N_boots = 50 f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', catalogue #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = catalogue+'_'+str(boot) print catalogue_1 f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print len(GC) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) f_blue = np.mean(f_cen_blue, axis=0) f_red = np.mean(f_cen_red, axis=0) N_blue = np.mean(N_cen_blue, axis=0) N_red = np.mean(N_cen_red, axis=0) err_blue = np.std(f_cen_blue, axis=0) err_red = np.std(f_cen_red, axis=0) print f_blue print err_blue print N_blue ax=axes[0] selection = np.where( N_blue > 50)[0] p2a_yang = ax.errorbar(mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='blue', ms=4, mec='blue', mfc='none') p2a_yang_fake = ax.errorbar(10**mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='black', ms=4, mec='black', mfc='none') selection = np.where( N_red > 50)[0] p2b = ax.errorbar(mass_bins[0:-1][selection],f_red[selection], yerr=err_red[selection], fmt='o', color='red', ms=4, mec='red', mfc='none') ax.legend((p2a_mock_fake, p2a_yang_fake),('age-matching','group finder on\n SDSS'), fontsize=10, numpoints=1, frameon=False ) group_cat = 'tinker' sample = 'sample3_L_model.mr19' filepath_cat = cu.get_output_path() + 'processed_data/tinker_groupcat/custom_catalogues/' catalogue = sample N_boots = 50 f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', catalogue #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = catalogue+'_'+str(boot) print catalogue_1 f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print len(GC) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) f_blue = np.mean(f_cen_blue, axis=0) f_red = np.mean(f_cen_red, axis=0) N_blue = np.mean(N_cen_blue, axis=0) N_red = np.mean(N_cen_red, axis=0) err_blue = np.std(f_cen_blue, axis=0) err_red = np.std(f_cen_red, axis=0) print f_blue print err_blue print N_blue ax=axes[1] selection = np.where( N_blue > 50)[0] p2a_yang = ax.errorbar(mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='blue', ms=4, mec='blue', mfc='none') p2a_yang_fake = ax.errorbar(10**mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='black', ms=4, mec='black', mfc='none') selection = np.where( N_red > 50)[0] p2b = ax.errorbar(mass_bins[0:-1][selection],f_red[selection], yerr=err_red[selection], fmt='o', color='red', ms=4, mec='red', mfc='none') group_cat = 'berlind' sample = 'sample3_L_model.mr19' filepath_cat = cu.get_output_path() + 'processed_data/berlind_groupcat/custom_catalogues/' catalogue = sample N_boots = 50 f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', catalogue #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = catalogue+'_'+str(boot) print catalogue_1 f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print len(GC) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) f_blue = np.mean(f_cen_blue, axis=0) f_red = np.mean(f_cen_red, axis=0) N_blue = np.mean(N_cen_blue, axis=0) N_red = np.mean(N_cen_red, axis=0) err_blue = np.std(f_cen_blue, axis=0) err_red = np.std(f_cen_red, axis=0) print f_blue print err_blue print N_blue ax=axes[2] selection = np.where( N_blue > 50)[0] p2a_yang = ax.errorbar(mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='blue', ms=4, mec='blue', mfc='none') p2a_yang_fake = ax.errorbar(10**mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='black', ms=4, mec='black', mfc='none') selection = np.where( N_red > 50)[0] p2b = ax.errorbar(mass_bins[0:-1][selection],f_red[selection], yerr=err_red[selection], fmt='o', color='red', ms=4, mec='red', mfc='none') plt.show() filepath = cu.get_plot_path()+'analysis/groupcats/' filename = 'mock_all_sdss_conformity_comparison.eps' fig.savefig(filepath+filename)
def main(): if len(sys.argv)>1: mock_1 = sys.argv[1] else: mock_1 = 'Mr19_age_distribution_matching_mock' if len(sys.argv)>2: mock_2 = sys.argv[2] else: mock_2 = 'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satrel_shuffle' if len(sys.argv)>3: group_cat = sys.argv[3] else: group_cat = 'yang_groupcat' #set up plotting space fig, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 2.66)) fig.subplots_adjust(hspace=0, wspace=0.05) fig.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() #plot 1, left ax = axes[0] ax.set_ylim([0,1]) ax.set_xlim([12,15]) ax.set_ylabel(r'$f_{\rm blue}$') # ax.set_xlabel(r'$M~M_{\odot}h^{-1}$') #plot 2, middle ax = axes[1] ax.set_ylim([0,1]) ax.set_xlim([10**12,10**15]) ax.set_xlabel(r'$\log[M/(h^{-1}M_{\odot})]$') #plot 3, right ax = axes[2] ax.set_ylim([0,1]) ax.set_xlim([12,15]) #ax.set_xlabel(r'$M~M_{\odot}h^{-1}$') ax.set_xticks([12,13,14,15]) ax.set_xticklabels([r'$12$', r'$13$', r'$14$',r' ']) #open age-matching mock filepath = cu.get_output_path() + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', mock_1+'.hdf5' f1 = h5py.File(filepath+mock_1+'.hdf5', 'r') #open catalogue file GC = f1.get(mock_1) #galaxy color h=1.0 color = GC['g-r'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) centrals = np.where(GC['ID_host'] == -1)[0] #central galaxies N_groups = len(centrals) mass_bins = np.arange(10,15.2,0.2) #log mass bins mass_hist, bins = np.histogram(GC['M_host'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['M_host'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['M_host'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['M_host'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['M_host'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['M_host'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) f_cen_blue = np.zeros(len(mass_bins)-1) #fraction of blue satellites for blue centrals f_cen_red = np.zeros(len(mass_bins)-1) #fraction of blue satellites for red centrals err_cen_blue = np.zeros(len(mass_bins)-1) #poisson error on blue fraction for blue centrals err_cen_red = np.zeros(len(mass_bins)-1) #poisson error on blue fraction for red centrals N_cen_blue = np.zeros(len(mass_bins)-1) #number of satellites for blue centrals N_cen_red = np.zeros(len(mass_bins)-1) #number of satellites for red centrals N_groups_blue= np.zeros(len(mass_bins)-1) #number of satellites for red centrals N_groups_red = np.zeros(len(mass_bins)-1) #number of satellites for red centrals for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['ID_halo'][centrals[ind]] sat_galaxy_members = np.in1d(GC['ID_host'],ids) #satellite galaxies in the mass bin sat_galaxy_members = np.where(sat_galaxy_members)[0] #indicies of galaxies cen_galaxy_members = np.in1d(GC['ID_halo'],ids) #central galaxies in the mass bin cen_galaxy_members = np.where(cen_galaxy_members)[0] #indicies of galaxies galaxy_members = np.hstack((sat_galaxy_members,cen_galaxy_members)) print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['ID_host'][galaxy_members]!=-1)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['ID_host'][galaxy_members]==-1)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['ID_host'][satellite_members],GC['ID_halo'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['ID_host'][satellite_members],GC['ID_halo'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[i] if len(red_central_satellites)>0: f_cen_red[i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[i] #number satellites in the bin N_cen_blue[i] = float(len(blue_central_satellites)) N_cen_red[i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[i] = float(len(blue_central_members)) N_groups_red[i] = float(len(red_central_members)) ax=axes[0] selection = np.where( N_cen_blue > 50)[0] p0a_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_blue[selection], 'o', color='blue', alpha=1, ms=4, mec='blue', mfc='none') p0a_mock_fake, = ax.plot(10*mass_bins[0:-1][selection],f_cen_blue[selection], 'o', color='black', alpha=1, ms=4, mec='black', mfc='none') selection = np.where( N_cen_red > 50)[0] p0b_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_red[selection], 'o', color='red', alpha=1, ms=4, mec='red', mfc='none') p0b_mock_fake, = ax.plot(10**mass_bins[0:-1][selection],f_cen_red[selection], 'o', color='black', alpha=1, ms=4, mec='black', mfc='none') #open age-matching mock filepath = cu.get_output_path() + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', mock_2+'.hdf5' f1 = h5py.File(filepath+mock_2+'.hdf5', 'r') #open catalogue file GC = f1.get(mock_2) #galaxy color h=1.0 color = GC['g-r'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) centrals = np.where(GC['ID_host'] == -1)[0] #central galaxies N_groups = len(centrals) mass_bins = np.arange(10,15.2,0.2) #log mass bins mass_hist, bins = np.histogram(GC['M_host'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['M_host'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['M_host'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['M_host'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['M_host'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['M_host'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) f_cen_blue = np.zeros(len(mass_bins)-1) #fraction of blue satellites for blue centrals f_cen_red = np.zeros(len(mass_bins)-1) #fraction of blue satellites for red centrals err_cen_blue = np.zeros(len(mass_bins)-1) #poisson error on blue fraction for blue centrals err_cen_red = np.zeros(len(mass_bins)-1) #poisson error on blue fraction for red centrals N_cen_blue = np.zeros(len(mass_bins)-1) #number of satellites for blue centrals N_cen_red = np.zeros(len(mass_bins)-1) #number of satellites for red centrals N_groups_blue= np.zeros(len(mass_bins)-1) #number of satellites for red centrals N_groups_red = np.zeros(len(mass_bins)-1) #number of satellites for red centrals for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['ID_halo'][centrals[ind]] sat_galaxy_members = np.in1d(GC['ID_host'],ids) #satellite galaxies in the mass bin sat_galaxy_members = np.where(sat_galaxy_members)[0] #indicies of galaxies cen_galaxy_members = np.in1d(GC['ID_halo'],ids) #central galaxies in the mass bin cen_galaxy_members = np.where(cen_galaxy_members)[0] #indicies of galaxies galaxy_members = np.hstack((sat_galaxy_members,cen_galaxy_members)) print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['ID_host'][galaxy_members]!=-1)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['ID_host'][galaxy_members]==-1)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['ID_host'][satellite_members],GC['ID_halo'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['ID_host'][satellite_members],GC['ID_halo'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[i] if len(red_central_satellites)>0: f_cen_red[i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[i] #number satellites in the bin N_cen_blue[i] = float(len(blue_central_satellites)) N_cen_red[i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[i] = float(len(blue_central_members)) N_groups_red[i] = float(len(red_central_members)) ax=axes[1] selection = np.where( N_cen_blue > 50)[0] p1a_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_blue[selection], 'o', color='blue', alpha=1, ms=4, mec='blue', mfc='none') p1a_mock_fake, = ax.plot(10**mass_bins[0:-1][selection],f_cen_blue[selection], 'o', color='black', alpha=1, ms=4, mec='black', mfc='none') selection = np.where( N_cen_red > 50)[0] p1b_mock, = ax.plot(mass_bins[0:-1][selection],f_cen_red[selection], 'o', color='red', alpha=1, ms=4, mec='red', mfc='none') #open yang run on mock 1 N_boots=50 filepath_cat = cu.get_output_path() + 'processed_data/yang_groupcat/mock_runs/4th_run/version_2/custom_catalogues/' group_catalogue = mock_1+'_groups' mass_bins = np.arange(10,15.2,0.2) #log mass bins f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', mock_1 #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = group_catalogue+'_'+str(boot) f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) f_blue = np.nanmean(f_cen_blue, axis=0) f_red = np.nanmean(f_cen_red, axis=0) N_blue = np.nanmean(N_cen_blue, axis=0) N_red = np.nanmean(N_cen_red, axis=0) err_blue = np.nanstd(f_cen_blue, axis=0) err_red = np.nanstd(f_cen_red, axis=0) ax=axes[0] selection = np.where( N_blue > 50)[0] p0a_yang_mock=ax.plot(mass_bins[0:-1][selection],f_blue[selection], '-', color='blue') p0a_yang_mock_fake,=ax.plot(10*mass_bins[0:-1][selection],f_blue[selection], '-', color='black') selection = np.where( N_red > 50)[0] p0b_yang_mock=ax.plot(mass_bins[0:-1][selection],f_red[selection], '-', color='red') ax.legend((p0a_yang_mock_fake,p0a_mock_fake),('group finder','age-matching'), fontsize=10, numpoints=1, frameon=False ) ax=axes[2] selection = np.where( N_blue > 50)[0] p2a_yang_mock=ax.plot(mass_bins[0:-1][selection],f_blue[selection], '-', color='blue') p2a_yang_mock_fake,=ax.plot(10**mass_bins[0:-1][selection],f_blue[selection], '-', color='black') selection = np.where( N_red > 50)[0] p2b_yang_mock=ax.plot(mass_bins[0:-1][selection],f_red[selection], '-', color='red') #open yang run on mock 1 N_boots=50 filepath_cat = cu.get_output_path() + 'processed_data/yang_groupcat/mock_runs/4th_run/version_2/custom_catalogues/' group_catalogue = mock_2+'_groups' mass_bins = np.arange(10,15.2,0.2) #log mass bins f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', mock_1 #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = group_catalogue+'_'+str(boot) f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) f_blue = np.nanmean(f_cen_blue, axis=0) f_red = np.nanmean(f_cen_red, axis=0) N_blue = np.nanmean(N_cen_blue, axis=0) N_red = np.nanmean(N_cen_red, axis=0) err_blue = np.nanstd(f_cen_blue, axis=0) err_red = np.nanstd(f_cen_red, axis=0) ax=axes[1] selection = np.where( N_blue > 50)[0] p1a_yang_mock=ax.plot(mass_bins[0:-1][selection],f_blue[selection], '-', color='blue') p1a_yang_mock_fake,=ax.plot(10**mass_bins[0:-1][selection],f_blue[selection], '-', color='black') selection = np.where( N_red > 50)[0] p1b_yang_mock=ax.plot(mass_bins[0:-1][selection],f_red[selection], '-', color='red') ax.legend((p1a_yang_mock_fake,p1a_mock_fake),('group finder','shuffled'), fontsize=10, numpoints=1, frameon=False ) group_cat = 'yang' sample = 'sample3_L_model.mr19' filepath_cat = cu.get_output_path() + 'processed_data/yang_groupcat/custom_catalogues/' catalogue = sample N_boots = 50 mass_bins = np.arange(10,15.2,0.2) #log mass bins f_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for blue centrals f_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #fraction of blue satellites for red centrals N_cen_blue = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for blue centrals N_cen_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_blue= np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals N_groups_red = np.zeros((N_boots,len(mass_bins)-1)) #number of satellites for red centrals for boot in range(0,N_boots): print 'opening group catalogue:', catalogue #open catalogue filepath = filepath_cat+'bootstraps/' catalogue_1 = catalogue+'_'+str(boot) print catalogue_1 f = h5py.File(filepath+catalogue_1+'.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) print len(GC) #do we have a measure of M_u? good = np.where(GC['M_g,0.1']!=-99.9)[0] bad = np.where(GC['M_g,0.1']==-99.9)[0] print 'number of galaxies without M_u:', len(bad) #galaxy color h=1.0 color = GC['M_g,0.1'] - GC['M_r,0.1'] #LHS = 0.7 - 0.032*(GC['M_r,0.1']-5.0*np.log10(h)+16.5) #Weinmann 2006 LHS = 0.21-0.03*GC['M_r,0.1'] blue = np.where(color<LHS)[0] #indices of blue galaxies red = np.where(color>LHS)[0] #indicies of red galaxies lookup = color<LHS #true if blue, false if red flip = (lookup == False) print 'number of blue galaxies:', len(blue) print 'number of red galaxies:', len(red) centrals = np.where(GC['RPROJ'][good] == 0)[0] #central galaxies centrals = good[centrals] bad_centrals = np.where(GC['RPROJ'][bad] == 0)[0] #central galaxies with ssfr measured bad_centrals = bad[bad_centrals] N_groups = len(centrals)+len(bad_centrals) mass_hist, bins = np.histogram(GC['MGROUP'][centrals], bins=mass_bins) #group histogram by log(mass) mass_bin_ind = np.digitize(GC['MGROUP'][centrals], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==True)[0] selection = np.intersect1d(selection,centrals) mass_hist_blue, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_blue = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = np.where(lookup==False)[0] selection = np.intersect1d(selection,centrals) mass_hist_red, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) mass_bin_ind_red = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins selection = bad_centrals mass_hist_grey, bins = np.histogram(GC['MGROUP'][selection], bins=mass_bins) #group histogram by log(mass) if len(bad_centrals)>0: mass_bin_ind_grey = np.digitize(GC['MGROUP'][selection], bins=mass_bins) #indices of groups in log(mass) bins width = 1.0 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 #normalize the hists mass_hist_grey = mass_hist_grey/float(N_groups) mass_hist_red = mass_hist_red/float(N_groups) mass_hist_blue = mass_hist_blue/float(N_groups) for i in range(0,len(mass_bins)-1): print i, mass_bins[i], mass_bins[i+1] ind = np.where(mass_bin_ind==i+1)[0] if len(ind)>0: print 'number of groups:', len(ind) ids = GC['GROUP_ID'][centrals[ind]] galaxy_members = np.in1d(GC['GROUP_ID'],ids) #galaxies in the mass bin galaxy_members = np.where(galaxy_members)[0] #indicies of galaxies print 'number of galaxies:', len(galaxy_members) satellite_members = np.where(GC['RPROJ'][galaxy_members]>0)[0] #satellites satellite_members = galaxy_members[satellite_members] #indices of satellites central_members = np.where(GC['RPROJ'][galaxy_members]==0)[0] #centrals central_members = galaxy_members[central_members] #indices of centrals print 'number of centrals:', len(central_members) print 'number of satellites:', len(satellite_members) print 'check:', len(central_members) + len(satellite_members) == len(galaxy_members) blue_central_members = np.where(lookup[central_members]==True)[0] #blue centrals blue_central_members = central_members[blue_central_members] #indicies of blue centrals red_central_members = np.where(lookup[central_members]==False)[0] #red centrals red_central_members = central_members[red_central_members] #indicies of red centrals print 'number of blue centrals:', len(blue_central_members) print 'number of red centrals:', len(red_central_members) print 'check:', len(blue_central_members)+len(red_central_members) == len(central_members) blue_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][blue_central_members]) blue_central_satellites = np.where(blue_central_satellites)[0] blue_central_satellites = satellite_members[blue_central_satellites] red_central_satellites = np.in1d(GC['GROUP_ID'][satellite_members],GC['GROUP_ID'][red_central_members]) red_central_satellites = np.where(red_central_satellites)[0] red_central_satellites = satellite_members[red_central_satellites] print 'number of blue central satellites:', len(blue_central_satellites) print 'number of red central satellites:', len(red_central_satellites) print 'check:', len(blue_central_satellites) + len(red_central_satellites) == len(satellite_members) blue_central_blue_satellites = np.where(lookup[blue_central_satellites]==True)[0] blue_central_blue_satellites = blue_central_satellites[blue_central_blue_satellites] blue_central_red_satellites = np.where(lookup[blue_central_satellites]==False)[0] blue_central_red_satellites = blue_central_satellites[blue_central_red_satellites] red_central_blue_satellites = np.where(lookup[red_central_satellites]==True)[0] red_central_blue_satellites = red_central_satellites[red_central_blue_satellites] red_central_red_satellites = np.where(lookup[red_central_satellites]==False)[0] red_central_red_satellites = red_central_satellites[red_central_red_satellites] N_blue_central_blue_satellites = float(len(blue_central_blue_satellites)) N_blue_central_red_satellites = float(len(blue_central_red_satellites)) N_red_central_blue_satellites = float(len(red_central_blue_satellites)) N_red_central_red_satellites = float(len(red_central_red_satellites)) print 'check:', N_blue_central_blue_satellites+N_blue_central_red_satellites==len(blue_central_satellites) print 'check:', N_red_central_blue_satellites+N_red_central_red_satellites==len(red_central_satellites) if len(blue_central_satellites)>0: f_cen_blue[boot,i] = N_blue_central_blue_satellites / \ (N_blue_central_blue_satellites + N_blue_central_red_satellites) print 'f_cen_blue:', f_cen_blue[boot,i] if len(red_central_satellites)>0: f_cen_red[boot,i] = N_red_central_blue_satellites / \ (N_red_central_blue_satellites + N_red_central_red_satellites) print 'f_cen_red:', f_cen_red[boot,i] #number satellites in the bin N_cen_blue[boot,i] = float(len(blue_central_satellites)) N_cen_red[boot,i] = float(len(red_central_satellites)) #number of centrals in the bin N_groups_blue[boot,i] = float(len(blue_central_members)) N_groups_red[boot,i] = float(len(red_central_members)) f_blue = np.mean(f_cen_blue, axis=0) f_red = np.mean(f_cen_red, axis=0) N_blue = np.mean(N_cen_blue, axis=0) N_red = np.mean(N_cen_red, axis=0) err_blue = np.std(f_cen_blue, axis=0) err_red = np.std(f_cen_red, axis=0) print f_blue print err_blue print N_blue ax=axes[2] selection = np.where( N_blue > 50)[0] p2a_yang = ax.errorbar(mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='blue', ms=4, mec='blue', mfc='none') p2a_yang_fake = ax.errorbar(10**mass_bins[0:-1][selection],f_blue[selection],yerr=err_blue[selection], fmt='o', color='black', ms=4, mec='black', mfc='none') selection = np.where( N_red > 50)[0] p2b = ax.errorbar(mass_bins[0:-1][selection],f_red[selection], yerr=err_red[selection], fmt='o', color='red', ms=4, mec='red', mfc='none') ax.legend((p2a_yang_mock_fake, p2a_yang_fake),('group finder on\n age-matching','group finder on\n SDSS'), fontsize=10, numpoints=1, frameon=False ) plt.show() filepath = cu.get_plot_path()+'analysis/groupcats/' filename = 'mock_sdss_conformity_comparison.eps' fig.savefig(filepath+filename)
def main(): catalogues_1 = ['sm_9.49_s0.0_sfr_c-1.0_250','sm_9.49_s0.1_sfr_c-1.0_250',\ 'sm_9.49_s0.2_sfr_c-1.0_250','sm_9.49_s0.3_sfr_c-1.0_250'] samples = ['all','q','sf'] sm_bins = ['9.0_9.5', '9.5_10.0', '10.0_10.5', '10.5_11.0', '11.0_11.5'] ###################################################################################### #set up plot ###################################################################################### fig1, axes = plt.subplots(nrows=1,ncols=3,sharex=True,sharey=True,figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05, left=0.1, right=0.95, bottom=0.2, top=0.9) ax = axes[0] ax.set_xlim([0.1,20]) ax.set_ylim([5,300]) ax.set_yscale('log') ax.set_xscale('log') ax.set_ylabel(r'$\omega_p(r_p)\times r_p$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$9.5<\log(M_{*}/M_{\odot}h^{-2})>10.0$') ax = axes[1] ax.set_xlim([0.1,20]) ax.set_ylim([5,300]) ax.set_yscale('log') ax.set_xscale('log') #ax.set_ylabel(r'$\omega_p(r_p)$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$10.0<\log(M_{*}/M_{\odot}h^{-2})>10.5$') ax = axes[2] ax.set_xlim([0.1,20]) ax.set_ylim([5,300]) ax.set_yscale('log') ax.set_xscale('log') #ax.set_ylabel(r'$\omega_p(r_p)$') ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$') ax.set_title(r'$10.5<\log(M_{*}/M_{\odot}h^{-2})>11.0$') ###################################################################################### #read in results and plot ###################################################################################### for i,sm_bin in enumerate(sm_bins[1:4]): print(i, sm_bin) filepath = cu.get_output_path() + 'analysis/central_quenching/observables/' names = ['r','wp'] filename = catalogues_1[0]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_1a = ascii.read(filepath+filename,names=names) filename = catalogues_1[0]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_1b = ascii.read(filepath+filename,names=names) filename = catalogues_1[0]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_1c = ascii.read(filepath+filename,names=names) filename = catalogues_1[1]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_2a = ascii.read(filepath+filename,names=names) filename = catalogues_1[1]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_2b = ascii.read(filepath+filename,names=names) filename = catalogues_1[1]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_2c = ascii.read(filepath+filename,names=names) filename = catalogues_1[2]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_3a = ascii.read(filepath+filename,names=names) filename = catalogues_1[2]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_3b = ascii.read(filepath+filename,names=names) filename = catalogues_1[2]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_3c = ascii.read(filepath+filename,names=names) filename = catalogues_1[3]+'_wp_'+samples[0]+'_'+sm_bin+'.dat' result_4a = ascii.read(filepath+filename,names=names) filename = catalogues_1[3]+'_wp_'+samples[1]+'_'+sm_bin+'.dat' result_4b = ascii.read(filepath+filename,names=names) filename = catalogues_1[3]+'_wp_'+samples[2]+'_'+sm_bin+'.dat' result_4c = ascii.read(filepath+filename,names=names) ax = axes[i] p1a, = ax.plot(result_1a['r'],result_1a['wp']*result_1a['r'],'-',color='black', alpha=1) p1b, = ax.plot(result_1b['r'],result_1b['wp']*result_1a['r'],'-',color='red', alpha=1) p1c, = ax.plot(result_1c['r'],result_1c['wp']*result_1a['r'],'-',color='blue', alpha=1) p2a, = ax.plot(result_2a['r'],result_2a['wp']*result_1a['r'],'-',color='black', alpha=0.8) p2b, = ax.plot(result_2b['r'],result_2b['wp']*result_1a['r'],'-',color='red',alpha=0.8) p2c, = ax.plot(result_2c['r'],result_2c['wp']*result_1a['r'],'-',color='blue',alpha=0.8) p3a, = ax.plot(result_3a['r'],result_3a['wp']*result_1a['r'],'-',color='black',alpha=0.6) p3b, = ax.plot(result_3b['r'],result_3b['wp']*result_1a['r'],'-',color='red', alpha=0.6) p3c, = ax.plot(result_3c['r'],result_3c['wp']*result_1a['r'],'-',color='blue', alpha=0.6) p4a, = ax.plot(result_4a['r'],result_4a['wp']*result_1a['r'],'-',color='black',alpha=0.4) p4b, = ax.plot(result_4b['r'],result_4b['wp']*result_1a['r'],'-',color='red', alpha=0.4) p4c, = ax.plot(result_4c['r'],result_4c['wp']*result_1a['r'],'-',color='blue', alpha=0.4) if i==0: ax.legend((p1a,p2a,p3a,p4a),\ (r"$\sigma=0.0$",r"$\sigma=0.1$",r"$\sigma=0.2$",r"$\sigma=0.3$"),\ loc=4,fontsize=10, frameon=False, labelspacing=0.01, title='all') if i==1: ax.legend((p1b,p2b,p3b,p4b),\ (r"$\sigma=0.0$",r"$\sigma=0.1$",r"$\sigma=0.2$",r"$\sigma=0.3$"),\ loc=4,fontsize=10, frameon=False, labelspacing=0.01, title='quenched') if i==2: ax.legend((p1c,p2c,p3c,p4c),\ (r"$\sigma=0.0$",r"$\sigma=0.1$",r"$\sigma=0.2$",r"$\sigma=0.3$"),\ loc=4,fontsize=10, frameon=False, labelspacing=0.01, title='star-forming') plt.show(block=True) savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'w_p_cross_r' fig1.savefig(savepath+filename+'.pdf')
def main(): if len(sys.argv)>1: catalogue = sys.argv[1] esle: catalogue = 'sample3_L_model.mr19' plotpath = cu.get_plot_path() + 'analysis/groupcats/' filepath_cat = cu.get_output_path() + 'analysis/yang_groupcat/' filename = catalogue+'_blue_central_conformity.npy' arr1_1 = np.load(filepath_cat+filename) filename = catalogue+'_red_central_conformity.npy' arr2_1 = np.load(filepath_cat+filename) filepath_cat = cu.get_output_path() + 'analysis/berlind_groupcat/' filename = catalogue+'_blue_central_conformity.npy' arr1_2 = np.load(filepath_cat+filename) filename = catalogue+'_red_central_conformity.npy' arr2_2 = np.load(filepath_cat+filename) filepath_cat = cu.get_output_path() + 'analysis/berlind_groupcat/' filename = catalogue+'_blue_central_conformity.npy' arr1_3 = np.load(filepath_cat+filename) filename = catalogue+'_red_central_conformity.npy' arr2_3 = np.load(filepath_cat+filename) catalogue_mock = 'Mr19_age_distribution_matching_mock' filepath_cat = cu.get_output_path() + 'analysis/hearin_mocks/' filename = catalogue_mock+'_blue_central_conformity.npy' arr1_mock = np.load(filepath_cat+filename) filename = catalogue_mock+'_red_central_conformity.npy' arr2_mock = np.load(filepath_cat+filename) mass_bins = np.arange(10,15.2,0.2) #log mass bins fig = plt.figure() #Yang f_cen_blue = arr1_1[0] N_cen_blue = arr1_1[2] f_cen_red = arr2_1[0] N_cen_red = arr2_1[2] selection = np.where( N_cen_blue > 50)[0] p1a, = plt.plot(mass_bins[0:-1][selection],f_cen_blue[selection], color='blue',linewidth=2) selection = np.where( N_cen_red > 50)[0] p2a, = plt.plot(mass_bins[0:-1][selection],f_cen_red[selection], color='red',linewidth=2 ) p3a, = plt.plot([0,1],[-1,-1], color='black',linewidth=2 ) #Berlind f_cen_blue = arr1_2[0] N_cen_blue = arr1_2[2] f_cen_red = arr2_2[0] N_cen_red = arr2_2[2] selection = np.where( N_cen_blue > 50)[0] p1b, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='blue', alpha=0.5,linewidth=2) selection = np.where( N_cen_red > 50)[0] p2b, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='red', alpha=0.5,linewidth=2) p3b, = plt.plot([0,1],[-1,-1], color='black',alpha=0.5,linewidth=2 ) #Wetzel f_cen_blue = arr1_3[0] N_cen_blue = arr1_3[2] f_cen_red = arr2_3[0] N_cen_red = arr2_3[2] selection = np.where( N_cen_blue > 50)[0] p1c, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='blue', ls='--',linewidth=2) selection = np.where( N_cen_red > 50)[0] p2c, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='red', ls='--',linewidth=2) p3c, = plt.plot([0,1],[-1,-1], color='black', ls='--', linewidth=2 ) #Hearin Mock ''' f_cen_blue = arr1_mock[0] N_cen_blue = arr1_mock[2] f_cen_red = arr2_mock[0] N_cen_red = arr2_mock[2] selection = np.where( N_cen_blue > 50)[0] p1d, = plt.plot(mass_bins[0:-1][selection], f_cen_blue[selection], color='green', lw=3) selection = np.where( N_cen_red > 50)[0] p2d, = plt.plot(mass_bins[0:-1][selection], f_cen_red[selection], color='magenta', lw=3) ''' font = {'size':19} matplotlib.rc('font', **font) plt.ylim([0,0.8]) plt.xlim([11,15]) plt.xlabel(r'$\mathrm{log}(M)$ $[{h}^{-1}{M}_{\odot}]$') plt.ylabel(r'$f_{\mathrm{late}}$',fontsize=25) #plt.title(catalogue) #plt.legend([p1a, p1b, p1c, p1d], ["Yang blue centrals", "Berlind blue centrals", "Tinker blue centrals", "mock blue centrals"]) #plt.legend([p1a, p1b, p1c], ["Yang et al. blue centrals", "Berlind et al. blue centrals", "Tinker et al. blue centrals"]) plt.legend([p3a, p3b, p3c], ["Yang et al.", "Berlind et al.", "Tinker et al."],prop={'size':20}) filename = catalogue+'_compare_conformity' fig.savefig(plotpath+filename+'.eps') plt.show(block=True)
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock' filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' plotpath = cu.get_plot_path() + 'analysis/hearin_mocks/' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) mock = np.array(mock) print 'length:', len(mock) for name in mock.dtype.names: print ' ', name #calculate the satellite fraction N_sat = float(np.sum((mock['ID_host'] != -1))) N_cen = float(np.sum((mock['ID_host'] == -1))) fsat = N_sat / (N_sat + N_cen) print 'satellite fraction:', fsat #subsample the galaxies to make plotting easier N = 10000 selection = np.random.permutation(len(mock))[0:N] mock = mock[selection] host = np.where(mock['ID_host'] == -1)[0] sub = np.where(mock['ID_host'] != -1)[0] color = mock['g-r'] LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5) #Weinmann 2006 blue = np.where((color < LHS) & (mock['M_r,0.1'] != -99))[0] red = np.where((color > LHS) & (mock['M_r,0.1'] != -99))[0] fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) p1, = ax.plot(10.0**mock['M_host'][host], mock['V_peak'][host], 'o', ms=1, alpha=1, color='orange', mew=0, rasterized=True) p2, = ax.plot(10.0**mock['M_host'][sub], mock['V_peak'][sub], 'o', ms=1, alpha=1, color='green', mew=0, rasterized=True) ax.plot([10**10, 10**16], [100, 100], '--', color='black') ax.plot([2 * 10**11, 2 * 10**11], [1, 800], '--', color='black') ax.set_yscale('log') ax.set_xscale('log') ax.set_ylim([50, 2000]) ax.set_xlim([10**10, 10**15]) ax.set_xlabel(r'$M_{\rm host}$ $[M_{\odot}/h]$') ax.set_ylabel(r'$V_{\rm peak}$') ax.legend((p1, p2), ('centrals', 'satellites'), loc=2, numpoints=1, fontsize=10, markerscale=2, frameon=False) plt.show() filename1 = 'mock_props_censata_MhVpeak.pdf' fig.savefig(plotpath + filename1, dpi=400) fig = plt.figure(figsize=(3.3, 3.3)) ax = fig.add_subplot(1, 1, 1) fig.subplots_adjust(left=0.2, right=0.9, bottom=0.2, top=0.9) p1, = ax.plot(10.0**mock['M_host'][red], mock['V_peak'][red], 'o', ms=1, alpha=1, color='red', mew=0, rasterized=True) p2, = ax.plot(10.0**mock['M_host'][blue], mock['V_peak'][blue], 'o', ms=1, alpha=1, color='blue', mew=0, rasterized=True) ax.plot([10**10, 10**16], [100, 100], '--', color='black') ax.plot([2 * 10**11, 2 * 10**11], [1, 800], '--', color='black') ax.set_yscale('log') ax.set_xscale('log') ax.set_ylim([50, 2000]) ax.set_xlim([10**10, 10**15]) ax.set_xlabel(r'$M_{\rm host}$ $[M_{\odot}/h]$') ax.set_ylabel(r'$V_{\rm peak}$') ax.legend((p1, p2), ('red subsample', 'blue subsample'), loc=2, numpoints=1, fontsize=10, markerscale=2, frameon=False) plt.show() filename2 = 'mock_props_color_MhVpeak.pdf' fig.savefig(plotpath + filename2, dpi=400)
def main(): #process user input if len(sys.argv) == 2: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satrel_shuffle' print "running for:", catalogue #setup figure fig1, axes = plt.subplots(nrows=2, ncols=3, sharex=True, sharey=True, figsize=(6.95, 6.6 - 0.99)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.1, top=0.95) axes = axes.flatten() #get figure saving information plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_f_red_sat_L' #number of bootstraps per group catalogue. N_boots = 3 #run code for intrinsic mock results ########################################################################################## filepath_mock = cu.get_output_path() + \ 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' #open catalogue f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.where(mock['ID_host'] == -1) satellites = np.where(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] LHS = 0.21 - 0.03 * mock['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies S_r = 4.64 L = solar_lum(mock['M_r,0.1'], S_r) bins = np.arange(9.5, 10.8, 0.1) bin_centers = (bins[:-1] + bins[1:]) / 2.0 result = np.digitize(L, bins=bins) f_red_cen = np.zeros(len(bin_centers)) f_red_sat = np.zeros(len(bin_centers)) f_sat_red = np.zeros(len(bin_centers)) f_sat_blue = np.zeros(len(bin_centers)) for i in range(0, len(bins) - 1): ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[i] = float( len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[i] = float(len(red_satellites)) / (len(red_satellites) + len(blue_satellites)) #f_sat_red[i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[i] = float( len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[i] = float( len(blue_satellites)) / (len(blue_centrals) + len(blue_satellites)) ax = axes[0] ax.set_xlim([9.5, 10.8]) ax.set_ylim([0, 1]) ax.set_ylabel(r'$f_{red}$') p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[3] p1b, = ax.plot(bin_centers, f_sat_red, color='red') p2b, = ax.plot(bin_centers, f_sat_blue, color='blue') ax = axes[1] ax.set_xlim([9.5, 10.8]) ax.set_ylim([0, 1]) p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[4] p1b, = ax.plot(bin_centers, f_sat_red, color='red') p2b, = ax.plot(bin_centers, f_sat_blue, color='blue') ax = axes[2] ax.set_xlim([9.5, 10.8]) ax.set_ylim([0, 1]) p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[5] p1b, = ax.plot(bin_centers, f_sat_red, color='red') p2b, = ax.plot(bin_centers, f_sat_blue, color='blue') #run code for Berlind group catalogue ########################################################################################## group_cat = 'berlind' filepath_cat = cu.get_output_path() + \ 'processed_data/'+group_cat+'_groupcat/mock_runs/4th_run/custom_catalogues/' group_catalogue = catalogue + '_groups' f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) print 'opening group catalogue:', catalogue_1 f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals = np.where(GC['RPROJ'] == 0) satellites = np.where(GC['RPROJ'] > 0) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies S_r = 4.64 L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) for i in range(0, len(bins) - 1): ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[boot, i] = float(len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[boot, i] = float(len(red_satellites)) / ( len(red_satellites) + len(blue_satellites)) #f_sat_red[boot,i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[boot,i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[boot, i] = float(len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[boot, i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) f_sat_red_111 = f_sat_red f_sat_blue_111 = f_sat_blue f_cen = np.nanmean(f_red_cen, axis=0) f_sat = np.nanmean(f_red_sat, axis=0) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) err_sat_red = np.nanstd(f_sat_red_111, axis=0) err_sat_blue = np.nanstd(f_sat_blue_111, axis=0) ax = axes[0] p3a = ax.errorbar(bin_centers, f_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p1a, p2a), ('halo central', 'halo satellite'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ax.set_title(r'Berlind FoF groups') ax = axes[3] p3b = ax.errorbar(bin_centers, f_sat_red, yerr=err_sat_red, fmt='o', color='red', mec='none', ms=3) p4b = ax.errorbar(bin_centers + 0.01, f_sat_blue, yerr=err_sat_blue, fmt='o', color='blue', mec='none', ms=3) ax.set_xlabel(r'$\log(L)$ $[L_{\odot}]$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_xlim([9.5, 10.7]) ax.set_ylabel(r'$f_{sat}$') ax.legend((p1b, p2b), ('halo red cen/sat', 'halo blue cen/sat'), loc='upper right', fontsize=10, numpoints=1, frameon=False) #run code for Tinker group catalogue ########################################################################################## group_cat = 'tinker' filepath_cat = cu.get_output_path() + \ 'processed_data/'+group_cat+'_groupcat/mock_runs/4th_run/custom_catalogues/' group_catalogue = catalogue + '_clf_groups_M19' f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) print 'opening group catalogue:', catalogue_1 f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals = np.where(GC['RPROJ'] == 0) satellites = np.where(GC['RPROJ'] > 0) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies S_r = 4.64 L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) for i in range(0, len(bins) - 1): ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[boot, i] = float(len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[boot, i] = float(len(red_satellites)) / ( len(red_satellites) + len(blue_satellites)) #f_sat_red[boot,i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[boot,i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[boot, i] = float(len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[boot, i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) f_sat_red_111 = f_sat_red f_sat_blue_111 = f_sat_blue f_cen = np.nanmean(f_red_cen, axis=0) f_sat = np.nanmean(f_red_sat, axis=0) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) err_sat_red = np.nanstd(f_sat_red_111, axis=0) err_sat_blue = np.nanstd(f_sat_blue_111, axis=0) ax = axes[1] p3a = ax.errorbar(bin_centers, f_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p3a, p4a), ('group central', 'group satellite'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ax.set_title(r'Tinker SO groups') ax = axes[4] p3b = ax.errorbar(bin_centers, f_sat_red, yerr=err_sat_red, fmt='o', color='red', mec='none', ms=3) p4b = ax.errorbar(bin_centers + 0.01, f_sat_blue, yerr=err_sat_blue, fmt='o', color='blue', mec='none', ms=3) ax.set_xlabel(r'$\log(L)$ $[L_{\odot}]$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_xlim([9.5, 10.7]) ax.legend((p3b, p4b), ('group red cen/sat', 'group blue cen/sat'), loc='upper right', fontsize=10, numpoints=1, frameon=False) #run code for Yang group catalogue ########################################################################################## group_cat = 'yang' filepath_cat = cu.get_output_path() + \ 'processed_data/'+group_cat+'_groupcat/mock_runs/4th_run/custom_catalogues/' group_catalogue = catalogue + '_groups' f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) print 'opening group catalogue:', catalogue_1 f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals = np.where(GC['RPROJ'] == 0) satellites = np.where(GC['RPROJ'] > 0) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.21 - 0.03 * GC['M_r,0.1'] blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies S_r = 4.64 L = solar_lum(GC['M_r,0.1'], S_r) result = np.digitize(L, bins=bins) for i in range(0, len(bins) - 1): ind = np.where(result == i + 1)[0] centrals_in_bin = np.in1d(ind, centrals) centrals_in_bin = ind[centrals_in_bin] satellites_in_bin = np.in1d(ind, satellites) satellites_in_bin = ind[satellites_in_bin] red_centrals = np.in1d(centrals_in_bin, red) red_centrals = centrals_in_bin[red_centrals] red_satellites = np.in1d(satellites_in_bin, red) red_satellites = satellites_in_bin[red_satellites] blue_centrals = np.in1d(centrals_in_bin, blue) blue_centrals = centrals_in_bin[blue_centrals] blue_satellites = np.in1d(satellites_in_bin, blue) blue_satellites = satellites_in_bin[blue_satellites] if (len(red_centrals) + len(blue_centrals)) > 0: f_red_cen[boot, i] = float(len(red_centrals)) / (len(red_centrals) + len(blue_centrals)) if (len(red_satellites) + len(blue_satellites)) > 0: f_red_sat[boot, i] = float(len(red_satellites)) / ( len(red_satellites) + len(blue_satellites)) #f_sat_red[boot,i] = float(len(red_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) #f_sat_blue[boot,i] = float(len(blue_satellites))/(len(centrals_in_bin)+len(satellites_in_bin)) f_sat_red[boot, i] = float(len(red_satellites)) / (len(red_centrals) + len(red_satellites)) f_sat_blue[boot, i] = float(len(blue_satellites)) / ( len(blue_centrals) + len(blue_satellites)) f_sat_red_111 = f_sat_red f_sat_blue_111 = f_sat_blue f_cen = np.nanmean(f_red_cen, axis=0) f_sat = np.nanmean(f_red_sat, axis=0) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) err_sat_red = np.nanstd(f_sat_red_111, axis=0) err_sat_blue = np.nanstd(f_sat_blue_111, axis=0) ax = axes[2] p3a = ax.errorbar(bin_centers, f_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) #ax.legend((p1a,p2a,p3a,p4a),('halo cen','halo sat','groups cen','groups sat'), loc='lower right', fontsize=10) ax.set_title(r'Yang SO groups') ax.set_yticks([0, 0.2, 0.4, 0.6, 0.8]) ax = axes[5] p3b = ax.errorbar(bin_centers, f_sat_red, yerr=err_sat_red, fmt='o', color='red', mec='none', ms=3) p4b = ax.errorbar(bin_centers + 0.01, f_sat_blue, yerr=err_sat_blue, fmt='o', color='blue', mec='none', ms=3) ax.set_xlabel(r'$\log(L)$ $[L_{\odot}]$') ax.set_xticks([9.6, 9.8, 10.0, 10.2, 10.4, 10.6]) ax.set_xlim([9.5, 10.7]) ax.set_yticks([0, 0.2, 0.4, 0.6, 0.8]) #plot results, show, and save. ########################################################################################## plt.show() fig1.savefig(plotpath + filename + '.pdf', dpi=400, bbox_inches='tight')
def main(): #open halo catalogue Lbox=250.0 filepath = cu.get_output_path() + 'processed_data/Multidark/Bolshoi/halo_catalogues/' halo_catalogue = 'hlist_1.00030.list' f = h5py.File(filepath+halo_catalogue+'.hdf5', 'r') HC = f.get(halo_catalogue) #halo catalogue HC = np.array(HC) for name in HC.dtype.names: print(name) #make completeness cuts #require all (sub-)haloes to had had >100 particles at some point mp_bolshoi = 1.35e8 mpeak_cut = mp_bolshoi*100.0 keep = (HC['Mpeak']>mpeak_cut) HC = HC[keep] #keep = (HC['upid']==-1) #HC = HC[keep] #define halo property to use to make mass function halo_prop = 'Mpeak' #calculate cumulative mass function #N = np.cumsum(np.ones(len(HC))) #N = N/(Lbox**3.0) #M = np.sort(HC[halo_prop])[::-1] #M = np.log10(M) #plt.plot(M,N) #plt.yscale('log') #plt.show() #assign jackknife labels sample = np.vstack((HC['x'],HC['y'],HC['z'])).T Nsub=np.array([5.0,5.0,5.0]) j_index, N_sub_vol = get_subvolume_labels(sample, Nsub, np.array([Lbox]*3)) N_subs = get_subvolume_numbers(j_index,N_sub_vol) N_sub_vol = np.prod(Nsub).astype(np.int) #calculate mass function bins = np.arange(10.2,16.0,0.1) bin_centers = (bins[:-1]+bins[1:])/2.0 weights = np.array([1.0/(Lbox**3.0)]*len(HC)) phi_full = mass_function(HC,halo_prop,bins,weights,use_log=True) phi_sub = np.zeros((N_sub_vol,len(phi_full))) for i in range(0,N_sub_vol): inds = (j_index==i+1) phi_sub[i,:] = mass_function(HC[inds], halo_prop, bins, weights[inds], use_log=True) cov = covariance_matrix(phi_sub,phi_full,N_sub_vol) err = np.sqrt(np.diagonal(cov)) print(err) raw_counts = np.histogram(np.log10(HC[halo_prop]), bins=bins)[0] err_pos = np.sqrt(raw_counts) err_pos = (1.0/err_pos)*phi_full print(err_pos) print(err/err_pos) keep = (raw_counts>0) phi_full = phi_full[keep] err= err[keep] bin_centers = bin_centers[keep] #fit function to data from scipy.optimize import curve_fit log_err = 0.434*err/phi_full #single schechter funciton fit params, cov = curve_fit(Log_Schechter_function, bin_centers, np.log10(phi_full),\ p0=[0.012,12.4,-1.5, 1.0], sigma=log_err) dndm_halo_fit_1 = cu.schechter_function.Log_Super_Schechter(*params) print("params:", params) print("error:", np.sqrt(np.diagonal(cov))) red_chi_2 = cu.fitting.redchisqg(phi_full,dndm_halo_fit_1(bin_centers),deg=3,sd=err) print("Reduced chi squared value of fit: {0}".format(red_chi_2)) """ #double schechter funciton fit params, cov = curve_fit(Log_Double_Schechter_function, bin_centers, np.log10(phi),\ p0=[13.4,14.5,0.012,0.01,-1.5,-0.8], sigma=log_err) dndm_halo_fit_2 = cu.schechter_function.Log_Double_Schechter(*params) print(params) """ """ #special function fit params, cov = curve_fit(log_special_fit, bin_centers, np.log10(phi),\ p0=[0.0012,14.5,-2.0, 0.01, 12.95, 2.5], sigma=log_err) dndm_halo_fit_2 = lambda x: special_fit(x,*params) print(params) """ #plot mass function m_sample=np.linspace(10,16,100) fig = plt.figure(figsize=(3.3,3.3)) fig.subplots_adjust(left=0.2, right=0.85, bottom=0.2, top=0.9) ax = fig.add_subplot(1,1,1) p1 = ax.errorbar(10**bin_centers,phi_full,yerr=err, fmt='.',color='black') p2, = ax.plot(10**m_sample,dndm_halo_fit_1(m_sample), color='black') plt.yscale('log') plt.xscale('log') plt.ylim([10**(-7),1]) plt.xlabel(r'$M_{\rm peak}~[h^{-1}M_{\odot}]$') plt.ylabel(r'$\phi(M_{\rm peak})~[h^{3}{\rm Mpc}^{-3}\log(M_{\rm peak})^{-1}]$') plt.legend((p1,p2),("mock", "fit"), loc=3, fontsize=10, frameon=False, numpoints=1) plt.show() savepath = cu.get_plot_path()+'/analysis/central_quenching/' filename = 'halo_mass_function' fig.savefig(savepath+filename+'.pdf', dpi=250) """
def main(): if len(sys.argv) > 1: catalogue = sys.argv[1] else: catalogue = 'Mr19_age_distribution_matching_mock' plotpath = cu.get_plot_path() + 'analysis/groupcats/' filename = catalogue + '_f_M.pdf' fig1, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True, figsize=(6.95, 3.3)) fig1.subplots_adjust(hspace=0, wspace=0.05) fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9) axes = axes.flatten() ax = axes[0] ax.set_xlim([10**11, 10**15]) ax.set_ylim([0, 1]) ax.set_ylabel(r'$f_{red}$') #ax.set_xlabel(r'$M/[M_{\odot}h^{-1}]$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') #ax.set_xticks([11.5,12.0,12.5,13,13.5,14,14.5]) ax.set_xscale('log') ax.set_title(r'Berlind FoF groups') ax = axes[1] ax.set_xlim([10**11, 10**15]) ax.set_ylim([0, 1]) #ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') #ax.set_xticks([11.5,12.0,12.5,13,13.5,14,14.5]) #ax.set_xlim([12,15]) ax.set_xscale('log') ax.set_title(r'Tinker SO groups') ax = axes[2] ax.set_xlim([10**11, 10**15]) ax.set_ylim([0, 1]) #ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') ax.set_xlabel(r'$log(M/[M_{\odot}h^{-1}])$') #ax.set_xticks([11.5,12.0,12.5,13,13.5,14,14.5]) #ax.set_xlim([12,15]) ax.set_xscale('log') ax.set_xticklabels(["", "$10^{12}$", "$10^{13}$", "$10^{14}$", ""]) ax.set_title(r'Yang SO groups') N_boots = 50 bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 bins = np.arange(12, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 bin_centers = 10.0**bin_centers #open mock catalogue filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/custom_catalogues/' print 'opening mock catalogue:', catalogue + '.hdf5' f1 = h5py.File(filepath_mock + catalogue + '.hdf5', 'r') #open catalogue file mock = f1.get(catalogue) centrals = np.array(mock['ID_host'] == -1) satellites = np.array(mock['ID_host'] != -1) #galaxy color color = mock['g-r'] #LHS = 0.21-0.03*mock['M_r,0.1'] LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5) blue = np.where(color < LHS)[0] #indices of blue galaxies red = np.where(color > LHS)[0] #indicies of red galaxies f_red_cen = f_prop(mock['M_host'], bins, red, blue, centrals) f_red_sat = f_prop(mock['M_host'], bins, red, blue, satellites) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen, color='orange') p2a, = ax.plot(bin_centers, f_red_sat, color='green') ################################################### # Ideal Groups ################################################### filepath_mock = cu.get_output_path( ) + 'processed_data/hearin_mocks/ideal_groups/' print 'opening mock catalogue:', catalogue + '_groups.hdf5' f1 = h5py.File(filepath_mock + catalogue + '_groups.hdf5', 'r') #open catalogue file GC = f1.get(catalogue + '_groups') f_red_cen = np.zeros((len(bin_centers))) f_red_sat = np.zeros((len(bin_centers))) f_sat_red = np.zeros((len(bin_centers))) f_sat_blue = np.zeros((len(bin_centers))) #with mass estimate but not cen/sat centrals_ind = np.where(GC['HALO_RANK'] == 0)[0] satellites_ind = np.where(GC['HALO_RANK'] != 0)[0] centrals_bool = (GC['HALO_RANK'] == 0) satellites_bool = (GC['HALO_RANK'] != 0) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen, ':', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, ':', color='green', alpha=0.5) ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen, ':', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, ':', color='green', alpha=0.5) ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen, ':', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, ':', color='green', alpha=0.5) #with cen/sat but not mass estimate centrals_ind = np.where(GC['RANK'] == 0)[0] satellites_ind = np.where(GC['RANK'] != 0)[0] centrals_bool = (GC['RANK'] == 0) satellites_bool = (GC['RANK'] != 0) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen = f_prop(GC['HALO_M'], bins, red_ind, blue_ind, centrals_bool) f_red_sat = f_prop(GC['HALO_M'], bins, red_ind, blue_ind, satellites_bool) f_sat_red = f_prop(GC['HALO_M'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue = f_prop(GC['HALO_M'], bins, satellites_ind, centrals_ind, blue_bool) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen, '--', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, '--', color='green', alpha=0.5) ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen, '--', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, '--', color='green', alpha=0.5) ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen, '--', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, '--', color='green', alpha=0.5) #with cen/sat and mass estimate centrals_ind = np.where(GC['RANK'] == 0)[0] satellites_ind = np.where(GC['RANK'] != 0)[0] centrals_bool = (GC['RANK'] == 0) satellites_bool = (GC['RANK'] != 0) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) ax = axes[0] p1a, = ax.plot(bin_centers, f_red_cen, '-', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, '-', color='green', alpha=0.5) ax = axes[1] p1a, = ax.plot(bin_centers, f_red_cen, '-', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, '-', color='green', alpha=0.5) ax = axes[2] p1a, = ax.plot(bin_centers, f_red_cen, '-', color='orange', alpha=0.5) p2a, = ax.plot(bin_centers, f_red_sat, '-', color='green', alpha=0.5) ################################################### bins = np.arange(11, 15, 0.2) bin_centers = (bins[:-1] + bins[1:]) / 2.0 bin_centers = 10.0**bin_centers groupcat = 'berlind' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[0] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p1a, p2a), ('halo cen', 'halo sat'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ################################################### groupcat = 'tinker' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[1] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) ax.legend((p3a, p4a), ('groups cen', 'groups sat'), loc='lower right', fontsize=10, numpoints=1, frameon=False) ################################################### groupcat = 'yang' filepath_cat = get_gc_path(groupcat) group_catalogue = get_gc_name(groupcat, catalogue) f_red_cen = np.zeros((N_boots, len(bin_centers))) f_red_sat = np.zeros((N_boots, len(bin_centers))) f_sat_red = np.zeros((N_boots, len(bin_centers))) f_sat_blue = np.zeros((N_boots, len(bin_centers))) for boot in range(0, N_boots): #open catalogue catalogue_1 = group_catalogue + '_' + str(boot) f = h5py.File(filepath_cat + 'bootstraps/' + catalogue_1 + '.hdf5', 'r') #open catalogue file GC = f.get(catalogue_1) centrals_ind = np.where(GC['RANK'] == 1)[0] satellites_ind = np.where(GC['RANK'] != 1)[0] centrals_bool = (GC['RANK'] == 1) satellites_bool = (GC['RANK'] != 1) centrals_mock_ind = np.where(GC['HALO_RANK'] == 1)[0] satellites_mock_ind = np.where(GC['HALO_RANK'] != 1)[0] N_sat_mock = float(len(satellites_mock_ind)) N_cen_mock = float(len(centrals_mock_ind)) #galaxy color color = GC['M_g,0.1'] - GC['M_r,0.1'] LHS = 0.7 - 0.032 * (GC['M_r,0.1'] + 16.5) #Weinmann 2006 blue_ind = np.where(color < LHS)[0] #indices of blue galaxies red_ind = np.where(color > LHS)[0] #indicies of red galaxies blue_bool = (color < LHS) #indices of blue galaxies red_bool = (color > LHS) #indicies of red galaxies f_red_cen[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, centrals_bool) f_red_sat[boot, :] = f_prop(GC['MGROUP'], bins, red_ind, blue_ind, satellites_bool) f_sat_red[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, red_bool) f_sat_blue[boot, :] = f_prop(GC['MGROUP'], bins, satellites_ind, centrals_ind, blue_bool) err_cen = np.nanstd(f_red_cen, axis=0) err_sat = np.nanstd(f_red_sat, axis=0) f_red_cen = np.nanmean(f_red_cen, axis=0) f_red_sat = np.nanmean(f_red_sat, axis=0) err_sat_red = np.nanstd(f_sat_red, axis=0) err_sat_blue = np.nanstd(f_sat_blue, axis=0) f_sat_red = np.nanmean(f_sat_red, axis=0) f_sat_blue = np.nanmean(f_sat_blue, axis=0) ax = axes[2] p3a = ax.errorbar(bin_centers, f_red_cen, yerr=err_cen, fmt='o', color='orange', mec='none', ms=3) p4a = ax.errorbar(bin_centers, f_red_sat, yerr=err_sat, fmt='o', color='green', mec='none', ms=3) plt.show(block=False) fig1.savefig(plotpath + filename)