コード例 #1
0
ファイル: zaemulus_fullrun.py プロジェクト: kokron/ZAemulus
def advected_field(cat, field_late, weight, nmesh):
    '''
    Get the advected component field with the weights given by the 'weight' column.

    Input:
        -cat: catalog of galaxy positions, assumed to have dimensions [3, N] right now
        -field_late: late-time density field (the delta_1 component) which is needed to 
            prevent an nbodykit bug when placing down weights
        -weight: the early time component field used for the weights. See Note about 1-1 mapping
        -nmesh: Nmesh for the late-time advected field. Can be different from the grid value of the component field.
    Output:
        -field_complate: late-time, advected component field for the given input weights.

    Notes: In ZAemulus it's assumed that there's a clear 1-1 mapping between positions
    and particle since this comes from reshaping the grids. This has to be changed for
    a more realistic particle catalog.
    '''
    Lbox = field_late.BoxSize[0]

    nbodycat = np.empty(nmesh**3,
                        dtype=[('Position', ('f8', 3)), ('Weight', 'f8')])
    nbodycat['Position'] = cat.T
    #Collapse the weight grids into catalog shape.
    #Need to change this for future runs.
    #+1 is needed if subtracting from field_late
    nbodycat['Weight'] = weight.value.reshape(nmesh**3) + 1

    nbkcat = ArrayCatalog(nbodycat, Nmesh=nmesh, BoxSize=Lbox)
    mesh = nbkcat.to_mesh(Nmesh=nmesh, BoxSize=Lbox, weight='Weight')

    #Paint and subtract from late field to avoid annoying nbodykit bugs
    field_component_late = (mesh.paint(mode='real') - 1)
    field_component_late -= field_late

    return field_component_late
コード例 #2
0
ファイル: zaemulus_fullrun.py プロジェクト: kokron/ZAemulus
def cat_to_mesh(cat, Lbox, Nmesh):
    '''
    Convert the late-time particle catalog to a friendly neighbourhood mesh
    Input:
        -cat: format is [Npos, Nparticles]
        -Lbox: units are Mpc/h
        -Nmesh: size of mesh you want to deposit particles in
    Output:
        -mesh
    '''
    nbodycat = np.empty(nmesh**3, dtype=[('Position', ('f8', 3))])
    nbodycat['Position'] = cat.T

    nbkcat = ArrayCatalog(nbodycat, Nmesh=nmesh, BoxSize=Lbox)
    mesh = nbkcat.to_mesh(Nmesh=nmesh, BoxSize=Lbox)

    field = (mesh.paint(mode='real') - 1)
    return field
コード例 #3
0
f = ArrayCatalog(data)

print(f)
print("columns = ", f.columns)  # default Weight,Selection also present
print("total size = ", f.csize)

f = ArrayCatalog({'Position': data['Position'], 'Mass': data['Mass']})

print(f)
print("columns = ", f.columns)  # default Weight,Selection also present
print("total size = ", f.csize)

# convert to a MeshSource, using CIC interpolation on 1280^3 mesh
mesh = f.to_mesh(window='cic',
                 Nmesh=1280,
                 BoxSize=4000.0,
                 compensated=True,
                 interlaced=True)

rfield = mesh.compute()
cfield = (rfield - 1).r2c()

cfield_real = np.zeros((1280, 1280, 641), dtype=float)
cfield_imag = np.zeros((1280, 1280, 641), dtype=float)
for i in np.arange(1280):
    print(i)
    for j in np.arange(1280):
        for k in np.arange(641):
            cfield_real[i][j][k] = cfield[i][j][k].real
            cfield_imag[i][j][k] = cfield[i][j][k].imag