Example #1
0
                assert action == 'F'
                yield action, af, ac, ai
            stack = []
        elif action == 'F':
            # need to do F after D to ensure the time tag is right.
            assert ac == af
            stack.append((action, af, ai, ai))
        else:
            yield action, af, ac, ai

print(list(leapfrog(stages)))
print('----')
print(list(gorfpael(stages)))
print('++++')
print(list(leapfrog(stages[::-1])))

state = solver.nbody(lpt.copy(), leapfrog(stages), monitor=monitor)
if pm.comm.rank == 0:
    print('----------------')
reverse = solver.nbody(state, leapfrog(stages[::-1]), monitor=monitor)
#print((lpt.X - reverse.X).max())

assert_allclose(lpt.X, reverse.X)

cat1 = ArrayCatalog({'Position' : lpt.X}, BoxSize=pm.BoxSize, Nmesh=pm.Nmesh)
cat2 = ArrayCatalog({'Position' : reverse.X}, BoxSize=pm.BoxSize, Nmesh=pm.Nmesh)

cat1.save('Janus/Truth', ('Position',))
cat2.save('Janus/Reverse', ('Position',))

Example #2
0
#    * np.exp(-0.5 * (k_perp/0.05)**2.)
#delta_smoothed = box.apply_transfer_fn(box.delta_k, transfer_fn=transfer_fn)

delta_ln = box.lognormal(delta_x=box.delta_x)

# Create halo distribution
halos = HaloDistribution(box, mass_range=(1e12, 1e15), mass_bins=10)
Nhalos = halos.halo_count_field(box.delta_x, nbar=1e-3, bias=1.)
#Nhalos2 = halos.halo_count_field(box.delta_x, nbar=1e-3, bias=1.)
halo_cat = halos.realise_halo_catalogue(Nhalos,
                                        scatter=True,
                                        scatter_type='uniform')
#halo_cat2 = halos.realise_halo_catalogue(Nhalos, scatter=True, scatter_type='uniform')

# Project catalogue onto mesh
array_cat = ArrayCatalog({'Position': halo_cat})
#array_cat2 = ArrayCatalog({'Position': halo_cat2})
mesh_cat = array_cat.to_mesh(Nmesh=box.N,
                             BoxSize=(box.Lx, box.Ly, box.Lz),
                             window='tsc',
                             compensated=True)
#mesh_cat2 = array_cat2.to_mesh(Nmesh=box.N, BoxSize=(box.Lx, box.Ly, box.Lz),
#                               window='tsc', compensated=True)

# Put density field onto mesh
mesh_delta = ArrayMesh(box.delta_x, BoxSize=(box.Lx, box.Ly, box.Lz))
#mesh_delta = ArrayMesh(delta_ln, BoxSize=(box.Lx, box.Ly, box.Lz))

# Calculate power spectra
pspec1 = FFTPower(first=mesh_cat, mode='1d', second=None, los=[0, 0, 1], Nmu=5)
pspec1.run()
Example #3
0
def make_galcat(aa,
                mmin,
                mcutc,
                m1,
                sigma=0.25,
                kappa=1,
                alpha=1,
                censuff=None,
                satsuff=None,
                seed=3333):
    '''do HOD with Zheng model using nbodykit'''
    zz = tools.atoz(aa)
    halocat = readincatalog(aa)
    rank = halocat.comm.rank
    if rank == 0:
        print('\n ############## Redshift = %0.2f ############## \n' % zz)

    hmass = halocat['Mass'].compute()
    hpos = halocat['Position'].compute()
    hvel = halocat['Velocity'].compute()
    rvir = HaloRadius(hmass, cosmo, 1 / aa - 1).compute() / aa
    vdisp = HaloVelocityDispersion(hmass, cosmo, 1 / aa - 1).compute()

    print('In rank = %d, Catalog size = ' % rank, hmass.size)
    #Do hod
    ofolder = myscratch + '/%s/fastpm_%0.4f/' % (sim, aa)
    try:
        os.makedirs(os.path.dirname(ofolder))
    except IOError:
        pass

    start = time()
    #(ncen, cpos, cvel), (nsat, spos, svel) = hod(seed*rank, hmass, halocat['Position'].compute(), halocat['Velocity'].compute(),\
    #                    conc=7, rvir=3, vdisp=1100, mcut=mcutc, m1=m1, sigma=0.25, \
    #                    kappa=kappa, alpha=alpha,vcen=0, vsat=0.5)

    (ncen, cpos, cvel), (nsat, spos, svel) = hod(seed*rank, hmass, hpos, hvel,
                        conc=7, rvir=rvir, vdisp=vdisp, mcut=mcutc, m1=m1, sigma=0.25, \
                        kappa=kappa, alpha=alpha, vcen=0, vsat=0.5)

    print('In rank = %d, Time taken = ' % rank, time() - start)
    print('In rank = %d, Number of centrals & satellites = ' % rank,
          ncen.sum(), nsat.sum())
    print('In rank = %d, Satellite occupancy: Max and mean = ' % rank,
          nsat.max(), nsat.mean())
    #
    #Assign mass to centrals
    hid = np.repeat(range(len(hmass)), ncen).astype(int)
    cmass = hmass[hid]
    cencat = ArrayCatalog(
        {
            'Position': cpos,
            'Velocity': cvel,
            'Mass': cmass,
            'HaloID': hid
        },
        BoxSize=halocat.attrs['BoxSize'],
        Nmesh=halocat.attrs['NC'])

    if censuff is not None:
        colsave = [cols for cols in cencat.columns]
        cencat.save(ofolder + 'cencat' + censuff, colsave)

    #
    #Assign mass to satellites
    hid = np.repeat(range(len(hmass)), nsat).astype(int)
    np.random.seed(seed * rank)

    smass = np.random.uniform(size=hid.size)
    mmax = hmass[hid] / 3.
    mmin = np.ones_like(mmax) * mmin
    mask = mmin > hmass[hid] / 10.  #Some fudge that should be discussed
    mmin[mask] = hmass[hid][mask] / 10.
    #smass = mmin * mmax / ((1-smass)*mmax + smass*mmin)
    smass = hmass[hid] * assign_msat(smass, mmin / hmass[hid],
                                     mmax / hmass[hid], alpha)

    satcat = ArrayCatalog(
        {
            'Position': spos,
            'Velocity': svel,
            'Mass': smass,
            'HaloID': hid
        },
        BoxSize=halocat.attrs['BoxSize'],
        Nmesh=halocat.attrs['NC'])
    if satsuff is not None:
        colsave = [cols for cols in satcat.columns]
        satcat.save(ofolder + 'satcat' + satsuff, colsave)