예제 #1
0
def test_lognormal_box():
    """Generate log-normal density field in box."""
    # Realise Gaussian box
    np.random.seed(11)
    box = CosmoBox(cosmo=default_cosmo,
                   box_scale=(1e2, 1e2, 1e2),
                   nsamp=16,
                   realise_now=True)

    # Apply log-normal transform
    delta_log = box.lognormal(box.delta_x)

    # Check that log-normal density field is valid
    assert delta_log.shape == (16, 16, 16)
    # assert delta_log.dtype == np.float64
    assert np.all(~np.isnan(delta_log))
    assert np.all(delta_log >= -1.)  # delta_log >= -1
예제 #2
0
# (1a) Generate Gaussian box
np.random.seed(10)
box = CosmoBox(cosmo=default_cosmo,
               box_scale=(4e3, 4e3, 4e3),
               nsamp=128,
               redshift=0.8,
               realise_now=False)
box.realise_density()

# (1b) Rescale tracer by bias [FIXME: Check this is being done in the right order]
tracer = fastbox.tracers.HITracer(box)
delta_hi = box.delta_x * tracer.bias_HI()

# (1c) Transform to a log-normal field
delta_ln = box.lognormal(delta_hi)

# (1d) Calculate radial velocity field (uses Gaussian density field; FIXME)
vel_k = box.realise_velocity(delta_x=box.delta_x, inplace=True)
vel_z = fft.ifftn(
    vel_k[2]).real  # inverse FFT to get real-space radial velocity

# (1e) Transform to redshift space
delta_s = box.redshift_space_density(delta_x=delta_ln.real,
                                     velocity_z=vel_z,
                                     sigma_nl=120.,
                                     method='linear')

# (1f) Scale by mean brightness temperature (in mK), and include mean
signal_cube = tracer.signal_amplitude() * (1. + delta_s)
예제 #3
0
import time

# Use linear matter power for log-normal field
default_cosmo['matter_power_spectrum'] = 'linear'

# Gaussian box
np.random.seed(10)
box = CosmoBox(cosmo=default_cosmo,
               box_scale=(1e3, 1e3, 1e3),
               nsamp=128,
               realise_now=False)
box.realise_density()
box.realise_velocity()

# Log-normal field and power spectrum
delta_log = box.lognormal(box.delta_x)
#logn_k, logn_pk, logn_stddev = box.binned_power_spectrum(delta_x=delta_log)

# Convert to nbodykit mesh
mesh = ArrayMesh(box.delta_x, BoxSize=box.Lx)
mesh2 = ArrayMesh(delta_log, BoxSize=box.Lx)

# Putting BoxSize in Mpc units (instead of Mpc/h) produces output in Mpc units
corrfn = FFTCorr(first=mesh,
                 mode='1d',
                 BoxSize=(box.Lx, box.Ly, box.Lz),
                 second=None,
                 los=[0, 0, 1],
                 Nmu=5,
                 dr=2.,
                 rmin=10.0,
예제 #4
0
# Gaussian box
np.random.seed(10)
box = CosmoBox(cosmo=default_cosmo,
               box_scale=(2e3, 2e3, 2e3),
               nsamp=64,
               realise_now=False)
box.realise_density()

# Gaussian box with beam smoothing and foreground cut
#transfer_fn = lambda k_perp, k_par: \
#    (1. - np.exp(-0.5 * (k_par/0.00001)**2.)) \
#    * 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),