示例#1
0
文件: map.py 项目: hr203/c2raytools
def map_dbt_hightemp():
    for i in range(start, len(redshifts)):
        filename = setup_dirs.resultsdir() + "map_dbt_hightemp" + str("%.3f" % redshifts[i]) + ".bin"
        temp_filename = setup_dirs.path() + "Temper3D_" + str("%.3f" % redshifts[i]) + ".bin"
        xfrac_filename = setup_dirs.path() + "xfrac3d_" + str("%.3f" % redshifts[i]) + ".bin"
        if i % 2 == 0:
            density_filename = (
                "/research/prace/244Mpc_RT/244Mpc_f2_8.2pS_250/coarser_densities/"
                + str("%.3f" % redshifts[i])
                + "n_all.dat"
            )
        else:
            density_filename = (
                "/research/prace/244Mpc_RT/244Mpc_f2_8.2pS_250/coarser_densities/"
                + str("%.3f" % redshifts[i - 1])
                + "n_all.dat"
            )

        tfile = c2t.TemperFile(temp_filename)
        xfile = c2t.XfracFile(xfrac_filename).xi

        if ss != " ":
            abu_he = 0.074
            G_grav = 6.674e-11
            pc = 3.086e16
            Mpc = 1e6 * pc
            H0 = 0.7 * 100.0 * 1.0e5 / Mpc
            rho_crit_0 = 3.0 * H0 * H0 / (8.0 * np.pi * G_grav)
            Omega_B = 0.044
            mu = (1.0 - abu_he) + 4.0 * abu_he
            m_p = 1.672661e-24

            dfile = np.ones(ss ** 3).reshape(ss, ss, ss)
            dfile = dfile * rho_crit_0 * Omega_B / (mu * m_p) * (1.0 + redshifts[i]) ** 3
            dfile = dfile * 1.23581719037e-35

        else:
            dfile = c2t.DensityFile(density_filename).cgs_density
        dT_box = c2t.calc_dt(xfile, dfile, redshifts[i])
        #        IO.writemap(dT_box,filename)
        IO.writebin(dT_box, filename)
        print "Written map to " + filename
示例#2
0
文件: mean.py 项目: hr203/c2raytools
def mean_dbt_hightemp():
    file = open(setup_dirs.resultsdir()+'mean_dbt_hightemp.dat','w')
    for i in range(len(redshifts)):
        filename = setup_dirs.resultsdir()+'map_dbt_hightemp'+str('%.3f' % redshifts[i])+'.dat'
        temp_filename = setup_dirs.path()+'Temper3D_'+str('%.3f' % redshifts[i]) + '.bin'
        xfrac_filename = setup_dirs.path() +'xfrac3d_'+str('%.3f' % redshifts[i]) + '.bin'
        if i%2==0:
            density_filename='/research/prace/244Mpc_RT/244Mpc_f2_8.2pS_250/coarser_densities/' + str('%.3f' % redshifts[i]) + 'n_all.dat'
        else:
            density_filename='/research/prace/244Mpc_RT/244Mpc_f2_8.2pS_250/coarser_densities/' + str('%.3f' % redshifts[i-1]) + 'n_all.dat'
        tfile = c2t.TemperFile(temp_filename)
        xfile =  c2t.XfracFile(xfrac_filename).xi
        if ss!=' ':
            dfile = np.ones(ss**3).reshape(ss,ss,ss)*1.981e-10*(1+redshifts[i])**3
        else:
            dfile = c2t.DensityFile(density_filename).cgs_density

        dT_box = c2t.calc_dt(xfile, dfile, redshifts[i]) #returned in micro kelvin! update plots
        file.write(str(np.mean(dT_box))+'\n')
    print "Written mean dbt to " + setup_dirs.resultsdir()+'mean_dbt_hightemp.dat'
    xfrac_file = ''.join(glob.glob(xfrac_path+'xfrac3d_%.3f.bin'%(z_arr[i])))
    print 'Ionized fraction file = %s' % xfrac_file
    xfile = c2t.XfracFile(xfrac_file)
    
    vel_file = ''.join(glob.glob(density_path+'%.3fv_all.dat'%(z_arr[i])))
    if not vel_file:
        vel_file = ''.join(glob.glob(density_path+'%.3fv_all.dat'%(z_arr[i-1])))
    print 'Velocity file = %s' % vel_file
    vfile = c2t.VelocityFile(vel_file)
    kms = vfile.get_kms_from_density(dfile)

    mesh = (xfile.mesh_x, xfile.mesh_y, xfile.mesh_z)
    print 'mesh = ', mesh

    dT_box = c2t.calc_dt(xfile, dfile, xfile.z)
    dT_file = './dT_boxes/dT_%.3f.cbin' % (z_arr[i])
    print 'dT_box file = %s' % dT_file
    
    #rho = dfile.cgs_density
    #print 'rho_crit*OmegaB',c2t.const.rho_crit_0*c2t.const.OmegaB#*(1+z_arr[i])**3
    #print 'rho.mean()',rho.mean()
    c2t.save_cbin(dT_file, dT_box, bits=64, order='F')

    dT_pv_box = c2t.get_distorted_dt(dT_box, kms, xfile.z, num_particles=40)
    dT_pv_file = './dT_pv_boxes/dT_pv_%.3f.cbin' % (z_arr[i])
    print 'dT_pv_box file = %s' % dT_pv_file
    c2t.save_cbin(dT_pv_file, dT_pv_box, bits=64, order='F')

    dT_mean = dT_box.mean()
    dT_rms_box = np.sqrt((dT_box - dT_mean)**2)
示例#4
0
print 'The mass-averaged mean ionized fraction is:', c2t.mass_weighted_mean_xi(xfile.xi, dfile.raw_density)

#Read a velocity data file and store it as a VelocityFile object
vfile = c2t.VelocityFile(velocity_filename)

#Since the velocity data is actually momentum, we need the density to convert it to km/s 
kms = vfile.get_kms_from_density(dfile)
print 'Gas velocity at cell (100,100,100) is ', kms[:,100,100,100], 'km/s'

#Calculate neutral hydrogen number density
n_hi = dfile.cgs_density*xfile.xi/c2t.m_p

#Calculate differential brightness temperature
#The calc_dt method can also take names of files so you don't have to load the
#files yourself in advance.
dT = c2t.calc_dt(xfile, dfile, z=xfile.z)

#Get a slice through the center
dT_slice = dT[128,:,:]

#Convolve with a Gaussian beam, assuming a 2 km maximum baseline
dT_slice_conv = c2t.beam_convolve(dT_slice, xfile.z, fov_mpc=c2t.conv.LB, \
                                  max_baseline=2000.)


#c2raytools comes with a few simple plotting functions to quickly 
#visualize data. For example, to plot a slice through the ionization
#fraction data, you can simply do:
c2t.plot_slice(xfile) 

#If you want more control over the plotting, you have to use, e.g.,
示例#5
0
#We are using the 114/h Mpc simulation box, so set all the proper conversion factors
c2t.set_sim_constants(boxsize_cMpc = 114.)

#Read density
dfile = c2t.DensityFile(density_filename)

#Read velocity data file and get the actual velocity 
vfile = c2t.VelocityFile(velocity_filename)
kms = vfile.get_kms_from_density(dfile)

#To speed things up, we will assume that the IGM is completely neutral, so instead
#of reading an ionization fraction file, we will just make an array of zeros
xi = np.zeros_like(dfile.cgs_density)

#Calculate the dT
dT_realspace = c2t.calc_dt(xi, dfile, z=dfile.z)

#Make the redshift-space volume
dT_redshiftspace = c2t.get_distorted_dt(dT_realspace, kms, \
                                 dfile.z, los_axis=0, num_particles=20)

#Calculate spherically-averaged power spectra, 
#using 20 logarithmically spaced k bins, from 1e-1 to 10
kbins = 10**np.linspace(-1, 1, 20)
ps_dist, k = c2t.power_spectrum_1d(dT_redshiftspace, kbins)
ps_nodist, k = c2t.power_spectrum_1d(dT_realspace, kbins)

#Plot ratio. On large scales, this should be close to 1.83
pl.semilogx(k, ps_dist/ps_nodist)
pl.xlabel('$k \; \mathrm{[Mpc^{-1}]}$')
pl.ylabel('$P_k^{\mathrm{PV}}/P_k^{\mathrm{NoPV}}$')
示例#6
0
print 'The volume-averaged mean ionized fraction is: ', xfile.xi.mean()
print 'The mass-averaged mean ionized fraction is:', c2t.mass_weighted_mean_xi(
    xfile.xi, dfile.raw_density)

#Read a velocity data file
vfile = c2t.VelocityFile(velocity_filename)

#Since the velocity data is actually momentum, we need the density to convert it to km/s
kms = vfile.get_kms_from_density(dfile)
print 'Gas velocity at cell (100,100,100) is ', kms[:, 100, 100, 100], 'km/s'

#Calculate neutral hydrogen number density
n_hi = dfile.cgs_density * xfile.xi / c2t.m_p

#Calculate differential brightness temperature
dT = c2t.calc_dt(xfile, dfile)

#Get a slice through the center
dT_slice = dT[128, :, :]

#Convolve with a Gaussian beam, assuming a 2 km maximum baseline
dT_slice_conv = c2t.beam_convolve(dT_slice, xfile.z, c2t.boxsize, \
                                  max_baseline=2000.)

#Plot some stuff
pl.figure()

pl.subplot(221)
pl.imshow(n_hi[128, :, :])
pl.colorbar()
pl.title('$n_{HI}$')
示例#7
0
print 'The volume-averaged mean ionized fraction is: ', xfile.xi.mean()
print 'The mass-averaged mean ionized fraction is:', c2t.mass_weighted_mean_xi(xfile.xi, dfile.raw_density)

#Read a velocity data file
vfile = c2t.VelocityFile(velocity_filename)

#Since the velocity data is actually momentum, we need the density to convert it to km/s 
kms = vfile.get_kms_from_density(dfile)
print 'Gas velocity at cell (100,100,100) is ', kms[:,100,100,100], 'km/s'

#Calculate neutral hydrogen number density
n_hi = dfile.cgs_density*xfile.xi/c2t.m_p

#Calculate differential brightness temperature
dT = c2t.calc_dt(xfile, dfile)

#Get a slice through the center
dT_slice = dT[128,:,:]

#Convolve with a Gaussian beam, assuming a 2 km maximum baseline
dT_slice_conv = c2t.beam_convolve(dT_slice, xfile.z, c2t.boxsize, \
                                  max_baseline=2000.) 

#Plot some stuff
pl.figure()

pl.subplot(221)
pl.imshow(n_hi[128,:,:])
pl.colorbar()
pl.title('$n_{HI}$')
示例#8
0
#We are using the 114/h Mpc simulation box, so set all the proper conversion factors
c2t.set_sim_constants(boxsize_cMpc=114.)

#Read density
dfile = c2t.DensityFile(density_filename)

#Read velocity data file and get the actual velocity
vfile = c2t.VelocityFile(velocity_filename)
kms = vfile.get_kms_from_density(dfile)

#To speed things up, we will assume that the IGM is completely neutral, so instead
#of reading an ionization fraction file, we will just make an array of zeros
xi = np.zeros_like(dfile.cgs_density)

#Calculate the dT
dT_realspace = c2t.calc_dt(xi, dfile, z=dfile.z)

#Make the redshift-space volume
dT_redshiftspace = c2t.get_distorted_dt(dT_realspace, kms, \
                                 dfile.z, los_axis=0, num_particles=20)

#Calculate spherically-averaged power spectra,
#using 20 logarithmically spaced k bins, from 1e-1 to 10
kbins = 10**np.linspace(-1, 1, 20)
ps_dist, k = c2t.power_spectrum_1d(dT_redshiftspace, kbins)
ps_nodist, k = c2t.power_spectrum_1d(dT_realspace, kbins)

#Plot ratio. On large scales, this should be close to 1.83
pl.semilogx(k, ps_dist / ps_nodist)
pl.xlabel('$k \; \mathrm{[Mpc^{-1}]}$')
pl.ylabel('$P_k^{\mathrm{PV}}/P_k^{\mathrm{NoPV}}$')
示例#9
0
xvs_ = 10**np.linspace(np.log10(3.44e-10),np.log10(0.20),10)
#xvs  = ph_count_info[[np.abs(ph_count_info[:,-2]-x).argmin() for x in xvs_],-2]
zs_  = ph_count_info[[np.abs(ph_count_info[:,-2]-x).argmin() for x in xvs_], 0]

dens_zs = owntools.get_zs_list(dens_dir, file_type='/*n_all.dat')
zs   = dens_zs[[np.abs(dens_zs-i).argmin() for i in zs_]]
xvs  = ph_count_info[[np.abs(ph_count_info[:,0]-i).argmin() for i in zs],-2]

z = 9.026 #8.636

gg_xf = c2t.XfracFile(grizzly_dir+str(z)+'xhiifrac.dat').xi
#cc_xf = owntools.coeval_xfrac(xfrac_dir, z)

cube_d  = owntools.coeval_dens(dens_dir, z)
cube_21 = c2t.calc_dt(gg_xf, cube_d, z); cube_21 -= cube_21.mean()
cube_m  = cube_d/cube_d.mean(dtype=np.float64) - 1. #owntools.coeval_overdens(dens_dir, z)

P_dd, ks_m = c2t.power_spectrum_1d(cube_m, kbins=100, box_dims=c2t.conv.LB)
P_21, ks_x = c2t.power_spectrum_1d(cube_21, kbins=100, box_dims=c2t.conv.LB)

f_dd, k_dd  = squeezed_bispectrum._integrated_bispectrum_normalized_cross(cube_m, cube_m, Ncuts=Ncuts)
f_21d, k_xd = squeezed_bispectrum._integrated_bispectrum_normalized_cross(cube_21, cube_m, Ncuts=Ncuts)
f_xx, k_xx  = squeezed_bispectrum._integrated_bispectrum_normalized_cross(cube_x-cube_x.mean(), cube_x-cube_x.mean(), Ncuts=Ncuts)
f_x_ = squeezed_bispectrum._integrated_bispectrum_normalized_cross1(1-cube_x, cube_m, Ncuts=Ncuts)

ks = k_dd.copy()

### Zeta calculation
sources = np.loadtxt(parent_dir+'sources/'+str(z)+'-coarser_sources.dat', skiprows=1)
M_min = sources[np.nonzero(sources[:,-2]),-2].min()*c2t.conv.M_grid*c2t.const.solar_masses_per_gram #solarunit
示例#10
0
    xfile.xi, dfile.raw_density)

#Read a velocity data file and store it as a VelocityFile object
vfile = c2t.VelocityFile(velocity_filename)

#Since the velocity data is actually momentum, we need the density to convert it to km/s
kms = vfile.get_kms_from_density(dfile)
print 'Gas velocity at cell (100,100,100) is ', kms[:, 100, 100, 100], 'km/s'

#Calculate neutral hydrogen number density
n_hi = dfile.cgs_density * xfile.xi / c2t.m_p

#Calculate differential brightness temperature
#The calc_dt method can also take names of files so you don't have to load the
#files yourself in advance.
dT = c2t.calc_dt(xfile, dfile, z=xfile.z)

#Get a slice through the center
dT_slice = dT[128, :, :]

#Convolve with a Gaussian beam, assuming a 2 km maximum baseline
dT_slice_conv = c2t.beam_convolve(dT_slice, xfile.z, fov_mpc=c2t.conv.LB, \
                                  max_baseline=2000.)

#c2raytools comes with a few simple plotting functions to quickly
#visualize data. For example, to plot a slice through the ionization
#fraction data, you can simply do:
c2t.plot_slice(xfile)

#If you want more control over the plotting, you have to use, e.g.,
#matplotlib directly