コード例 #1
0
ファイル: calculate_ee_nhalo.py プロジェクト: ssamuroff/mbii
def compute_ee(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'])

    ee_1h, ee_2h = ee_3d(pvec2,
                         avec2,
                         hids2,
                         pvec1,
                         avec1,
                         hids1,
                         rbins,
                         period=period,
                         num_threads=1)

    return ee_1h, ee_2h
コード例 #2
0
ファイル: calculate_ee.py プロジェクト: ssamuroff/mbii
def compute_ee(cat1, cat2, options, period=100., rbins=None, nbins=6):

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

    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

    ee = ee_3d(pvec2[mask2],
               avec2[mask2],
               pvec1[mask1],
               avec1[mask1],
               rbins,
               period=period,
               num_threads=1)

    return ee
コード例 #3
0
def jackknife_ee_3d(sample1, orientations1, sample2, orientations2, 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, :] = ee_3d(sample1[mask1], orientations1[mask1],
                              sample2[mask2], orientations2[mask2], rbins,
                              period=period, num_threads=num_threads,
                              approx_cell1_size=None, approx_cell2_size=None)

        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
コード例 #4
0
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
コード例 #5
0
ファイル: untitled.py プロジェクト: ssamuroff/mbii
cat2 = data[np.invert(mask)]
cat0 = data
data_sym = fi.FITS(options['2pt']['shapes'].replace('.fits', '-symmetrised.fits'))[-1].read()
cat1_sym = data_sym[mask]
cat2_sym = data_sym[np.invert(mask)]
cat0_sym = data_sym


avec2 = np.vstack((cat2_sym['a1'], cat2_sym['a2'], cat2_sym['a3'])).T
avec1 = np.vstack((cat2_sym['a1'], cat2_sym['a2'], cat2_sym['a3'])).T
pvec1 = np.vstack((cat2['x'], cat2['y'], cat2['z'])).T
pvec2 = np.vstack((cat2['x'], cat2['y'], cat2['z'])).T
rbins = np.logspace(np.log10(options['2pt']['rmin']), np.log10(options['2pt']['rmax']), options['2pt']['nbin'])

period=100.
ee = ee_3d(pvec2, avec2, pvec1, avec1, rbins, period=period, num_threads=1)
pvec1 = np.vstack((cat2_sym['x'], cat2_sym['y'], cat2_sym['z'])).T                 
pvec2 = np.vstack((cat2_sym['x'], cat2_sym['y'], cat2_sym['z'])).T
ee0 = ee_3d(pvec2, avec2, pvec1, avec1, rbins, period=period, num_threads=1)

dee=ee0-ee

plt.close()
plt.subplot(211)
plt.plot(x, ee0, color='purple', ls='--', label='Symmetrised', lw=2.5)
plt.plot(x, ee, color='plum', ls=':', label='Symmetrised Shapes', lw=2.5)
plt.xscale('log')
plt.xlabel('$r$ / $h^{-1}$ Mpc', fontsize=18)
plt.ylim(1e-3,1e-1)
plt.ylabel('EE Correlation', fontsize=18)
plt.legend(loc='lower left')
コード例 #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_ee_3d
    from halotools.mock_observables.alignments import ee_3d

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

    N = 10
    ee = 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

        ee[i, :] = ee_3d(coords,
                         orientations,
                         coords,
                         orientations,
                         rbins,
                         period=halocat.Lbox)
        err = np.zeros(len(ee))

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

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