def position_dependent_powerspectra(xfrac_dir, dens_dir, z, ps_quantity='signal', quantity='density', statistic='mean', kbins=100, Ncuts=4): quantities = ['density', 'xfrac', 'signal'] stats = ['mean', 'skewness', 'kurtosis'] assert quantity in quantities assert statistic in stats if ps_quantity == 'signal': cube = owntools.coeval_21cm(xfrac_dir, dens_dir, z) elif ps_quantity == 'density': cube = owntools.coeval_dens(dens_dir, z) elif ps_quantity == 'xfrac': cube = owntools.coeval_xfrac(xfrac_dir, z) stat_functions = [np.mean, scipy.stats.skew, scipy.stats.kurtosis] P_k_s = np.zeros((kbins, Ncuts**3)) k_s = np.zeros((kbins, Ncuts**3)) stat = np.zeros(Ncuts**3) stat_func = stat_functions[stats.index(statistic)] if quantity == 'density': quant = owntools.coeval_dens(dens_dir, z) quant = quant / quant.mean(dtype=np.float64) - 1. elif quantity == 'xfrac': quant = owntools.coeval_xfrac(xfrac_dir, z) elif quantity == 'signal': quant = owntools.coeval_21cm(xfrac_dir, dens_dir, z) Lx, Ly, Lz = cube.shape[0] / Ncuts, cube.shape[1] / Ncuts, cube.shape[ 2] / Ncuts smaller_cubes = [ cube[i * Lx:(i + 1) * Lx, j * Ly:(j + 1) * Ly, k * Lz:(k + 1) * Lz] for i in xrange(Ncuts) for j in xrange(Ncuts) for k in xrange(Ncuts) ] smaller_quant = [ quant[i * Lx:(i + 1) * Lx, j * Ly:(j + 1) * Ly, k * Lz:(k + 1) * Lz] for i in xrange(Ncuts) for j in xrange(Ncuts) for k in xrange(Ncuts) ] for i in xrange(len(smaller_cubes)): pk, ks = c2t.power_spectrum_1d(smaller_cubes[i], kbins=kbins, box_dims=c2t.conv.LB / Ncuts) P_k_s[:, i], k_s[:, i] = pk, ks stat[i] = stat_func(smaller_quant[i]) return P_k_s, k_s, stat
def position_dependent_cross_correlation_PS(fieldx, fieldy, xfrac_dir, dens_dir, z, quantity='density', kbins=100, Ncuts=4, statistic='mean'): assert fieldx.ndim == fieldy.ndim stats = ['mean', 'skewness', 'kurtosis'] stat_functions = [np.mean, scipy.stats.skew, scipy.stats.kurtosis] stat_func = stat_functions[stats.index(statistic)] R_k_s = np.zeros((kbins, Ncuts**3)) k_s = np.zeros((kbins, Ncuts**3)) stat = np.zeros(Ncuts**3) if quantity == 'density': quant = owntools.coeval_dens(dens_dir, z) quant = quant / quant.mean(dtype=np.float64) - 1. elif quantity == 'xfrac': quant = owntools.coeval_xfrac(xfrac_dir, z) elif quantity == 'signal': quant = owntools.coeval_21cm(xfrac_dir, dens_dir, z) Lx, Ly, Lz = np.array(fieldx.shape) / Ncuts smaller_x = [ fieldx[i * Lx:(i + 1) * Lx, j * Ly:(j + 1) * Ly, k * Lz:(k + 1) * Lz] for i in xrange(Ncuts) for j in xrange(Ncuts) for k in xrange(Ncuts) ] smaller_y = [ fieldy[i * Lx:(i + 1) * Lx, j * Ly:(j + 1) * Ly, k * Lz:(k + 1) * Lz] for i in xrange(Ncuts) for j in xrange(Ncuts) for k in xrange(Ncuts) ] smaller_quant = [ quant[i * Lx:(i + 1) * Lx, j * Ly:(j + 1) * Ly, k * Lz:(k + 1) * Lz] for i in xrange(Ncuts) for j in xrange(Ncuts) for k in xrange(Ncuts) ] for i in xrange(len(smaller_x)): rk, ks = cross_correlation_power_spectra(smaller_x[i], smaller_y[i], kbins=kbins, box_dims=c2t.conv.LB / Ncuts) R_k_s[:, i], k_s[:, i] = rk, ks stat[i] = stat_func(smaller_quant[i]) return R_k_s, k_s, stat
def apply_integrated_bispectrum(xfrac_dir, dens_dir, zs, kbins=100, Ncuts=4, field='21cm'): B_k_s = np.zeros((kbins, len(zs))) k_s = np.zeros((kbins, len(zs))) for i in xrange(len(zs)): if field == '21cm': cube = owntools.coeval_21cm(xfrac_dir, dens_dir, zs[i]) elif field == 'matter' or field == 'density': cube = owntools.coeval_dens(dens_dir, zs[i]) cube = cube / cube.mean(dtype=np.float64) - 1. B_k_s[:, i], k_s[:, i] = integrated_bispectrum_normalized(cube, Ncuts=Ncuts, kbins=kbins) print "Squeezed-limit bispectrum has been calculated for redshift =", zs[ i] return B_k_s, k_s
Ncuts = 3 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] i = 9 z = 6.549 cube_21 = owntools.coeval_21cm(xfrac_dir, dens_dir, z, mean_subtract=True) cube_m = owntools.coeval_overdens(dens_dir, z) cube_d = owntools.coeval_dens(dens_dir, z) cube_x = owntools.coeval_xfrac(xfrac_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
quantity = 'density' if quantity == 'density': norm = matplotlib.colors.Normalize(vmin=-0.091, vmax=0.114) label = '$\delta$' elif quantity == 'xfrac': norm = matplotlib.colors.Normalize(vmin=0.049, vmax=0.956) label = '$x_{HII}$' elif quantity == 'signal': norm = matplotlib.colors.Normalize(vmin=-5.1, vmax=5.1) label = '$\delta T_b$' ii = 1 for z in zs: field_21 = owntools.coeval_21cm(xfrac_dir, dens_dir, z) field_d = owntools.coeval_dens(dens_dir, z) yy, xx, pp = squeezed_bispectrum.position_dependent_cross_correlation_PS( field_21, field_d, xfrac_dir, dens_dir, z, Ncuts=5, quantity=quantity) plt.subplot(2, 2, ii) if quantity == 'signal': pp = pp - pp.mean() print pp.min(), pp.max() color_plot_lines(xx, yy, pp, cmap='jet', label=label, norm=norm) plt.title('$x_v$=' + str(xvs[zs.index(z)])) plt.ylabel('R$_{\delta,21cm}$') plt.xlabel('k (Mpc$^{-1}$)') ii += 1 for z in zs: cube = owntools.coeval_21cm(xfrac_dir, dens_dir, z) cube2 = owntools.coeval_overdens(dens_dir, z) ibc, kc = squeezed_bispectrum.integrated_bispectrum_normalized_cross(