def mc_plot(result_arr, mc_arr, img_name): img = Image_Plot(fig_x=6, fig_y=4, xpad=0.25, ypad=0.2) img.subplots(1, 2) scale = 1000 img.axs[0][0].errorbar(result_arr[0], result_arr[1], result_arr[2], marker="s", fmt=" ", label="g1", capsize=img.cap_size) img.axs[0][0].errorbar(result_arr[3], result_arr[4], result_arr[5], marker="s", fmt=" ", label="g2", capsize=img.cap_size) img.axs[0][1].errorbar(result_arr[0], scale * (result_arr[1] - result_arr[0]), scale * result_arr[2], marker="s", fmt=" ", label="g1", capsize=img.cap_size) img.axs[0][1].errorbar(result_arr[3], scale * (result_arr[4] - result_arr[3]), scale * result_arr[5], marker="s", fmt=" ", label="g2", capsize=img.cap_size) mc_str = "Mean\n$m_1 = %.5f (%.5f)$\n$c_1 = %.5f (%.5f)$\n$m_2 = %.5f (%.5f)$\n$c_2 = %.5f (%.5f)$" \ % (mc_arr[0, 0], mc_arr[0, 1], mc_arr[0, 2], mc_arr[0, 3], mc_arr[1, 0], mc_arr[1, 1], mc_arr[1, 2], mc_arr[1, 3]) img.axs_text(0, 0, 0.8, 0.05, mc_str, text_fontsize=img.legend_size) img.set_label(0, 0, 0, "EST g") img.set_label(0, 1, 1, "$10^3 (\hat{g} - g_{true})$") img.axs[0][0].plot([-0.1, 0.1], [-0.1, 0.1], ls="dashed", c="grey", alpha=0.5) img.axs[0][0].set_ylim(-0.05, 0.05) img.axs[0][1].set_ylim(-0.1, 0.1) for i in range(2): img.set_label(0, i, 1, "TRUE g") img.axs[0][i].legend(fontsize=img.legend_size, loc="lower right") img.axs[0][i].set_xlim(-0.05, 0.05) img.save_img(img_name) img.close_img()
def plot_gf_pix(x, y, ichip, gf1, gf2, gf, gf1_scale, gf2_scale,gf_scale,dot_size=1,pic_path=None): chip_row, chip_col = numpy.divmod(ichip, 9) x = x + chip_col * 2112 y = y + chip_row * 4644 img = Image_Plot(xpad=0.2,ypad=0.1) img.subplots(1, 3) color_cm = 'bwr' norm = plt.Normalize(vmin=numpy.min(gf1_scale[0]), vmax=numpy.max(gf1_scale[1])) cmap = plt.get_cmap(color_cm) cl = cmap(norm(gf1)) fig = img.axs[0][0].scatter(x, y, color=cl, s=dot_size) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] img.figure.colorbar(sm, ax=img.axs[0][0]) norm = plt.Normalize(vmin=numpy.min(gf2_scale[0]), vmax=numpy.max(gf2_scale[1])) cmap = plt.get_cmap(color_cm) cl = cmap(norm(gf2)) fig = img.axs[0][1].scatter(x, y, color=cl, s=dot_size) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] img.figure.colorbar(sm, ax=img.axs[0][1]) norm = plt.Normalize(vmin=numpy.min(gf_scale[0]), vmax=numpy.max(gf_scale[1])) cmap = plt.get_cmap(color_cm) cl = cmap(norm(gf)) fig = img.axs[0][2].scatter(x, y, color=cl, s=dot_size) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] img.figure.colorbar(sm, ax=img.axs[0][2]) for i in range(3): img.axis_sci_ticklabel(0,i,0) img.axis_sci_ticklabel(0,i,1) img.set_label(0,i,0,"y") img.set_label(0,i,1,"x") if pic_path: img.save_img(pic_path) # img.show_img() img.close_img()
def plot_label(x, y, cent_xy, cent_label, title, show=None, pic_path=None): ncent = cent_label.shape[0] img = Image_Plot() img.subplots(1, 1) for i in range(ncent): img.axs[0][0].scatter(cent_xy[0][i], cent_xy[1][i], color="C%d" % i, marker="*", s=80) idx = cent_label[i] == 1 img.axs[0][0].scatter(x[idx], y[idx], edgecolors="C%d" % i, color="none", label="%d, %d" % (i, idx.sum()), s=5) img.axs[0][0].set_title(title) img.axs[0][0].legend() if pic_path: img.save_img(pic_path) if show: img.show_img() img.close_img()
h5f.close() h5f = h5py.File("E:/mask_12.hdf5", "r") mask = h5f["/data"][()] h5f.close() idx = mask > 0 print(idx.sum() / idx.shape[0]) matplotlib.style.use('default') plt.rcParams['font.family'] = 'serif' scale = [24.2423, 23.4742] line_labels = ["$30%$ cutoff", "$60%$ cutoff"] img = Image_Plot(legend_size=14, fig_x=6, fig_y=4, plt_line_width=2, axis_linewidth=2, xpad=0.2) img.subplots(1, 1) # img.set_style() img.axis_type(0, "major", tick_len=6, tick_width=1.2) img.axis_type(1, "major", tick_len=6, tick_width=1.2) bins = img.axs[0][0].hist(-mag_true, 50, ec="gray", label="Entire sample")[1] img.axs[0][0].hist(-mag_true[idx], bins, ec="gray", label="Detected sample") ys = img.axs[0][0].set_ylim() for i, s in enumerate(scale): img.axs[0][0].plot([s, s], [ys[0], ys[1]], lw=img.plt_line_width, ls="--", label=line_labels[i])
# ori_detect[idx] = 1 # snr_stack = snr_stack/ori_detect # snr_stack[idx] = -1000 # # idx = detect_num < 1 # detect_num[idx] = 1 # result_stack = result_stack/detect_num # result_stack[idx] = -1000 # print(result_stack) numpy.savez("./imgs/stack_result.npz", shears, result_stack, error_bar_stack, pk_pool, mag_auto_pool, snr_pool, snr_stack) # plot # matplotlib.style.use('default') img = Image_Plot(fig_x=6, fig_y=4, ypad=0.22, xpad=0) img.subplots(2, 2) # img.set_style_default() img.set_style() img.axis_type(0, "major") img.axis_type(1, "major") markers = ['o', 'v', 's', 'h', 'd', 'p', "4", "*", "X", "^", ">", "+"] colors = ["C%d" % i for i in range(10)] plot_data = [ result_stack[:flux_num], result_stack[flux_num:2 * flux_num], result_stack[2 * flux_num:3 * flux_num], result_stack[3 * flux_num:4 * flux_num] ] plot_data_err = [ error_bar_stack[:flux_num], error_bar_stack[flux_num:2 * flux_num], error_bar_stack[2 * flux_num:3 * flux_num],
scale = st + i * dg if bins[-1] <= ed_: bins.append(scale) else: break i += 1 bins = numpy.array(bins) # calculate the flow num_move = gauss_fit_fun.get_flow(mix_data, 1, gh) scale = num_move.sum() # N/dg x_fit, y_fit = gh[1:], num_move / scale / dg img = Image_Plot(plt_line_width=2.5, fig_x=12, fig_y=9) img.subplots(1, 1) img.axs[0][0].scatter(x_fit, y_fit, c="black", s=15, label="data flow (normalized)") # img.axs[0][1].hist(mix_data, bins, histtype="step", linewidth=img.plt_line_width,label="PDF") # fitting text_content = [] fit_res_1 = scipy.optimize.curve_fit(gauss_fit_fun.gauss_fun_2_, x_fit, y_fit)[0]
import numpy import matplotlib.pyplot as plt from sys import path # import os # my_home = os.popen("echo $HOME").readlines()[0][:-1] # path.append('%s/work/mylib/'%my_home) path.append("D:/Github/astrophy-research/mylib/") from plot_tool import Image_Plot import tool_box parent_path = "F:/works/GGL/1/w1/" img = Image_Plot() img.subplots(1, 1) file_num = 6 bin_num = 13 x = tool_box.set_bin_log(0.04, 15, bin_num + 1) print(x) signal = numpy.zeros((file_num, bin_num)) sigma = numpy.zeros((file_num, bin_num)) los_dist = numpy.zeros((file_num, bin_num)) for i in range(file_num): data_path = parent_path + "cmass_result_w_1_%s.npz" % i data = numpy.load(data_path)["arr_0"] signal[i] = data[0] sigma[i] = data[1] los_dist[i] = data[-1]
dec_n_min, dec_n_max = dec_n.min(), dec_n.max() z_n_min, z_n_max = z_n.min(), z_n.max() ra_s, dec_s, z_s = data_s["RA"], data_s["DEC"], data_s["Z"] ra_s_min, ra_s_max = ra_s.min(), ra_s.max() dec_s_min, dec_s_max = dec_s.min(), dec_s.max() z_s_min, z_s_max = z_s.min(), z_s.max() print("North: RA: %.3f ~ %.3f, DEC: %.3f ~ %.3f, Z: %.4f ~ %.4f"%(ra_n_min, ra_n_max,dec_n_min, dec_n_max,z_n_min, z_n_max)) print("South: RA: %.3f ~ %.3f, DEC: %.3f ~ %.3f, Z: %.4f ~ %.4f"%(ra_s_min, ra_s_max,dec_s_min, dec_s_max,z_s_min, z_s_max)) # The original catalog img = Image_Plot(fig_x=12, fig_y=9) img.set_style() img.plot_img(1,1) img.axs[0][0].scatter(ra_n, dec_n, s=3, label="CMASS_NORTH") img.axs[0][0].scatter(ra_s, dec_s, s=3, label="CMASS_SOUTH") h5f = h5py.File("/mnt/ddnfs/data_users/hkli/CFHT/catalog/cfht_cata/cata.hdf5","r") labels = ["w_1", "w_2", "w_3", "w_4"] for i in range(1,5): data = h5f[labels[i-1]].value dec = data[:,1] ra = data[:,0] ra_min, ra_max = ra.min(), ra.max() dec_min, dec_max = dec.min(), dec.max() pts_1 = [ra_min, ra_max, ra_max, ra_min, ra_min]
nbytes = 0 # on rank 0 of comm, create the contiguous shared block win1 = MPI.Win.Allocate_shared(nbytes, itemsize, comm=comm) buf1, itemsize = win1.Shared_query(0) result_min = numpy.ndarray(buffer=buf1, dtype='d', shape=(4, dilute_num)) comm.Barrier() for tag in task_list_sub: num_non = int(num_s * dilute_case[tag]) num_total = num_s + num_non num_corr = num_non img = Image_Plot(xpad=0.25, ypad=0.25) img.subplots(1, 2) t1 = time.time() gh_mix, gh_mix_sig, coeff_mix, asym_mix = gglensing_tool.find_shear_grid( mg1[:num_total], mnu1[:num_total], G1_bin, G1_hist_bin, NU1_hist_bin, chisq_gap=50, max_iters=50, fit_num=20, dg=0.002, ax=img.axs[0][0])[:4] t2 = time.time()
files = "mag_auto" ch_num = 9 cuts_num = 10 x_coord = [i * cuts_num for i in range(ch_num)] ch = [i for i in range(ch_num)] ylabels = [ "$m_1 \\times 10^2$", "$m_2 \\times 10^2$", "$m_1 \\times 10^2$", "$m_2 \\times 10^2$" ] x_tick = [i * cuts_num for i in range(0, ch_num, 2)] fmt = '%2.f%%' xticks = mtick.FormatStrFormatter(fmt) img = Image_Plot(fig_x=6, fig_y=4, legend_size=12, plt_line_width=2, xpad=0.20) img.subplots(1, 2) img.axis_type(0, "major", tick_len=6, tick_width=1.5) img.axis_type(1, "major", tick_len=6, tick_width=1.5) dys = (-0.1, 0.3) legend_pos = (0.02, 0.96) col = 0 gauss_size = [2, 4, 2, 4] sig_scale = [1.5, 1.5, 4, 4] color = ["C0", "C4", "C1", "C3"] for tag, filter_name in enumerate(sex_filters): print(filter_name, files)
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]) G2_hist_bin = set_bin(G2[:3000], bins_nums[j], 1.001, bin_type[j]) NU2_hist_bin = set_bin(NU2[:3000], bins_nums[j], 1.001, bin_type[j])
h5f["/shear_true"] = shear_field_grid_true h5f.close() # true, mean, measured, sigma, diff_percent, number plt_data_com = [ shear_field_grid_true, shear_field_grid_mean, shear_field_grid, shear_field_grid_mean - shear_field_grid_true, shear_field_grid - shear_field_grid_true ] plt_data_m = [shear_field_grid_err, num_in_grid] plt_data_coms.append(plt_data_com) plt_data_ms.append(plt_data_m) img = Image_Plot(fig_x=5, fig_y=5 / 4 * 3) img.subplots(len(grid_nx), 5) titles = [ "True", "Mean in grid", "Measured", "Mean - True", "Measured - True" ] for tag in range(len(grid_nx)): nx = grid_nx[tag] inverse = range(nx - 1, -1, -1) grid_min = min([plt_data_coms[tag][i].min() for i in range(3)]) grid_max = min([plt_data_coms[tag][i].max() for i in range(3)]) diff_min = min([plt_data_coms[tag][i].min() for i in range(3, 5)]) diff_max = min([plt_data_coms[tag][i].max() for i in range(3, 5)])
else: exit() t1 = time.time() with Pool(ncpus) as pool: sampler = emcee.EnsembleSampler( nwalkers, ndim, MCMC_program.ln_prob_g, args=[MG, NU, mg_bins, bin_num2, inverse, ra, dec, shear_tag], pool=pool) pos, prob, state = sampler.run_mcmc(p0, step) t2 = time.time() print("Time: %2.f sec" % (t2 - t1)) # Plot the walkers img = Image_Plot(fig_x=16, fig_y=4) img.subplots(ndim, 1) for i in range(nwalkers): for j in range(ndim): img.axs[j][0].plot(range(step), sampler.chain[i, :, j], color='grey', alpha=0.6) img.axs[j][0].plot([0, step], [parameters[j], parameters[j]]) img.save_img(parent_path + "pic/%s_mcmc_walkers_nw_%d_stp_%d_expo_%d.png" % (shear_cmd, nwalkers, step, expo_num)) img.close_img() # Plot the panels samples = sampler.chain[:, 150:, :].reshape((-1, ndim)) print(samples.shape)
import matplotlib # matplotlib.use("Agg") from sys import path,argv path.append("/home/hklee/work/mylib") path.append("D:/GitHub/astrophy-research/mylib") from plot_tool import Image_Plot import numpy import h5py parent_path = "E:/works/Group_meeting/2019-11-25-shear_bias_checking/result/data_from_pi/3" img = Image_Plot(fig_x=6,fig_y=8, ypad=0.1) img.subplots(1,2) img.set_style() color_tag = [0] x = numpy.linspace(-1, 1, 100) pts_size = 7 for i in range(12): if i>0: h5f = h5py.File(parent_path+"/%d/result_noisy_bin_num_40.hdf5"%(i-1),"r") else: h5f = h5py.File(parent_path + "/result_all/result_noisy.hdf5", "r") mc = h5f["/sym_mc"].value h5f.close() tag = 3*i + 2 if i in color_tag: color = "C3" else:
import numpy from sys import path path.append("D:/Github/astrophy-research/mylib") path.append("D:/Github/astrophy-research/multi_shear_detect") from Fourier_Quad import Fourier_Quad import h5py from plot_tool import Image_Plot import tool_box img = Image_Plot(fig_x=6, fig_y=8, xpad=0.1, ypad=0.2) img.subplots(1, 3) signal = 0.01 bin_num = [2, 4, 8, 12, 14, 16, 20, 32, 64, 96, 128, 192] data_num = len(bin_num) y = range(data_num) titles = [ "Num = $10^5$,$\sigma=1$,$\mu=0.01$", "Num = $10^6$,$\sigma=1$,$\mu=0.01$", "Num = $10^7$,$\sigma=1$,$\mu=0.01$" ] scale = [100, 100, 1000] x_ticks = numpy.linspace(-0.02, 0.01, 4) for i in range(3): h5f = h5py.File("D:/data_%d.hdf5" % (i + 1), "r") data = h5f["/data"][()] img.axs[0][i].errorbar(data[1, :data_num], y, xerr=data[2, :data_num], capsize=img.cap_size - 1) ys = img.axs[0][i].set_ylim() img.axs[0][i].plot([signal, signal], [ys[0], ys[1]],
print("E-PSF") gal_imgs = numpy.zeros((size, 4*size)) # gal_imgs_cpp = numpy.zeros((size, 4*size)) psf_imgs = numpy.zeros((size, 4*size)) # psf_imgs_cpp = numpy.zeros((size, 4*size)) for i in range(4): psf = fq.cre_psf(psf_scale,ellip_theta=(psf_e, numpy.pi/4*i + theta)) gal = fq.convolve_psf(pts, psf_scale, 1, ellip_theta=(psf_e, numpy.pi/4*i + theta)) gal_imgs[:,int(i*size):int((i+1)*size)] = gal psf_imgs[:,int(i*size):int((i+1)*size)] = psf diff_psf = psf_imgs - epsf_cpp print(diff_psf.min(), diff_psf.max()) img = Image_Plot(fig_x=4,fig_y=3) img.subplots(3, 1) fig = img.axs[0][0].imshow(psf_imgs) img.figure.colorbar(fig,ax=img.axs[0][0]) fig = img.axs[1][0].imshow(epsf_cpp) img.figure.colorbar(fig,ax=img.axs[1][0]) fig = img.axs[2][0].imshow(diff_psf) img.figure.colorbar(fig,ax=img.axs[2][0]) img.show_img() diff_gal = gal_imgs - gal_epsf_cpp print(diff_gal.min(), diff_gal.max()) img = Image_Plot(fig_x=4,fig_y=3) img.subplots(3, 1) fig = img.axs[0][0].imshow(gal_imgs)
import numpy from sys import path path.append("D:/Github/astrophy-research/mylib") path.append("D:/Github/astrophy-research/multi_shear_detect") from Fourier_Quad import Fourier_Quad import h5py from plot_tool import Image_Plot import tool_box img = Image_Plot(xpad=0.28, ypad=0.2) img.subplots(2,2) data_path = "D:/TEMP/PDF_grid_test" h5f = h5py.File(data_path + "/shear.hdf5","r") g1t = h5f["/g1"][()] g2t = h5f["/g2"][()] h5f.close() result = numpy.load(data_path + "/cache.npz")["arr_0"] print(result.shape) # noise free g1 ori PDF mc = tool_box.data_fit(g1t,result[:,0],result[:,1]) label = "ori PDF_SYM noise-free\nm: %.4f(%.4f) c: %.5f(%.5f)"%(mc[0]-1, mc[1], mc[2], mc[3]) img.axs[0][0].errorbar(g1t, result[:,0],result[:,1],c="C0",fmt=" ", label=label,marker="s",ms=5) # noise free g2 ori PDF mc = tool_box.data_fit(g2t,result[:,2],result[:,3]) label = "ori PDF_SYM noise-free\nm: %.4f(%.4f) c: %.5f(%.5f)"%(mc[0]-1, mc[1], mc[2], mc[3]) img.axs[0][1].errorbar(g2t, result[:,2],result[:,3],c="C0",fmt=" ", label=label,marker="s",ms=5)
sigma8_bin = h5f["/sigma8"][()] h5f.close() print(chisqs.shape) print(chisqs.min(), chisqs.max()) omega_cm_num = omega_cm_bin.shape[0] omega_bm_num = omega_bm_bin.shape[0] sigma8_num = sigma8_bin.shape[0] my, mx = numpy.zeros((omega_cm_num, sigma8_num)), numpy.zeros( (omega_cm_num, sigma8_num)) for i in range(omega_cm_num): my[i] = omega_cm_bin[i] for j in range(sigma8_num): mx[:, j] = sigma8_bin[j] img = Image_Plot(fig_x=4, fig_y=3, xpad=0.25, ypad=0.28) img.subplots(2, 5) for i in range(2): for j in range(5): tag = i * 2 + j idx = chisqs[tag] > -200 print(idx.sum()) x = mx[idx].flatten() y = my[idx].flatten() z = chisqs[tag][idx].flatten() img.scatter_pts(i, j, x, y, z, color_map="jet", pts_size=18) img.axs[i][j].set_title("$\Omega_b=%.3f$" % omega_bm_bin[tag]) img.set_label(i, j, 0, "$\Omega_m$")
for j in range(5): total_path = "E:/data/new_pdf/galsim_sample/imgs_%d" % j data_path = total_path + "/chisq" h5f = h5py.File(data_path + "/shear.hdf5", "r") g1 = h5f["/g1"][()] g2 = h5f["/g2"][()] h5f.close() for n in nm: for i in range(10): h5f = h5py.File(data_path + "/chisq_%d_%s.hdf5" % (i, n), "r") chisq1 = h5f["/chisq1"][()] chisq2 = h5f["/chisq2"][()] shear_h = h5f["/shear"][()] h5f.close() print(chisq1.min(), chisq2.min()) idx1 = chisq1 < 10000 idx2 = chisq2 < 10000 img = Image_Plot(xpad=0.15, ypad=0.15) img.subplots(1, 1) img.axs[0][0].plot(shear_h[idx1], chisq1[idx1], label="g1") img.axs[0][0].plot(shear_h[idx2], chisq2[idx2], label="g2") img.axs[0][0].set_xlim(-0.11, 0.11) img.axs[0][0].legend() img.axs[0][0].set_title("g1=%.4f, g2=%.4f" % (g1[i], g2[i])) img.set_label(0, 0, 0, "$\chi^2$") img.set_label(0, 0, 1, "$g$") img.save_img(data_path + "/chisq_%s_%d.png" % (n, i)) # img.show_img() img.close_img()
import h5py from plot_tool import Image_Plot c_scale = 1000 m_scale = 100 names = ["%d" % i for i in range(10)] # names = [] # names.append("total") data_type = "noise_free" for nm in names: parent_path = "E:/data/weight_test/step_1_psf_4_large_sample_48x48" data_path = parent_path + "/%s" % nm pic_nm = parent_path + "/%s_%s.png" % (data_type, nm) img = Image_Plot(xpad=0.2, ypad=0.1, fig_x=5, fig_y=4) img.subplots(2, 3) # weight_label = [5,6,7] # weight_pow = [1,2,3] weight_label = [4, 5, 6] weight_pow = [1, 2, 3, 4] xlabels = ["$w^%d$" % i for i in range(len(weight_pow) + 1)] # weight = ["$w=\\frac{1}{P_{k0,fit}}$", # "$w=\\frac{1}{Max(P_{k0},P_{k0,fit})}$", "$w=\\frac{1}{Flux_{true}}$"] weight = [ "$w=\\frac{1}{P_{k0}}$", "$w=\\frac{1}{P_{k0,fit}}$", "$w=\\frac{1}{Max(P_{k0},P_{k0,fit})}$" ] print(xlabels)
import os my_home = os.popen("echo $MYWORK_DIR").readlines()[0][:-1] from sys import path, argv path.append('%s/work/mylib/' % my_home) import h5py import numpy from plot_tool import Image_Plot src_path = argv[1] ra_bin = [1000, 5000, 10000, 15000, 30000] labels = [] sub_num = numpy.array([75, 34, 56, 35], dtype=numpy.intc) img = Image_Plot(fig_x=8, fig_y=6) img.subplots(2, 2) for i in range(2): for j in range(2): tag = int(i * 2 + j) h5f = h5py.File(src_path + "/group_predict_%d.hdf5" % tag, "r") group_label = h5f["/data"][()] ra_dec = h5f["/ra_dec"][()] h5f.close() for k in range(sub_num[tag]): idx = group_label == k print(k, idx.sum()) # group_label += sub_num[:tag].sum() print(tag, group_label.min(), group_label.max(), sub_num[:tag].sum()) print("\n") img.pts_scatter(i, j, ra_dec[:, 0], ra_dec[:, 1], group_label,
import os # my_home = os.popen("echo $MYWORK_DIR").readlines()[0][:-1] from sys import path, argv # path.append('%s/work/mylib/' % my_home) path.append("D:/GitHub/astrophy-research/mylib") from plot_tool import Image_Plot import h5py import numpy import matplotlib.pyplot as plt import tool_box data_path = "E:/works/correlation/CFHT/2021_6_15/cut_2.5_new/unsmooth/ODDS_0.4" h5f = h5py.File(data_path + "/bias_test.hdf5", "r") img = Image_Plot(fig_x=4, fig_y=3, xpad=0.14, ypad=0.2) img.subplots(2, 4) for i in range(2): for j in range(2): tag = int(2 * i + j) data = numpy.abs(h5f["/%d" % tag][()]) scale = 1 # img.axs[0][tag].errorbar(data[:,0], data[:,1]*scale, data[:,2]*scale,fmt=" ",capsize=3,marker="s", label="$10^3 c_1$") img.axs[0][tag].scatter(data[:, 0], data[:, 1] * scale / data[:, 2] * scale, marker="s", label="$|c_1|/\delta_{c_1}$") # img.axs[1][tag].errorbar(data[:,0], data[:,3]*scale, data[:,4]*scale,fmt=" ",capsize=3,marker="s", label="$10^3 c_2$") img.axs[1][tag].scatter(data[:, 0], data[:, 3] * scale / data[:, 4] * scale,
g2 = h5f["/g2"][()] h5f.close() h5f = h5py.File(data_path + "/new_pdf_noise_free.hdf5", "r") ave_result = h5f["/average"][()].T pdf_result = h5f["/PDF"][()].T new_pdf_result1 = h5f["/new_PDF/g1"][()] new_pdf_result2 = h5f["/new_PDF/g2"][()] h5f.close() shear_num = ave_result.shape[1] img = Image_Plot(cap_size=4, xpad=0.2, ypad=0.2) img.subplots(1, 2) print(ave_result) mc1 = numpy.array(tool_box.data_fit(g1, ave_result[0], ave_result[1])) mc2 = numpy.array(tool_box.data_fit(g2, ave_result[2], ave_result[3])) mc1[0] = mc1[0] - 1 mc2[0] = mc2[0] - 1 print(mc1) print(mc2) img.axs[0][0].errorbar(0, mc1[0], mc1[1], label="ave m1", marker="s",
plt_data = [[ mg2_noise_free, mg2_noise_residual + mg2_noise_free, mg2_cross_term + mg2_noise_free ], [mn_noise_free, mn_noise_residual, mn_cross_term], [mu_noise_free, mu_noise_residual, mu_cross_term], [ mn_noise_free + mu_noise_free, mn_noise_residual + mu_noise_free, mn_cross_term + mu_noise_free ]] labels = [["NF G1", "NR G1", "CT G1"], ["NF N", "NR N", "CT N"], ["NF U", "NR U", "CT U"], ["NF U + N", "NR U + N", "CT U + N"]] img = Image_Plot(fig_x=5, fig_y=4, xpad=0.1, ypad=0.13) img.subplots(2, 2) for i in range(4): m, n = divmod(i, 2) img.axs[m][n].hist(plt_data[i][0][idx], 20, label=labels[i][0], alpha=alpha, histtype="step", linewidth=ls) img.axs[m][n].hist(plt_data[i][1][idx], 20, label=labels[i][1], alpha=alpha, histtype="step",
import matplotlib matplotlib.use("Agg") from sys import path, argv path.append("/home/hklee/work/mylib") path.append("/home/hkli/work/mylib") path.append("D:/GitHub/astrophy-research/mylib") from plot_tool import Image_Plot import numpy import h5py import os parent_path = "/mnt/ddnfs/data_users/hkli/bias_check/data_from_pi/psf_scale_test" img = Image_Plot(fig_x=7, fig_y=2, ypad=0, xpad=0.2) img.subplots(4, 1) m_scale = 100 c_scale = 10000 x_tick_pos = [] for i in range(7): noise_free_path = parent_path + "/data_%d/shear_result_noise_free_epsf_ori_pdf.hdf5" % i noisy_path = parent_path + "/data_%d/shear_result_noisy_cpp_epsf_ori_pdf.hdf5" % i print(i, os.path.exists(noise_free_path)) print(os.path.exists(noisy_path)) # # continue h5f = h5py.File(noise_free_path, "r") sym_mc_nf = h5f["/sym_mc"][()] mean_mc_nf = h5f["/mean_mc"][()] h5f.close()
def plot_gf(ra, dec, gf1, gf2, pic_path, gf1_bin_num = 15, gf2_bin_num = 18,gf_bin_num = 18): gf = numpy.sqrt(gf1**2 + gf2**2) label_1 = numpy.zeros_like(gf1) label_2 = numpy.zeros_like(gf2) label_3 = numpy.zeros_like(gf) gf1_bin = numpy.linspace(gf1.min(), gf1.max(), gf1_bin_num+1) gf2_bin = numpy.linspace(gf2.min(), gf2.max(), gf2_bin_num+1) gf_bin = numpy.linspace(gf.min(), gf.max(), gf_bin_num+1) for i in range(gf1_bin_num): idx1 = gf1 >= gf1_bin[i] idx2 = gf1 < gf1_bin[i+1] idx = idx1 & idx2 label_1[idx] = (gf1_bin[i]+ gf1_bin[i+1])/2 for i in range(gf2_bin_num): idx1 = gf2 >= gf2_bin[i] idx2 = gf2 < gf2_bin[i+1] idx = idx1 & idx2 label_2[idx] = (gf2_bin[i]+ gf2_bin[i+1])/2 for i in range(gf_bin_num): idx1 = gf >= gf_bin[i] idx2 = gf < gf_bin[i+1] idx = idx1 & idx2 label_3[idx] = (gf_bin[i]+ gf_bin[i+1])/2 img = Image_Plot() img.subplots(1,3) norm = plt.Normalize(vmin=numpy.min(label_1), vmax=numpy.max(label_1)) cmap = plt.get_cmap('YlOrRd',gf1_bin_num) cl = cmap(norm(label_1)) fig = img.axs[0][0].scatter(ra, dec, color=cl, s=3) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] img.figure.colorbar(sm, ax=img.axs[0][0]) norm = plt.Normalize(vmin=numpy.min(label_2), vmax=numpy.max(label_2)) cmap = plt.get_cmap('YlOrRd',gf2_bin_num) cl = cmap(norm(label_2)) fig = img.axs[0][1].scatter(ra, dec, color=cl, s=3) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] img.figure.colorbar(sm, ax=img.axs[0][1]) norm = plt.Normalize(vmin=numpy.min(label_3), vmax=numpy.max(label_3)) cmap = plt.get_cmap('YlOrRd',gf_bin_num) cl = cmap(norm(label_3)) fig = img.axs[0][2].scatter(ra, dec, color=cl, s=3) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm._A = [] img.figure.colorbar(sm, ax=img.axs[0][2]) img.save_img(pic_path) # img.show_img() img.close_img()
pic_nm = "./result/galsim/mc_%s_ellip_mix.png"%psf_tag pic_nm_pdf = "./result/galsim/mc_%s_ellip_mix.pdf"%psf_tag else: numpy.savez("./result/galsim/cache_%s_ellip_%.2f.npz"%(psf_tag,ellip), mcs) pic_nm = "./result/galsim/mc_%s_ellip_%.2f.png"%(psf_tag, ellip) pic_nm_pdf = "./result/galsim/mc_%s_ellip_%.2f.pdf"%(psf_tag, ellip) y = numpy.zeros((si_num*sr_num,)) x = numpy.zeros((si_num*sr_num,)) for i in range(si_num): for j in range(sr_num): tag = int(i*sr_num + j) y[tag] = sersic_index[i] x[tag] = scale_radius[j] titles = ["$m_1$","$c_1$","$m_2$", "$c_2$"] img = Image_Plot(xpad=0.3,ypad=0.3,fig_x=4,fig_y=3) img.subplots(2, 2) for i in range(2): for j in range(2): tag = int(i*2 + j) z = mcs[tag].flatten() img.scatter_pts(i,j,x,y,z,pts_size=30,color_map="bwr") img.set_label(i,j,0,"Sersic Index") img.set_label(i,j,1,"Scale Radius") img.axs[i][j].set_title(titles[tag],fontsize=img.xy_lb_size) img.save_img(pic_nm) img.save_img(pic_nm_pdf) # img.show_img()
plt.show() num_g = 6 result = numpy.zeros((5,num_g)) dz = 0.1 for i in range(num_g): z1 = redshift.min() + i*dz z2 = z1+dz idx_1 = redshift >= z1 idx_2 = redshift < z2 idx = idx_1 & idx_2 # img = Image_Plot() # img.subplots(1, 2) left, right = -0.1, 0.1 gt, gt_sig = fq.fmin_g_new(mgt[idx], mnut[idx], 8, left=left, right=right)[:2] gx, gx_sig = fq.fmin_g_new(mgx[idx], mnux[idx], 8, left=left, right=right)[:2] print("gamma_t: %.4f (%.4f).Num: %d.\nMead dist: %.4f Mpc/h. Z bin [%.4f, %.4f].\n" %(gt, gt_sig,idx.sum(),dist_len[idx].mean(),z1, z2)) result[0, i] = gt result[1, i] = gt_sig result[2, i] = gx result[3, i] = gx_sig result[4, i] = dist_len[idx].mean() # img.show_img() img = Image_Plot(fig_x=12, fig_y=8) img.subplots(1, 1) img.axs[0][0].errorbar(result[4],result[0], result[1], c="C4", label="$\gamma_t$") img.set_label(0,0,0,"$\gamma_t$",size=15) img.set_label(0,0,1,"$Dist_S\ [\\rm{Mpc \cdot h^{-1}}]$",size=15) img.show_img()
h5f = h5py.File( data_path + "/cuts_pi_all_sample_w_maxpkfit_sq/sym/sex2_1.5/flux2_ex3/total.hdf5", "r") mc1_mpk_pk_fit = h5f["/mc1"][()][:, ch] mc2_mpk_pk_fit = h5f["/mc2"][()][:, ch] h5f.close() h5f = h5py.File( data_path + "/cuts_pi_all_sample_w_maxpkfit_sq/sym/sex2_1.5/mag_true/total.hdf5", "r") mc1_mpk_tmag = h5f["/mc1"][()][:, ch] mc2_mpk_tmag = h5f["/mc2"][()][:, ch] h5f.close() matplotlib.rcParams["font.family"] = "serif" img = Image_Plot(fig_x=6, fig_y=4, xpad=0.2, ypad=0.2, legend_size=13) img.subplots(1, 1) img.axis_type(0, "major", tick_len=6, tick_width=1.5) img.axis_type(1, "major", tick_len=6, tick_width=1.5) img.axs[0][0].errorbar(x_coord, 100 * mc1_tf_pk_fit[0], 100 * mc1_tf_pk_fit[1], linewidth=img.plt_line_width - 0.5, capsize=img.cap_size, marker="o", fillstyle="none", c="C2", label="$m_1$, weight=$F^{-2}$") img.axs[0][0].errorbar(x_coord, 100 * mc2_tf_pk_fit[0],
data_path = "E:/works/correlation/CFHT/cut_2.5/deblend_1" h5f = h5py.File(data_path + "/chisq_diff_expo.hdf5","r") chisq = h5f["/chisq"][()] omg_b = h5f["/omega_bm_bin"][()] omg_c = h5f["/omega_cm_bin"][()] sig8 = h5f["/sigma8"][()] x, y = numpy.zeros_like(chisq[0]), numpy.zeros_like(chisq[0]) for i in range(len(sig8)): x[:,i] = sig8[i] for i in range(len(omg_c)): y[i] = omg_c[i] img = Image_Plot(fig_x=5,fig_y=4,xpad=0.25,ypad=0.25) img.subplots(2,5) for i in range(2): for j in range(5): chisq_i = -chisq[int(i*5 + j)] idx = chisq_i < 70 xi = x[idx].flatten() yi = y[idx].flatten() zi = chisq_i[idx].flatten() idx = zi == zi.min() xi_min, yi_min = xi[idx], yi[idx] print(xi_min, yi_min) img.scatter_pts(i,j, xi,yi,numpy.log10(zi),color_map='jet',pts_size=5)