Пример #1
0
def plot_syvsz(z_phot, z_true, binning, s, s_label, sp_label, x_label, y_ref, sig="nan"):

    z_bin = tool.c_binning(binning)

    if x_label == "z(true)":
        z = z_true
    if x_label == "z(phot)":
        z = z_phot

    if delta_z_str == "$\Delta z$":
        delta_z = z_phot - z_true
    if delta_z_str == "$\Delta z/(1+z)$":
        delta_z = (z_phot - z_true) / (1 + z_true)

    # sp: estimator percentage (median, sigma68, ...)
    # s: estimator (mean, sigma, ...)

    if s == "bias":
        sp_y, err_sp_y, s_y, err_s_y = tool.biasvsz(z, delta_z, binning)
        np.savetxt(
            "/Users/polstein/Desktop/" + s + "_" + x_label + ".txt", np.array([z_bin, sp_y, err_sp_y]).T, fmt="%5.5f"
        )
    if s == "sigma":
        sp_y, err_sp_y, s_y, err_s_y = tool.sigmavsz(z, delta_z, binning)
        plt.ylim(ymax=yrange_sigma * sigma_ref)
        np.savetxt(
            "/Users/polstein/Desktop/" + s + "_" + x_label + ".txt", np.array([z_bin, sp_y, err_sp_y]).T, fmt="%5.5f"
        )
    if s == str(sig) + "$\sigma$ outliers fraction":
        sp_y, err_sp_y_low, err_sp_y_high, s_y, err_s_y_low, err_s_y_high = tool.outliersvsz(z, delta_z, binning, sig)
        err_sp_y = [err_sp_y_low, err_sp_y_high]
        err_s_y = [err_s_y_low, err_s_y_high]
        np.savetxt(
            "/Users/polstein/Desktop/" + s + "_" + x_label + ".txt",
            np.array([z_bin, s_y, err_s_y_low, err_s_y_high]).T,
            fmt="%5.5f",
        )
        if sig == 2:
            plt.ylim(ymax=yrange_out2)
        if sig == 3:
            plt.ylim(ymax=yrange_out3)

    plt.errorbar(z_bin, s_y, err_s_y, color="black", label=s_label)
    plt.errorbar(z_bin, sp_y, err_sp_y, color="blue", label=sp_label)
    plt.axhline(y=y_ref, linewidth=1, color="red")
    if s != "bias":
        plt.ylim(ymin=0)
    # plt.ylim(ymax = 0.25)
    plt.xlim(xmin=z_min, xmax=z_max)
    plt.xlabel(x_label)
    plt.ylabel(s + " " + delta_z_str)
    plt.legend(loc="best")

    return sp_y, err_sp_y
Пример #2
0
def plot_syvsz(z_phot, z_true, binning, s ,s_label, sp_label, x_label , y_ref, sig = "nan"):

	z_bin = tool.c_binning(binning)
	
	if(x_label == "z(true)"): z = z_true
	if(x_label == "z(phot)"): z = z_phot 
	
	if(delta_z_str == "$\Delta z$"): delta_z = z_phot - z_true
	if(delta_z_str == "$\Delta z/(1+z)$"): delta_z = (z_phot - z_true) / (1 + z_true)
	
	#sp: estimator percentage (median, sigma68, ...)
	#s: estimator (mean, sigma, ...)
	
	if(s == "bias"): 
		sp_y, err_sp_y, s_y , err_s_y = tool.biasvsz(z, delta_z, binning)
		np.savetxt('/Users/pmarti/Desktop/' + s + '_' + x_label + '.txt', np.array([z_bin, sp_y, err_sp_y]).T, fmt = '%5.5f')
	if(s == "sigma"): 
		sp_y, err_sp_y, s_y , err_s_y = tool.sigmavsz(z, delta_z, binning)
		plt.ylim(ymax = yrange_sigma * sigma_ref)
		np.savetxt('/Users/pmarti/Desktop/' + s + '_' + x_label + '.txt', np.array([z_bin, sp_y, err_sp_y]).T, fmt = '%5.5f')
	if(s == str(sig) + "$\sigma$ outliers fraction"): 
		sp_y, err_sp_y_low, err_sp_y_high, s_y , err_s_y_low, err_s_y_high  = tool.outliersvsz(z, delta_z, binning, sig)
		err_sp_y = [err_sp_y_low, err_sp_y_high]
		err_s_y = [err_s_y_low, err_s_y_high]
		np.savetxt('/Users/pmarti/Desktop/' + s + '_' + x_label + '.txt', np.array([z_bin, s_y, err_s_y_low, err_s_y_high]).T, fmt = '%5.5f')
		if(sig == 2): plt.ylim(ymax = yrange_out2)
		if(sig == 3): plt.ylim(ymax = yrange_out3)
		
	plt.errorbar(z_bin, s_y, err_s_y, color = 'black', label = s_label)
	plt.errorbar(z_bin, sp_y, err_sp_y, color = 'blue', label = sp_label)
	plt.axhline( y = y_ref, linewidth = 1, color = 'red')
	if(s != "bias"): plt.ylim(ymin = 0)
	#plt.ylim(ymax = 0.25)
	plt.xlim(xmin = z_min, xmax = z_max)
	plt.xlabel(x_label)
	plt.ylabel(s + " " + delta_z_str)
	plt.legend(loc = 'best')
	
	return sp_y, err_sp_y
Пример #3
0
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()
Пример #4
0
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()
Пример #5
0
	#print "Num. gal. after z(photo)<%2.2f cut: %d %1.1f%%" % (z_cut, n , 100 * float(n)/float(N) )
	
	#Seeting dictionary before odds cut......................
	cat_before = pt.dict(cat_col)

	#odds cut...............................................
	cat_col, n, N = pt.odds_cut(cat_col, odds_cut)
	#print "Num. gal. after odds> %2.2f cut: %d %1.1f%%" % (odds_cut, n , 100 * float(n)/float(N) )
	
	#Seeting dictionary.....................................
	cat = pt.dict(cat_col)

	#Defining binning.......................................
	binning = pt.set_binning(cat)
	
	z_bin = pt.c_binning(binning)
	
	sp_y, err_sp_y = pl.plot_syvsz(cat['z_phot'], cat['z_true'], binning, "sigma", "$\sigma$", "$\sigma_{68}$", "z(true)" , sigma_ref)
	
	sig68 = np.append(sig68, sp_y)
	err_sig68 = np.append(err_sig68, err_sp_y)

sig68 = np.reshape(sig68, (shape, -1))
err_sig68 = np.reshape(err_sig68, (shape, -1))

plt.close()

for i in range(len(sig68)): plt.errorbar(z_bin, sig68[i], err_sig68[i], label = files[i])
#for i in range(len(sig68)): plt.plot(z_bin, sig68[i], label = files[i])
plt.rcParams['legend.fontsize'] = 'small'
plt.axhline( y = sigma_ref, linewidth = 1, color = 'red')
Пример #6
0
#Gencat_nonobs............................................
cat_file = "des_auto_bpz.bpz"

#Main.....................................................
cat = np.loadtxt(cat_file, usecols = (1,5,9), unpack = True)

zp = cat[0]
zs = cat[2]
od = cat[1]
dz = zs - zp

print zp, zs, od

binning = np.arange(0,1.01,0.05)
c_od = pt.c_binning(binning)
n_bin = len(binning) - 1 

sig68 = np.zeros(n_bin)
std = np.zeros(n_bin)

for i in range(n_bin):
	mask = (od > binning[i]) & (od < 1.0)
	x = np.compress(mask, dz)
	sig68[i] = pt.Sigma68(x)
	std[i] = np.std(x)

plt.plot(od, dz, 'o', color = 'black', markersize = 2)
plt.plot(c_od, sig68, 'g', linewidth = 2, label = '$\sigma_{68}$')
plt.plot(c_od, std, 'b', linewidth = 2, label = 'RMS')
plt.axhline(y = 0, linestyle = 'dashed', linewidth = 1, color = 'red')