def plot_dzvsodds(cat_before, cat, binning, Dz_range, z_min, z_max, qual_para, od_bin): if(delta_z_str == "$\Delta z$"): delta_z = cat_before['z_phot'] - cat_before['z_true'] if(delta_z_str == "$\Delta z/(1+z)$"): delta_z = (cat_before['z_phot'] - cat_before['z_true']) / (1 + cat_before['z_true']) od_min = cat_before['odds'].min() od_max = cat_before['odds'].max() #if(od_max > 1.0): od_max = 1. odds_binning = np.arange(od_min, od_max, od_bin) odds_bin = tool.c_binning(odds_binning) s_y, err_s_y = tool.sigmavsodds(cat_before['odds'], delta_z, odds_bin = odds_binning) mult = 1 plt.figure(figsize=(13, 7)) plt.subplot(121) plt.plot(cat_before['odds'], delta_z, 'o', markersize = 1) plt.errorbar(odds_bin, mult*s_y, mult*err_s_y, color = 'green', label = "cumulative RMSx" + str(mult)) plt.axhline( 0, linewidth = 1, color = 'red') plt.axvline( odds_cut, linewidth = 1, color = 'blue', label = qual_para + " cut = " + str(odds_cut)) plt.xlim(xmin = 0, xmax = 1) if (qual_para == 'odds'): plt.xlim(xmin = 0, xmax = 1) if (qual_para == 'PDZbest'): plt.xlim(xmin = 0, xmax = 100) plt.ylim(ymin = -Dz_range, ymax = Dz_range) plt.xlabel(qual_para) plt.ylabel(delta_z_str) z_bin = tool.c_binning(binning) n_true, N_true = tool.hist_oddscut(cat_before['z_true'], cat['z_true'], binning) n_phot, N_phot = tool.hist_oddscut(cat_before['z_phot'], cat['z_phot'], binning) #c:completeness c_true = np.array([]) c_true_high = np.array([]) c_true_low = np.array([]) c_phot = np.array([]) c_phot_high = np.array([]) c_phot_low = np.array([]) for i in range(len(binning)-1): if N_true[i] > 1: c, c_low, c_high = tool.Completeness(0, n_true[i], N_true[i]) else: c = nan c_high = nan c_low = nan c_true = np.append(c_true, c) c_true_high = np.append(c_true_high, c_high) c_true_low = np.append(c_true_low, c_low) if N_phot[i] > 1: c, c_low, c_high = tool.Completeness(0, n_phot[i], N_phot[i]) else: c = nan c_high = nan c_low = nan c_phot = np.append(c_phot, c) c_phot_high = np.append(c_phot_high, c_high) c_phot_low = np.append(c_phot_low, c_low) err_c_true = [c_true_low, c_true_high] err_c_phot = [c_phot_low, c_phot_high] plt.subplot(122) plt.errorbar(z_bin, c_true, err_c_true, color = 'blue', label = "z(true)") plt.errorbar(z_bin, c_phot, err_c_phot, color = 'red', label = "z(phot)") plt.ylabel("Completeness") plt.xlabel("z") plt.xlim(xmin = z_min, xmax = z_max) plt.ylim(ymin = 0, ymax = 1.) plt.legend(loc = 'best') plt.savefig(plot_folder + "odds_cut.png", bbox_inches='tight') plt.close()
def plot_dzvserrz(cat_before, cat, binning, Dz_range, z_min, z_max): if(delta_z_str == "$\Delta z$"): delta_z = cat_before['z_phot'] - cat_before['z_true'] if(delta_z_str == "$\Delta z/(1+z)$"): delta_z = (cat_before['z_phot'] - cat_before['z_true']) / (1 + cat_before['z_true']) errz_bin = tool.c_binning(errz_binning) s_y, err_s_y = tool.sigmavserrz(cat_before['err_z_phot'], delta_z) mult = 1 plt.figure(figsize=(13, 7)) plt.subplot(121) plt.plot(cat_before['err_z_phot'], delta_z, 'o', markersize = 1) plt.errorbar(errz_bin, mult*s_y, mult*err_s_y, color = 'green', label = "cumulative RMSx" + str(mult)) plt.axhline( 0, linewidth = 1, color = 'red') plt.axvline( errz_cut, linewidth = 1, color = 'blue', label = "ERR z(phot) cut = " + str(errz_cut)) plt.xlim(xmin = 0, xmax = yrange_sigma * sigma_ref) plt.ylim(ymin = -Dz_range, ymax = Dz_range) plt.xlabel("ERR z(phot)") plt.ylabel(delta_z_str) plt.legend(loc = 'best') z_bin = tool.c_binning(binning) n_true, N_true = tool.hist_oddscut(cat_before['z_true'], cat['z_true'], binning) n_phot, N_phot = tool.hist_oddscut(cat_before['z_phot'], cat['z_phot'], binning) #c:completeness c_true = np.array([]) c_true_high = np.array([]) c_true_low = np.array([]) c_phot = np.array([]) c_phot_high = np.array([]) c_phot_low = np.array([]) for i in range(len(binning)-1): if N_true[i] > 1: c, c_low, c_high = tool.Completeness(0, n_true[i], N_true[i]) else: c = nan c_high = nan c_low = nan c_true = np.append(c_true, c) c_true_high = np.append(c_true_high, c_high) c_true_low = np.append(c_true_low, c_low) if N_phot[i] > 1: c, c_low, c_high = tool.Completeness(0, n_phot[i], N_phot[i]) else: c = nan c_high = nan c_low = nan c_phot = np.append(c_phot, c) c_phot_high = np.append(c_phot_high, c_high) c_phot_low = np.append(c_phot_low, c_low) err_c_true = [c_true_low, c_true_high] err_c_phot = [c_phot_low, c_phot_high] plt.subplot(122) plt.errorbar(z_bin, c_true, err_c_true, color = 'blue', label = "z(true)") plt.errorbar(z_bin, c_phot, err_c_phot, color = 'red', label = "z(phot)") plt.ylabel("Completeness") plt.xlabel("z") plt.xlim(xmin = z_min, xmax = z_max) plt.ylim(ymin = 0, ymax = 1.) plt.legend(loc = 'best') plt.savefig(plot_folder + "errz_cut.png") plt.close()