Exemplo n.º 1
0
def compute_ed(cat1, cat2, options, period=100., rbins=None, nbins=6):

    aname = 'a%d'
    if ('shapes_suffix' in options['2pt'].keys()):
        aname += options['2pt']['shapes_suffix']
        print('Using column %s' % aname)

    avec2 = np.vstack((cat2[aname % 1], cat2[aname % 2], cat2[aname % 3])).T
    avec1 = np.vstack((cat1[aname % 1], cat1[aname % 2], cat1[aname % 3])).T
    pvec1 = np.vstack((cat1['x'], cat1['y'], cat1['z'])).T
    pvec2 = np.vstack((cat2['x'], cat2['y'], cat2['z'])).T

    if options['2pt']['binning'] == 'log' and (rbins is None):
        rbins = np.logspace(np.log10(options['2pt']['rmin']),
                            np.log10(options['2pt']['rmax']), nbins + 1)
    elif options['2pt']['binning'] == 'equal' and (rbins is None):
        rbins = util.equalise_binning(cat1, cat2, options['2pt']['rmin'],
                                      options['2pt']['rmax'], nbins + 1)

    mask1 = avec1.T[0] != 0.0
    mask2 = avec2.T[0] != 0.0

    ed = ed_3d(pvec2[mask2],
               avec2[mask2],
               pvec1[mask1],
               rbins,
               period=period,
               num_threads=1)

    return ed
Exemplo n.º 2
0
def compute_ed(cat1, cat2, options, period=100., rbins=None):
    avec2 = np.vstack((cat2['a1'], cat2['a2'], cat2['a3'])).T
    avec1 = np.vstack((cat1['a1'], cat1['a2'], cat1['a3'])).T
    pvec1 = np.vstack((cat1['x'], cat1['y'], cat1['z'])).T
    pvec2 = np.vstack((cat2['x'], cat2['y'], cat2['z'])).T
    hids1 = cat1['halo_id']
    hids2 = cat2['halo_id']

    if options['2pt']['binning'] == 'log' and (rbins is None):
        rbins = np.logspace(np.log10(options['2pt']['rmin']),
                            np.log10(options['2pt']['rmax']),
                            options['2pt']['nbin'])
    elif options['2pt']['binning'] == 'equal' and (rbins is None):
        rbins = util.equalise_binning(cat1, cat2, options['2pt']['rmin'],
                                      options['2pt']['rmax'],
                                      options['2pt']['nbin'])

    ed_1h, ed_2h = ed_3d(pvec2,
                         avec2,
                         hids2,
                         pvec1,
                         hids1,
                         rbins,
                         period=period,
                         num_threads=1)

    return ed_1h, ed_2h
Exemplo n.º 3
0
def jackknife_ed_3d(sample1, orientations1, sample2, rbins,
                    Nsub=[5, 5, 5], period=None,
                    num_threads=1, verbose=False,
                    approx_cell1_size=None, approx_cell2_size=None):
    """
    """

    sample1, sample2, j_index_1, j_index_2, Nsub, N_sub_vol, Lbox, PBCs =\
        _process_args(sample1, sample2, period, Nsub)

    # loop through jackknife samples (note that zero is not used as a label)
    results = np.zeros((N_sub_vol+1, len(rbins)-1))
    for i in range(0, N_sub_vol+1):
        start = time.time()

        # remove one sample at a time
        mask1 = (j_index_1 != i)
        mask2 = (j_index_2 != i)

        results[i, :] = ed_3d(sample1[mask1], orientations1[mask1],
                              sample2[mask2], rbins,
                              period=period, num_threads=num_threads,
                              approx_cell1_size=approx_cell1_size,
                              approx_cell2_size=approx_cell2_size)

        dt = time.time()-start
        if (verbose is True) & (i == 0):
            print("estimated time to complete jackknife",
                  "calculation (s): {0}".format(dt*N_sub_vol))

    # get jackknife samples
    result_sub = results[1:, :]

    # get full sample result
    # result = results[0, :]
    result = np.mean(result_sub, axis=0)

    # calculate the covariance matrix
    cov = np.matrix(np.cov(result_sub.T, bias=True))*(N_sub_vol-1.0)

    return result, cov
def calculate_ed_ee(halocat, central_alignment_strength, satellite_alignment_strength, rbins):


    gal_sample_mask = (halocat.halo_table['halo_mpeak']>10**12.0)


    table = halocat.halo_table[gal_sample_mask]

    # satellite position model
    satellite_position_model = SubHaloPositions()
    table = Table(np.copy(satellite_position_model.assign_gal_type(table=table)))
    table = Table(np.copy(satellite_position_model.assign_positions(table=table)))

    # central alignment model
    cen_alignment_model = CentralAlignment(central_alignment_strength=central_alignment_strength)
    table = Table(np.copy(cen_alignment_model.assign_central_orientation(table=table)))

    # satellite alignment model
    sat_alignment_model = SatelliteAlignment(satellite_alignment_strength=satellite_alignment_strength)
    table = Table(np.copy(sat_alignment_model.assign_satellite_orientation(table=table)))

    # calculate observables
    galaxy_coords = np.vstack((table['x'],
                               table['y'],
                               table['z'])).T

    galaxy_orientations = np.vstack((table['galaxy_axisA_x'],
                                     table['galaxy_axisA_y'],
                                     table['galaxy_axisA_z'])).T

    gal_omega = ed_3d(galaxy_coords, galaxy_orientations,
                           galaxy_coords,
                           rbins, period=halocat.Lbox, num_threads=4)

    gal_eta = ee_3d(galaxy_coords, galaxy_orientations,
                         galaxy_coords, galaxy_orientations,
                         rbins, period=halocat.Lbox, num_threads=4)

    return gal_omega, gal_eta
Exemplo n.º 5
0
def main():

    nu_cens = np.linspace(0,1,2)
    nu_sats = np.linspace(-0.3,0.8, 2)

    # get simulation information
    if len(sys.argv)>1:
        sim_name = sys.argv[1]
        snapnum = int(sys.argv[2])
        shape_type = sys.argv[3]
        sample_name = sys.argv[4]
    else:
        sim_name = 'TNG300-1' # full physics high-res run
        snapnum = 99  # z=0
        shape_type = 'reduced'  # non-reduced, reduced, iterative
        sample_name = 'sample_3'

    # load a test halo catalog
    from halotools.sim_manager import CachedHaloCatalog
    halocat = CachedHaloCatalog(simname='bolplanck', halo_finder='rockstar',
                                redshift=0.0, dz_tol=0.1, version_name='halotools_v0p4')

    from halotools.empirical_models import HodModelFactory

    # define the central occupatoion model
    from halotools.empirical_models import TrivialPhaseSpace, Zheng07Cens
    cens_occ_model =  Zheng07Cens()
    cens_prof_model = TrivialPhaseSpace()

    # define the satellite occupation model
    from halotools.empirical_models import Zheng07Sats
    from halotools.empirical_models import NFWPhaseSpace, SubhaloPhaseSpace
    from intrinsic_alignments.ia_models.anisotropic_nfw_phase_space import AnisotropicNFWPhaseSpace
    sats_occ_model =  Zheng07Sats()
    #sats_prof_model = AnisotropicNFWPhaseSpace()
    sats_prof_model = SubhaloPhaseSpace('satellites', np.logspace(10.5, 15.2, 15))

    # define the alignment models
    from intrinsic_alignments.ia_models.ia_model_components import CentralAlignment,\
        RadialSatelliteAlignment,  MajorAxisSatelliteAlignment, HybridSatelliteAlignment
    central_orientation_model = CentralAlignment()
    satellite_orientation_model = RadialSatelliteAlignment()

    if sample_name == 'sample_1':
        cens_occ_model.param_dict['logMmin'] = 12.54
        cens_occ_model.param_dict['sigma_logM'] = 0.26

        sats_occ_model.param_dict['alpha'] = 1.0
        sats_occ_model.param_dict['logM0'] = 12.68
        sats_occ_model.param_dict['logM1'] = 13.48

        central_orientation_model.param_dict['central_alignment_strength'] = 0.755
        satellite_orientation_model.param_dict['satellite_alignment_strength'] = 0.279
    elif sample_name == 'sample_2':
        cens_occ_model.param_dict['logMmin'] = 11.93
        cens_occ_model.param_dict['sigma_logM'] = 0.26

        sats_occ_model.param_dict['alpha'] = 1.0
        sats_occ_model.param_dict['logM0'] = 12.05
        sats_occ_model.param_dict['logM1'] = 12.85

        central_orientation_model.param_dict['central_alignment_strength'] = 0.64
        satellite_orientation_model.param_dict['satellite_alignment_strength'] = 0.084
    elif sample_name =='sample_3':
        cens_occ_model.param_dict['logMmin'] = 11.61
        cens_occ_model.param_dict['sigma_logM'] = 0.26

        sats_occ_model.param_dict['alpha'] = 1.0
        sats_occ_model.param_dict['logM0'] = 11.8
        sats_occ_model.param_dict['logM1'] = 12.6

        central_orientation_model.param_dict['central_alignment_strength'] = 0.57172919
        satellite_orientation_model.param_dict['satellite_alignment_strength'] = 0.01995

    # combine model components
    model_instance = HodModelFactory(centrals_occupation = cens_occ_model,
                                 centrals_profile = cens_prof_model,
                                 satellites_occupation = sats_occ_model,
                                 satellites_profile = sats_prof_model,
                                 centrals_orientation = central_orientation_model,
                                 satellites_orientation = satellite_orientation_model,
                                 model_feature_calling_sequence = (
                                 'centrals_occupation',
                                 'centrals_profile',
                                 'satellites_occupation',
                                 'satellites_profile',
                                 'centrals_orientation',
                                 'satellites_orientation')
                                )
    
    from intrinsic_alignments.utils.jackknife_observables import jackknife_ed_3d
    from halotools.mock_observables.alignments import ed_3d

    rbins = np.logspace(-1,1.5,15)
    rbin_centers = (rbins[:-1]+rbins[1:])/2.0

    N1 = len(nu_cens)
    N2 = len(nu_sats)
    
    fpath = fpath = PROJECT_DIRECTORY + 'modelling_illustris/data/'
    fname = sim_name + '_' + str(snapnum) + '-' + sample_name +'_model_ed_grid.dat'

    outF = open(fpath + fname, "w")
    
    for i in range(0,N1):
        for j in range(0,N2):

            print(i, j)

            # assign parameters
            central_orientation_model.param_dict['central_alignment_strength'] = nu_cens[i]
            satellite_orientation_model.param_dict['satellite_alignment_strength'] = nu_sats[j]
            
            # populate mock catalog
            start = time.time()
            model_instance.populate_mock(halocat)
            print("time to populate mock: ", time.time() - start)

            mock = model_instance.mock.galaxy_table

            # galaxy coordinates and orientations
            coords = np.vstack((mock['x'],
                                mock['y'],
                                mock['z'])).T

            orientations = np.vstack((mock['galaxy_axisA_x'],
                                      mock['galaxy_axisA_y'],
                                      mock['galaxy_axisA_z'])).T

            # calculate ED
            start = time.time()
            ed = ed_3d(coords, orientations,coords,
                       rbins, period=halocat.Lbox,
                       num_threads=4)
            print("time to calculate ED stat: ", time.time() - start)

            # calculate EE
            start = time.time()
            ee = ee_3d(coords, orientations, coords, orientations,
                       rbins, period=halocat.Lbox,
                       num_threads=4)
            print("time to calculate EE stat: ", time.time() - start)

            s = str(nu_cens[i]) + ' ' + str(nu_sats[j]) + ' ' + np.array_str(ed)[1:-1] + ' ' + np.array_str(ee)[1:-1]
            outF.write(s)
            outF.write("\n")
    
    outF.close()
Exemplo n.º 6
0
def main():

    # get simulation information
    if len(sys.argv) > 1:
        sim_name = sys.argv[1]
        snapnum = int(sys.argv[2])
        shape_type = sys.argv[3]
        sample_name = sys.argv[4]
    else:
        sim_name = 'TNG300-1'  # full physics high-res run
        snapnum = 99  # z=0
        shape_type = 'reduced'  # non-reduced, reduced, iterative
        sample_name = 'sample_3'

    # load a test halo catalog
    from halotools.sim_manager import CachedHaloCatalog
    halocat = CachedHaloCatalog(simname='bolplanck',
                                halo_finder='rockstar',
                                redshift=0.0,
                                dz_tol=0.1,
                                version_name='halotools_v0p4')

    from halotools.empirical_models import HodModelFactory

    # define the central occupatoion model
    from halotools.empirical_models import TrivialPhaseSpace, Zheng07Cens
    cens_occ_model = Zheng07Cens()
    cens_prof_model = TrivialPhaseSpace()

    # define the satellite occupation model
    from halotools.empirical_models import Zheng07Sats
    from halotools.empirical_models import NFWPhaseSpace, SubhaloPhaseSpace
    from intrinsic_alignments.ia_models.anisotropic_nfw_phase_space import AnisotropicNFWPhaseSpace
    sats_occ_model = Zheng07Sats()
    #sats_prof_model = AnisotropicNFWPhaseSpace()
    sats_prof_model = SubhaloPhaseSpace('satellites',
                                        np.logspace(10.5, 15.2, 15))

    # define the alignment models
    from intrinsic_alignments.ia_models.ia_model_components import CentralAlignment,\
        RadialSatelliteAlignment,  MajorAxisSatelliteAlignment, HybridSatelliteAlignment
    central_orientation_model = CentralAlignment()
    satellite_orientation_model = RadialSatelliteAlignment()

    if sample_name == 'sample_1':
        cens_occ_model.param_dict['logMmin'] = 12.54
        cens_occ_model.param_dict['sigma_logM'] = 0.26

        sats_occ_model.param_dict['alpha'] = 1.0
        sats_occ_model.param_dict['logM0'] = 12.68
        sats_occ_model.param_dict['logM1'] = 13.48

        central_orientation_model.param_dict[
            'central_alignment_strength'] = 0.755
        satellite_orientation_model.param_dict[
            'satellite_alignment_strength'] = 0.279
    elif sample_name == 'sample_2':
        cens_occ_model.param_dict['logMmin'] = 11.93
        cens_occ_model.param_dict['sigma_logM'] = 0.26

        sats_occ_model.param_dict['alpha'] = 1.0
        sats_occ_model.param_dict['logM0'] = 12.05
        sats_occ_model.param_dict['logM1'] = 12.85

        central_orientation_model.param_dict[
            'central_alignment_strength'] = 0.64
        satellite_orientation_model.param_dict[
            'satellite_alignment_strength'] = 0.084
    elif sample_name == 'sample_3':
        cens_occ_model.param_dict['logMmin'] = 11.61
        cens_occ_model.param_dict['sigma_logM'] = 0.26

        sats_occ_model.param_dict['alpha'] = 1.0
        sats_occ_model.param_dict['logM0'] = 11.8
        sats_occ_model.param_dict['logM1'] = 12.6

        central_orientation_model.param_dict[
            'central_alignment_strength'] = 0.57172919
        satellite_orientation_model.param_dict[
            'satellite_alignment_strength'] = 0.01995

    # combine model components
    model_instance = HodModelFactory(
        centrals_occupation=cens_occ_model,
        centrals_profile=cens_prof_model,
        satellites_occupation=sats_occ_model,
        satellites_profile=sats_prof_model,
        centrals_orientation=central_orientation_model,
        satellites_orientation=satellite_orientation_model,
        model_feature_calling_sequence=('centrals_occupation',
                                        'centrals_profile',
                                        'satellites_occupation',
                                        'satellites_profile',
                                        'centrals_orientation',
                                        'satellites_orientation'))

    from intrinsic_alignments.utils.jackknife_observables import jackknife_ed_3d
    from halotools.mock_observables.alignments import ed_3d

    rbins = np.logspace(-1, 1.5, 15)
    rbin_centers = (rbins[:-1] + rbins[1:]) / 2.0

    N = 10
    ed = np.zeros((N, len(rbins) - 1))
    for i in range(0, N):

        # populate mock catalog
        model_instance.populate_mock(halocat)
        print("number of galaxies: ", len(model_instance.mock.galaxy_table))

        mock = model_instance.mock.galaxy_table

        # galaxy coordinates and orientations
        coords = np.vstack((mock['x'], mock['y'], mock['z'])).T

        orientations = np.vstack(
            (mock['galaxy_axisA_x'], mock['galaxy_axisA_y'],
             mock['galaxy_axisA_z'])).T

        rbins = np.logspace(-1, 1.5, 15)
        rbin_centers = (rbins[:-1] + rbins[1:]) / 2.0

        ed[i, :] = ed_3d(coords,
                         orientations,
                         coords,
                         rbins,
                         period=halocat.Lbox)

    err = np.std(ed, axis=0)
    ed = np.mean(ed, axis=0)

    # save measurements
    fpath = fpath = PROJECT_DIRECTORY + 'modelling_illustris/data/'
    fname = sim_name + '_' + str(snapnum) + '-' + sample_name + '_model_ed.dat'
    ascii.write([rbin_centers, ed, err],
                fpath + fname,
                names=['r', 'ed', 'err'],
                overwrite=True)