Example #1
0
def main():

    if len(sys.argv) > 1:
        catalogue = sys.argv[1]
    else:
        catalogue = 'Mr19_age_distribution_matching_mock'

    #open the ra,dec mock
    filepath = cu.get_output_path(
    ) + 'processed_data/hearin_mocks/custom_catalogues/'
    filename = catalogue + '_radec_mock.dat'
    mock_radec = ascii.read(filepath + filename,
                            delimiter='\s',
                            Reader=ascii.Basic,
                            data_start=1)
    mock_radec = np.array(mock_radec)
    for name in mock_radec.dtype.names:
        print '\t', name

    #open full mock
    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)
    mock = np.array(mock)
    for name in mock.dtype.names:
        print '\t', name

    app_mag_lim = 17.77
    Lbox = 250.0  #Mpc/h
    cosmo = cosmology.core.FlatLambdaCDM(H0=100.0, Om0=0.27)  #h=1
    c = 299792.458  #speed of light in km/s

    #determine abs mag limit as afunction of z to overplot
    app_mag_r_lim = 17.77
    z_bins = np.arange(1.0, 0.001, -0.001)
    dm = dist_mod(z_bins, cosmo)
    abs_mag_r_lim = app_mag_r_lim - dm
    f_r = interp1d(abs_mag_r_lim,
                   z_bins,
                   kind='cubic',
                   bounds_error=False,
                   fill_value=max(z_bins))

    z_lim = f_r(-19)
    print z_lim

    plt.figure()
    plt.plot(mock_radec['z'], mock['M_r,0.1'][mock_radec['k']], '.', ms=2)
    plt.plot(z_bins, abs_mag_r_lim, color='green')
    plt.plot([0, z_lim], [-19, -19], color='red')
    plt.plot([z_lim, z_lim], [-19, -24], color='red')
    plt.plot([0.02, 0.02], [-19, -24], color='red')
    plt.plot([0.068, 0.068], [-19, -24], '--', color='red')
    plt.ylim([-18.5, -23])
    plt.xlim([0, 0.1])
    plt.show()
Example #2
0
def get_gc_path(groupcat):

    if groupcat=='berlind':
        s = cu.get_output_path() + 'processed_data/berlind_groupcat/mock_runs/4th_run/custom_catalogues/'
    if groupcat=='tinker':
        s = cu.get_output_path() + 'processed_data/tinker_groupcat/mock_runs/4th_run/custom_catalogues/'
    if groupcat=='yang':
        s = cu.get_output_path() + 'processed_data/yang_groupcat/mock_runs/4th_run/version_2/custom_catalogues/'
    return s
Example #3
0
def get_mock(dm_sim):
    """
    load dark matter simulation halo catalogue and make completeness cuts
    """
    if dm_sim=='Bolshoi_250':
        #open Bolshoi halo catalogue
        box_size=250
        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
        #for name in HC.dtype.names: print(name)
    elif dm_sim=='Chinchilla_125':
        #open Chinchilla halo catalogue
        box_size=125
        filepath = cu.get_output_path() + 'processed_data/Chinchilla/halo_catalogues/Lb125/'
        halo_catalogue = 'hlist_1.00000.list'
        f =  h5py.File(filepath+halo_catalogue+'.hdf5', 'r')
        HC = f.get(halo_catalogue) #halo catalogue
        #for name in HC.dtype.names: print(name)
    elif dm_sim=='Chinchilla_250':
        #open Chinchilla halo catalogue
        box_size=125
        filepath = cu.get_output_path() + 'processed_data/Chinchilla/halo_catalogues/Lb250/'
        halo_catalogue = 'hlist_1.00000.list'
        f =  h5py.File(filepath+halo_catalogue+'.hdf5', 'r')
        HC = f.get(halo_catalogue) #halo catalogue
        #for name in HC.dtype.names: print(name)
    else: print('simulation not available.')
    
    if dm_sim=='Bolshoi_250':
        mp_bolshoi = 1.35e8
        mpeak_cut = mp_bolshoi*200.0
        keep = (HC['Mpeak']>mpeak_cut)
        HC = HC[keep]
        #keep = (HC['vmax']>50.0)
        #HC = HC[keep]
        #print("number of (sub-)haloes in catalogue after cuts: {0}".format(len(HC)))
    if dm_sim=='Chinchilla_125':
        mp_bolshoi = 1.35e8
        mp_chinchilla = mp_bolshoi/8.0
        mpeak_cut = mp_chinchilla*200.0
        keep = (HC['Mpeak']>mpeak_cut)
        HC = HC[keep]
        #keep = (HC['vmax']>50.0)
        #HC = HC[keep]
        #print("number of (sub-)haloes in catalogue after cuts: {0}".format(len(HC)))
    if dm_sim=='Chinchilla_250':
        mp_bolshoi = 1.35e8
        mpeak_cut = mp_bolshoi*200.0
        keep = (HC['Mpeak']>mpeak_cut)
        HC = HC[keep]
        #keep = (HC['vmax']>50.0)
        #HC = HC[keep]
        #print("number of (sub-)haloes in catalogue after cuts: {0}".format(len(HC)))
     
    return HC, box_size
def main():
    filepath = cu.get_output_path() + 'processed_data/CFHTLens/random_catalogues/'
    savepath = cu.get_output_path() + 'processed_data/CFHTLens/random_catalogues/'

    field1=sys.argv[1]
    field=field1.lower()
    print field1, field

    filenames = os.listdir(filepath)
    filenames = fnmatch.filter(filenames, field+'*.npy')

    dtype = [('ra',float),('dec',float),('flag',int),('num_tile',int)]
    randoms = np.recarray((0,), dtype = dtype)

    #open up all the tile random catalogues and combine
    for filename in filenames:
        print filename
        tile_randoms = np.load(filepath+filename)
        randoms = np.hstack((randoms,tile_randoms))

    print 'maximum number of tiles a random falls in:', max(randoms['num_tile'])

    keep = np.where(np.logical_not((randoms['flag']==8192) & (randoms['num_tile']>1)))[0]
    randoms = randoms[keep]
    

    print len(randoms)
    '''
    #where tiles overlap, take a proportional number of randoms
    #2 tiles overlap
    result_2 = np.where(randoms['num_tile']==2)[0] #identify randoms
    ran_int_2 = np.random.random_integers(1,2,len(result_2)) #roll a dice to keep it
    keep_2 = np.where(ran_int_2==1)[0] #keep 1/(N tiles) of the points
    keep_2 = result_2[keep_2]
    #3 tiles overlap
    result_3 = np.where(randoms['num_tile']==3)[0] #identify randoms
    ran_int_3 = np.random.random_integers(1,3,len(result_3)) #roll a dice to keep it
    keep_3 = np.where(ran_int_3==1)[0] #keep 1/(N tiles) of the points
    keep_3 = result_3[keep_3]
    #4 tiles overlap
    result_4 = np.where(randoms['num_tile']==4)[0] #identify randoms
    ran_int_4 = np.random.random_integers(1,4,len(result_4)) #roll a dice to keep it
    keep_4 = np.where(ran_int_4==1)[0] #keep 1/(N tiles) of the points
    keep_4 = result_4[keep_4]

    #generate master list of randoms to keep
    keep = np.where(randoms['num_tile']==1)[0] #all points in non-pverlap regions
    keep = np.hstack((keep, keep_2, keep_3, keep_4)) #combine the "keep" lists

    randoms = randoms[keep]
    print len(randoms)
    '''

    np.save(savepath+field1+'_randoms', randoms)
Example #5
0
def main():

    ###make sure to change these when running in a new enviorment!###
    #location of data directories
    filepath_1 = cu.get_output_path() + 'processed_data/mpa_dr7/'
    filepath_2 = cu.get_output_path() + 'processed_data/NYU_VAGC/'
    #################################################################

    catalogue_1 = 'mpa_dr7_unique'
    catalogue_2 = 'nyu_vagc_dr7'

    f_1 = h5py.File(filepath_1 + catalogue_1 + '.hdf5', 'r')
    dset_1 = f_1.get(catalogue_1)
    dset_1 = np.array(dset_1)
    #print(dset_1.dtype.names)

    f_2 = h5py.File(filepath_2 + catalogue_2 + '.hdf5', 'r')
    dset_2 = f_2.get(catalogue_2)
    dset_2 = np.array(dset_2)
    #print(dset_2.dtype.names)

    #open matching files.  these are created with the 'match_to_NYU_VAGC.py' script.
    filename = 'matches_into_nyu_vagc.npy'
    match_1 = np.load(filepath_1 + 'matches/' + filename)
    filename = 'nyu_vagc_matched_to_mpa.npy'
    match_2 = np.load(filepath_1 + 'matches/' + filename)

    N_col_1 = len(dset_1.dtype.descr)
    N_col_2 = len(
        dset_2.dtype.descr[8:])  #number of columns used from NYU VAGC

    names_1 = dset_1.dtype.names
    names_2 = dset_2.dtype.names[8:]

    dtype = np.dtype(dset_1.dtype.descr + dset_2.dtype.descr[8:])

    combined_data = np.recarray((len(dset_1), ), dtype=dtype)
    combined_data.fill(-99)

    for name in names_1:
        print(name)
        combined_data[name] = dset_1[name]

    for name in names_2:
        print(name)
        combined_data[name][match_1] = dset_2[name][match_2]

    filename = 'mpa_nyu_vagc_dr7'
    savepath = filepath_1
    f = h5py.File(savepath + filename + '.hdf5', 'w')
    dset = f.create_dataset(filename, data=combined_data)
Example #6
0
def main():
    
    ###make sure to change these when running in a new enviorment!###
    #location of data directories
    filepath_2 = cu.get_output_path() + 'processed_data/mpa_dr7/'
    filepath_1 = cu.get_output_path() + 'processed_data/NYU_VAGC/'
    #################################################################

    catalogue_2 = 'mpa_dr7_unique'
    catalogue_1 = 'nyu_vagc_dr7'
  
    f_1 =  h5py.File(filepath_1+catalogue_1+'.hdf5', 'r')
    dset_1 = f_1.get(catalogue_1)
    dset_1 = np.array(dset_1)
    print(dset_1.dtype.names)

    f_2 =  h5py.File(filepath_2+catalogue_2+'.hdf5', 'r')
    dset_2 = f_2.get(catalogue_2)
    dset_2 = np.array(dset_2)
    print(dset_2.dtype.names)
    
    #open matching files.  these are created with the 'match_to_NYU_VAGC.py' script. 
    filename = 'matches_into_mpa_vagc.npy'
    match_1 = np.load(filepath_1+'matches/'+filename)
    filename = 'mpa_vagc_matched_to_nyu.npy'
    match_2 = np.load(filepath_1+'matches/'+filename)
    
    
    N_col_1 = len(dset_1.dtype.descr)
    N_col_2 = len(dset_2.dtype.descr[25:]) #number of columns used from NYU VAGC
    
    names_1 = dset_1.dtype.names
    names_2 = dset_2.dtype.names[25:]
    
    dtype = np.dtype(dset_1.dtype.descr + dset_2.dtype.descr[25:])
    
    combined_data = np.recarray((len(dset_1),),dtype=dtype)
    combined_data.fill(-99)
    
    for name in names_1:
        print(name)
        combined_data[name] = dset_1[name]
    
    for name in names_2:
        print(name)
        combined_data[name][match_1] = dset_2[name][match_2]
    
    filename = 'nyu_mpa_vagc_dr7'
    savepath = filepath_1
    f = h5py.File(savepath+filename+'.hdf5', 'w')
    dset = f.create_dataset(filename, data=combined_data)
def main():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath_cat1 = cu.get_output_path() + 'processed_data/yang_groupcat/'
    filepath_cat2 = cu.get_output_path() + 'processed_data/mpa_dr7/'
    #save data to directory...
    savepath1 = filepath_cat1+'mpa_dr7_match/'
    savepath2 = filepath_cat2+'yang_groupcat_match/'
    #################################################################

    catalogues_1=['sample1_L_petro','sample2_L_petro','sample3_L_petro',\
                  'sample1_M_petro','sample2_M_petro','sample3_M_petro',\
                  'sample1_L_model','sample2_L_model','sample3_L_model',\
                  'sample1_M_model','sample2_M_model','sample3_M_model']
    catalogues_2=['gal_info_gal_totspecsfr_dr7_v5_2']


    for catalogue in catalogues_1:
        catalogue1 = catalogue
        catalogue2 = catalogues_2[0]
        print catalogue1,'match into', catalogue2
    
        f1 =  h5py.File(filepath_cat1+catalogue1+'.hdf5', 'r')  #open catalogue file
        GC = f1.get(catalogue1)

        f2 =  h5py.File(filepath_cat2+catalogue2+'.hdf5', 'r')  #open catalogue file
        W = f2.get(catalogue2)

        da=2.0*1.0/3600.0 #matching length
        result_1 = np.array(cu.spherematch(GC['RAgal'], GC['DECgal'], W['RA'], W['DEC'], tol=da, nnearest=1))
        #result_2 = np.array(cu.spherematch(GC['RAgal'], GC['DECgal'], W['RA'], W['DEC'], tol=da, nnearest=2)) #not used
        repeats = [item for item, count in Counter(result_1[1]).iteritems() if count > 1] #double matched objects
        if len(repeats) > 0:
            remove=np.zeros((0,),dtype=np.int) #which entries to remove
            for repeat in repeats:
                result_a = np.where(result_1[1]==repeat)[0] #find indices of the double matched object into catalogue2
                result_b = np.where(result_1[2][result_a]>np.min(result_1[2][result_a]))[0] #find less good matches
                result_c = result_a[result_b] #indices of less good matches into catalogue2
                remove = np.hstack((remove,result_c)) #indices which should be removed
            keep = np.arange(0,len(result_1[0]),1).astype(int)
            keep = np.in1d(keep,remove)==False
            result = result_1[:,keep]
            #unique = np.setdiff1d(result_2[0], result_1[0]) #not used
        else: result = result

        filename1 = catalogue2+'_'+catalogue1+'_match'
        filename2 = catalogue1+'_'+catalogue2+'_match'

        np.save(savepath1+filename1, result[1].astype(int))
        np.save(savepath2+filename2, result[0].astype(int))
def main():
    """
    Make a random catalogue for each tile in a field in the CFHTLens survey.
    example: python make_cfhtlens_random_cat.py W3
    
    options: second user input specifies the mask file to use. A "?" argument returns the 
    list of mask files.
    """
    global filepath
    global savepath
    filepath = cu.get_data_path() + 'CFHTLens/masks/'
    savepath = cu.get_output_path() + 'processed_data/CFHTLens/random_catalogues/'

    field = sys.argv[1]
    print 'field:', field

    if len(sys.argv)>2:
        filenames = sys.argv[2]
    else:
        filenames = os.listdir(cu.get_data_path()+'CFHTLens/masks/')
        filenames = fnmatch.filter(filenames, field+'*.fits')
    # a "?" as the 2nd user input returns the lost of mask files and exits.
    if filenames == '?':
        filenames = os.listdir(cu.get_data_path()+'CFHTLens/masks/')
        filenames = fnmatch.filter(filenames, field+'*.fits')
        for filename in filenames: print(filename)
        return 0

    p = Pool(8)
    p.map(do_work,filenames)
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/'
    savepath = cu.get_output_path() + 'processed_data/berlind_groupcat/'
    #################################################################

    catalogues=['mr19_groups.fits', 'smthresh10.2.groups.dat', 'smthresh9.8.groups.dat']

    filename = catalogues[0]
    hdulist = fits.open(filepath+filename, memmap=True)
    data = hdulist[1].data
    print 'saving as:', savepath+filename[:-5]+'.hdf5'
    f = h5py.File(savepath+filename[:-5]+'.hdf5', 'w')
    dset = f.create_dataset(filename[:-5], data=data)
    f.close()
    gc.collect()

    names = ['ra','dec','z','groupID','rank','Mstar','Mr','SSFR','Mgroup']

    filename = catalogues[1]
    data = ascii.read(filepath+filename, guess=True, Reader=ascii.Basic, names=names,data_start=0)
    print 'saving as:', savepath+filename[:-4]+'.hdf5'
    f = h5py.File(savepath+filename[:-4]+'.hdf5', 'w')
    dset = f.create_dataset(filename[:-4], data=data)
    f.close()
    gc.collect()

    filename = catalogues[2]
    data = ascii.read(filepath+filename, guess=True, Reader=ascii.Basic, names=names,data_start=0)
    print 'saving as:', savepath+filename[:-4]+'.hdf5'
    f = h5py.File(savepath+filename[:-4]+'.hdf5', 'w')
    dset = f.create_dataset(filename[:-4], data=data)
    f.close()
    gc.collect()
Example #10
0
def main():
    filepath = cu.get_data_path() + 'CFHTLens/masks/'
    savepath = cu.get_output_path() + 'processed_data/CFHTLens/masks/'

    field = 'W1'

    filenames = os.listdir('/scratch/dac29/data/CFHTLens/masks/')
    filenames = fnmatch.filter(filenames, field + '*.fits')

    #for filename in filenames:
    filename = filenames[0]
    hdulist = fits.open(filepath + filename, memmap=True)
    header = hdulist[0].header
    print header
    nxpix = header['NAXIS1']
    nypix = header['NAXIS2']
    tile = header['OBJECT']
    w = wcs.WCS(hdulist[0].header)
    corners = np.array(
        [[0, 0], [0, nypix - 1], [nxpix - 1, nypix - 1], [nxpix - 1, 0]],
        np.float_)
    world = w.wcs_pix2world(corners, 1)
    print world
    data = hdulist[0].data
    hdulist.close()
Example #11
0
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)
    
    for i in range(284,360):
        print(i)
        fig = plt.figure(figsize=(10.0,10.0))
        ax = fig.add_subplot(111, projection='3d')
        ax.set_axis_bgcolor('black')
        ax._axis3don = False
        #fig.subplots_adjust(left=0.2, right=0.82, bottom=0.2, top=0.9)
        r = [0, 250]
        from itertools import product, combinations
        for s, e in combinations(np.array(list(product(r,r,r))), 2):
            if np.sum(np.abs(s-e)) == r[1]-r[0]:
                ax.plot3D(*zip(s,e), color="white")
        p = ax.scatter(mock['x'],mock['y'],mock['z'],c=mock['SSFR'],\
                cmap='jet_r',vmax=-9.5, vmin=-12.5, marker='.',\
                lw=0, s=3, rasterized=False)
        ax.set_xlim([0,250])
        ax.set_ylim([0,250])
        ax.set_zlim([0,250])
        ax.view_init(azim=i)
    
        filepath = '/Users/duncan/Documents/projects/mpeak_vpeak_mock/movies/frames/movie_11/'
        filename = str(i).zfill(3)+'_mock_3D.png'
        plt.savefig(filepath+filename, dpi=400)
        plt.clf()
Example #12
0
def main():

    catalogue = "sm_9.5_s0.2_sfr_c-1.0_250"
    # catalogue = 'sm_9.5_s0.0_sfr_c-1.0_250_cen_shuffle'

    # 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(mock.dtype.names)

    hosts = mock["upid"] == -1
    subs = mock["upid"] != -1

    N = len(mock)
    Ncen = np.sum(hosts)
    Nsat = np.sum(subs)

    print("N galaxies: ", N)
    print("N centrals: ", Ncen)
    print("N satellites: ", Nsat)
    print("N ejected centrals: ", np.sum(mock["ejected"]))
    print("N abandoned satellites: ", np.sum(mock["abandoned"]))
    print("N ghosted satellites: ", np.sum(mock["ghost"]))

    print("satellite fraction: ", Nsat / (1.0 * (Nsat + Ncen)))
def main():

    sample='q'
    sm_bin='10.0_10.5'
    catalogue = 'sm_9.5_s0.2_sfr_c-0.75_250'

    #load in fiducial mock
    filepath = './'
    filename = 'sm_9.5_s0.2_sfr_c-0.8_Chinchilla_250_wp_fiducial_'+sample+'_'+sm_bin+'_cov.npy'
    cov = np.matrix(np.load(filepath+filename))
    diag = np.diagonal(cov)
    filepath = cu.get_output_path() + 'analysis/central_quenching/observables/'
    filename = 'sm_9.5_s0.2_sfr_c-0.8_Chinchilla_250_wp_fiducial_'+sample+'_'+sm_bin+'.dat'
    data = ascii.read(filepath+filename)
    rbins = np.array(data['r'])
    mu = np.array(data['wp'])
    
    #load in comparison mock
    
    
    
    
    plt.figure()
    plt.errorbar(rbins, mu, yerr=np.sqrt(np.diagonal(cov)), color='black')
    plt.plot(rbins, wp,  color='red')
    plt.xscale('log')
    plt.yscale('log')
    plt.show()
    
    inv_cov = cov.I
    Y = np.matrix((wp-mu))
    
    X = Y*inv_cov*Y.T
    
    print(X)
def main():
  ###make sure to change these when running in a new enviorment!###
  #location of data directory
  filepath = cu.get_output_path() + 'processed_data/berlind_groupcat/'
  #################################################################

  catalogues=['mr19_groups', 'smthresh10.2.groups', 'smthresh9.8.groups']
  filepath = cu.get_output_path() + 'processed_data/berlind_groupcat/'

  for catalogue in catalogues:
      print catalogue
      f =  h5py.File(filepath+catalogue+'.hdf5', 'r')
      dset = f.get(catalogue)
      dset = np.array(dset)
      print 'length:', len(dset)
      for name in dset.dtype.names: print '\t', name
Example #15
0
def main():
    """
    read in cfhtlens catalogue and check object mask values against fits mask.
    """
    import h5py
    
    if len(sys.argv)>1:
        field = sys.argv[1]
    else: field='W3'
    if len(sys.argv)>2:
        N_test = sys.argv[2]
    else: N_test = 100
    
    #import cfhtlens catalogues
    filepath = cu.get_output_path()+'processed_data/CFHTLens/'
    f = h5py.File(filepath+'catalogues/'+field+'.hdf5', 'r')
    W = f.get(field)
    
    for i in range(0,N_test):
        ind = np.random.randint(0,len(W),1)[0]
        field = W['field'][ind]
        object_mask_value = W['MASK'][ind]
        
        mask_filename = field+'_izrgu_finalmask_mosaic.fits'
        filepath = cu.get_data_path()+'CFHTLens/masks/'
        data, w = read_mask(filepath, mask_filename)
        
        x,y = get_pixel((W['ALPHA_J2000'],W['DELTA_J2000']),w)
        fits_mask_value = data[y,x] #row,column ---> y,x
        print(i,object_mask_value,fits_mask_value)
        assert object_mask_value==fits_mask_value, "fits mask does not match catalogue mask!"
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/mock_runs/2nd_run/'
    savepath = cu.get_output_path(
    ) + 'processed_data/berlind_groupcat/mock_runs/2nd_run/'
    #################################################################

    catalogues=['Mr19_age_distribution_matching_mock_cen_shuffle_radec_mock_groups.dat',\
                'Mr19_age_distribution_matching_mock_radec_mock_groups.dat',\
                'Mr19_age_distribution_matching_mock_satsys_shuffle_radec_mock_groups.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_cen_shuffle_radec_mock_groups.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_radec_mock_groups.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satrel_shuffle_radec_mock_groups.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satsys_shuffle_radec_mock_groups.dat']

    names = ['IDgroup', 'IDgal', 'ra', 'dec', 'cz']

    for i in range(0, len(catalogues)):
        filename = catalogues[i]
        data = ascii.read(filepath + filename, names=names)
        print data
        print savepath + filename[:-4] + '.hdf5'
        f = h5py.File(savepath + filename[:-4] + '.hdf5', 'w')
        dset = f.create_dataset(filename[:-4], data=data)
        f.close()
Example #17
0
def main():

    filepath = cu.get_data_path() + 'Chinchilla/halo_catalogues/'
    savepath = cu.get_output_path(
    ) + 'processed_data/Chinchilla/halo_catalogues/'

    catalogue = 'hlist_1.00000.list'
    name = ['scale', 'id', 'desc_scale', 'desc_id', 'num_prog', 'pid', 'upid',\
            'desc_pid', 'phantom', 'sam_mvir', 'mvir', 'rvir', 'rs', 'vrms',\
            'mmp?', 'scale_of_last_MM', 'vmax', 'x', 'y', 'z', 'vx', 'vy', 'vz',\
            'Jx', 'Jy', 'Jz', 'Spin', 'Breadth_first_ID', 'Depth_first_ID',\
            'Tree_root_ID', 'Orig_halo_ID', 'Snap_num', 'Next_coprogenitor_depthfirst_ID',\
            'Last_progenitor_depthfirst_ID', 'Rs_Klypin', 'Mvir_all', 'M200b', 'M200c',\
            'M500c', 'M2500c', 'Xoff', 'Voff', 'Spin_Bullock', 'b_to_a', 'c_to_a',\
            'A[x]', 'A[y]', 'A[z]', 'T/|U|', 'Macc', 'Mpeak', 'Vacc', 'Vpeak',\
            'Halfmass_Scale', 'Acc_Rate_Inst', 'Acc_Rate_100Myr', 'Acc_Rate_1*Tdyn',\
            'Acc_Rate_2*Tdyn', 'Acc_Rate_Mpeak', 'Mpeak_Scale', 'Acc_Scale','M4%_Scale']

    print 'reading in:', catalogue
    filename = catalogue
    data = ascii.read(filepath+filename, delimiter='\s', names=name, \
                      guess=False, Reader=ascii.Basic, data_start = 0)
    f = h5py.File(savepath + catalogue + '.hdf5', 'w')
    dset = f.create_dataset(catalogue, data=data)
    f.close()
    filename = catalogue
    data_table = table.table.Table(data=data)
    ascii.write(data_table, savepath + filename + '.dat')
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)
Example #19
0
def main():
  ###make sure to change these when running in a new enviorment!###
  #location of data directory
  filepath = cu.get_output_path() + 'processed_data/tinker_groupcat/'
  #################################################################

  catalogues=['group_dr7_m.star9.7','group_dr7_m.star10.1','group_dr7_m.star10.6','group_dr7_mag.r19']
  filepath = cu.get_output_path() + 'processed_data/tinker_groupcat/'

  for catalogue in catalogues:
      print catalogue
      f =  h5py.File(filepath+catalogue+'.hdf5', 'r')
      dset = f.get(catalogue)
      dset = np.array(dset)
      print 'length:', len(dset)
      for name in dset.dtype.names: print '\t', name
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/mock_runs/3rd_run/'
    savepath = cu.get_output_path() + 'processed_data/berlind_groupcat/mock_runs/3rd_run/'
    #################################################################

    catalogues=['Mr19_age_distribution_matching_mock_cen_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_satsys_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_cen_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satrel_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satsys_shuffle_radec_mock.dat']

    #names = ['IDgroup','richness','ra_center','dec_center','z_center','sigma_v','rms_size','foo1','foo1b','IDgal',\
    #         'ra','dec','z','foo2','foo3','foo4','foo5','R_proj']
    names = ['IDgroup','IDgal','ra','dec','z']

    N = len(catalogues)
    for i in range(0,N):
        filename = catalogues[i]
        data = ascii.read(filepath+filename,names=names)
        print data
        print savepath+filename[:-4]+'.hdf5'
        f = h5py.File(savepath+filename[:-4]+'.hdf5', 'w')
        dset = f.create_dataset(filename[:-4], data=data)
        f.close()
Example #21
0
def main():

    #set random seed to make mocks reproducible
    np.random.seed(1)

    #get parameters to make mock
    if len(sys.argv)<5:
        dm_sim = 'Bolshoi_250'
        sfr_cor = -1.0
        sm_lim = 9.5
        sm_scat = 0.2
    else:
        sfr_cor = float(sys.argv[1])
        sm_lim = float(sys.argv[2])
        sm_scat = float(sys.argv[3])
        dm_sim = sys.argv[4]
    
    if dm_sim =='Bolshoi_250': box_size=250.0
    if dm_sim == 'Chinchilla_250': box_size=250.0
    elif dm_sim == 'Chinchilla_125': box_size=125.0
    
    mock = return_mock(sm_lim = sm_lim, sigma = sm_scat, rho = sfr_cor, sim = dm_sim)
    
    #save mock
    savepath = cu.get_output_path() + 'processed_data/campbell_mocks/'
    
    print('saving hdf5 version of the extended catalogue...')
    filename = 'sm_'+str(sm_lim)+'_s'+str(sm_scat)+'_sfr_c'+str(sfr_cor)+'_'+dm_sim
    print(filename)
    f = h5py.File(savepath+filename+'.hdf5', 'w')
    dset = f.create_dataset(filename, data=mock)
    f.close()
def main():

    if len(sys.argv)>1:
        catalogue = sys.argv[1]
    else: catalogue = 'Mr19_age_distribution_matching_mock'

    #open the ra,dec mock
    filepath   = cu.get_output_path()+'processed_data/hearin_mocks/custom_catalogues/'
    filename   = catalogue+'_radec_mock.dat'
    mock_radec = ascii.read(filepath+filename, delimiter='\s', Reader=ascii.Basic, data_start=1)
    mock_radec = np.array(mock_radec)
    for name in mock_radec.dtype.names: print '\t', name
    
    #open full mock
    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)
    mock = np.array(mock)
    for name in mock.dtype.names: print '\t', name
    
    app_mag_lim = 17.77
    Lbox = 250.0 #Mpc/h
    cosmo = cosmology.core.FlatLambdaCDM(H0=100.0,Om0=0.27) #h=1
    c = 299792.458 #speed of light in km/s
    
    #determine abs mag limit as afunction of z to overplot
    app_mag_r_lim = 17.77 
    z_bins        = np.arange(1.0,0.001,-0.001)
    dm            = dist_mod(z_bins,cosmo)
    abs_mag_r_lim = app_mag_r_lim - dm
    f_r           = interp1d(abs_mag_r_lim, z_bins, kind='cubic', bounds_error=False, fill_value=max(z_bins))
    
    z_lim =  f_r(-19)
    print z_lim
    
    plt.figure()
    plt.plot(mock_radec['z'],mock['M_r,0.1'][mock_radec['k']],'.',ms=2)
    plt.plot(z_bins,abs_mag_r_lim,color='green')
    plt.plot([0,z_lim],[-19,-19],color='red')
    plt.plot([z_lim,z_lim],[-19,-24],color='red')
    plt.plot([0.02,0.02],[-19,-24],color='red')
    plt.plot([0.068,0.068],[-19,-24],'--',color='red')
    plt.ylim([-18.5,-23])
    plt.xlim([0,0.1])
    plt.show()
def main():
    
    if len(sys.argv)>1: catalogue = sys.argv[1]
    else: catalogue = 'Mr19_age_distribution_matching_mock'

    #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
    mock1 = f1.get(catalogue)
    
    #open mock catalogue
    filepath_mock = cu.get_output_path() + 'processed_data/hearin_mocks/ideal_groups/'
    catalogue = catalogue+'_groups'
    print 'opening mock catalogue:', catalogue+'.hdf5'
    f2 = h5py.File(filepath_mock+catalogue+'.hdf5', 'r') #open catalogue file
    mock2 = f2.get(catalogue)

    ind = np.where(mock2['MGROUP']==-99.9)[0]
    print len(ind)

    #sys.exit()

    plt.figure()
    plt.plot(mock2['MGROUP'], mock2['HALO_M'],'.', ms=1, alpha=0.25)
    plt.xlim([10,16])
    plt.show()

    print min(mock2['RANK']), max(mock2['RANK'])
    print min(mock2['HALO_RANK']), max(mock2['HALO_RANK'])

    b_sats = np.where(mock2['HALO_RANK']==1)[0]

    print len(np.where(mock2['HALO_RANK']==-99)[0])
    print len(np.where(mock2['HALO_RANK']==0)[0])
    print len(np.where(mock2['HALO_RANK']==1)[0])

    dM = mock2['M_r,0.1'][b_sats]-mock2['M_r,0.1'][mock2['CEN_IND'][b_sats]]
    print dM
    
    mag_bins = np.arange(-5,2,0.1)
    mag_bin_centers = (mag_bins[:-1]+mag_bins[1:])/2.0
    print mag_bin_centers
    result = np.histogram(dM, bins=mag_bins)[0]
    plt.figure()
    plt.plot(mag_bin_centers,result)
    plt.show()
Example #24
0
def main():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath = cu.get_output_path() + 'processed_data/berlind_groupcat/'
    #################################################################

    catalogues = ['mr19_groups', 'smthresh10.2.groups', 'smthresh9.8.groups']
    filepath = cu.get_output_path() + 'processed_data/berlind_groupcat/'

    for catalogue in catalogues:
        print catalogue
        f = h5py.File(filepath + catalogue + '.hdf5', 'r')
        dset = f.get(catalogue)
        dset = np.array(dset)
        print 'length:', len(dset)
        for name in dset.dtype.names:
            print '\t', name
Example #25
0
def main():

    sm_min=9.5
    sm_max=10.0

    #open mock
    #catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250'
    catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250_cen_shuffle'
    #catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250_cen_sat_shuffle'
    #catalogue = 'sm_8.5_s0.2_sfr_c-1.0_125'
    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)
    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
    
    #define sm threshold for central galaxies
    sm_bin = (mock['Mstar']>sm_min) & (mock['Mstar']<sm_max)
    red_host = red_host & sm_bin
    blue_host = blue_host & sm_bin
    
    #count pairs
    rbins = np.linspace(-1,1.25,20)
    rbins = 10**rbins
    rbin_centers = (rbins[1:]+rbins[:-1])/2.0
    
    data0 = np.vstack((mock['x'], mock['y'], mock['z'])).T
    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]
    
    weights = mock['SSFR']
    
    result = clustering.marked_tpcf(data0, rbins, marks1=weights, wfunc=10, period=Lbox)
    
    print(result)
    
    plt.figure()
    plt.plot(rbin_centers, result)
    plt.xscale('log')
    plt.show()
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')
Example #27
0
def main():

    catalogue = 'Mr19_age_distribution_matching_mock_radec_mock'
    
    filepath = cu.get_output_path()+'processed_data/yang_groupcat/mock_runs/4th_run/'
    
    f = h5py.File(filepath+catalogue+'.hdf5', 'r')
    GC = f.get(catalogue)
    
    print GC.dtype.names
    print len(GC)
Example #28
0
def main():

    ###make sure to change these when running in a new enviorment!###
    #location of data directories
    filepath_1 = cu.get_output_path() + 'processed_data/mpa_dr7/'
    filepath_2 = cu.get_output_path() + 'processed_data/NYU_VAGC/'
    #################################################################

    catalogue_1 = 'mpa_dr7_unique'
    catalogue_2 = 'nyu_vagc_dr7'

    f_1 = h5py.File(filepath_1 + catalogue_1 + '.hdf5', 'r')
    dset_1 = f_1.get(catalogue_1)
    dset_1 = np.array(dset_1)
    #print(dset_1.dtype.names)

    f_2 = h5py.File(filepath_2 + catalogue_2 + '.hdf5', 'r')
    dset_2 = f_2.get(catalogue_2)
    dset_2 = np.array(dset_2)
    #print(dset_2.dtype.names)

    print("number of objects in MPA-JHU catalogue: {0}".format(len(dset_1)))
    print("number of objects in NYU catalogue: {0}".format(len(dset_2)))

    da = 1 / 3600.0 * 2.0  #match length is 2"
    ind1, ind2, ds = cu.spherematch(dset_1['RA'], dset_1['DEC'],\
                                    dset_2['RA'], dset_2['DEC'],\
                                    tol=da, nnearest=1)

    print("minimum angular seperation: {0}''".format(np.min(ds) * 3600.0))
    print("maximum angular seperation: {0}''".format(np.max(ds) * 3600.0))
    print("number of matchs: {0}".format(len(ind1)))

    print(dset_1[ind1]['Z'])
    print(dset_2[ind2]['Z'])

    #save matching file
    filename = 'matches_into_nyu_vagc'
    np.save(filepath_1 + 'matches/' + filename, ind1)
    filename = 'nyu_vagc_matched_to_mpa'
    np.save(filepath_1 + 'matches/' + filename, ind1)
def main():

    catalogue = 'sm9.8_age_matching_SFR_mock'
    sm_lim = 9.5
    
    filepath_mock = cu.get_output_path() + 'processed_data/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)
    print(mock.dtype.names)

    new_mock = get_mock_array(mock)
    
    new_mock['id'] = mock['ID_halo']
    new_mock['upid'] = mock['ID_host']
    new_mock['x'] = mock['x']
    new_mock['y'] = mock['y']
    new_mock['z'] = mock['z']
    new_mock['vx'] = mock['Vx']
    new_mock['vy'] = mock['Vy']
    new_mock['vz'] = mock['Vz']
    new_mock['mvir'] = mock['M_vir']
    new_mock['vz'] = mock['Vz']
    new_mock['Mstar'] = mock['M_star']-(0.7**2)
    new_mock['SSFR'] = mock['SSFR']
    new_mock['Vpeak'] = mock['V_peak']
    
    #make completeness cut
    keep = (new_mock['Mstar']>sm_lim)
    new_mock = new_mock[keep]
    
    #save mock
    savepath = cu.get_output_path() + 'processed_data/campbell_mocks/'
    
    print('saving hdf5 version of the extended catalogue...')
    filename = 'age_matching'
    print(filename)
    f = h5py.File(savepath+filename+'.hdf5', 'w')
    dset = f.create_dataset(filename, data=new_mock)
    f.close()
Example #30
0
def main():
    
    ###make sure to change these when running in a new enviorment!###
    #location of data directories
    filepath_1 = cu.get_output_path() + 'processed_data/mpa_dr7/'
    filepath_2 = cu.get_output_path() + 'processed_data/NYU_VAGC/'
    #################################################################

    catalogue_1 = 'mpa_dr7_unique'
    catalogue_2 = 'nyu_vagc_dr7'
  
    f_1 =  h5py.File(filepath_1+catalogue_1+'.hdf5', 'r')
    dset_1 = f_1.get(catalogue_1)
    dset_1 = np.array(dset_1)
    #print(dset_1.dtype.names)

    f_2 =  h5py.File(filepath_2+catalogue_2+'.hdf5', 'r')
    dset_2 = f_2.get(catalogue_2)
    dset_2 = np.array(dset_2)
    #print(dset_2.dtype.names)
    
    print("number of objects in MPA-JHU catalogue: {0}".format(len(dset_1)))
    print("number of objects in NYU catalogue: {0}".format(len(dset_2)))
    
    da = 1/3600.0 * 2.0 #match length is 2"
    ind1, ind2, ds = cu.spherematch(dset_1['RA'], dset_1['DEC'],\
                                    dset_2['RA'], dset_2['DEC'],\
                                    tol=da, nnearest=1)
    
    print("minimum angular seperation: {0}''".format(np.min(ds)*3600.0))
    print("maximum angular seperation: {0}''".format(np.max(ds)*3600.0))
    print("number of matchs: {0}".format(len(ind1)))
    
    print(dset_1[ind1]['Z'])
    print(dset_2[ind2]['Z'])
    
    #save matching file
    filename = 'matches_into_nyu_vagc'
    np.save(filepath_1+'matches/'+filename,ind1)
    filename = 'nyu_vagc_matched_to_mpa'
    np.save(filepath_1+'matches/'+filename,ind1)
Example #31
0
def main():
    import numpy as np
    import h5py
    import matplotlib.pyplot as plt
    import custom_utilities as cu
    import sys

    catalogue = sys.argv[1]

    bins = np.arange(7.5, 11.5, 0.1)
    bin_centers = (bins[:-1] + bins[1:]) / 2.0
    S_r = 4.64

    print 'opening mock catalogue:', catalogue + '.hdf5'
    #open catalogue
    filepath_mock = cu.get_output_path(
    ) + 'processed_data/hearin_mocks/custom_catalogues/'
    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]
    L = solar_lum(mock['M_r,0.1'], S_r)
    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))

    host_ID = mock['ID_host']
    host_ID[host] = mock['ID_halo'][host]

    mass_bin = [12.9, 13.2]
    phi = clf(host_ID, L, bins, mock['M_host'], mass_bin)
    mask = red
    phi_red = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask)
    mask = blue
    phi_blue = clf(host_ID, L, bins, mock['M_host'], mass_bin, mask)

    plt.figure()
    plt.plot(bin_centers, phi, color='black')
    plt.plot(bin_centers, phi_red, color='red')
    plt.plot(bin_centers, phi_blue, color='blue')
    plt.yscale('log')
    plt.ylim([0.1, 100])
    plt.ylabel(r'$\phi(L)dL/{\rm group}$')
    plt.xlabel('L')
    plt.show()
def main():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath = cu.get_output_path()+'processed_data/CFHTLens/catalogues/'
    #################################################################
  
    fields=['W1','W2','W3','W4']

    for field in fields:
        filename = field
        print 'running for:', field
        f =  h5py.File(filepath+filename+'.hdf5', 'r')
        dset = f.get(field)
  
        dtype=[('id','S13'),('ALPHA_J2000','<f8'),('DELTA_J2000','<f8'), \
               ('x','<f8'),('y','<f8'),('z','<f8'), \
               ('Flag', '<i8'),('MASK', '<i8'), \
               ('MAG_u', '<f8'),('MAG_g', '<f8'),('MAG_r', '<f8'),('MAG_i', '<f8'),('MAG_y', '<f8'),('MAG_z', '<f8'), \
               ('PDZ', np.float64, (70,)),('Z_B', '<f8')]
        dtype = np.dtype(dtype)
        data = np.recarray((len(dset),), dtype=dtype)

        data['id']  = dset['id']
        data['ALPHA_J2000'] = dset['ALPHA_J2000']
        data['DELTA_J2000'] = dset['DELTA_J2000']
        
        data['Flag']  = dset['Flag']
        data['MASK']  = dset['MASK']
        data['MAG_u']  = dset['MAG_u']
        data['MAG_g']  = dset['MAG_g']
        data['MAG_r']  = dset['MAG_r']
        data['MAG_i']  = dset['MAG_i']
        data['MAG_y']  = dset['MAG_y']
        data['MAG_z']  = dset['MAG_z']
        data['Z_B']  = dset['Z_B']
        
        #process pdz column
        string = np.array(dset['PZ_full'])
        for i in range(0,len(dset)):
            print i
            data['PDZ'][i] = np.array([float(x) for x in string[i].split(',')])

        print 'converting ra,dec coordinates into vectors...'
        x, y, z = spherical_to_cartesian(dset['ALPHA_J2000'],dset['DELTA_J2000'], threads=4)
        data['x'] = x
        data['y'] = y
        data['z'] = z

        print 'saving hdf5 version of the catalogue...'
        filename = filename+'_abbreviated'
        f = h5py.File(filepath+filename+'.hdf5', 'w')
        dset = f.create_dataset(field, data=data)
        f.close()
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():

    catalogues_1 = ['sm_9.5_s0.2_sfr_c-1.0_250','sm_9.5_s0.2_sfr_c-1.0_250_cen_shuffle']

    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']

    sm_bin = sm_bins[2]

    #open correlation functions
    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)

    ######################################################################################
    #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, left=0.2, right=0.9, bottom=0.2, top=0.9)
    
    ax = axes
    ax.set_xlim([0.1,20])
    #ax.set_ylim([5,300])
    ax.set_yscale('log')
    ax.set_xscale('log')
    ax.set_ylabel(r'$(\omega_{\rm red}-\omega_{\rm blue})/\omega_{\rm all}$')
    ax.set_xlabel(r'$r_p~[{\rm Mpc}~h^{-1}]$')
    ax.set_title(r'10.0$<\log(M_{*}/M_{\odot}h^{-2})<10.5$')
    #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_2a['r'],'--',color='black', alpha=1)
    #p2b, = ax.plot(result_2b['r'],result_2b['wp']*result_2a['r'],'--',color='red', alpha=1)
    #p2c, = ax.plot(result_2c['r'],result_2c['wp']*result_2a['r'],'--',color='blue', alpha=1)
    p1a, = ax.plot(result_1a['r'],(result_1b['wp']-result_1c['wp'])/result_1a['wp'],'-',color='black', alpha=1)
    p1b, = ax.plot(result_2a['r'],(result_2b['wp']-result_2c['wp'])/result_2a['wp'],'--',color='black', alpha=1)
    plt.legend((p1a,p1b),('CAM mock','shuffled mock'),fontsize=10, frameon=False, loc=4)
    plt.show()
    
    fig1.savefig('/Users/duncan/Desktop/compare_wp.pdf')
def main():

    #catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250_cen_shuffle'
    #catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250_sat_shuffle'
    #catalogue = 'sm_9.5_s0.2_sfr_c-1.0_250'
    catalogue = 'sm_9.5_s0.2_sfr_c1.0_Halfmass_Scale_250'
        
    #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(mock.dtype.names)
    
    host = (mock['upid']==-1)
    sub = (mock['upid']!=-1)
    red = (mock['red']==1)
    blue = (mock['red']==0)
    
    halo_prop = 'mvir'
    
    bins = np.arange(9.5,12.5,0.2)
    bin_centers = (bins[:-1]+bins[1:])/2.0
    mean_red_halo_mass = cu.statistics.binned_mean(mock[host&red], bins, 'Mstar', halo_prop, use_log=True)[1]
    mean_blue_halo_mass = cu.statistics.binned_mean(mock[host&blue], bins, 'Mstar', halo_prop, use_log=True)[1]
    
    std_red_halo_mass = cu.statistics.binned_std(mock[host&red], bins, 'Mstar', halo_prop, use_log=True)[1]
    std_blue_halo_mass = cu.statistics.binned_std(mock[host&blue], bins, 'Mstar', halo_prop, use_log=True)[1]
    
    print(std_red_halo_mass*10**mean_red_halo_mass)
    
    #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.9, bottom=0.2, top=0.9)
    p = plt.scatter(10.0**mock['Mstar'][host],mock['mvir'][host],c=mock['SSFR'][host],\
                    cmap='jet_r',vmax=-9.5, vmin=-12.5, marker='.',
                    lw=0, s=2, rasterized=True)
    #p = plt.plot(10.0**mock['Mstar'][host & red],mock['mvir'][host & red], '.', color='red', ms=2)
    #p = plt.plot(10.0**mock['Mstar'][host & blue],mock['mvir'][host & blue], '.', color='blue', ms=2)
    p1a = plt.errorbar(10**bin_centers, 10**mean_red_halo_mass, yerr=std_red_halo_mass*10**mean_red_halo_mass, color='red')
    p1b = plt.errorbar(10**bin_centers, 10**mean_blue_halo_mass, yerr=std_blue_halo_mass*10**mean_blue_halo_mass, color='blue')
    plt.title('age-matching')
    plt.ylabel(r'$M_{\rm halo}~[h^{-1}M_{\odot}]$')
    plt.xlabel(r'$M_{*} ~[h^{-2}M_{\odot}]$')
    plt.xlim([10.0**9.5,10.0**12.5])
    plt.ylim([10.0**11.0,10.0**15.0])
    plt.yscale('log')
    plt.xscale('log')
    plt.show()
    
    fig.savefig('/Users/duncan/Desktop/SMHM_age_matching.pdf')
Example #36
0
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')
Example #37
0
def main():
    filepath_cat = cu.get_output_path(
    ) + 'processed_data/yang_groupcat/custom_catalogues/'
    savepath = filepath_cat

    abs_mag_lim = float(sys.argv[1])
    print abs_mag_lim

    catalogues = ['sample1_L_model', 'sample2_L_model',
                  'sample3_L_model']  #groupcat catalogues

    z = np.arange(0.01, 0.21, 0.01)
    lim = np.zeros(len(z))
    for i in range(0, len(z)):
        print z[i]
        lim[i] = abs_mag_lim_func(z[i])
    print z
    print lim
    func = interpolate.interp1d(lim[::-1], z[::-1], kind='cubic')

    for i in range(0, len(catalogues)):
        catalogue = catalogues[i]
        #open catalogue
        f = h5py.File(filepath_cat + catalogue + '.hdf5',
                      'r')  #open catalogue file
        GC = f.get(catalogue)
        print 'read in', catalogue + '.'

        zmax = func(abs_mag_lim)

        selection_1 = GC['ZGROUP'] < zmax
        selection_2 = GC['M_r,0.1'] < abs_mag_lim
        selection = selection_1 * selection_2
        sample = GC[selection]

        filename = catalogue + '.mr' + str(int(abs(abs_mag_lim)))
        f = h5py.File(savepath + filename + '.hdf5', 'w')
        dset = f.create_dataset(filename, data=sample)
        f.close()

        plt.plot(GC['ZGROUP'], GC['M_r,0.1'], '.', color='black', alpha=0.1)
        plt.plot(sample['ZGROUP'], sample['M_r,0.1'], '.')
        plt.plot(z, lim, color='red')
        plt.ylim([-15, -25])
        plt.xlabel('group z')
        plt.ylabel('M_r,0.1')
        plt.show(block=True)
def main():

    catalogues_1 = ['sm_9.5_s0.2_sfr_c-1.0_250','sm_9.5_s0.2_sfr_c-1.0_250_cen_shuffle']

    samples = ['all','q','sf']
    sm_bins = ['12.0_12.5']

    sm_bin = sm_bins[0]

    #open correlation functions
    filepath = cu.get_output_path() + 'analysis/central_quenching/observables/'
    names = ['r','wp']
    filename = catalogues_1[0]+'_wp_'+samples[0]+'_halo_'+sm_bin+'.dat'
    result_1a = ascii.read(filepath+filename,names=names)
    filename = catalogues_1[0]+'_wp_'+samples[1]+'_halo_'+sm_bin+'.dat'
    result_1b = ascii.read(filepath+filename,names=names)
    filename = catalogues_1[0]+'_wp_'+samples[2]+'_halo_'+sm_bin+'.dat'
    result_1c = ascii.read(filepath+filename,names=names)
    
    filename = catalogues_1[1]+'_wp_'+samples[0]+'_halo_'+sm_bin+'.dat'
    result_2a = ascii.read(filepath+filename,names=names)
    filename = catalogues_1[1]+'_wp_'+samples[1]+'_halo_'+sm_bin+'.dat'
    result_2b = ascii.read(filepath+filename,names=names)
    filename = catalogues_1[1]+'_wp_'+samples[2]+'_halo_'+sm_bin+'.dat'
    result_2c = ascii.read(filepath+filename,names=names)

    ######################################################################################
    #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, left=0.2, right=0.9, bottom=0.2, top=0.9)
    
    ax = axes
    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'$12.0<\log(M_{\rm vir}/M_{\odot}h^{-2})<12.5$')
    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_1b['r'],'-',color='red', alpha=1)
    p1c, = ax.plot(result_1c['r'],result_1c['wp']*result_1c['r'],'-',color='blue', alpha=1)
    p2a, = ax.plot(result_2a['r'],result_2a['wp']*result_2a['r'],'--',color='black', alpha=1)
    p2b, = ax.plot(result_2b['r'],result_2b['wp']*result_2b['r'],'--',color='red', alpha=1)
    p2c, = ax.plot(result_2c['r'],result_2c['wp']*result_2c['r'],'--',color='blue', alpha=1)
    plt.show()
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/'
    savepath = cu.get_output_path() + 'processed_data/berlind_groupcat/'
    #################################################################

    catalogues = [
        'mr19_groups.fits', 'smthresh10.2.groups.dat', 'smthresh9.8.groups.dat'
    ]

    filename = catalogues[0]
    hdulist = fits.open(filepath + filename, memmap=True)
    data = hdulist[1].data
    print 'saving as:', savepath + filename[:-5] + '.hdf5'
    f = h5py.File(savepath + filename[:-5] + '.hdf5', 'w')
    dset = f.create_dataset(filename[:-5], data=data)
    f.close()
    gc.collect()

    names = [
        'ra', 'dec', 'z', 'groupID', 'rank', 'Mstar', 'Mr', 'SSFR', 'Mgroup'
    ]

    filename = catalogues[1]
    data = ascii.read(filepath + filename,
                      guess=True,
                      Reader=ascii.Basic,
                      names=names,
                      data_start=0)
    print 'saving as:', savepath + filename[:-4] + '.hdf5'
    f = h5py.File(savepath + filename[:-4] + '.hdf5', 'w')
    dset = f.create_dataset(filename[:-4], data=data)
    f.close()
    gc.collect()

    filename = catalogues[2]
    data = ascii.read(filepath + filename,
                      guess=True,
                      Reader=ascii.Basic,
                      names=names,
                      data_start=0)
    print 'saving as:', savepath + filename[:-4] + '.hdf5'
    f = h5py.File(savepath + filename[:-4] + '.hdf5', 'w')
    dset = f.create_dataset(filename[:-4], data=data)
    f.close()
    gc.collect()
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/mock_runs/Berlind_run/'
    savepath = cu.get_output_path() + 'processed_data/berlind_groupcat/mock_runs/Berlind_run/'
    #################################################################

    catalogue = 'Age_matching_group_tags.dat'

    names = ['IDgal','IDgroup']

    filename = catalogue
    data = ascii.read(filepath+filename,names=names)
    print data
    print savepath+filename[:-4]+'.hdf5'
    f = h5py.File(savepath+filename[:-4]+'.hdf5', 'w')
    dset = f.create_dataset(filename[:-4], data=data)
    f.close()
Example #41
0
def main():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath = cu.get_output_path() + 'processed_data/mpa_dr7/'
    #################################################################

    catalogues = [
        'gal_totspecsfr_dr7_v5_2', 'gal_info_dr7_v5_2', 'totlgm_dr7_v5_2'
    ]

    for catalogue in catalogues:
        print catalogue
        f = h5py.File(filepath + catalogue + '.hdf5', 'r')
        dset = f.get(catalogue)
        dset = np.array(dset)
        print 'length:', len(dset)
        for name in dset.dtype.names:
            print '\t', name
Example #42
0
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/mock_runs/Berlind_run/'
    savepath = cu.get_output_path(
    ) + 'processed_data/berlind_groupcat/mock_runs/Berlind_run/'
    #################################################################

    catalogue = 'Age_matching_group_tags.dat'

    names = ['IDgal', 'IDgroup']

    filename = catalogue
    data = ascii.read(filepath + filename, names=names)
    print data
    print savepath + filename[:-4] + '.hdf5'
    f = h5py.File(savepath + filename[:-4] + '.hdf5', 'w')
    dset = f.create_dataset(filename[:-4], data=data)
    f.close()
def main():
    filepath_cat = cu.get_output_path() + 'processed_data/yang_groupcat/custom_catalogues/'
    savepath = filepath_cat

    mass_lim = float(sys.argv[1])
    mag_lim = float(sys.argv[2])
    
    catalogues=['sample1_M_model', 'sample2_M_model', 'sample3_M_model'] #groupcat catalogues

    z = np.arange(0.01,0.21,0.01)
    lim=np.zeros(len(z))
    for i in range(0, len(z)):
        print z[i]
        lim[i] = abs_mag_lim_func(z[i])
    print z
    print lim
    func = interpolate.interp1d(lim[::-1], z[::-1], kind='cubic')

    for i in range(0,len(catalogues)):
        catalogue = catalogues[i]
        #open catalogue
        f =  h5py.File(filepath_cat+catalogue+'.hdf5', 'r')  #open catalogue file
        GC = f.get(catalogue)
        print 'read in',catalogue+'.'

        zmax = func(mag_lim)

        selection_1 = GC['ZGROUP']<zmax
        selection_2 = GC['MSTAR']>mass_lim
        selection = selection_1*selection_2
        sample = GC[selection]

        filename = catalogue+'.sm'+str(abs(mass_lim))
        f = h5py.File(savepath+filename+'.hdf5', 'w')
        dset = f.create_dataset(filename, data=sample)
        f.close()

        plt.plot(GC['ZGROUP'],GC['MSTAR'],'.', color='black', alpha=0.1)
        plt.plot(sample['ZGROUP'],sample['MSTAR'],'.')
        plt.plot(z,lim, color='red')
        plt.ylim([8,12])
        plt.xlabel('group z')
        plt.ylabel('$\log(M_{*})$')
        plt.show(block=True)
def main():

    filepath = cu.get_data_path() + 'tinker_groupcat/'
    savepath = cu.get_output_path() + 'processed_data/tinker_groupcat/'
    #################################################################

    names=['ID','ra','dec','z','M_star','Mag_r','Mag_g','SSFR','p_sat','central_ind','M_halo','R_vir','d_proj']

    catalogues=['group_dr7_m.star9.7','group_dr7_m.star10.1','group_dr7_m.star10.6','group_dr7_mag.r19']

    for catalogue in catalogues:
        print catalogue
        filename = catalogue+'.txt'
        print filepath+filename
        data = ascii.read(filepath+filename, delimiter='\s', names=names, \
                      guess=False, Reader=ascii.Basic)
        f = h5py.File(savepath+catalogue+'.hdf5', 'w')
       dset = f.create_dataset(catalogue, data=data)
       f.close()
       gc.collect()
Example #45
0
def main():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath = cu.get_output_path(
    ) + 'processed_data/yang_groupcat/catalogues/'
    #################################################################

    catalogues=['sample1_L_petro','sample2_L_petro','sample3_L_petro',\
                'sample1_M_petro','sample2_M_petro','sample3_M_petro',\
                'sample1_L_model','sample2_L_model','sample3_L_model',\
                'sample1_M_model','sample2_M_model','sample3_M_model']

    for catalogue in catalogues:
        print 'reading in:', catalogue
        f = h5py.File(filepath + catalogue + '.hdf5', 'r')
        dset = f.get(catalogue)
        dset = np.array(dset)
        print 'length:', len(dset)
        for name in dset.dtype.names:
            print '\t', name
Example #46
0
def main():

    filepath = cu.get_data_path() + 'Berlind_groupcat/mock_runs/4th_run/'
    savepath = cu.get_output_path(
    ) + 'processed_data/berlind_groupcat/mock_runs/4th_run/'
    #################################################################

    catalogues=['Mr19_age_distribution_matching_mock_cen_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_satsys_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_cen_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satrel_shuffle_radec_mock.dat',\
                'Mr19_age_distribution_matching_mock_sys_empty_shuffle_satsys_shuffle_radec_mock.dat']

    names = ['IDgroup', 'IDgal', 'ra', 'dec', 'cz']

    for i in range(0, len(catalogues)):
        filename = catalogues[i]
        catalogue = filename[:-4]
        data_1 = ascii.read(filepath + filename,
                            names=names,
                            format='no_header',
                            comment='#')

        #create output file with galaxy ID and group ID
        dtype = [('gal_ID', '>i8'), ('group_ID', '>i8')]
        dtype = np.dtype(dtype)
        data = np.recarray((len(data_1), ), dtype=dtype)

        #fill in data structure.
        data['gal_ID'] = data_1['IDgal']
        data['group_ID'] = data_1['IDgroup']

        #save
        print 'saving:', savepath + catalogue + '.hdf5'
        f = h5py.File(savepath + catalogue + '.hdf5', 'w')
        dset = f.create_dataset(catalogue, data=data)
        f.close()
        print 'done.'
Example #47
0
def get_sdss_sample():
    
    from scipy import interpolate
    
    filepath = cu.get_output_path() + 'processed_data/NYU_VAGC/'
    galaxy_catalogue = 'nyu_lss_mpa_vagc_dr7'
    f =  h5py.File(filepath+galaxy_catalogue+'.hdf5', 'r')
    GC = f.get(galaxy_catalogue) #halo catalogue
    GC = np.array(GC)
    #for name in GC.dtype.names: print(name)
    
    #trim the catalogue a bit
    zmin = 0.01
    zmax = 0.2
    selection = (GC['M']<=17.6) & (GC['Z']<zmax) & (GC['Z']>zmin) &\
                (GC['ZTYPE']==1) & (GC['FGOTMAIN']>0)
    GC = GC[selection]
    
    sm_key = 'sm_MEDIAN'
    GC[sm_key] = GC[sm_key]+np.log10(0.7**2.0)
    
    #make cuts on data to get a clean and complete sample
    cosmo = FlatLambdaCDM(H0=100, Om0=0.3)
    z = np.linspace(0.001,1,1000)
    dL = cosmo.luminosity_distance(z).value
    
    #make cheater fit to dl(z) function
    dL_z = interpolate.interp1d(z,dL,kind='linear')
    Mstar_lim = (4.852 + 2.246*np.log10(dL) + 1.123*np.log10(1+z) - 1.186*z)/(1.0-0.067*z)
    
    #dL = cosmo.luminosity_distance(GC['Z']).value
    dL = dL_z(GC['Z'])
    z = GC['Z']
    LHS = (4.852 + 2.246*np.log10(dL) + 1.123*np.log10(1.0+z) - 1.186*z)/(1.0-0.067*z)
    keep = (GC[sm_key]>LHS)
    GC = GC[keep]
    
    return GC
def main():

    filepath = cu.get_data_path() + 'Multidark/Bolshoi/particle_catalogues/'
    savepath = cu.get_output_path(
    ) + 'processed_data/Multidark/Bolshoi/particle_catalogues/'

    catalogue = 'bolshoi_a1.0003_2e5_particles'

    print 'reading in:', catalogue
    filename = catalogue

    hdulist = fits.open(filepath + catalogue + '.fits')
    header = hdulist[1]

    print header.data

    x = np.array(header.data['POS'][:, 0])
    y = np.array(header.data['POS'][:, 1])
    z = np.array(header.data['POS'][:, 2])

    data = np.recarray((len(x), ),
                       formats=['f4', 'f4', 'f4'],
                       names=['x', 'y', 'z'])

    data['x'] = x
    data['y'] = y
    data['z'] = z

    filename = catalogue
    f = h5py.File(savepath + filename + '.hdf5', 'w')
    dset = f.create_dataset(catalogue, data=data)
    f.close()

    filename = catalogue
    data_table = table.table.Table(data=data)
    ascii.write(data_table, savepath + filename + '.dat')
    print data_table
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():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath = cu.get_output_path() + 'processed_data/hearin_mocks/'
    savepath = cu.get_output_path(
    ) + 'processed_data/hearin_mocks/custom_catalogues/'
    #################################################################

    catalogues = [
        'Mr19_age_distribution_matching_mock', 'sm9.8_age_matching_mock'
    ]

    catalogue = sys.argv[1]
    print 'runing satellite shuffle on:', catalogue
    f = h5py.File(filepath + catalogue + '.hdf5', 'r')
    GC = f.get(catalogue)

    #remove all haloes not occupied in the original mock
    #remove empty haloes
    keep = np.where(GC_new['g-r'] != -99)[0]
    GC = GC[keep]

    print GC.dtype
    #make new catalogue
    dtype = GC.dtype.descr
    dtype = np.dtype(dtype)
    GC_new = np.recarray((len(GC), ), dtype=dtype)
    GC_new.fill(0.0)
    GC_new = np.array(GC, copy=True)

    #identify centrals
    centrals = np.where(GC['ID_host'] == -1)[0]  #central galaxies
    print 'number of centrals:', len(centrals)

    #define mass bins, and which central are in each mass bin
    mass_bins = np.arange(8.0, 16.0, 0.1)  #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

    #go through each mass bin
    for i in range(0, len(mass_bins) - 1):
        print 'mass bin:', i, mass_bins[i], mass_bins[i + 1]
        ind = np.where(mass_bin_ind == i + 1)[0]
        if len(ind) > 0:  #if there are any haloes in the mass bin
            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)
            #now shuffle satellites amongst groups in mass bin
            shuffle = np.random.permutation(
                np.arange(0, len(satellite_members), 1))
            if len(satellite_members) > 0:
                GC_new['M_r,0.1'][satellite_members] = GC['M_r,0.1'][
                    satellite_members[shuffle]]
                GC_new['M_star'][satellite_members] = GC['M_star'][
                    satellite_members[shuffle]]
                GC_new['g-r'][satellite_members] = GC['g-r'][
                    satellite_members[shuffle]]

    print 'saving hdf5 version of the catalogue...'
    filename = catalogue + '_sat_shuffle'
    f = h5py.File(savepath + filename + '.hdf5', 'w')
    dset = f.create_dataset(catalogue, data=GC_new)
    f.close()

    print 'saving ascii version of the catalogue...'
    filename = catalogue + '_sat_shuffle'
    data_table = table.table.Table(data=GC_new)
    ascii.write(data_table, savepath + filename + '.dat')
    print data_table
def main():
    catalogue = 'Mr19_age_distribution_matching_mock'
    if len(sys.argv) > 1: catalogue = sys.argv[1]

    #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)  #central galaxies
    satellites = np.array(mock['ID_host'] != -1)  #satellite galaxies
    LHS = 0.7 - 0.032 * (mock['M_r,0.1'] + 16.5)  #Weinmann 2006 color cut
    blue = np.array(mock['g-r'] < LHS)[0]  #blue galaxies
    red = np.array(mock['g-r'] > LHS)[0]  #red galaxies
    L = solar_lum(mock['M_r,0.1'], 4.64)

    lumbins = np.arange(9.6, 11.0, 0.15)
    lumbin_centers = (lumbins[:-1] + lumbins[1:]) / 2.0
    luminds = np.digitize(solar_lum(mock['M_r,0.1'], 4.64), bins=lumbins)

    massbins = np.arange(11, 15, 0.2)
    massbin_centers = (massbins[:-1] + massbins[1:]) / 2.0
    massinds = np.digitize(mock['M_host'], bins=massbins)

    colorbins = np.arange(0, 1.5, 0.1)
    colorbin_centers = (colorbins[:-1] + colorbins[1:]) / 2.0
    colorinds = np.digitize(mock['g-r'], bins=colorbins)

    #fig = plt.figure()
    #ax = fig.add_subplot(111, projection='3d')
    #ax.scatter(L[satellites],mock['g-r'][satellites],mock['M_host'][satellites],marker='.',alpha=0.1)
    #ax.set_ylim([0,1.5])
    #plt.show()

    fig1, axes = plt.subplots(nrows=3,
                              ncols=3,
                              sharex=True,
                              sharey=True,
                              figsize=(10, 10))
    fig1.subplots_adjust(hspace=0, wspace=0.0)
    fig1.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9)
    axes = axes.flatten()

    #satellites
    ax = axes[0]
    selection = np.array(luminds == 0)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[0])
    ax = axes[1]
    selection = np.array(luminds == 1)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[1])
    ax = axes[2]
    selection = np.array(luminds == 2)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[2])
    ax = axes[3]
    selection = np.array(luminds == 3)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[3])
    ax = axes[4]
    selection = np.array(luminds == 4)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[4])
    ax = axes[5]
    selection = np.array(luminds == 5)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[5])
    ax = axes[6]
    selection = np.array(luminds == 6)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[6])
    ax = axes[7]
    selection = np.array(luminds == 7)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[7])
    ax = axes[8]
    selection = np.array(luminds == 8)
    selection = selection & satellites
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(11.5, 1.1, lumbin_centers[8])

    #centrals
    ax = axes[0]
    selection = np.array(luminds == 0)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[1]
    selection = np.array(luminds == 1)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[2]
    selection = np.array(luminds == 2)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[3]
    selection = np.array(luminds == 3)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[4]
    selection = np.array(luminds == 4)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[5]
    selection = np.array(luminds == 5)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[6]
    selection = np.array(luminds == 6)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[7]
    selection = np.array(luminds == 7)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[8]
    selection = np.array(luminds == 8)
    selection = selection & centrals
    ax.plot(mock['M_host'][selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')

    ax.set_xlim([11, 15])
    ax.set_ylim([0, 1.25])
    plt.show()

    fig2, axes = plt.subplots(nrows=3,
                              ncols=3,
                              sharex=True,
                              sharey=True,
                              figsize=(10, 10))
    fig2.subplots_adjust(hspace=0, wspace=0.0)
    fig2.subplots_adjust(left=0.1, right=0.95, bottom=0.2, top=0.9)
    axes = axes.flatten()

    #satellites
    ax = axes[0]
    selection = np.array(massinds == 5)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[5])
    ax = axes[1]
    selection = np.array(massinds == 6)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[6])
    ax = axes[2]
    selection = np.array(massinds == 7)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[7])
    ax = axes[3]
    selection = np.array(massinds == 8)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[8])
    ax = axes[4]
    selection = np.array(massinds == 9)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[9])
    ax = axes[5]
    selection = np.array(massinds == 10)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[10])
    ax = axes[6]
    selection = np.array(massinds == 11)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[11])
    ax = axes[7]
    selection = np.array(massinds == 12)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[12])
    ax = axes[8]
    selection = np.array(massinds == 13)
    selection = selection & satellites
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='green')
    ax.text(9.5, 1.1, massbin_centers[13])

    #centrals
    ax = axes[0]
    selection = np.array(massinds == 5)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[1]
    selection = np.array(massinds == 6)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[2]
    selection = np.array(massinds == 7)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[3]
    selection = np.array(massinds == 8)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[4]
    selection = np.array(massinds == 9)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[5]
    selection = np.array(massinds == 10)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[6]
    selection = np.array(massinds == 11)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[7]
    selection = np.array(massinds == 12)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')
    ax = axes[8]
    selection = np.array(massinds == 13)
    selection = selection & centrals
    ax.plot(L[selection],
            mock['g-r'][selection],
            '.',
            ms=1,
            alpha=0.2,
            color='orange')

    ax.set_xlim([9.5, 11])
    ax.set_ylim([0, 1.25])
    plt.show()

    plt.figure()
    selection = np.array(massinds <= 8) & np.array(massinds > 6)
    selection = selection & centrals
    plt.plot(L[selection],
             mock['g-r'][selection],
             '.',
             ms=1,
             alpha=0.2,
             color='orange')
    plt.xlim([9.5, 11])
    plt.ylim([0, 1.25])
    plt.figure()
    selection = np.array(massinds > 8)
    selection = selection & centrals
    plt.plot(L[selection],
             mock['g-r'][selection],
             '.',
             ms=1,
             alpha=0.2,
             color='orange')
    plt.xlim([9.5, 11])
    plt.ylim([0, 1.25])

    plt.figure()
    selection = np.array(massinds < 5)
    selection = selection & centrals
    plt.plot(L[selection],
             mock['g-r'][selection],
             '.',
             ms=1,
             alpha=0.2,
             color='orange')
    plt.xlim([9.5, 11])
    plt.ylim([0, 1.25])
    plt.show()
def main():

    filepath = cu.get_output_path(
    ) + 'processed_data/hearin_mocks/custom_catalogues/'
    savepath = filepath
    filename = sys.argv[1]
    catalogue = filename[0:-33]

    #file format: ID x y z Vx Vy Vz Mag with headers
    data = table.Table.read(filepath + filename, format='ascii')
    data = np.array(data)
    dtype = [('k', '>i8'), ('ID', '>i8'), ('ra', '>f8'), ('dec', '>f8'),
             ('z', '>f8'), ('app_mag', '>f8')]
    dtype = np.dtype(dtype)
    mock = np.recarray((len(data), ), dtype=dtype)
    mock['ID'] = data['ID']
    mock['k'] = np.arange(0, len(mock), 1, dtype=int)

    app_mag_lim = 17.77
    Lbox = 250.0  #Mpc/h
    cosmo = cosmology.core.FlatLambdaCDM(H0=100.0, Om0=0.27)  #h=1
    c = 299792.458  #speed of light in km/s

    #compute comoving distance from observer
    r = np.sqrt(data['x']**2 + data['y']**2 + data['z']**2)

    #compute radial velocity
    ct = data['z'] / r
    st = np.sqrt(1.0 - ct**2)
    cp = data['x'] / np.sqrt(data['x']**2 + data['y']**2)
    sp = data['y'] / np.sqrt(data['x']**2 + data['y']**2)
    vr = data['Vx'] * st * cp + data['Vy'] * st * sp + data['Vz'] * ct

    #compute cosmological redshift and add contribution from perculiar velocity
    y = np.arange(0, 2.0, 0.01)
    x = cosmology.funcs.comoving_distance(y, cosmo=cosmo)
    f = interp1d(x, y, kind='cubic')
    z_cos = f(r)
    mock['z'] = z_cos + (vr / c) * (1.0 + z_cos)

    #calculate spherical coordinates
    theta = np.arccos(data['z'] / r)
    phi = np.arccos(cp)  #atan(y/x)

    #convert spherical coordinates into ra,dec in radians
    mock['ra'] = phi
    mock['dec'] = (math.pi / 2.0) - theta

    #remove galaxies beyond r=L_box
    keep_1 = (r < Lbox)

    #calculate the luminosity distance
    dl = (1.0 + z_cos) * r  #flat cosmology
    #compute the apparant magnitude
    mock['app_mag'] = data['Mag'] + 5.0 * np.log10(dl) + 25.0
    #apply apparant magnitude limit
    keep_2 = (mock['app_mag'] < app_mag_lim)
    keep = (keep_2 & keep_1)
    mock = mock[keep]

    #determine abs mag limit as afunction of z to overplot
    app_mag_r_lim = 17.77
    z_bins = np.arange(1.0, 0.001, -0.001)
    dm = dist_mod(z_bins, cosmo)
    abs_mag_r_lim = app_mag_r_lim - dm
    f_r = interp1d(abs_mag_r_lim,
                   z_bins,
                   kind='cubic',
                   bounds_error=False,
                   fill_value=max(z_bins))

    print max(mock['z']), f(Lbox), (max(mock['z']) - f(Lbox)) * c

    #convert ra,dec into degrees
    mock['ra'] = mock['ra'] * 180.0 / math.pi
    mock['dec'] = mock['dec'] * 180.0 / math.pi

    #save output
    print 'saving ascii version of the catalogue...'
    filename = catalogue + '_radec_mock'
    print filename
    data_table = table.table.Table(data=mock)
    data_table.write(savepath + filename + '.dat', format='ascii')
    print data_table
def main():
    ###make sure to change these when running in a new enviorment!###
    #location of data directory
    filepath_cat1 = cu.get_output_path() + 'processed_data/yang_groupcat/'
    filepath_cat2 = cu.get_output_path() + 'processed_data/mpa_dr7/'
    #save data to directory...
    savepath1 = filepath_cat1 + 'mpa_dr7_match/'
    savepath2 = filepath_cat2 + 'yang_groupcat_match/'
    #################################################################

    catalogues_1=['sample1_L_petro','sample2_L_petro','sample3_L_petro',\
                  'sample1_M_petro','sample2_M_petro','sample3_M_petro',\
                  'sample1_L_model','sample2_L_model','sample3_L_model',\
                  'sample1_M_model','sample2_M_model','sample3_M_model']
    catalogues_2 = ['gal_info_gal_totspecsfr_dr7_v5_2']

    for catalogue in catalogues_1:
        catalogue1 = catalogue
        catalogue2 = catalogues_2[0]
        print catalogue1, 'match into', catalogue2

        f1 = h5py.File(filepath_cat1 + catalogue1 + '.hdf5',
                       'r')  #open catalogue file
        GC = f1.get(catalogue1)

        f2 = h5py.File(filepath_cat2 + catalogue2 + '.hdf5',
                       'r')  #open catalogue file
        W = f2.get(catalogue2)

        da = 2.0 * 1.0 / 3600.0  #matching length
        result_1 = np.array(
            cu.spherematch(GC['RAgal'],
                           GC['DECgal'],
                           W['RA'],
                           W['DEC'],
                           tol=da,
                           nnearest=1))
        #result_2 = np.array(cu.spherematch(GC['RAgal'], GC['DECgal'], W['RA'], W['DEC'], tol=da, nnearest=2)) #not used
        repeats = [
            item for item, count in Counter(result_1[1]).iteritems()
            if count > 1
        ]  #double matched objects
        if len(repeats) > 0:
            remove = np.zeros((0, ), dtype=np.int)  #which entries to remove
            for repeat in repeats:
                result_a = np.where(
                    result_1[1] == repeat
                )[0]  #find indices of the double matched object into catalogue2
                result_b = np.where(
                    result_1[2][result_a] > np.min(result_1[2][result_a]))[
                        0]  #find less good matches
                result_c = result_a[
                    result_b]  #indices of less good matches into catalogue2
                remove = np.hstack(
                    (remove, result_c))  #indices which should be removed
            keep = np.arange(0, len(result_1[0]), 1).astype(int)
            keep = np.in1d(keep, remove) == False
            result = result_1[:, keep]
            #unique = np.setdiff1d(result_2[0], result_1[0]) #not used
        else:
            result = result

        filename1 = catalogue2 + '_' + catalogue1 + '_match'
        filename2 = catalogue1 + '_' + catalogue2 + '_match'

        np.save(savepath1 + filename1, result[1].astype(int))
        np.save(savepath2 + filename2, result[0].astype(int))
Example #54
0
def main():
    import numpy as np
    import h5py
    import matplotlib.pyplot as plt
    import custom_utilities as cu
    import sys

    catalogue = sys.argv[1]

    bins = np.arange(10, 15, 0.1)
    bin_centers = (bins[:-1] + bins[1:]) / 2.0

    print 'opening mock catalogue:', catalogue + '.hdf5'
    #open catalogue
    filepath_mock = cu.get_output_path(
    ) + 'processed_data/hearin_mocks/custom_catalogues/'
    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.where((color < LHS) & (mock['M_r,0.1'] != -99))[0]
    red = np.where((color > LHS) & (mock['M_r,0.1'] != -99))[0]

    print len(red), len(blue)

    Ngal = np.zeros(len(mock))
    Ngal[occupied] = 1
    host_ID = mock['ID_host']
    host_ID[host] = mock['ID_halo'][host]

    mask = np.zeros(len(mock))
    mask[:] = 1
    avg_N = hod(host_ID, mock['M_host'], Ngal, bins, mask)
    print sum(Ngal[np.where(mask == 0)[0]])

    mask = np.zeros(len(mock))
    mask[red] = 1
    avg_N_red = hod(host_ID, mock['M_host'], Ngal, bins, mask)
    print sum(Ngal[np.where(mask == 0)[0]])

    mask = np.zeros(len(mock))
    mask[blue] = 1
    avg_N_blue = hod(host_ID, mock['M_host'], Ngal, bins, mask)
    print sum(Ngal[np.where(mask == 0)[0]])

    plt.figure()
    plt.plot(bin_centers, avg_N, color='black')
    plt.plot(bin_centers, avg_N_red, color='red')
    plt.plot(bin_centers, avg_N_blue, color='blue')
    plt.yscale('log')
    plt.ylim([0.01, 500])
    plt.ylabel('<N>')
    plt.xlabel('M')
    plt.show()
def main():
    catalogue = 'Mr19_age_distribution_matching_mock'
    if len(sys.argv) > 1: catalogue = sys.argv[1]

    #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.array(color < LHS)  #indices of blue galaxies
    red = np.array(color > LHS)  #indicies of red galaxies

    massbins = np.arange(11, 15, 0.2)
    massbin_centers = (massbins[:-1] + massbins[1:]) / 2.0
    mass_inds = np.digitize(mock['M_host'], bins=massbins)

    lumbins = np.arange(9.6, 11.8, 0.2)
    lumbin_centers = (lumbins[:-1] + lumbins[1:]) / 2.0
    lum_inds = np.digitize(solar_lum(mock['M_r,0.1'], 4.64), bins=lumbins)

    colorbins = np.arange(0, 1.5, 0.05)
    colorbin_centers = (colorbins[:-1] + colorbins[1:]) / 2.0

    lum_selection = np.array(lum_inds == 5)
    selection = lum_selection & centrals
    result_cen = np.histogram(mock['M_host'][selection], bins=massbins)[0]
    result_cen = result_cen / np.float(np.sum(result_cen))
    selection = lum_selection & satellites
    result_sat = np.histogram(mock['M_host'][selection], bins=massbins)[0]
    result_sat = result_sat / np.float(np.sum(result_sat))

    lower_cen = max(np.where(np.cumsum(result_cen) < 0.25)[0])
    upper_cen = min(np.where(np.cumsum(result_cen) > .75)[0])
    print lower_cen, upper_cen
    '''
    plt.figure()
    plt.step(massbins[:-1],result_cen,where='pre')
    plt.step(massbins[:-1],result_sat,where='pre')
    plt.show()
    '''

    plt.figure()
    for i in range(lower_cen, upper_cen):
        mass_selection = np.array(mass_inds == i)
        selection = mass_selection & lum_selection
        selection = selection & centrals
        colors = np.sort(mock['g-r'][selection])
        N = np.cumsum(np.zeros(len(colors)) + 1.0)
        N = N / np.float(len(N))
        plt.plot(colors, N, color='black')

    c = [(0.1,1,0,0.1),(0.1,1,0,0.2),(0.1,1,0,0.3),(0.1,1,0,0.4),(0.1,1,0,0.5),\
         (0.1,1,0,0.6),(0.1,1,0,0.7),(0.1,1,0,0.8),(0.1,1,0,0.9),(0.1,1,0,1),(0.1,1,0,1),(0.1,1,0,1)]
    print colors
    for i in range(upper_cen, len(massbins) - 1):
        print i
        mass_selection = np.array(mass_inds == i)
        selection = mass_selection & lum_selection
        selection = selection & satellites
        colors = np.sort(mock['g-r'][selection])
        N = np.cumsum(np.zeros(len(colors)) + 1.0)
        N = N / np.float(len(N))
        print c[i - upper_cen]
        plt.plot(colors, N, color=c[i - upper_cen])

    plt.xlim([0, 1.5])
    plt.ylim([0, 1])
    plt.show()