def cal_Gm(l, rank): #n_l = default_num_l_in_rank * rank + l n_l = np.sum(num_ell_array[0:rank]) + l ell = l_min + n_l * delta_l ell = alpha * ell ##offset_Gm = n_l * N_dset * num_kout * data_type_size Gmatrix_l = np.zeros((N_dset, num_kout)) # j denotes column for j in range(num_kout): #chi_k: comoving distance from k chi_k = ell / k_mid[ j] # I would have to say I could only do approximation here, e.g., using k_mid z_k = interpolate.splev(chi_k, tck_zchi, der=0) # i denotes row if z_k < zmax: GF = (growth_factor(z_k, cosmic_params.omega_m) / G_0)**2.0 for i in range(N_dset): # redshift bin i: rb_i rb_i = iu1[0][i] gi = lens_eff(zbin, center_z, n_z, nz_y2, rb_i, z_k, sigma_z_const) # redshift bin j: rb_j rb_j = iu1[1][i] gj = lens_eff(zbin, center_z, n_z, nz_y2, rb_j, z_k, sigma_z_const) # here too, I did approximation for the integration, e.g., the term (1/k1 - 1/k2) Gmatrix_l[i][j] = pow( (1.0 + z_k), 2.0) * gi * gj * ell * ( 1.0 / kout[j] - 1.0 / kout[j + 1]) * GF * Pnorm_out[j] return Gmatrix_l
def cal_cijl(l, rank): #n_l = default_num_l_in_rank * rank + l n_l = np.sum(num_ell_array[0:rank]) + l ell = l_min + n_l * delta_l ell = alpha * ell ##offset_cijl = n_l * N_dset * data_type_size c_temp = np.zeros((nbin_ext, nbin_ext)) for c_i in range(nbin_ext): g_nr = nbin_ext - c_i #print('g_nr:', g_nr) # gmatrix_jk is used to store integration elements to calculate array C^ij(l) from Pk for a certain l # j=i, i+1,...nbin_ext; j in the name gmatrix_jk also denotes row index gmatrix_jk = np.zeros((g_nr, num_par)) #print(gmatrix_jk) # g_col is the column index of gmatrix_jk for g_col in range(num_par): chi_k = ell / k_par[g_col] z_k = interpolate.splev( chi_k, tck_zchi, der=0 ) # Here z_k is understood as the spectroscopic redshift z g_i = lens_eff(zbin, center_z, n_z, nz_y2, c_i, z_k, sigma_z_const) if z_k < zmax: # zmax corresponding to \chi_h in the expression of C^ij(l) GF = (growth_factor(z_k, cosmic_params.omega_m) / G_0)**2.0 #print('zmax, z_k, GF:', zmax, z_k, GF) c_j = c_i # here g_row is the row index of gmatrix_jk for g_row in range(g_nr): g_j = lens_eff(zbin, center_z, n_z, nz_y2, c_j, z_k, sigma_z_const) gmatrix_jk[g_row][g_col] = pow( (1.0 + z_k), 2.0) * g_i * g_j * ell * ( 1.0 / k_camb[g_col] - 1.0 / k_camb[g_col + 1]) * GF ###gmatrix_jk[g_row][g_col] = pow((1.0+z_k), 2.0)*lens_eff(c_i, chi_k)*lens_eff(c_j, chi_k)*ell*(1.0/k_par[g_col]-1.0/k_par[g_col+1])*GF c_j += 1 c_temp[c_i][c_i:nbin_ext] = np.dot(gmatrix_jk, Pk_par) # print(c_temp) cijl = np.asarray( c_temp[iu1], dtype=np.float64) # extract upper-triangle of c_temp if rank == 0: print('ell from rank', rank, 'is', ell) return cijl
def main(): scale_n = 1.10 # Tully-Fisher total surface number density (unit: arcmin^-2), from Eric et al.(2013), Table 2 (TF-Stage) c = 2.99792458e5 # speed of light unit in km/s N_dset = (nrbin + 1) * nrbin // 2 # numbe of C^ij(l) data sets zbin = np.zeros(nrbin + 1) # for both zbin and chibin, the first element is 0. chibin = np.zeros(nrbin + 1) eps = 0.1 inputf = '../Input_files/nz_stage_IV.txt' # Input file of n(z) which is the galaxy number density distribution in terms of z # Here center_z denotes z axis of n(z). It may not be appropriate since we don't have redshift bin setting center_z, n_z = np.loadtxt(inputf, dtype='f8', comments='#', unpack=True) spl_nz = InterpolatedUnivariateSpline(center_z, n_z) n_sum = spl_nz.integral(center_z[0], center_z[-1]) # Calculate the total number density #print(n_sum) scale_dndz = 1.0 / n_sum n_z = n_z * scale_dndz # Normalize n(z) spl_nz = InterpolatedUnivariateSpline( center_z, n_z) # Interpolate n(z) in terms of z using spline # bin interval z_min = center_z[0] z_max = 2.0 # based on the data file, at z=2.0, n(z) is very small zbin_avg = (z_max - z_min) / float(nrbin) for i in range(nrbin): zbin[i] = i * zbin_avg + z_min if zbin[i] <= z_target: target_i = i zbin[-1] = z_max # Note that here chibin[0] is not equal to 0, since there is redshift cut at low z. for i in range(0, nrbin + 1): chibin[i] = comove_d(zbin[i]) * c / 100.0 print('Xmax', c / 100.0 * comove_d(zbin[-1])) #Xmax = comove_d(zbin[-1]) print('Xmax') print('target_i:', target_i) #z_array = np.linspace(0.0, zbin[target_i+1], 1000, endpoint=False) z_array = np.linspace(0.0, z_max, 1000, endpoint=True) chi_array = np.array([comove_d(z_i) for z_i in z_array]) * c / 100.0 print("chi_array:", chi_array) g_i_array = np.array([], dtype=np.float64) for chi_k in chi_array: g_i = lens_eff(target_i, chi_k, chibin, eps) g_i_array = np.append(g_i_array, g_i) print('min_gi:', np.min(g_i_array), 'at chi=', chi_array[np.argmin(g_i_array)]) odir0 = '/Users/ding/Documents/playground/shear_ps/project_final/fig_lens_eff/gi_data/' odir = odir0 + '{}/'.format(survey_stage) if not os.path.exists(odir): os.mkdir(odir) ofile = odir + 'gi_nrbin{}_zk_{}_rbinid_{}.npz'.format( nrbin, z_target, target_i) np.savez(ofile, z=z_array, gi=g_i_array) odir = './figs/lens_eff_gi/' if not os.path.exists(odir): os.makedirs(odir) ofile = odir + 'gi_{}_nrbin{}_zi_{}.pdf'.format(survey_stage, nrbin, z_target) plot_lens_eff(z_array, g_i_array, nrbin, z_target, ofile) ofile = odir + 'gi_{}_nrbin{}_zi_{}_version2.pdf'.format( survey_stage, nrbin, z_target) plot_lens_eff_version2(z_array, chi_array, g_i_array, nrbin, z_target, ofile)
def main(): c = 2.99792458e5 # speed of light unit in km/s sigma_z_const = 0.05 # for PW-Stage IV, from Table 3 in Eric et al. 2015 #scale_n = 31.0 # input galaxy number density n(z) file inputf = '../Input_files/nz_stage_IV.txt' # Input file of n(z) which is the galaxy number density distribution in terms of z # Here center_z denotes z axis of n(z). It may not be appropriate since we don't have redshift bin setting center_z, n_z = np.loadtxt(inputf, dtype='f8', comments='#', unpack=True) num_z = len(center_z) spl_nz = InterpolatedUnivariateSpline(center_z, n_z) n_sum = spl_nz.integral(center_z[0], center_z[-1]) # Calculate the total number density #print(n_sum) scale_dndz = 1.0 / n_sum n_z = n_z * scale_dndz # normalize n(z) to match the total number density from the data file equal to 1.0/arcmin^2 tck_nz = interpolate.splrep(center_z, n_z) zmax = 2.0 # Based on Eric's n(z) data file for Stage IV weak lensing survey, we cut number density at z=2.0, after which n(z) is very small. #---------------------------------------------------------------------------------------------- #-- Removed this extrapolation part for n(z) since the given data file covers large z range. # ... #---------------------------------------------------------------------------------------------- # Set zmax_ext as the maximum z after extension, it's about 2.467 in this case. zmax_ext = zmax + math.sqrt(2.0) * 0.05 * ( 1 + zmax) * 2.2 # 2.2 is from erf(2.2) which is close to 1.0 print('zmax_ext: ', zmax_ext) # It's about 2.467. nz_y2 = np.zeros(num_z) #**** Different from the previous case that zmin is 0, zmin is not 0 in the new n(z) file. ****# zmin = center_z[0] zbin_avg = (zmax - zmin) / float(nrbin) # bin interval nbin_ext = int(zmax_ext / zbin_avg) #print('# of redshift bins (extended): ', nbin_ext) zbin = np.zeros(nbin_ext + 1) for i in range(nbin_ext + 1): zbin[i] = i * zbin_avg + zmin if zbin[i] <= z_target: target_i = i #z_array = np.linspace(0.0, zbin[target_i+1], 1000, endpoint=False) z_array = np.linspace(0.0, zmax, 1000, endpoint=False) chi_array = np.array([comove_d(z_i) for z_i in z_array ]) # not including the unit of distance g_i_array = np.array([], dtype=np.float64) for z_k in z_array: g_i = lens_eff(zbin, center_z, n_z, nz_y2, target_i, z_k, sigma_z_const) g_i_array = np.append(g_i_array, g_i) odir0 = '/Users/ding/Documents/playground/shear_ps/project_final/fig_lens_eff/gi_data/' odir = odir0 + '{}/'.format(survey_stage) if not os.path.exists(odir): os.makedirs(odir) ofile = odir + 'gi_nrbin{}_zk_{}_rbinid_{}.npz'.format( nrbin, z_target, target_i) #ofile = './gi_nrbin{}_zk_{}_rbinid_{}_30abscissas.npz'.format(nrbin, z_target, target_i) #ofile = './gi_nrbin{}_zk_{}_rbinid_{}_50abscissas.npz'.format(nrbin, z_target, target_i) #ofile = './gi_nrbin{}_zk_{}_rbinid_{}_50abscissas_5sigma.npz'.format(nrbin, z_target, target_i) #ofile = './gi_nrbin{}_zk_{}_rbinid_{}_50abscissas_largerintlim_in_denominator.npz'.format(nrbin, z_target, target_i) np.savez(ofile, z=z_array, gi=g_i_array) odir = './figs/lens_eff_gi/' if not os.path.exists(odir): os.makedirs(odir) ofile = odir + 'gi_nrbin{}_zk_{}.pdf'.format(nrbin, z_target) plot_lens_eff(z_array, g_i_array, nrbin, z_target, ofile) ofile = odir + 'gi_nrbin{}_zk_{}_version2.pdf'.format(nrbin, z_target) plot_lens_eff_version2(z_array, chi_array, g_i_array, nrbin, z_target, ofile)