Exemple #1
0
	new_good = np.array(new_good)
	Nspec = np.array(Nspec)
	N200 = N200[new_good]


## Calculate Average Halo Positions from Galaxies
calc_avg = False
if calc_avg == True:
	from stack_class_c4 import CFOUR
	from causticpy import Caustic
	
	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()

	# Load Halos
        halos = fits.open(root+'/C4/'+data_loc+'/halos.fits')[1].data
        HaloID = halos['orig_order']
        RA = halos['halo_ra']
        DEC = halos['halo_dec']
        Z = halos['halo_z']
        Nspec = halos['Nspec']
        N200 = halos['N200']
        HVD = halos['HVD']
        RVIR = halos['RVIR']
        SINGLE = halos['single']
        SUB = halos['sub']
        NC4 = halos['nc4']
Exemple #2
0
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 ''
Exemple #3
0
def clus_avg(data_loc,halo_file,chris_data_root,newfilename,write_data=True,clobber=True):

	C4 = CFOUR({'H0':70,'chris_data_root':chris_data_root})
	C = Caustic()

	# Load Halos
        halos = fits.open(data_loc+'/'+halo_file)[1].data
        HaloID = halos['orig_order']
        RA = halos['ra_bcg']
        DEC = halos['dec_bcg']
        Z = halos['z_biwt']
        RVIR = halos['RVIR']
        SINGLE = halos['single']
        SUB = halos['sub']
        NC4 = halos['nc4']

	RA_AVG,DEC_AVG,Z_AVG = [],[],[]

	# Loop Over Halos
	print ''
	print '-'*40
	print '...running average cluster center code'
	for i in range(len(halos)):
		if i % 100 == 0: print '...working on cluster '+str(i)+' out of '+str(len(halos))
		try:
			# Assign Halo Properties
			clus_ra = RA[i]
			clus_dec = DEC[i]
			clus_z = Z[i]

			# Load Galaxies
			galdata = C4.load_chris_gals(HaloID[i])
			gal_ra,gal_dec,gal_z,gal_gmags,gal_rmags,gal_imags = galdata

			# Take Iterative Average, four times
			# vlim = 1500, rlim = 1.5
			clus_ra,clus_dec,clus_z = proj_avg(clus_ra,clus_dec,clus_z,gal_ra,gal_dec,gal_z,1500,1.5,C)
			# vlim = 1000, rlim = 1.5
			clus_ra,clus_dec,clus_z = proj_avg(clus_ra,clus_dec,clus_z,gal_ra,gal_dec,gal_z,1000,1.5,C)
			# vlim = 1500, rlim = 1.5
			clus_ra,clus_dec,clus_z = proj_avg(clus_ra,clus_dec,clus_z,gal_ra,gal_dec,gal_z,1000,1.5,C)
			# vlim = 2000, rlim = 1.5
			clus_ra,clus_dec,clus_z = proj_avg(clus_ra,clus_dec,clus_z,gal_ra,gal_dec,gal_z,2000,1.5,C)

		except:
			print i
			clus_ra,clus_dec,clus_z = 0, 0, 0

		RA_AVG.append(clus_ra)
		DEC_AVG.append(clus_dec)
		Z_AVG.append(clus_z)

	RA_AVG,DEC_AVG,Z_AVG = np.array(RA_AVG),np.array(DEC_AVG),np.array(Z_AVG)

	print '...finished average cluster-center calculations'

	## Write Data Out
	if write_data == True:
		print '...writing out cluster catalgoue with average centers included'
		# Dictionary of new columns
		new_keys = ['RA_AVG','DEC_AVG','Z_AVG']
		new_dic = ez.create(new_keys,locals())

		# Original fits record file
		orig_table = halos

		# Write own fits file
		keys = ['HaloID','RA','DEC','Z','RVIR','RA_AVG','DEC_AVG','Z_AVG']
		dic = ez.create(keys,locals())
		fits_table(dic,keys,data_loc+'/avg_centers.fits',clobber=True)

		# Append new columns
		fits_append(orig_table,new_dic,new_keys,filename=data_loc+'/'+newfilename,clobber=clobber)
		print '-'*40
		print ''
Exemple #4
0
def clus_avg(data_loc,
             halo_file,
             chris_data_root,
             newfilename,
             write_data=True,
             clobber=True):

    C4 = CFOUR({'H0': 70, 'chris_data_root': chris_data_root})
    C = Caustic()

    # Load Halos
    halos = fits.open(data_loc + '/' + halo_file)[1].data
    HaloID = halos['orig_order']
    RA = halos['ra_bcg']
    DEC = halos['dec_bcg']
    Z = halos['z_biwt']
    RVIR = halos['RVIR']
    SINGLE = halos['single']
    SUB = halos['sub']
    NC4 = halos['nc4']

    RA_AVG, DEC_AVG, Z_AVG = [], [], []

    # Loop Over Halos
    print ''
    print '-' * 40
    print '...running average cluster center code'
    for i in range(len(halos)):
        if i % 100 == 0:
            print '...working on cluster ' + str(i) + ' out of ' + str(
                len(halos))
        try:
            # Assign Halo Properties
            clus_ra = RA[i]
            clus_dec = DEC[i]
            clus_z = Z[i]

            # Load Galaxies
            galdata = C4.load_chris_gals(HaloID[i])
            gal_ra, gal_dec, gal_z, gal_gmags, gal_rmags, gal_imags = galdata

            # Take Iterative Average, four times
            # vlim = 1500, rlim = 1.5
            clus_ra, clus_dec, clus_z = proj_avg(clus_ra, clus_dec, clus_z,
                                                 gal_ra, gal_dec, gal_z, 1500,
                                                 1.5, C)
            # vlim = 1000, rlim = 1.5
            clus_ra, clus_dec, clus_z = proj_avg(clus_ra, clus_dec, clus_z,
                                                 gal_ra, gal_dec, gal_z, 1000,
                                                 1.5, C)
            # vlim = 1500, rlim = 1.5
            clus_ra, clus_dec, clus_z = proj_avg(clus_ra, clus_dec, clus_z,
                                                 gal_ra, gal_dec, gal_z, 1000,
                                                 1.5, C)
            # vlim = 2000, rlim = 1.5
            clus_ra, clus_dec, clus_z = proj_avg(clus_ra, clus_dec, clus_z,
                                                 gal_ra, gal_dec, gal_z, 2000,
                                                 1.5, C)

        except:
            print i
            clus_ra, clus_dec, clus_z = 0, 0, 0

        RA_AVG.append(clus_ra)
        DEC_AVG.append(clus_dec)
        Z_AVG.append(clus_z)

    RA_AVG, DEC_AVG, Z_AVG = np.array(RA_AVG), np.array(DEC_AVG), np.array(
        Z_AVG)

    print '...finished average cluster-center calculations'

    ## Write Data Out
    if write_data == True:
        print '...writing out cluster catalgoue with average centers included'
        # Dictionary of new columns
        new_keys = ['RA_AVG', 'DEC_AVG', 'Z_AVG']
        new_dic = ez.create(new_keys, locals())

        # Original fits record file
        orig_table = halos

        # Write own fits file
        keys = [
            'HaloID', 'RA', 'DEC', 'Z', 'RVIR', 'RA_AVG', 'DEC_AVG', 'Z_AVG'
        ]
        dic = ez.create(keys, locals())
        fits_table(dic, keys, data_loc + '/avg_centers.fits', clobber=True)

        # Append new columns
        fits_append(orig_table,
                    new_dic,
                    new_keys,
                    filename=data_loc + '/' + newfilename,
                    clobber=clobber)
        print '-' * 40
        print ''