示例#1
0
文件: hod.py 项目: mjvakili/gambly
    def _sum_stat(self, theta, prior_range=None):
        
        self.model.param_dict['logM0'] = theta[0]
        self.model.param_dict['sigma_logM'] = theta[1]
        self.model.param_dict['logMmin'] = theta[2]
        self.model.param_dict['alpha'] = theta[3]
        self.model.param_dict['logM1'] = theta[4]

        self.model.populate_mock(self.halocat) 
        x = self.model.mock.galaxy_table['x']
        y = self.model.mock.galaxy_table['y']
        z = self.model.mock.galaxy_table['z']
        vz = self.model.mock.galaxy_table['vz']
        # applying RSD
        pos = return_xyz_formatted_array(x, y, z, velocity = vz, velocity_distortion_dimension = 'z')
        # enforcing PBC
        pos = enforce_periodicity_of_box(pos, self.boxsize)
        pos = pos.astype(np.float32)
        x, y, z = pos[:,0] , pos[:,1] , pos[:,2]
        results_wp = _countpairs.countpairs_wp(self.boxsize, self.pimax, 
                                           self.nthreads,
                                           self.binfile, x, y, z)
        wp = np.array(results_wp)[:,3]
        nbar = 1.*len(pos)/(self.boxsize)**3.

        return nbar , wp
示例#2
0
def measure_nbar_clustering(Mr):
    '''measure wp for the galaxy catalog
       with the luminosity threshold Mr'''

    #Corrfunc settings for wp measurements:

    boxsize = 250
    nthreads = 4
    pimax = 40.0
    binfile = path.join(path.dirname(path.abspath(__file__)),
                        "../", "bin")
    autocorr = 1

    filename = util.dat_dir()+'AM_Mr'+str(Mr)+'dat'
    cat = np.loadtxt(filename)
    pos = cat[:,1:4]
    x, y, z = pos[:,0], pos[:,1], pos[:,2] 
    vel = cat[:,4:7]
    vx, vy, vz =  vel[:,0], vel[:,1], vel[:,2] 
    #applying RSD:
    pos = return_xyz_formatted_array(x, y, z, velocity = vz, velocity_distortion_dimension = 'z')
    #enforcing periodic boundary conditions:
    pos = enforce_periodicity_of_box(pos, boxsize)
    pos = pos.astype(np.float32)
    x, y, z = pos[:,0] , pos[:,1] , pos[:,2]
    wp_result = _countpairs.countpairs_wp(boxsize, pimax, 
                                   nthreads, binfile, 
				   x, y, z)
    nbar = 1.*len(pos)/boxsize**3.
    wp = np.array(wp_result)[:,3]

    return nbar , wp    
示例#3
0
def main():
     
    # Entire MultiDark Volume (Analytic xi) 
    cov = np.loadtxt("../data/wpxicov_dr72_bright0_mr21.0_z0.159_nj400")
    print(cov.shape)
    model = PrebuiltHodModelFactory('zheng07', threshold=-21)
    print(model.param_dict)
    model.param_dict['logM0'] =  12.59
    model.param_dict['sigma_logM'] =  0.49
    model.param_dict['logMmin'] =  12.78
    model.param_dict['alpha'] =  1.14
    model.param_dict['logM1'] =  13.99
    #, 'sigma_logM': 0.39, 'logMmin': 12.79, 'alpha': 1.15, 'logM1': 13.94}

    halocat = CachedHaloCatalog(simname = 'bolplanck', redshift = 0, halo_finder = 'rockstar')
    model.populate_mock(halocat, enforce_PBC = True)
    pos = three_dim_pos_bundle(model.mock.galaxy_table, 'x', 'y', 'z')

    tstart = time.time()
    t0 = tstart
    pos = pos.astype(np.float32)
    x, y, z = pos[:,0] , pos[:,1] , pos[:,2]
    t1 = time.time()
    print("Done reading the data - time taken = {0:10.1f} seconds"
          .format(t1 - t0))
    print("Beginning Correlation functions calculations")
    boxsize = 250
    nthreads = 4
    pimax = 40.0
    binfile = path.join(path.dirname(path.abspath(__file__)),
                        "../", "bin")
    autocorr = 1
    numbins_to_print = 12
    
    print("\nRunning 2-D projected correlation function wp(rp)")
    results_wp = _countpairs.countpairs_wp(boxsize, pimax, nthreads,
                                           binfile, x, y, z)
    print("\n#            ******    wp: first {0} bins  *******         "
          .format(numbins_to_print))
    print("#      rmin        rmax       rpavg        wp       npairs")
    print("##########################################################")
    for ibin in range(numbins_to_print):
        items = results_wp[ibin]
        print("{0:12.4f} {1:12.4f} {2:10.4f} {3:10.1f} {4:10d}"
              .format(items[0], items[1], items[2], items[3], items[4]))
    print("-----------------------------------------------------------")
    
    data_wp = np.loadtxt("../data/wpxi_dr72_bright0_mr21.0_z0.159_nj400")[:,1]
    print(data_wp.shape)
    data_wp_error = np.sqrt(np.diag(cov)[:12])
    print(data_wp_error.shape) 
    rbins = np.loadtxt(binfile)
    rs = np.mean(rbins , axis = 1)
    plt.figure(figsize=(10,10))
    plt.errorbar(rs , data_wp , data_wp_error , fmt=".k" , capsize = 2)
    plt.plot(rs , np.array(results_wp)[:,3])
    plt.loglog()
    plt.savefig("wp.pdf")
示例#4
0
    def wp_hod(self, hod_parameters):
        """
    An HOD model for wp(rp) computed by direct simulation 
    population.
    hod_parameters[0] : alpha
    hod_parameters[1] : logM1
    hod_parameters[2] : sigma_logM
    hod_parameters[3] : logM0
    hod_parameters[4] : logMmin
    hod_parameters[5] : Acen
    hod_parameters[6] : Asat
    """

        # The first step is to set the param_dict of the hod_model.
        self.hod_model.param_dict['alpha'] = hod_parameters[0]
        self.hod_model.param_dict['logM1'] = hod_parameters[1]
        self.hod_model.param_dict['sigma_logM'] = hod_parameters[2]
        self.hod_model.param_dict['logM0'] = hod_parameters[3]
        self.hod_model.param_dict['logMmin'] = hod_parameters[4]
        self.hod_model.param_dict[
            'mean_occupation_centrals_assembias_param1'] = hod_parameters[5]
        self.hod_model.param_dict[
            'mean_occupation_satellites_assembias_param1'] = hod_parameters[6]

        # Populate a mock galaxy catalog
        #self.hod_model.populate_mock()
        try:
            self.hod_model.mock.populate()
        except:
            self.hod_model.populate_mock(self.halocatalog)

        # Instruct wp(rp) routine to compute autocorrelation
        autocorr = 1
        # Number of threads
        nthreads = 4

        # use the z-direction as line-of-sight and add RSD
        z_distorted = self.hod_model.mock.galaxy_table[
            'z'] + self.hod_model.mock.galaxy_table['vz'] / 100.0

        # enforce periodicity of the box

        self.hod_model.mock.galaxy_table[
            'zdist'] = z_distorted % self.hod_model.mock.Lbox[0]

        # Return projected correlation function computed using
        # Manodeep Simha's optimized C code.
        cpout = np.array(
            _countpairs.countpairs_wp(
                self.hod_model.mock.Lbox[0], self.pi_max, nthreads,
                self.binfile,
                self.hod_model.mock.galaxy_table['x'].astype('float32'),
                self.hod_model.mock.galaxy_table['y'].astype('float32'),
                self.hod_model.mock.galaxy_table['zdist'].astype('float32')))
        return np.array(cpout[0])[:, 3]
示例#5
0
def compute_jackknife_covariance(Mr , nsub):
    
    box_size = 250.
    filename = util.dat_dir()+'AM_Mr'+str(Mr)+'dat'
    cat = np.loadtxt(filename)
    pos = cat[:,1:4]  #positions of all galaxies in the box
    vel = cat[:,4:7]  #velocities of all galaxies
    
    x , y , z = pos[:,0], pos[:,1], pos[:,2]
    vx, vy, vz = vel[:,0], vel[:,1], vel[:,2]
    rsd_pos = return_xyz_formatted_array(x, y, z, velocity = vz, velocity_distortion_dimension = 'z')
    rsd_pos = enforce_periodicity_of_box(rsd_pos, box_size)
    
    number_of_subboxes = nsub ** 3
   
    #Corrfunc settings for wp measurements:
    
    subbox_size = box_size / nsub
    nthreads = 4
    pimax = 25.0
    binfile = path.join(path.dirname(path.abspath(__file__)),
                        "../", "bin")
    len_wp = len(np.loadtxt(binfile))
    wps = np.zeros((number_of_subboxes , len_wp)) 
    nbars = np.zeros((number_of_subboxes , 1))

    for subvol_index in xrange(number_of_subboxes):

        sub_rsd_pos = mask_positions(rsd_pos , subvol_index , nsub)
        sub_rsd_pos = sub_rsd_pos.astype(np.float32)
        sub_x, sub_y, sub_z = sub_rsd_pos[:,0] , sub_rsd_pos[:,1] , sub_rsd_pos[:,2]
        wp_result = _countpairs.countpairs_wp(subbox_size, pimax, 
                                   nthreads, binfile, 
				   sub_x, sub_y, sub_z)
        nbars[subvol_index] = 1.*len(sub_rsd_pos)/subbox_size**3.
        wps[subvol_index] = np.array(wp_result)[:,3]
           
    nbar_covar = np.array([np.var(nbars)])    
    wp_covar = np.cov(wps.T)    

    return nbar_covar , wp_covar
示例#6
0
def main():
     
    cov = np.loadtxt("../../data/wpxicov_dr72_bright0_mr21.0_z0.159_nj400")
    f_MD = (1. + 71.74*10**6. / (1000.)**3.)
    f_bol = (1. + 71.74*10.**6. / (250.)**3.)
      
    print("covariance correction factor=" , f_bol/f_MD)
    cov = cov*f_bol/f_MD
   
    model.param_dict['logM0'] =  12.59
    model.param_dict['sigma_logM'] =  0.49
    model.param_dict['logMmin'] =  12.78
    model.param_dict['alpha'] =  1.14
    model.param_dict['logM1'] =  13.99

    model.param_dict['mean_occupation_satellites_assembias_param1'] = 0.0
    halocat = CachedHaloCatalog(simname = 'bolplanck', redshift = 0, halo_finder = 'rockstar')
    model.populate_mock(halocat, enforce_PBC = True)
    pos = three_dim_pos_bundle(model.mock.galaxy_table, 'x', 'y', 'z')
  
    print("modelnumber density=" , len(pos)/halocat.Lbox**3.)
    print("data number density=" , 1.16*10**-3.) 
    x = model.mock.galaxy_table['x']
    y = model.mock.galaxy_table['y']
    z = model.mock.galaxy_table['z']
    vz = model.mock.galaxy_table['vz']

    # applying RSD
    pos = return_xyz_formatted_array(x, y, z, velocity = vz, velocity_distortion_dimension = 'z')
    # enfprcing PBC
    pos =  enforce_periodicity_of_box(pos, halocat.Lbox)

    tstart = time.time()
    t0 = tstart
    pos = pos.astype(np.float32)
    x, y, z = pos[:,0] , pos[:,1] , pos[:,2]
    t1 = time.time()
    print("Done reading the data - time taken = {0:10.1f} seconds"
          .format(t1 - t0))
    print("Beginning Correlation functions calculations")
    boxsize = halocat.Lbox
    nthreads = 4
    pimax = 40.0
    binfile = path.join(path.dirname(path.abspath(__file__)),
                        "../../", "bin")
    autocorr = 1
    numbins_to_print = 12
    
    print("\nRunning 2-D projected correlation function wp(rp)")
    results_wp = _countpairs.countpairs_wp(boxsize, pimax, nthreads,
                                           binfile, x, y, z)
    print("\n#            ******    wp: first {0} bins  *******         "
          .format(numbins_to_print))
    print("#      rmin        rmax       rpavg        wp       npairs")
    print("##########################################################")
    for ibin in range(numbins_to_print):
        items = results_wp[ibin]
        print("{0:12.4f} {1:12.4f} {2:10.4f} {3:10.1f} {4:10d}"
              .format(items[0], items[1], items[2], items[3], items[4]))
    print("-----------------------------------------------------------")
    
    data_wp = np.loadtxt("../../data/wpxi_dr72_bright0_mr21.0_z0.159_nj400")[:,1]
    print(data_wp.shape)
    data_wp_error = np.sqrt(np.diag(cov)[:12])
    print(data_wp_error.shape) 
    rbins = np.loadtxt(binfile)
    rs = np.mean(rbins , axis = 1)
    plt.figure(figsize=(10,10))
    plt.errorbar(rs , data_wp , data_wp_error , fmt=".k" , capsize = 2)
    plt.plot(rs , np.array(results_wp)[:,3])
    plt.loglog()
    plt.savefig("wp.pdf")