Example #1
0
def smoothed_lightcone_dbt(id="", ht=""):
    infile = open(setup_dirs.resultsdir() + "dbt_lightcone" + ht + ".bin", "rb")
    outfile = setup_dirs.resultsdir() + "dbt_lightcone_smooth" + ht + ".bin"
    zfile = open(setup_dirs.resultsdir() + "dbt_lightcone_redshifts.bin", "rb")
    dT_box = np.load(infile)
    log = open("stats.dat", "w")
    zs = np.load(zfile)

    dT_box3 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :])))
    dT_box2 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :])))
    for z in range(len(dT_box[1, 1, :]) - 1, -1, -1):
        wl = 0.21 * (1 + zs[z])
        c = 299792.458
        omm = 0.27
        oml = 0.73
        omr = 0.0
        omk = 1.0 - omm - oml - omr
        H0 = 70.0

        def integrand(x, omm, oml, omr, omk):
            return 1.0 / np.sqrt(omr * ((1 + x) ** 4) + omm * ((1 + x) ** 3) + oml + omk * ((1 + x) ** 2))

        def dc(z, omm, oml, omr, omk):
            return quad(integrand, 0, z, args=(omm, oml, omr, omk))[0]  # /(1.0+z)

        vec_dc = np.vectorize(dc)

        bw_r = wl / (2.0e3)  # radians
        bw = bw_r * 3437.74677  # arcminutesi
        log.write("Wavelength of 21-cm from redshift " + str(zs[z]) + " is " + str(wl) + "m\n")
        log.write("At redshift: " + str(zs[z]) + " smoothing with a " + str(bw) + " arc minute beam.\n")

        rc = bw_r * c / H0 * vec_dc(zs[z], omm, oml, omr, omk)  # comoving Mpc
        Hz = H0 * np.sqrt(omr * (1 + zs[z]) ** 4 + omm * (1 + zs[z]) ** 3 + oml + omk * (1 + zs[z]) ** 2)

        log.write("rc = " + str(rc) + "\n")
        #        dnu=nu0*Hz*rc/(c*(1+zs[z])**2)
        dz = rc * Hz / c
        log.write("$\Delta$ z = " + str(dz) + "\n")
        ncs = rc * 250.0 * 0.7 / 244.0
        log.write(str(ncs) + " cells in the z direction\n")
        log.write("\n")
        #        rc_h=rc/0.7 # comoving Mpc/h
        #        print "This corresponds to "+str(rc_h)+"Mpc/h on the sky"

        dT_box2[:, :, z] = c2t.beam_convolve(dT_box[:, :, z], zs[z], 244.0, beam_w=bw)

        if z > ncs and z + ncs < zs[len(zs) - 1]:
            for x in range(len(dT_box2)):
                for y in range(len(dT_box2)):
                    dT_box3[x, y, z] = np.mean(dT_box2[x, y, z - ncs / 2.0 : z + ncs / 2.0])
        else:
            print "..."
            dT_box3[:, :, z] = dT_box2[:, :, z]

        IO.writebin(dT_box3[:, :, z], setup_dirs.resultsdir() + "smoothed_map_dbt_" + ht + str("%.3f" % zs[z]) + ".bin")

    IO.writebin(dT_box3, outfile)
    print "Written map to " + outfile
Example #2
0
def plot_smoothed_dbt():

    mini = -457
    maxi=83
#    print mini,maxi
    for i in range(start,len(redshifts)):
        print "Doing redshift " + str(redshifts[i])+"..."
        dbt = np.load("../generate_data/"+setup_dirs.resultsdir()+"map_dbt_"+str('%.3f' % redshifts[i])+".bin")
        dbt = c2t.beam_convolve(dbt[len(dbt[:,0,0])/2,:,:],redshifts[i],244.,beam_w=3.)
#IO.readmap("dbt_"+str('%.3f' % redshifts[i]))
#        print np.min(dbt)
        plot(dbt,i,"$\delta T_b$","smoothed_dbt",mini,maxi,'seismic')
    print "Complete"
Example #3
0
def smoothed_lightcone_dbt2(id="", ht=""):
    print "hello"
    infile = open(setup_dirs.resultsdir() + "dbt_lightcone" + ht + ".bin", "rb")
    outfile = setup_dirs.resultsdir() + "dbt_lightcone_smooth" + ht + ".bin"
    zfile = open(setup_dirs.resultsdir() + "dbt_lightcone_redshifts.bin", "rb")
    dT_box = np.load(infile)
    log = open("stats.dat", "w")
    zs = np.load(zfile)

    dT_box3 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :])))
    dT_box2 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :])))
    for z in range(len(dT_box[1, 1, :])):
        wl = 0.21 * (1 + zs[z])
        c = 299792.458
        omm = 0.27
        oml = 0.73
        omr = 0.0
        omk = 1.0 - omm - oml - omr
        H0 = 70.0
        print 1

        def integrand(x, omm, oml, omr, omk):
            return 1.0 / np.sqrt(omr * ((1 + x) ** 4) + omm * ((1 + x) ** 3) + oml + omk * ((1 + x) ** 2))

        def dc(z, omm, oml, omr, omk):
            return quad(integrand, 0, z, args=(omm, oml, omr, omk))[0]  # /(1.0+z)

        vec_dc = np.vectorize(dc)

        print 2
        bw_r = wl / (2.0e3)  # radians
        bw = bw_r * 3437.74677  # arcminutesi
        stats.write("Wavelength of 21-cm from redshift " + str(zs[z]) + " is " + str(wl) + "m")
        stats.write("At redshift: " + str(zs[z]) + " smoothing with a " + str(bw_r) + " radian beam")
        stats.write("At redshift: " + str(zs[z]) + " smoothing with a " + str(bw) + " arc minute beam")
        stats.write("\n")

        print 3
        dT_box2[:, :, z] = c2t.beam_convolve(dT_box[:, :, z], zs[z], 244.0, beam_w=bw)

        print 4
        dT_box3 = lightcone_smooth.frequency_direction_same(dT_box2, zs[0], 244.0, 2)
        print 5
        IO.writebin(dT_box3[:, :, z], setup_dirs.resultsdir() + "smoothed_map_dbt_" + ht + str("%.3f" % zs[z]) + ".bin")

    IO.writebin(dT_box3, outfile)
    print "Written map to " + outfile
    dTconv_rsd_var = 0.
    count = 0
    width = int(width)

    # Add up the dT slices in the bandwidth and find mean, rms, skewness
    while (k < len(dT_box)-width-1):
        #print 'k=',k
        dT_slice = frac*dT_box[k,:,:]
        dT_rsd_slice = frac*dT_rsd_box[k,:,:]
        for j in range(1,width+1):
            dT_slice += dT_box[k+j,:,:]
            dT_rsd_slice += dT_rsd_box[k+j,:,:]
        dT_slice /= n_cells
        dT_rsd_slice /= n_cells
        #print 'slices', dT_slice, dT_rsd_slice
        dTconv_slice = c2t.beam_convolve(dT_slice, z_arr[i], c2t.conv.LB, beam_w=beam)
        dTconv_rsd_slice = c2t.beam_convolve(dT_rsd_slice, z_arr[i], c2t.conv.LB, beam_w=beam)
        #print 'shapes conv', dTconv_slice, dTconv_rsd_slice

        if k == 0:
            dT_PDF_box = dTconv_slice
            dT_rsd_PDF_box = dTconv_rsd_slice
            
        elif k > 0:
            dT_PDF_box = np.dstack((dT_PDF_box,dTconv_slice))
            dT_rsd_PDF_box = np.dstack((dT_rsd_PDF_box,dTconv_rsd_slice))
            #print 'shapes ', k, dT_PDF_box.shape, dT_rsd_PDF_box.shape
            
        dTconv_mean += dTconv_slice.mean()
        dTconv_rsd_mean += dTconv_rsd_slice.mean()
        dTconv_var += np.mean(pow(dTconv_slice-dTconv_mean,2))
Example #5
0
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
pl.figure()

pl.subplot(221)
pl.imshow(n_hi[128,:,:])
pl.colorbar()
pl.title('$n_{HI}$')
Example #6
0
def smoothed_coeval_box(ht=""):
    log2 = open("coeval_stats.dat", "w")
    for z in range(len(redshifts)):
        infile = "map_dbt_" + ht + str("%0.3f" % redshifts[z]) + ".bin"
        dT_box = IO.readbin(infile)
        dT_box3 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :])))
        dT_box2 = np.zeros((len(dT_box[:, 1, 1]) / 2, len(dT_box[1, :, 1]) / 2, len(dT_box[1, 1, :])))
        wl = 0.21 * (1 + redshifts[z])
        c = 299792.458
        omm = 0.27
        oml = 0.73
        omr = 0.0
        omk = 1.0 - omm - oml - omr
        H0 = 70.0

        def integrand(x, omm, oml, omr, omk):
            return 1.0 / np.sqrt(omr * ((1 + x) ** 4) + omm * ((1 + x) ** 3) + oml + omk * ((1 + x) ** 2))

        def dc(z, omm, oml, omr, omk):
            return quad(integrand, 0, z, args=(omm, oml, omr, omk))[0]  # /(1.0+z)

        vec_dc = np.vectorize(dc)
        bw_r = wl / (2.0e3)  # radians
        bw = bw_r * 3437.74677  # arcminutesi
        log2.write("Wavelength of 21-cm from redshift " + str(redshifts[z]) + " is " + str(wl) + "m\n")
        log2.write("At redshift: " + str(redshifts[z]) + " smoothing with a " + str(bw) + " arc minute beam.\n")

        rc = bw_r * c / H0 * vec_dc(redshifts[z], omm, oml, omr, omk)  # comoving Mpc
        Hz = H0 * np.sqrt(
            omr * (1 + redshifts[z]) ** 4 + omm * (1 + redshifts[z]) ** 3 + oml + omk * (1 + redshifts[z]) ** 2
        )
        log2.write("rc = " + str(rc) + "\n")
        dz = rc * Hz / c
        log2.write("$\Delta$ z = " + str(dz) + "\n")
        ncs = rc * 250.0 * 0.7 / 244.0
        log2.write(str(ncs) + " cells in the z direction\n")
        log2.write("\n")
        for k in range(len(dT_box2[1, 1, :])):
            dT_box2[:, :, k] = c2t.beam_convolve(dT_box[:, :, k], redshifts[z], 244.0, beam_w=bw)
        for i in range(0):  # len(dT_box2[:,1,1])):
            for j in range(0):  # len(dT_box2[1,:,1])):
                for k in range(0):  # len(dT_box2[1,1,:])):
                    L = len(dT_box2[1, 1, :])
                    if k - ncs / 2 > 0 and k + ncs / 2 < L:
                        dT_box3[i, j, k] = np.mean(dT_box2[i, j, k - ncs / 2.0 : k + ncs / 2.0])
                        if k + ncs / 2.0 - k + ncs / 2.0 != ncs:
                            print "Wrong smoothing width for tophat function!!"
                    elif (k - ncs) / 2 < 0:
                        if k + ncs / 2.0 + k - ncs / 2 != ncs:
                            print "Wrong smoothing width for tophat function!!"
                        dT_box3[i, j, k] = (
                            np.sum(dT_box2[i, j, 0 : (k + ncs / 2.0)]) + np.sum(dT_box2[i, j, L - ncs / 2 + k : L])
                        ) / ncs
                    elif (k + ncs) / 2 > 10:
                        if L - k + ncs / 2 + L - k + ncs / 2 != ncs:
                            print "Wrong smoothing width for tophat function!!"
                        dT_box3[i, j, k] = (
                            np.sum(dT_box2[i, j, k - ncs / 2 : L]) + np.sum(dT_box2[i, j, L - k + ncs / 2 : L])
                        ) / ncs

        IO.writebin(
            dT_box2, setup_dirs.resultsdir() + "smooth_coevalmap_dbt_" + ht + str("%.3f" % redshifts[z]) + ".bin"
        )
        print np.mean(dT_box2)
        print "Written map"
Example #7
0
#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}$')

pl.subplot(222)
pl.imshow(dT_slice)
pl.colorbar()
pl.title('dT')

pl.subplot(223)
Example #8
0
#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}$')

pl.subplot(222)
pl.imshow(dT_slice)
pl.colorbar()
pl.title('dT')

pl.subplot(223)
Example #9
0
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
pl.figure()

pl.subplot(221)
pl.imshow(n_hi[128, :, :])
pl.colorbar()
pl.title('$n_{HI}$')