示例#1
0
def test_box_transfer_function():
    """Check that a transfer function can be applied to the density field."""

    # Realise Gaussian box
    np.random.seed(11)
    box = CosmoBox(cosmo=default_cosmo,
                   box_scale=(1e2, 1e2, 1e2),
                   nsamp=16,
                   realise_now=True)

    # Gaussian box with beam smoothing and foreground cut
    transfer_fn = lambda k_perp, k_par: \
        (1. - np.exp(-0.5 * (k_par/0.001)**2.)) \
        * np.exp(-0.5 * (k_perp/0.1)**2.)
    delta_smoothed = box.apply_transfer_fn(box.delta_k,
                                           transfer_fn=transfer_fn)

    # Check that smoothed density field is valid
    assert delta_smoothed.shape == (16, 16, 16)
    # assert delta_smoothed.dtype == np.float64
    assert np.all(~np.isnan(delta_smoothed))
示例#2
0
mesh_proc4 = ArrayMesh(cleaned_cube4, BoxSize=boxsize)
mesh_proc8 = ArrayMesh(cleaned_cube8, BoxSize=boxsize)

# Correlation function of true signal
corrfn_true = FFTCorr(first=mesh_true,
                      mode='1d',
                      BoxSize=boxsize,
                      los=[0, 0, 1],
                      dr=2.,
                      rmin=20.0,
                      rmax=200.)
corr_true, _ = corrfn_true.run()

# Perform high-pass filter on foreground-cleaned data
highpass = lambda kperp, kpar: 1. - np.exp(-0.5 * (np.abs(kpar) / 0.009)**3.)
cleaned_cube4_hp = box.apply_transfer_fn(fft.fftn(cleaned_cube4),
                                         transfer_fn=highpass)
mesh_proc4_hp = ArrayMesh(cleaned_cube4_hp.real, BoxSize=boxsize)

# Correlation function of processed (FG-subtracted) signal
corrfn_proc4 = FFTCorr(first=mesh_proc4,
                       mode='1d',
                       BoxSize=boxsize,
                       los=[0, 0, 1],
                       dr=2.,
                       rmin=20.0,
                       rmax=200.)
corr_proc4, _ = corrfn_proc4.run()

# 4 modes subtracted, high-pass filtered
corrfn_proc4_hp = FFTCorr(first=mesh_proc4_hp,
                          mode='1d',
示例#3
0
#plt.plot(th_k, th_pk, 'k-')
#plt.plot(re_k, re_pk, 'r.')
#plt.plot(logn_k, logn_pk, 'bx')
#plt.plot(lnpk_data['k'], lnpk_data['power'], 'g+')
#plt.xscale('log')
#plt.yscale('log')
plt.show()


sys.exit(0)

# Gaussian box with beam smoothing and foreground cut
transfer_fn = lambda k_perp, k_par: \
    (1. - np.exp(-0.5 * (k_par/0.001)**2.)) \
    * np.exp(-0.5 * (k_perp/0.1)**2.)
delta_smoothed = box.apply_transfer_fn(box.delta_k, transfer_fn=transfer_fn)


plt.matshow(delta_smoothed[:,:,0].real, vmin=-1., vmax=2., cmap='cividis')
plt.title("Density field (smoothed, x,y)")
plt.colorbar()
#plt.show()

plt.matshow(delta_smoothed[:,0,:].real, vmin=-1., vmax=2., cmap='cividis')
plt.title("Density field (smoothed, x,z)")
plt.colorbar()
#plt.show()

# Log-normal box
smre_k, smre_pk, smre_stddev \
    = box.binned_power_spectrum(delta_k=fft.fftn(delta_smoothed))