Esempio n. 1
0
def compute_Pk(T_maps, BoxSize, fout):
    Pk = np.zeros((T_maps.shape[0], 45), dtype=np.float64)
    for i in range(T_maps.shape[0]):
        Pk_real = PKL.Pk_plane(T_maps[i],
                               BoxSize,
                               MAS='None',
                               threads=1,
                               verbose=False)
        k, Pk[i] = Pk_real.k, Pk_real.Pk
    np.savetxt(fout, np.transpose([k,
                                   np.mean(Pk, axis=0),
                                   np.std(Pk, axis=0)]))
    return k, np.mean(Pk, axis=0), np.std(Pk, axis=0)
# do a loop over all the maps
for i in numbers:

    if i % 10000 == 0: print(i)

    # get the value of the Pk
    Pk_in = A[i] * k_in**B

    # generate density field
    maps_partial[i] = DFL.gaussian_field_2D(grid, k_in, Pk_in,
                                            Rayleigh_sampling, seed[i],
                                            BoxSize, threads, verbose)

    # compute power spectrum
    Pk_partial[i] = PKL.Pk_plane(maps_partial[i], BoxSize, MAS, threads,
                                 verbose).Pk
    #np.savetxt('Pk1.txt', np.transpose([Pk.k, Pk.Pk, Pk.Nmodes]))
    #print(1.0/np.sqrt(np.sum(Pk.Nmodes)))

    # make some statistics
    #print(np.mean(maps[i]), np.min(maps[i]), np.max(maps[i]))

    # make image
    """
    fig=figure()
    ax1=fig.add_subplot(111) 

    cax = ax1.imshow(df,cmap=get_cmap('jet'),origin='lower',interpolation='spline36',
                     extent=[0, BoxSize, 0, BoxSize])
    #vmin=min_density,vmax=max_density)
    #norm = LogNorm(vmin=min_density,vmax=max_density))
Esempio n. 3
0
import numpy as np
import sys, os
import Pk_library as PKL

BoxSize = 75.0  #Mpc/h
MAS = 'CIC'
threads = 1
f1 = 'HI_Predicted_Full2.npy'
f2 = 'HI_Full_True.npy'

HI_pred = np.load(f1)
#HI_pred = HI_pred/np.mean(HI_pred) - 1.0
HI_true = np.load(f2)
#HI_true = HI_true/np.mean(HI_true) - 1.0
print HI_pred.shape
print HI_true.shape
print np.min(HI_true), np.max(HI_true), np.mean(HI_true)
print np.min(HI_pred), np.max(HI_pred), np.mean(HI_pred)

Pk = PKL.Pk_plane(HI_true, BoxSize, MAS, threads)
np.savetxt('Pk_true.txt', np.transpose([Pk.k, Pk.Pk]))

Pk = PKL.Pk_plane(HI_pred, BoxSize, MAS, threads)
np.savetxt('Pk_pred.txt', np.transpose([Pk.k, Pk.Pk]))
    # get the name of the output file
    fpk = '%s/%s/%d/Pk2D_m_z=%s.txt' % (folder_out, cosmo, i, z)
    if os.path.exists(fpk): continue

    # find the density field file and read it
    f_df = '%s/%s/%d/df_z=%s.npy' % (root, cosmo, i, z)
    if not (os.path.exists(f_df)): continue
    df = np.load(f_df)

    # create output folder if it does not exists
    if not (os.path.exists('%s/%s/%d' % (folder_out, cosmo, i))):
        os.system('mkdir %s/%s/%d' % (folder_out, cosmo, i))

    # compute matter Pk
    Pk = PKL.Pk_plane(df, BoxSize, MAS, threads)
    np.savetxt(fpk, np.transpose([Pk.k, Pk.Pk]))

###### paired fixed realizations ######
for i in numbers:

    for pair in [0, 1]:

        # get the name of the output file
        fpk = '%s/%s/NCV_%d_%d/Pk2D_m_z=%s.txt' % (folder_out, cosmo, pair, i,
                                                   z)
        if os.path.exists(fpk): continue

        # find the density field file and read it
        f_df = '%s/%s/NCV_%d_%d/df_z=%s.npy' % (root, cosmo, pair, i, z)
        if not (os.path.exists(f_df)): continue