## Calculate Cluster Richnesses cluster_rich = False if cluster_rich == True: root = '/nfs/christoq_ls/nkern' data_loc = 'MassRich/TRUTH_CAUSTIC' write_loc = 'individual' C4 = CFOUR({'H0':70,'chris_data_root':'/nfs/christoq_ls/MILLENNIUM/Henriques/TRUTH_CAUSTIC'}) C = Caustic() H0 = 72.0 c = 2.99792e5 Cosmo = cosmo.LambdaCDM(H0,0.3,0.7) keys = ['C','H0','c','Cosmo','C4'] varib = ez.create(keys,locals()) R = RICHNESS(varib) # Load Halos halos = fits.open(root+'/C4/'+data_loc+'/halos.fits')[1].data HaloID = halos['orig_order'] RA = halos['ra_avg'] DEC = halos['dec_avg'] Z = halos['z_avg'] RVIR = halos['RVIR'] # Load Galaxy Data gals = fits.open('/nfs/christoq_ls/MILLENNIUM/Henriques/TRUTH_CAUSTIC/m19.1_allgals_wsdss_specerrs_abs.fits')[1].data # Derive Gal Cut Out Parameters arcs = np.array(Cosmo.arcsec_per_kpc_proper(Z))*15000. / 3600. # 15 Mpc in degrees
def cluster_rich(data_loc,halo_file,chris_data_root,chris_data_file,newfilename,write_data=True,clobber=True): """ Calculate a Cluster's richness via Miller N200 and Kern N200 data_loc : e.g. MassRich/TRUTH_CAUSTIC halo_file : e.g. halos.fits chris_data_root : e.g. /nfs/christoq_ls/C4/sdssdr12 chris_data_file : e.g. DR12_GalaxyPhotoData_wabs_wedges.fits or m19.1_allgals_wsdss_specerrs_abs.fits """ # Run through Kern richness estimator, mainly to get cluster pairs root = '/nfs/christoq_ls/nkern' C4 = CFOUR({'H0':70,'chris_data_root':chris_data_root}) C = Caustic() H0 = 70.0 c = 2.99792e5 Cosmo = cosmo.LambdaCDM(H0,0.3,0.7) keys = ['C','H0','c','Cosmo','C4'] varib = ez.create(keys,locals()) R = RICHNESS(varib) # Load Halos halos = fits.open(data_loc+'/'+halo_file)[1].data HaloID = halos['orig_order'] RA = halos['ra_avg'] DEC = halos['dec_avg'] Z = halos['z_avg'] RVIR = halos['RVIR'] # Load Galaxy Data gals = fits.open(chris_data_root+'/'+chris_data_file)[1].data # Change gals keys according to SDSSDR12 galaxy file if data_loc[-4:] != 'DR12': gals = dict(map(lambda x: (x,gals[x]),gals.names)) gals['objid'] = gals.pop('GAL_HALOID') gals['ra'] = gals.pop('GAL_RA') gals['dec'] = gals.pop('GAL_DEC') gals['z'] = gals.pop('GAL_Z_APP') gals['u_mag'] = gals.pop('GAL_SDSS_U') gals['g_mag'] = gals.pop('GAL_SDSS_G') gals['r_mag'] = gals.pop('GAL_SDSS_R') gals['i_mag'] = gals.pop('GAL_SDSS_I') gals['z_mag'] = gals.pop('GAL_SDSS_Z') gals['r_absmag'] = gals.pop('R_ABSMAG') # Derive Gal Cut Out Parameters arcs = np.array(Cosmo.arcsec_per_kpc_proper(Z))*15000. / 3600. # 15 Mpc in degrees # Kern richness arrays kern_N200 = [] HVD = [] pair_avg = [] Nspec = [] kern_obs_tot = [] kern_obs_back = [] # obs_back is number of non-member galaxies in central aperture around cluster (aka. already scaled to inner aperture) # Miller Richness Arrays new = fits.open(chris_data_root+'/richness_cr200_bcg/new.fits')[0].data newb = fits.open(chris_data_root+'/richness_cr200_bcg/newb.fits')[0].data newb *= 0.2 miller_N200 = [] miller_obs_tot = [] miller_obs_back = [] colfac = 9 bakfac = 1 mag3 = 4 v = 2 radfac = 1 # Loop over clusters print '' print '-'*40 print '...calculating cluster richnesses' for i in range(len(HaloID)): if i % 100 == 0: print '...working on cluster '+str(i)+' out of '+str(len(HaloID)) # Define Cluster parameters clus_ra = RA[i] clus_dec = DEC[i] clus_z = Z[i] clus_rvir = RVIR[i] haloid = HaloID[i] if np.isnan(clus_ra) == True or np.isnan(clus_dec) == True or np.isnan(clus_z) == True: richness.append(0) HVD.append(0) pair_avg.append(False) Nspec.append(0) continue # 15 Mpc in degrees of declination and degrees of RA d_dec = arcs[i] d_ra = d_dec/np.cos(clus_dec*np.pi/180) d_z = 0.04 # Cut Out Galaxy Data Around Cluster cut = np.where( (np.abs(gals['ra']-clus_ra)<d_ra) & (np.abs(gals['dec']-clus_dec)<d_dec) & (np.abs(gals['z']-clus_z) < d_z))[0] gal_ra = gals['ra'][cut];gal_dec = gals['dec'][cut];gal_z=gals['z'][cut];gal_gmags=gals['g_mag'][cut];gal_rmags=gals['r_mag'][cut];gal_imags=gals['i_mag'][cut];gal_absr=gals['r_absmag'][cut] # Run Kern Richness Estimator rich = R.richness_est(gal_ra,gal_dec,gal_z,np.zeros(len(gal_z)),gal_gmags,gal_rmags,gal_imags,gal_absr,haloid,clus_ra,clus_dec,clus_z,clus_rvir=clus_rvir,spec_list=None,use_specs=False,use_bcg=False,fit_rs=False,fixed_vdisp=False,fixed_aperture=False,plot_sky=False,plot_gr=False,plot_phase=False,find_pairs=True) kern_N200.append(rich) HVD.append(R.vel_disp) pair_avg.append(R.pair) Nspec.append(R.Nspec) kern_obs_tot.append(R.obs_tot) kern_obs_back.append(R.obs_back_scaled) # Append Miller Richness Values k = halos['orig_order'][i] miller_N200.append(new[k,colfac,mag3,v,radfac] - newb[k,bakfac,mag3,v,radfac]) miller_obs_tot.append(new[k,colfac,mag3,v,radfac]) miller_obs_back.append(newb[k,bakfac,mag3,v,radfac]) kern_N200 = np.array(kern_N200) HVD = np.array(HVD) pair_avg = np.array(pair_avg) Nspec = np.array(Nspec) kern_obs_tot = np.array(kern_obs_tot) kern_obs_back = np.array(kern_obs_back) miller_N200 = np.array(miller_N200) miller_obs_tot = np.array(miller_obs_tot) miller_obs_back = np.array(miller_obs_back) print '...finished calculating richnesses' ## Write Data Out if write_data == True: print '...writing out halos.fits file' # Dictionary of new columns new_keys = ['kern_N200','HVD','pair_avg','Nspec','kern_obs_tot','kern_obs_back','miller_N200','miller_obs_tot','miller_obs_back'] new_dic = ez.create(new_keys,locals()) # Original fits record file orig_table = halos # Write out own fits file keys = ['HaloID','RVIR'] + new_keys dic = ez.create(keys,locals()) fits_table(dic,keys,data_loc+'/richnesses.fits',clobber=True) # Append new columns fits_append(orig_table,new_dic,new_keys,filename=data_loc+'/'+newfilename,clobber=clobber) print '-'*40 print ''
rdata = angles * C.zdistance(clus_z,H0)[0] vdata = c * (gal_z - clus_z) / (1 + clus_z) cut = np.where((rdata<Rlim)&(np.abs(vdata)<Vlim))[0] Nspec.append(cut.size) Index.append(i) except IOError: Nspec.append(-1) Index.append(i) Nspec = np.array(Nspec) Index = np.array(Index) # Calculate Richnesses R = RICHNESS(varib) calc_rich = False if calc_rich == True: ra_lim = (123,250) dec_lim = (-4,66) arcs = np.array(Cosmo.arcsec_per_kpc_proper(Z))*15000. / 3600. # 15 Mpc in degrees d_dec = np.copy(arcs) d_ra = arcs/np.cos(DEC*np.pi/180) danger = np.where( (RA+d_ra > ra_lim[1]) | (RA-d_ra < ra_lim[0]) | (DEC+d_dec > dec_lim[1]) | (DEC-d_dec < dec_lim[0]))[0] use_specs = False clus_id = [] richness = [] nspec = [] vel_disp = []
def cluster_rich(data_loc, halo_file, chris_data_root, chris_data_file, newfilename, write_data=True, clobber=True): """ Calculate a Cluster's richness via Miller N200 and Kern N200 data_loc : e.g. MassRich/TRUTH_CAUSTIC halo_file : e.g. halos.fits chris_data_root : e.g. /nfs/christoq_ls/C4/sdssdr12 chris_data_file : e.g. DR12_GalaxyPhotoData_wabs_wedges.fits or m19.1_allgals_wsdss_specerrs_abs.fits """ # Run through Kern richness estimator, mainly to get cluster pairs root = '/nfs/christoq_ls/nkern' C4 = CFOUR({'H0': 70, 'chris_data_root': chris_data_root}) C = Caustic() H0 = 70.0 c = 2.99792e5 Cosmo = cosmo.LambdaCDM(H0, 0.3, 0.7) keys = ['C', 'H0', 'c', 'Cosmo', 'C4'] varib = ez.create(keys, locals()) R = RICHNESS(varib) # Load Halos halos = fits.open(data_loc + '/' + halo_file)[1].data HaloID = halos['orig_order'] RA = halos['ra_avg'] DEC = halos['dec_avg'] Z = halos['z_avg'] RVIR = halos['RVIR'] # Load Galaxy Data gals = fits.open(chris_data_root + '/' + chris_data_file)[1].data # Change gals keys according to SDSSDR12 galaxy file if data_loc[-4:] != 'DR12': gals = dict(map(lambda x: (x, gals[x]), gals.names)) gals['objid'] = gals.pop('GAL_HALOID') gals['ra'] = gals.pop('GAL_RA') gals['dec'] = gals.pop('GAL_DEC') gals['z'] = gals.pop('GAL_Z_APP') gals['u_mag'] = gals.pop('GAL_SDSS_U') gals['g_mag'] = gals.pop('GAL_SDSS_G') gals['r_mag'] = gals.pop('GAL_SDSS_R') gals['i_mag'] = gals.pop('GAL_SDSS_I') gals['z_mag'] = gals.pop('GAL_SDSS_Z') gals['r_absmag'] = gals.pop('R_ABSMAG') # Derive Gal Cut Out Parameters arcs = np.array( Cosmo.arcsec_per_kpc_proper(Z)) * 15000. / 3600. # 15 Mpc in degrees # Kern richness arrays kern_N200 = [] HVD = [] pair_avg = [] Nspec = [] kern_obs_tot = [] kern_obs_back = [ ] # obs_back is number of non-member galaxies in central aperture around cluster (aka. already scaled to inner aperture) # Miller Richness Arrays new = fits.open(chris_data_root + '/richness_cr200_bcg/new.fits')[0].data newb = fits.open(chris_data_root + '/richness_cr200_bcg/newb.fits')[0].data newb *= 0.2 miller_N200 = [] miller_obs_tot = [] miller_obs_back = [] colfac = 9 bakfac = 1 mag3 = 4 v = 2 radfac = 1 # Loop over clusters print '' print '-' * 40 print '...calculating cluster richnesses' for i in range(len(HaloID)): if i % 100 == 0: print '...working on cluster ' + str(i) + ' out of ' + str( len(HaloID)) # Define Cluster parameters clus_ra = RA[i] clus_dec = DEC[i] clus_z = Z[i] clus_rvir = RVIR[i] haloid = HaloID[i] if np.isnan(clus_ra) == True or np.isnan(clus_dec) == True or np.isnan( clus_z) == True: richness.append(0) HVD.append(0) pair_avg.append(False) Nspec.append(0) continue # 15 Mpc in degrees of declination and degrees of RA d_dec = arcs[i] d_ra = d_dec / np.cos(clus_dec * np.pi / 180) d_z = 0.04 # Cut Out Galaxy Data Around Cluster cut = np.where((np.abs(gals['ra'] - clus_ra) < d_ra) & (np.abs(gals['dec'] - clus_dec) < d_dec) & (np.abs(gals['z'] - clus_z) < d_z))[0] gal_ra = gals['ra'][cut] gal_dec = gals['dec'][cut] gal_z = gals['z'][cut] gal_gmags = gals['g_mag'][cut] gal_rmags = gals['r_mag'][cut] gal_imags = gals['i_mag'][cut] gal_absr = gals['r_absmag'][cut] # Run Kern Richness Estimator rich = R.richness_est(gal_ra, gal_dec, gal_z, np.zeros(len(gal_z)), gal_gmags, gal_rmags, gal_imags, gal_absr, haloid, clus_ra, clus_dec, clus_z, clus_rvir=clus_rvir, spec_list=None, use_specs=False, use_bcg=False, fit_rs=False, fixed_vdisp=False, fixed_aperture=False, plot_sky=False, plot_gr=False, plot_phase=False, find_pairs=True) kern_N200.append(rich) HVD.append(R.vel_disp) pair_avg.append(R.pair) Nspec.append(R.Nspec) kern_obs_tot.append(R.obs_tot) kern_obs_back.append(R.obs_back_scaled) # Append Miller Richness Values k = halos['orig_order'][i] miller_N200.append(new[k, colfac, mag3, v, radfac] - newb[k, bakfac, mag3, v, radfac]) miller_obs_tot.append(new[k, colfac, mag3, v, radfac]) miller_obs_back.append(newb[k, bakfac, mag3, v, radfac]) kern_N200 = np.array(kern_N200) HVD = np.array(HVD) pair_avg = np.array(pair_avg) Nspec = np.array(Nspec) kern_obs_tot = np.array(kern_obs_tot) kern_obs_back = np.array(kern_obs_back) miller_N200 = np.array(miller_N200) miller_obs_tot = np.array(miller_obs_tot) miller_obs_back = np.array(miller_obs_back) print '...finished calculating richnesses' ## Write Data Out if write_data == True: print '...writing out halos.fits file' # Dictionary of new columns new_keys = [ 'kern_N200', 'HVD', 'pair_avg', 'Nspec', 'kern_obs_tot', 'kern_obs_back', 'miller_N200', 'miller_obs_tot', 'miller_obs_back' ] new_dic = ez.create(new_keys, locals()) # Original fits record file orig_table = halos # Write out own fits file keys = ['HaloID', 'RVIR'] + new_keys dic = ez.create(keys, locals()) fits_table(dic, keys, data_loc + '/richnesses.fits', clobber=True) # Append new columns fits_append(orig_table, new_dic, new_keys, filename=data_loc + '/' + newfilename, clobber=clobber) print '-' * 40 print ''