示例#1
0
def make_galcat(aa, save=True):
    '''do HOD with Zheng model using nbodykit'''
    zz = tools.atoz(aa)
    print('Redshift = %0.2f' % zz)
    halocat = readincatalog(aa)
    #Do hod
    ofolder = project + '/%s/fastpm_%0.4f/' % (sim, aa)
    galcat = dohod.make_galcat(halocat, ofolder, z=zz, pm=pm)
    if save:
        colsave = [cols for cols in galcat.columns]
        galcat.save(ofolder + 'galcat', colsave)
        print('Galaxies saved at path\n%s' % ofolder)
示例#2
0
def assignH1mass(aa, save=True):
    '''assign H1 masses to halos based on numbers from arxiv...'''
    zz = tools.atoz(aa)
    print('Redshift = %0.2f' % zz)

    halocat = readincatalog(aa)
    #Do hod
    ofolder = project + '/%s/fastpm_%0.4f/' % (sim, aa)
    halocat['H1mass'] = dohod.assignH1mass(halocat, z=zz)

    if save:
        colsave = [cols for cols in halocat.columns]
        colsave = ['ID', 'Position', 'Mass', 'H1mass']
        print(colsave)
        halocat.save(ofolder + 'halocat', colsave)
        print('Halos saved at path\n%s' % ofolder)
示例#3
0
import tools, dohod
from time import time

dpath = '/project/projectdirs/m3127/H1mass/'
myscratch = '/global/cscratch1/sd/chmodi/m3127/H1mass/'
# dpath = '../data/'

bs, nc = 256, 256
pm = ParticleMesh(BoxSize=bs, Nmesh=[nc, nc, nc])
# sim = '/lowres/%d-9100-fixed'%256
sim = '/highres/%d-9100-fixed' % 2560
aafiles = np.array(
    [0.1429, 0.1538, 0.1667, 0.1818, 0.2000, 0.2222, 0.2500, 0.2857, 0.3333])

#aafiles = aafiles[:1]
zzfiles = np.array([round(tools.atoz(aa), 2) for aa in aafiles])

hpos, hmass, hid, h1mass = tools.readinhalos(aafiles, sim)

print('Bin Halos')
hbins, hcount, hm, hh1 = {}, {}, {}, {}
dmesh, pkm = {}, {}
for iz, zz in enumerate(zzfiles):

    print('For redshift : ', zz)
    #measure power
    dmesh[zz] = BigFileMesh(
        dpath + sim + '/fastpm_%0.4f/' % aafiles[iz] + '/dmesh_N%04d' % nc,
        '1').paint()
    pk = FFTPower(dmesh[zz] / dmesh[zz].cmean(), mode='1d').power
    k, pkm = pk['k'], pk['power']
示例#4
0
args = parser.parse_args()

boxsize = args.size
amp = args.amp
res = args.res

#Global, fixed things
scratchyf = '/global/cscratch1/sd/yfeng1/m3127/'
project = '/project/projectdirs/m3127/H1mass/'
myscratch = '/global/cscratch1/sd/chmodi/m3127/H1mass/'
cosmodef = {'omegam': 0.309167, 'h': 0.677, 'omegab': 0.048}
aafiles = [
    0.1429, 0.1538, 0.1667, 0.1818, 0.2000, 0.2222, 0.2500, 0.2857, 0.3333
]
#aafiles = aafiles[4:]
zzfiles = [round(tools.atoz(aa), 2) for aa in aafiles]

#Paramteres
if res == 'high':
    if boxsize == 'small':
        bs, nc, ncsim, sim, prefix = 256, 512, 2560, 'highres/%d-9100-fixed' % 2560, 'highres'
    elif boxsize == 'big':
        bs, nc, ncsim, sim, prefix = 1024, 1024, 10240, 'highres/%d-9100-fixed' % 10240, 'highres'
else:
    bs, nc, ncsim, sim, prefix = 256, 256, 256, 'lowres/%d-9100-fixed' % 256, 'lowres'

if amp is not None:
    if amp == 'up' or amp == 'dn': sim = sim + '-%s' % amp
    else:
        print(
            'Amplitude not understood. Should be "up" or "dn". Given : {}. Fallback to fiducial'
示例#5
0
def make_galcat(aa,
                mmin,
                m1f,
                alpha=-1,
                censuff=None,
                satsuff=None,
                ofolder=None,
                seed=3333):
    '''Assign 0s to 
    '''
    zz = tools.atoz(aa)
    #halocat = readincatalog(aa)
    halocat = BigFileCatalog(scratch + sim + '/fastpm_%0.4f/' % aa,
                             dataset='LL-0.200')
    rank = halocat.comm.rank

    halocat.attrs['BoxSize'] = np.broadcast_to(halocat.attrs['BoxSize'], 3)

    ghid = halocat.Index.compute()
    halocat['GlobalIndex'] = ghid
    mp = halocat.attrs['MassTable'][1] * 1e10
    halocat['Mass'] = halocat['Length'] * mp
    halocat['Position'] = halocat[
        'Position'] % bs  # Wrapping positions assuming periodic boundary conditions
    rank = halocat.comm.rank

    halocat = halocat.to_subvolumes()

    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()
    ghid = halocat['GlobalIndex'].compute()

    print('In rank = %d, Catalog size = ' % rank, hmass.size)
    #Do hod
    start = time()
    ncen = np.ones_like(hmass)
    nsat = hod.nsat_martin(msat=mmin, mh=hmass, m1f=m1f, alpha=alpha).astype(
        int)  #this needs to be addresseed

    #Centrals
    cpos, cvel, gchid, chid = hpos, hvel, ghid, np.arange(ncen.size)
    spos, svel, shid = hod.mksat(nsat,
                                 pos=hpos,
                                 vel=hvel,
                                 vdisp=vdisp,
                                 conc=7,
                                 rvir=rvir,
                                 vsat=0.5,
                                 seed=seed)
    gshid = ghid[shid]
    svelh1 = svel * 2 / 3 + cvel[shid] / 3.

    smmax = hmass[shid] / 10.
    smmin = np.ones_like(smmax) * mmin
    mask = smmin > smmax / 3.  #Some fudge that should be discussed
    smmin[mask] = smmax[mask] / 3.
    smass = hod.get_msat(hmass[shid], smmax, smmin, alpha)

    sathmass = np.zeros_like(hmass)
    tot = np.bincount(shid, smass)
    sathmass[np.unique(shid)] = tot

    cmass = hmass - sathmass  # assign remaining mass in centrals

    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())
    #
    #Save
    cencat = ArrayCatalog(
        {
            'Position': cpos,
            'Velocity': cvel,
            'Mass': cmass,
            'GlobalID': gchid,
            'Nsat': nsat,
            'HaloMass': hmass
        },
        BoxSize=halocat.attrs['BoxSize'],
        Nmesh=halocat.attrs['NC'])
    minid, maxid = cencat['GlobalID'].compute().min(
    ), cencat['GlobalID'].compute().max()
    if minid < 0 or maxid < 0:
        print('before ', rank, minid, maxid)
    cencat = cencat.sort('GlobalID')
    minid, maxid = cencat['GlobalID'].compute().min(
    ), cencat['GlobalID'].compute().max()
    if minid < 0 or maxid < 0:
        print('after ', rank, minid, maxid)

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

    satcat = ArrayCatalog(
        {
            'Position': spos,
            'Velocity': svel,
            'Velocity_HI': svelh1,
            'Mass': smass,
            'GlobalID': gshid,
            'HaloMass': hmass[shid]
        },
        BoxSize=halocat.attrs['BoxSize'],
        Nmesh=halocat.attrs['NC'])
    minid, maxid = satcat['GlobalID'].compute().min(
    ), satcat['GlobalID'].compute().max()
    if minid < 0 or maxid < 0:
        print('before ', rank, minid, maxid)
    satcat = satcat.sort('GlobalID')
    minid, maxid = satcat['GlobalID'].compute().min(
    ), satcat['GlobalID'].compute().max()
    if minid < 0 or maxid < 0:
        print('after ', rank, minid, maxid)

    if satsuff is not None:
        colsave = [cols for cols in satcat.columns]
        satcat.save(ofolder + 'satcat' + satsuff, colsave)
示例#6
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)