f_h5.close() if argv[1] == "e1": idx = 0 else: idx = 1 e1 = es_data[:, idx] ch = numpy.random.choice(range(len(e1)), 10000, replace=False) # para_path = total_path + "parameters/para_%d.hdf5"%source # para_h5 = h5py.File(para_path, "r") # mag_t = para_h5["/mag"].value # e1 = para_h5["/e1"].value # # e1 = para_h5["/%s"%argv[2]].value # para_h5.close() bins = tool_box.set_bin(e1, bin_num, 1.02) fourier_path = total_path + "result/data/data_1.5sig/data_%d.hdf5" % source f_h5 = h5py.File(fourier_path, "r") f_data = f_h5["/data"].value f_h5.close() sex_path = total_path + "result/data/sex2_1.5/sex_%d.npz" % source s_data = numpy.load(sex_path)["arr_0"] detect_f = f_data[:, -1] > -1 detect_s = s_data[:, 0] > 0 # P(k=0) pk0 = f_data[:, 4] / 64 / 60 print(pk0.max(), pk0.min())
h5f = h5py.File(data_path1, "r") mg1[:num_s] = h5f["/data"][()][:, 0] mnu1[:num_s] = h5f["/data"][()][:, 2] + h5f["/data"][()][:, 3] h5f.close() # non-sheared galaxies h5f = h5py.File(data_path2, "r") mg1[num_s:] = h5f["/data"][()][:, 0] mnu1[num_s:] = h5f["/data"][()][:, 2] + h5f["/data"][()][:, 3] h5f.close() h5f = h5py.File(data_path3, "r") mg1_corr = h5f["/data"][()][:, 0] mnu1_corr = h5f["/data"][()][:, 2] + h5f["/data"][()][:, 3] h5f.close() G1_bin = tool_box.set_bin(mg1[:num_s], mg_bin_num, 1000) G1_hist_bin = gglensing_tool.set_bin(mg1[:num_s], 2500, 1.001, "log") NU1_hist_bin = gglensing_tool.set_bin(mnu1[:num_s], 2500, 1.001, "log") dilute_case = [0, 0.1, 0.2, 0.3, 0.4, 0.5] dilute_num = len(dilute_case) task_list = [i for i in range(dilute_num)] task_list_sub = tool_box.alloc(task_list, numprocs)[rank] itemsize = MPI.DOUBLE.Get_size() if rank == 0: # bytes for 10 double elements nbytes = 4 * dilute_num * itemsize else: nbytes = 0
g2 = h5f["/g2"][()] h5f.close() shear_tag = rank print(shear_tag, g1[shear_tag], g2[shear_tag]) h5f = h5py.File(data_path + "/data_%d_noisy_cpp.hdf5" % shear_tag, "r") data = h5f["/data"][()] h5f.close() G1 = numpy.ascontiguousarray(data[:, 0], dtype=numpy.float64) G2 = numpy.ascontiguousarray(data[:, 1], dtype=numpy.float64) NU1 = numpy.ascontiguousarray(data[:, 2] + data[:, 3], dtype=numpy.float64) NU2 = numpy.ascontiguousarray(data[:, 2] - data[:, 3], dtype=numpy.float64) G1_bin = tool_box.set_bin(G1, 10, 100) G2_bin = tool_box.set_bin(G2, 10, 100) img = Image_Plot(xpad=0.2, ypad=0.2) img.subplots(2, 5) bin_type = [bins for i in range(5)] bins_nums = [[100, 50], [100, 100], [200, 100], [200, 200], [500, 200]] for j in range(5): num_g, num_nu = bins_nums[j] G1_hist_bin = set_bin(G1[:3000], bins_nums[j], 1.001, bin_type[j]) NU1_hist_bin = set_bin(NU1[:3000], bins_nums[j], 1.001, bin_type[j])
gx = data[:, 1] n = data[:, 2] u = data[:, 3] crit = data[:, 4]*3.882833518*100 g1 = data[:, 5] gt_c = gt*crit gx_c = gx*crit nu1 = n + u nu2 = n - u print(gt) print(g1) print(crit) gtc_bin = tool_box.set_bin(gt_c,8, 100) gt_bin = tool_box.set_bin(gt,8, 100) fq = Fourier_Quad(1, 1) g_corr_t, corr_sig_t = fq.fmin_g_new(g=gt_c, nu=nu1, bin_num=10, scale=100, pic_path="%s/%d_t.png"%(data_path,tag), left=-500, right=500) g_corr_x, corr_sig_x = fq.fmin_g_new(g=gx_c, nu=nu2, bin_num=10, scale=100, pic_path="%s/%d_x.png"%(data_path,tag), left=-500, right=500) print(g_corr_t,corr_sig_t) print(g_corr_x,corr_sig_x) result[0, rank] = g_corr_t result[1, rank] = corr_sig_t
dec=dec * units.arcsec, frame="fk5") position_theta = len_pos.position_angle(src_pos).rad cos_2theta = numpy.cos(2 * position_theta) sin_2theta = numpy.sin(2 * position_theta) cos_4theta = numpy.cos(4 * position_theta) sin_4theta = numpy.sin(4 * position_theta) mg1r = (mg1 * cos_2theta - mg2 * sin_2theta) * crit_coeff mg2r = (mg1 * sin_2theta + mg2 * cos_2theta) * crit_coeff mur = mu * cos_4theta - mv * sin_4theta mnur1 = mn + mur mnur2 = mn - mur G1_bin = tool_box.set_bin(mg1r, mg_bin_num, 100) G1_hist_bin = gglensing_tool.set_bin(mg1r, 4000, 1.001, "log") NU1_hist_bin = gglensing_tool.set_bin(mnur1, 4000, 1.001, "log") img = Image_Plot(xpad=0.25, ypad=0.25) img.subplots(1, 2) result = gglensing_tool.find_shear_grid(mg1r, mnur1, G1_bin, G1_hist_bin, NU1_hist_bin, chisq_gap=50, dg=10, fit_num=20, ax=img.axs[0][0])[:4]
fg1 = field_data[:, 14][idx] fg2 = field_data[:, 15][idx] FG1 = field_data[:, 16][idx] FG2 = field_data[:, 17][idx] FN = field_data[:, 18][idx] FU = field_data[:, 19][idx] idx_thres = fsnr >= thresh for i in range(g1num): idx11 = fg1 >= fd_g1[i] - dg1 / 2 idx12 = fg1 <= fd_g1[i] + dg1 / 2 mg1 = FG1[idx11 & idx12 & idx_thres] mn = FN[idx11 & idx12 & idx_thres] mu = FU[idx11 & idx12 & idx_thres] mg1_bins = tool_box.set_bin(mg1, bin_num) chi_1 = fq.G_bin(mg1, mn, mu, est_g1[i], 1, mg1_bins, 0) chi_1s.append(chi_1) for j in range(g2num): idx21 = fg2 >= fd_g2[j] - dg2 / 2 idx22 = fg2 <= fd_g2[j] + dg2 / 2 mg2 = FG2[idx21 & idx22 & idx_thres] mn = FN[idx21 & idx22 & idx_thres] mu = FU[idx21 & idx22 & idx_thres] mg2_bins = tool_box.set_bin(mg2, bin_num) chi_2 = fq.G_bin(mg2, mn, mu, est_g2[j], 2, mg2_bins, 0) chi_2s.append(chi_2) total_chi_1.append(chi_1s) total_chi_2.append(chi_2s) field_name.append(name)
field_name = [] with open(fourier_cata_path + "/cat_inform/exposure_avail.dat", "r") as f: f_lines = f.readlines() for ff in f_lines: field_name.append(ff.split("\n")[0]) # set up bins for G1(or G2) for PDF_SYM for i in range(20): h5f_src = h5py.File(field_name[i], "r") temp = h5f_src["/data"][()][:, mg1_idx:mg2_idx + 1] if i == 0: src_data = temp else: src_data = numpy.row_stack((src_data, temp)) mg_bin = tool_box.set_bin(src_data[:, 0], mg_bin_num, 100000) h5f_cor = h5py.File(result_cata_path + "/gg_cor.hdf5", "w") for i in range(chi_guess_num): mean = [0, 0] cov = [[numpy.abs(chi_guess_bin[i] * 2), chi_guess_bin[i]], [chi_guess_bin[i], numpy.abs(chi_guess_bin[i] * 2)]] gg = tool_box.rand_gauss2n(cor_gg_len, mean, cov).astype(dtype=numpy.float32) if i == 0: gg_1 = gg[0] gg_2 = gg[1]