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()
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)
def plot_gf_celestial(ra, dec, gf1, gf2, gf, gf1_scale, gf2_scale,gf_scale,dot_size=1,pic_path=None): 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(ra,dec, 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(ra,dec, 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(ra,dec, 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()
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()
fore_source = argv[1] area = argv[2] z1, z2 = float(argv[3]), float(argv[4]) new_name = argv[5] parent_path = "/mnt/perc/hklee/CFHT/gg_lensing/data/foreground/%s/" % fore_source data_path = "%s/%s.hdf5" % (parent_path, area) pic_path = "%s/%s.png" % (parent_path, new_name) h5f = h5py.File(data_path, "r") names = list(h5f.keys()) redshift = h5f["/Z"].value num = redshift.shape[0] idx1 = redshift >= z1 idx2 = redshift < z2 idx = idx1 & idx2 img = Image_Plot() img.subplots(1, 1) bins = img.axs[0][0].hist(redshift, label="All")[1] img.axs[0][0].hist(redshift[idx], bins=bins, label="[%.3f, %.3f]" % (z1, z2)) img.save_img(pic_path) h5f_new = h5py.File(parent_path + new_name + ".hdf5", "w") for nm in names: h5f_new["/%s" % nm] = h5f["/%s" % nm].value[idx] print("%d == > %d in [%.3f, %.3f] Z bin" % (num, idx.sum(), z1, z2)) h5f.close() h5f_new.close()
result[los_dist_lb, ir] = cosmos.comoving_distance(redshift.mean()).value * h print("[%.5f, %.5f], %d galaxy pairs at radius %f (%f)" % (radius_bin[ir], radius_bin[ir + 1], pair_num, r_mean, (radius_bin[ir] + radius_bin[ir + 1]) / 2)) else: print("Skip [%.5f, %.5f], 0 galaxy pairs" % (radius_bin[ir], radius_bin[ir + 1])) h5f = h5py.File(tool_box.file_name(result_path), "w") h5f["/data"] = result h5f.close() numpy.savez(tool_box.file_name(result_path_npz), result) img = Image_Plot() img.set_style() img.subplots(1, 1) # img.axs[0][0].errorbar(result[r_lb], result[gt_lb], result[gt_lb + 1], c="C1", capsize=4, label="T", marker="s") # img.axs[0][0].errorbar(result[r_lb], result[gx_lb], result[gx_lb + 1], c="C2", capsize=4, label="X", marker="s") img.axs[0][0].errorbar(result[trans_dist_lb], result[crit_t_lb], result[crit_t_sig_lb], c="C1", capsize=4, label="T", marker="s") img.axs[0][0].errorbar(result[trans_dist_lb], result[crit_x_lb], result[crit_x_sig_lb + 1],
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],
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)
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_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",
# img.del_ticks(i, j, [0, 1]) # img.set_label(i, j, 0, "+ G1 -") # img.set_label(i, j, 1, "- G2 +") # # for j in range(3): # img.axs[i][j].set_title(titles[i][j]) # # pic_name = pic_path + "/%s_%d_sym.png" % (pic_nm, rank) # img.save_img(pic_name) # img.close_img() ################################################################################# # compare img = Image_Plot(fig_x=5, fig_y=4,xpad=0.25, ypad=0.25) img.subplots(2, 3) titles = [["$\chi^2$", "dipole-fit", "quadrupole-fit"], ["$\chi^2-SYM$", "dipole-fit_SYM", "quadruple-fit_SYM"]] img.axs[0][0].plot(gh, chisq1, label="$\chi^2_{g1}$,g1=%.3f" % g1t[rank]) img.axs[0][0].plot(gh, chisq2, label="$\chi^2_{g2}$,g2=%.3f" % g2t[rank]) img.axs[1][0].plot(gh, chisq1_sym, label="$\chi^2_{g1}$,g1=%.3f" % g1t[rank]) img.axs[1][0].plot(gh, chisq2_sym, label="$\chi^2_{g2}$,g2=%.3f" % g2t[rank]) img.set_label(0, 0, 0, "$\chi^2$") img.set_label(0, 0, 1, "$\hat{g}$")
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,
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()
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)
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 from plot_tool import Image_Plot import matplotlib.pyplot as plt from matplotlib import cm psf_type = "Moffat" psf_flux = 1 psf_scale = 4 stamp_size = 48 seed = 56525 fq = Fourier_Quad(stamp_size, seed) img = Image_Plot() img.subplots(1, 1) fig = img.axs[0][0].imshow(fq.kx2 + fq.ky2) img.figure.colorbar(fig, ax=img.axs[0][0]) img.axs[0][0].set_title("$k^2$") img.del_ticks(0, 0, [0, 1]) img.save_img("E:/kxy.png") img.show_img() pst_num = 50 gal_fluxs = [4000, 16000, 32000, 100000] steps = [0.6, 1, 2, 4] fq = Fourier_Quad(stamp_size, seed) max_radius = 7
print("cpsf") data_noisy_e = h5f["/data"][()] h5f.close() scale = 10000 diff = (data_noise_free_e - data_noisy_e) estimator = [diff[:,0],diff[:,2],diff[:,2]+diff[:,3], diff[:,1],diff[:,3],diff[:,2]-diff[:,3]] est = ["G1","N","N+U", "G2","U","N-U"] bin_num = 5000 img = Image_Plot() img.subplots(2,3) for i in range(6): m,n = divmod(i,3) img.axs[m][n].hist(estimator[i]/scale,bin_num) fit = tool_box.gaussnosie_fit(estimator[i]/scale,bin_num) img.axs[m][n].plot(fit[0],fit[1],c="C1",ls="--",linewidth=1.5) print("plot %s"%est[i]) ys = img.axs[m][n].set_ylim() img.axs[m][n].plot([0,0],[ys[0],ys[1]],ls="--",alpha=0.5,c="k",linewidth=1) print(fit[4]) text_str = "%s\n%.4f\n%.4f\n%.4f"%(est[i],fit[4][0],fit[4][1],fit[4][2])
crit = phy_dist_s / phy_dist_f / (phy_dist_s - phy_dist_f) * (1 + z_f) crit_integ = phy_dist_integ_s / phy_dist_integ_f / ( phy_dist_integ_s - phy_dist_integ_f) * (1 + z_f) # radius bin radius_num = 24 radius_bin = tool_box.set_bin_log(0.1, 25.12, radius_num + 1) print("Radius bin:", radius_bin) theta = numpy.linspace(0, 2 * numpy.pi, 1000) # mask mask_py = numpy.zeros((source_num, radius_num), dtype=numpy.intc) - 1 img = Image_Plot() img.subplots(1, 1) result = numpy.zeros((3, radius_num)) for i in range(radius_num): idx1 = sep_dist >= radius_bin[i] idx2 = sep_dist < radius_bin[i + 1] idx = idx1 & idx2 pair_num = idx.sum() if pair_num > 0: mask_py[:, i][idx] = i
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,
# the galactic parameters h5f = h5py.File(parent_path + "param_slope.hdf5", "w") h5f["/FIELD_g"] = shear_field h5f["/x"] = x mag_i = tool_box.mag_generator(total_num, 20, 23.5) flux_i = tool_box.mag_to_flux(mag_i) h5f["/mag"] = mag_i h5f["/flux"] = flux_i print(flux_i.min(), flux_i.max()) # Plot img = Image_Plot() img.subplots(1, 3) img.set_style() inverse = range(nx - 1, -1, -1) norm_g = plt.Normalize(vmin=numpy.min(shear_field_ch), vmax=numpy.max(shear_field_ch)) cmap_g = plt.get_cmap('jet') for i in range(3): if i == 0: fig = img.axs[0][i].imshow(shear_field[inverse], cmap="jet") img.figure.colorbar(fig, ax=img.axs[0][i]) elif i == 1: num_dens = numpy.histogram2d(gal_coord[0], gal_coord[1], [ra_bin, dec_bin])[0]
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",
src_com_dist = [cosmos.comoving_distance(z).value * h for z in src_z] # Mpc/h for tag, z in enumerate(src_z): print("Source plane 1 at z = %.2f, %.5f Mpc/h" % (z, src_com_dist[tag])) # show the shear/kappa map bin_num = 100 Rmax = 1000 print("Max to %.3f Mpc/h" % (com_dist_len * Rmax / 3600 / 180 * numpy.pi)) if rank == 0: ra_bin = numpy.linspace(-Rmax, Rmax, bin_num + 1) dec_bin = numpy.linspace(-Rmax, Rmax, bin_num + 1) ra, dec = GGLensing_tool.get_pos(ra_bin, dec_bin, bin_num) shear_data = [GGLensing_tool.cal_shear(ra, dec, nfw, z) for z in src_z] img = Image_Plot(xpad=0.25, ypad=0.25) img.subplots(4, src_plane_num) for i in range(src_plane_num): kappa, g1, g2 = shear_data[i][0], shear_data[i][1], shear_data[i][2] g = numpy.sqrt(g1**2 + g2**2) img.scatter_pts(0, i, ra, dec, kappa) img.scatter_pts(1, i, ra, dec, g) img.scatter_pts(2, i, ra, dec, g1) img.scatter_pts(3, i, ra, dec, g2) img.axs[0][i].set_title("kappa from source plane at Z=%.3f" % src_z[i]) img.axs[1][i].set_title("g from source plane at Z=%.3f" % src_z[i]) img.axs[2][i].set_title("g1 from source plane at Z=%.3f" % src_z[i]) img.axs[3][i].set_title("g2 from source plane at Z=%.3f" % src_z[i])
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()
mg_ori[i] = rng.normal(0, 0.3, 1) # mg[i] = rng.normal(shear_slope_1d[i], 0.3, 1) mg[i] = mg_ori[i] + shear_slope_1d[i] mg_bins = fq.set_bin(mg, bin_num, 10) mg_bins_test = fq.set_bin(mg, bin_num_test, 10) num_ini = numpy.histogram(mg, mg_bins)[0] n1 = num_ini[0:bin_num2][inverse] n2 = num_ini[bin_num2:] num_exp = (n1 + n2) / 2 test_num = 15 a2_test = numpy.linspace(a2-0.1, a2+0.1, test_num) img = Image_Plot() img.subplots(1,2) x_plt = numpy.linspace(-8, 8, 20) fx = a2*x_plt # img.axs[0][1].plot(x_plt, fx) chi_temp = fq.get_chisq(mg_ori, 0, 0, mg_bins, bin_num2, inverse, 0) chi_temp_sym = fq.get_chisq(mg, 1, a2*x, mg_bins, bin_num2, inverse, 0) print(chi_temp,chi_temp_sym) bin_idx = [] for i in range(bin_num): idx_1 = mg_ori >= mg_bins[i] idx_2 = mg_ori < mg_bins[i+1] idx = idx_1 & idx_2 bin_idx.append(idx) print(idx.shape)
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()
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$")
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],
from sys import path path.append("D:/GitHub/astrophy-research/mylib") import numpy from Fourier_Quad import Fourier_Quad import tool_box from plot_tool import Image_Plot from astropy.io import fits expo = fits.open("D:/frame-1.fits")[0].data print(expo.shape) expo_pixel = numpy.sort(expo.flatten()) sigma = expo_pixel.std() mean = expo_pixel.mean() pixel_num = len(expo_pixel) idx1 = expo_pixel >= -0.5 #expo_pixel[int(pixel_num/20)]#mean - sigma*2 idx2 = expo_pixel <= 0.1 #expo_pixel[int(pixel_num/20*19)]#mean + sigma*10 idx = idx1 & idx2 print(expo_pixel[int(pixel_num / 20)], expo_pixel[int(pixel_num * 19 / 20)]) print(numpy.std(expo_pixel[idx])) # idx = expo_pixel < 0.15 bin_num = 50 num, bins = numpy.histogram(expo_pixel[idx], bin_num)[:2] x = (bins[:bin_num] + bins[1:]) / 2 print(num) img = Image_Plot() img.subplots(1, 2) img.axs[0][0].imshow(expo) img.axs[0][1].hist(expo_pixel[idx], bin_num) img.show_img()