def compute_distances(data):
    """Compute the distances to select stars in the sdss_sspp sample.

    Distance are determined using empirical color/magnitude fits from
    Ivezic et al 2008, ApJ 684:287

    Extinction correcctions come from Berry et al 2011, arXiv 1111.4985

    This distance only works for stars with log(g) > 3.3
    Other stars will have distance=-1
    """
    Ar = data['Ar']
    Au = 1.81 * Ar
    Ag = 1.4 * Ar
    Ai = 0.759 * Ar
    Az = 0.561 * Ar
    gmag = data['gpsf'] - Ag
    rmag = data['rpsf'] - Ar
    imag = data['ipsf'] - Ai
    gi = gmag - imag
    FeH = data['FeH']
    Mr0 = (-5.06 + 14.32 * gi - 12.97 * gi ** 2 + 6.127 * gi ** 3 - 1.267 *
        gi ** 4 + 0.0967 * gi ** 5)
    FeHoffset = 4.5 - 1.11 * FeH - 0.18 * FeH ** 2
    Mr = Mr0 + FeHoffset
    dist = 0.01 * 10 ** (0.2 * (rmag - Mr))
    dist[data['logg'] < 3.3] = -1
    return dist
