コード例 #1
0
ファイル: calc.py プロジェクト: vipasu/addseds
def cross_correlation_function(gals, red_cut=-11.0, cols=['ssfr', 'pred'],
                               box_size=250.0):
    pi_max = 40.0
    octants = util.jackknife_octant_samples(gals, box_size)
    actual_wps, pred_wps = [], []
    rp_bins = np.logspace(-1, np.log10(25), 18)
    rp_centers = np.sqrt(rp_bins[:-1] * rp_bins[1:])
    for octant in octants:
        reds = gals[cols[0]] < red_cut
        blues = gals[cols[0]] > red_cut
        reds_pred = gals[cols[1]] < red_cut
        blues_pred = gals[cols[1]] > red_cut
        x = gals['x']
        y = gals['y']
        z = gals['z']
        pos_red = return_xyz_formatted_array(x, y, z, mask=reds)
        pos_blue = return_xyz_formatted_array(x, y, z, mask=blues)
        pos_red_pred = return_xyz_formatted_array(x, y, z, mask=reds_pred)
        pos_blue_pred = return_xyz_formatted_array(x, y, z, mask=blues_pred)
        actual_wps.append(wp(pos_red, rp_bins=rp_bins, pi_max=pi_max,
                             sample2=pos_blue, period=box_size)[1])
        pred_wps.append(wp(pos_red_pred, rp_bins=rp_bins, pi_max=pi_max,
                           sample2=pos_blue_pred, period=box_size)[1])

    n_jack = len(octants)
    true_wp = np.mean(actual_wps, axis=1)
    pred_wp = np.mean(pred_wps, axis=1)
    errs = np.sqrt(np.diag(np.cov(np.array(actual_wps) - np.array(pred_wps),
                                  rowvar=0, bias=1)) * (n_jack - 1)),
    return rp_centers, true_wp, pred_wp, errs
コード例 #2
0
def wp_size_ratios_mock(mock,
                        logsm_min,
                        sample_cut,
                        size_key='r50_magr_kpc_meert15',
                        rp_bins=np.logspace(-1, 1.25, 20),
                        pi_max=20.,
                        period=250.):
    """
    """
    rp_mids = 10**(0.5 * (np.log10(rp_bins[:-1]) + np.log10(rp_bins[1:])))

    mask_sm_thresh = mock['obs_sm'] > 10**logsm_min

    if sample_cut == 'sf':
        sample_mask = mask_sm_thresh & (mock['ssfr'] >= -10.75)
    elif sample_cut == 'q':
        sample_mask = mask_sm_thresh & (mock['ssfr'] < -11.25)
    elif sample_cut == 'bulge':
        sample_mask = mask_sm_thresh & (mock['bt_meert15_random'] > 0.75)
    elif sample_cut == 'disk':
        sample_mask = mask_sm_thresh & (mock['bt_meert15_random'] < 0.25)
    elif sample_cut == 'mixed':
        sample_mask = mask_sm_thresh & (mock['bt_meert15_random'] >= 0.25) & (
            mock['bt_meert15_random'] < 0.75)
    else:
        raise ValueError("sample_cut = {0} not recognized")

    size_cut = np.median(mock[size_key][sample_mask])
    sample_mask_small = sample_mask & (mock[size_key] < size_cut)
    sample_mask_large = sample_mask & (mock[size_key] >= size_cut)

    pos_sm_sf = return_xyz_formatted_array(mock['x'],
                                           mock['y'],
                                           mock['z'],
                                           velocity=mock['vz'],
                                           velocity_distortion_dimension='z',
                                           period=period,
                                           mask=sample_mask)
    pos_sm_sf_small = return_xyz_formatted_array(
        mock['x'],
        mock['y'],
        mock['z'],
        velocity=mock['vz'],
        velocity_distortion_dimension='z',
        period=period,
        mask=sample_mask_small)
    pos_sm_sf_large = return_xyz_formatted_array(
        mock['x'],
        mock['y'],
        mock['z'],
        velocity=mock['vz'],
        velocity_distortion_dimension='z',
        period=period,
        mask=sample_mask_large)

    wp_sm = wp(pos_sm_sf, rp_bins, pi_max, period=period)
    wp_sm_small = wp(pos_sm_sf_small, rp_bins, pi_max, period=period)
    wp_sm_large = wp(pos_sm_sf_large, rp_bins, pi_max, period=period)

    return rp_mids, wp_sm, wp_sm_small, wp_sm_large
コード例 #3
0
def single_component_ratios(mock,
                            rp_bins=np.logspace(-1, 1.25, 20),
                            pi_max=20.,
                            period=250.,
                            size_key='r50',
                            num_gals_max=int(1e5)):
    """
    """
    result_collector = []
    rp_mids = 10**(0.5 * (np.log10(rp_bins[:-1]) + np.log10(rp_bins[1:])))
    result_collector.append(rp_mids)

    for logsm_cut in (9.75, 10.25, 10.75, 11.25):
        sample = mock[mock['mstar'] > 10**logsm_cut]
        if len(sample) > num_gals_max:
            downsampling_mask = np.random.choice(np.arange(len(sample)),
                                                 num_gals_max,
                                                 replace=False)
            sample = sample[downsampling_mask]

        pos_all = return_xyz_formatted_array(sample['x'],
                                             sample['y'],
                                             sample['z'],
                                             velocity=sample['vz'],
                                             velocity_distortion_dimension='z',
                                             period=period)

        pos_small = return_xyz_formatted_array(
            sample['x'],
            sample['y'],
            sample['z'],
            velocity=sample['vz'],
            velocity_distortion_dimension='z',
            period=period,
            mask=(sample[size_key] < sample[size_key + '_median']))
        pos_large = return_xyz_formatted_array(
            sample['x'],
            sample['y'],
            sample['z'],
            velocity=sample['vz'],
            velocity_distortion_dimension='z',
            period=period,
            mask=(sample[size_key] >= sample[size_key + '_median']))

        wp_all = wp(pos_all, rp_bins, pi_max, period=period)
        wp_small = wp(pos_small, rp_bins, pi_max, period=period)
        wp_large = wp(pos_large, rp_bins, pi_max, period=period)
        fracdiff = (wp_large - wp_small) / wp_all
        result_collector.append(fracdiff)

    return result_collector
コード例 #4
0
def wp_measurement_iterator(table, *masks, **kwargs):
    """
    """
    pi_max = kwargs.get('pi_max', 20)
    rp_bins = kwargs.get('rp_bins', np.logspace(-1, 1.5, 25))
    period = kwargs.get('period', np.inf)
    for sample1 in clustering_sample_iterator(table, *masks, **kwargs):
        yield rp_bins, wp(sample1, rp_bins, pi_max, period=period)
コード例 #5
0
def calc_all_observables(param):

    model.param_dict.update(dict(
        zip(param_names,
            param)))  ##update model.param_dict with pairs (param_names:params)
    c = Ngal_estimate(halocat, param)
    n_est = c.ngal_estimate()
    if n_est < 1e5 and n_est > 7.8e4:
        try:
            model.mock.populate()
        except:
            model.populate_mock(halocat)

        gc.collect()

        output = []

        if model.mock.galaxy_table[
                'x'].size < 9.8e4 and model.mock.galaxy_table['x'].size > 8e4:

            pos_gals = return_xyz_formatted_array(*(model.mock.galaxy_table[ax]
                                                    for ax in 'xyz'),
                                                  period=Lbox)
            pos_gals = np.array(pos_gals, dtype=float)

            pos_gals_d = return_xyz_formatted_array(*(model.mock.galaxy_table[ax] for ax in 'xyz'), \
             velocity=model.mock.galaxy_table['vz'], velocity_distortion_dimension='z',\
                                     period=Lbox)             ##redshift space distorted
            pos_gals_d = np.array(pos_gals_d, dtype=float)

            #ngals
            output.append(model.mock.galaxy_table['x'].size)

            #delta sigma

            deltasigma = delta_sigma(pos_gals,
                                     pos_part,
                                     particle_masses=particle_masses,
                                     downsampling_factor=downsampling_factor,
                                     rp_bins=rp_bins,
                                     period=Lbox)

            output.append(deltasigma[1])
            output.append(deltasigma[0])

            # wprp
            output.append(wp(pos_gals_d, r_wp, pi_max, period=Lbox))

            # parameter set
            output.append(param)
    else:
        output = 1

    return output
コード例 #6
0
def calc_all_observables(param, seed=seed):

    model.param_dict.update(dict(
        zip(param_names,
            param)))  ##update model.param_dict with pairs (param_names:params)

    try:
        model.mock.populate(seed=seed)
    except:
        model.populate_mock(halocat, seed=seed)

    gc.collect()

    output = []

    pos_gals_d = return_xyz_formatted_array(*(model.mock.galaxy_table[ax] for ax in 'xyz'), \
            velocity=model.mock.galaxy_table['vz'], velocity_distortion_dimension='z',\
                                          period=Lbox)             ##redshift space distorted
    pos_gals_d = np.array(pos_gals_d, dtype=float)

    pos_gals = return_xyz_formatted_array(*(model.mock.galaxy_table[ax]
                                            for ax in 'xyz'),
                                          period=Lbox)
    pos_gals = np.array(pos_gals, dtype=float)
    particle_masses = halocat.particle_mass
    total_num_ptcls_in_snapshot = halocat.num_ptcl_per_dim**3
    downsampling_factor = total_num_ptcls_in_snapshot / float(num_ptcls_to_use)

    vpf = void_prob_func(pos_gals_d,
                         r_vpf,
                         random_sphere_centers=vpf_centers,
                         period=Lbox)
    wprp = wp(pos_gals_d, r_wp, pi_max, period=Lbox)
    Pcic = np.bincount(counts_in_cylinders(pos_gals_d, pos_gals_d, proj_search_radius, \
            cylinder_half_length, period=Lbox), minlength=100)[1:71]/float(pos_gals_d.shape[0])
    Pcic_40 = np.add.reduceat(Pcic, sum_40)
    ggl = delta_sigma(pos_gals, ptclpos, particle_masses=particle_masses, downsampling_factor=downsampling_factor,\
                      rp_bins=rp_bins_ggl, period=Lbox)[1]/1e12

    func = np.concatenate((np.array(
        (pos_gals_d.shape[0] / float(Lbox**3), )), wprp, ggl, vpf, Pcic_40))

    output.append(func)

    # parameter set
    output.append(param)

    output.append(np.where(param - fid != 0)[0][0])

    return output
コード例 #7
0
def masked_wp(subhalos, mask=None):
    """
    """
    if mask is None:
        mask = np.ones_like(subhalos).astype(bool)

    rp_bins, pi_max = np.logspace(-1, 1.35, 25), 20.
    rmids = 10**(0.5 * (np.log10(rp_bins[:-1]) + np.log10(rp_bins[1:])))
    pos = return_xyz_formatted_array(subhalos['x'],
                                     subhalos['y'],
                                     subhalos['z'],
                                     mask=mask,
                                     period=250,
                                     velocity=subhalos['vz'],
                                     velocity_distortion_dimension='z')
    return rmids, wp(pos, rp_bins, pi_max, period=250.)
コード例 #8
0
def calc_all_observables(param):

    model.param_dict.update(dict(
        zip(param_names,
            param)))  ##update model.param_dict with pairs (param_names:params)

    try:
        model.mock.populate()
    except:
        model.populate_mock(halocat)

    gc.collect()

    output = []


    pos_gals_d = return_xyz_formatted_array(*(model.mock.galaxy_table[ax] for ax in 'xyz'), \
            velocity=model.mock.galaxy_table['vz'], velocity_distortion_dimension='z',\
                                          period=Lbox)             ##redshift space distorted
    pos_gals_d = np.array(pos_gals_d, dtype=float)
    if args.central:
        mask_cen = model.mock.galaxy_table['gal_type'] == 'centrals'
        pos_gals_d = pos_gals_d[mask_cen]

    if args.Vmax != 0:
        idx_galaxies, idx_halos = crossmatch(
            model.mock.galaxy_table['halo_id'], halocat.halo_table['halo_id'])
        model.mock.galaxy_table['halo_vmax'] = np.zeros(
            len(model.mock.galaxy_table),
            dtype=halocat.halo_table['halo_vmax'].dtype)
        model.mock.galaxy_table['halo_vmax'][
            idx_galaxies] = halocat.halo_table['halo_vmax'][idx_halos]
        mask_Vmax = model.mock.galaxy_table['halo_vmax'] > args.Vmax
        pos_gals_d = pos_gals_d[mask_Vmax]

    # ngals
    output.append(model.mock.galaxy_table['x'].size)

    # wprp
    output.append(wp(pos_gals_d, r_wp, pi_max, period=Lbox))

    # parameter set
    output.append(param)

    return output
コード例 #9
0
ファイル: wp_model.py プロジェクト: mjvakili/gambly
def model(theta, Mstar, prior_range = None):

    '''
    Given theta (HOD parameters) and stellar mass threshold Mstar, 
    compute wp
    not sure prior_range is necessary here
    '''

    model = PrebuiltHodModelFactory('hearin15', threshold = Mstar, 
                                     redshift = 0.0 ,
                                     central_assembias_strength = 0.,
                                     satellite_assembias_strength = 0.)

    model.param_dict['alphasat'] = theta[0]#1.0
    model.param_dict['bcut'] = theta[1]#1.47, 
    model.param_dict['betacut'] = theta[2]#0.13
    model.param_dict['betasat'] =  theta[3]#0.859
    model.param_dict['bsat'] = theta[4]#0.62
    model.param_dict['mean_occupation_centrals_assembias_param1'] = theta[5] # 0
    model.param_dict['mean_occupation_satellites_assembias_param1'] = theta[6] #.75
    model.param_dict['scatter_model_param1'] = theta[7]#0.2
    model.param_dict['smhm_beta_0'] = theta[8]# 0.43 
    model.param_dict['smhm_beta_a'] = theta[9]#0.18 
    model.param_dict['smhm_delta_0'] = theta[10]#0.56
    model.param_dict['smhm_delta_a'] = theta[11]#0.18, 
    model.param_dict['smhm_gamma_0']= theta[12]#1.54 
    model.param_dict['smhm_gamma_a'] = theta[13]#2.52, 
    model.param_dict['smhm_m0_0'] = theta[14]# 10.72, 
    model.param_dict['smhm_m0_a'] = theta[15]# 0.59 
    model.param_dict['smhm_m1_0'] = theta[16]# 12.35, 
    model.param_dict['smhm_m1_a'] = theta[17]#0.3
 
    
    model.populate_mock(simname = 'bolshoi', redshift = 0, halo_finder = 'rockstar')
    #x = model.mock.galaxy_table['x']
    #y = model.mock.galaxy_table['y']
    #z = model.mock.galaxy_table['z']
    #all_positions = return_xyz_formatted_array(x, y, z)    
    all_positions = three_dim_pos_bundle(model.mock.galaxy_table, 'x', 'y', 'z')
    
    wp_all = wp(all_positions, rp_bins, pi_bins,
                period=model.mock.Lbox, estimator = 'Landy-Szalay', num_threads = 1)
    #wp = proj_clustering(pos , rbins , pbins , cellsize = [rmax, rmax, rmax])
    print 1
    return rp_bin_centers, wp_all
コード例 #10
0
def calc_all_observables(param):

    model.param_dict.update(dict(
        zip(param_names,
            param)))  ##update model.param_dict with pairs (param_names:params)

    try:
        model.mock.populate()
    except:
        model.populate_mock(halocat)

    gc.collect()

    output = []

    pos_gals_d = return_xyz_formatted_array(*(model.mock.galaxy_table[ax] for ax in 'xyz'), \
            velocity=model.mock.galaxy_table['vz'], velocity_distortion_dimension='z',\
                                          period=Lbox)             ##redshift space distorted
    pos_gals_d = np.array(pos_gals_d, dtype=float)

    vpf = void_prob_func(pos_gals_d,
                         r_vpf,
                         random_sphere_centers=vpf_centers,
                         period=Lbox)
    wprp = wp(pos_gals_d, r_wp, pi_max, period=Lbox)
    Pcic = np.bincount(counts_in_cylinders(pos_gals_d, pos_gals_d, proj_search_radius, \
            cylinder_half_length,period=Lbox), minlength=100)[1:71]/float(pos_gals_d.shape[0])

    func = np.concatenate((np.array(
        (pos_gals_d.shape[0] / float(Lbox**3), )), wprp, vpf, Pcic))

    output.append(func)

    # parameter set
    output.append(param)

    output.append(np.where(param - median_w != 0)[0][0])

    return output
コード例 #11
0
                            min_ptcl * cat.pmass]  #mass cut
galaxy_catalog = halo_catalog[halo_catalog[mag_key] < mag_cut]  # mag cut

if shuffle_type:
    sham_pos = np.c_[galaxy_catalog['halo_%s_x'%shuffle_type],\
                 galaxy_catalog['halo_%s_y'%shuffle_type],\
                 galaxy_catalog['halo_%s_z'%shuffle_type]]
else:
    sham_pos = np.c_[galaxy_catalog['halo_x'],\
                 galaxy_catalog['halo_y'],\
                 galaxy_catalog['halo_z']]

y = np.log10(
    wp(sham_pos * cat.h,
       rp_bins,
       40.0 * cat.h,
       period=cat.Lbox * cat.h,
       num_threads=1))
obs_nd = len(galaxy_catalog) * 1.0 / ((cat.Lbox * cat.h)**3)

wp_vals = []
nds = []
for i in xrange(50):
    cat.populate(em_params)
    wp_vals.append(cat.calc_wp(rp_bins, 40))
    nds.append(cat.calc_number_density())
#y = np.mean(np.log10(np.array(wp_vals)),axis = 0 )
# TODO need a way to get a measurement cov for the shams
cov = np.cov(np.log10(np.array(wp_vals).T))  #/np.sqrt(50)

#obs_nd = np.mean(np.array(nds))
コード例 #12
0
ファイル: wp_tutorial.py プロジェクト: mjvakili/gambly
def proj_clustering(pos , rbins, pbins , cellsize):

    return wp(sample1 = pos, rp_bins = rbins, 
              pi_bins = pbins, sample2 = None, 
              period = np.array([250,250,250]), approx_cell1_size = cellsize)