def get_area(z, pdf, z1, z2): """ Compute area under photo-z Pdf between z1 and z2, PDF must add to 1 :param float z: redshift :param float pdf: photo-z PDF :param float z1: Lower boundary :param float z2: Upper boundary :return: area between z1 and z2 :rtype: float """ PP = spl(z, pdf, bounds_error=False, fill_value=0.0) area = rom(PP, z1, z2, tol=1.0e-05, rtol=1.0e-05) dz = z[1] - z[0] return area / dz
def compute_error2(z, pdf, zv): L1 = 0.0001 L2 = (max(z) - min(z)) / 2. PP = spl(z, pdf, bounds_error=False, fill_value=0.0) dz = z[1] - z[0] eps = 0.05 za1 = zv - L1 zb1 = zv + L1 area = 0 LM = L2 while abs(area - 0.68) > eps: za2 = zv - LM zb2 = zv + LM area = rom(PP, za2, zb2, tol=1.0e-04, rtol=1.0e-04) / dz Lreturn = LM if area > 0.68: L2 = LM LM = (L1 + L2) / 2. else: L1 = LM LM = (L1 + L2) / 2. return Lreturn
def compute_error(z, pdf, zv): """ Computes the error in the PDF calculation using a reference values from PDF it computes the 68% percentile limit around this value :param float z: redshift :param float pdf: photo-z PDF :param float zv: Reference value from PDF (can be mean, mode, median, etc.) :return: error associated to reference value :rtype: float """ res = 0.001 PP = spl(z, pdf, bounds_error=False, fill_value=0.0) dz = z[1] - z[0] j = 0 area = 0 while area <= 0.68: j += 1 za = zv - res * j zb = zv + res * j area = rom(PP, za, zb, tol=1.0e-04, rtol=1.0e-04) / dz return j * res