def _get_nn_for_timestamp(kd_tree, X, timestep, aso_idx, k, radius):
    """Returns the nearest ASOs to the provided `aso_idx` ASO.  If a `radius` is
    provided then the results are all the ASOs within that given radius, otherwise
    the results are the `k` nearest ASOs

    :param kd_tree: The KD-tree build for the prediction timestep
    :type kd_tree: sklearn.neighbors.KDTree

    :param X: The numpy array of orbital predictions for each ASO for the
              prediction timestep
    :type X: numpy.array

    :param timestep: The orbital prediction timestep that the `X` array
                     represents
    :type timestep: int

    :param aso_idx: The index in `X` of the ASO to find nearest ASOs for
    :type aso_idx: int

    :param k: The number of nearest ASOs to return. Not used if `radius` is passed
    :type k: int

    :param radius: The radius, in meters, to use in determining what is a near ASO
    :type radius: float

    :return: A list of tuples representing all ASOs that match the provided query
             where the first value is the index in `X` of the matching ASO, the
             second value is the timestep where this match occurred, and the third
             value is the distance from the query ASO to the matching ASO.
    :rtype: [(int, int, float)]
    """
    query_point = X[aso_idx].reshape(1, -1)
    if radius:
        result_idxs, dists = kd_tree.query_radius(query_point,
                                                  r=radius,
                                                  return_distance=True)
    else:
        dists, result_idxs = kd_tree.query(query_point, k=k+1)

    idx_dists = zip(result_idxs[0], dists[0])
    if radius:
        # Only return results that have non-zero distance
        result = [(int(i), int(timestep), float(d))
                  for i, d in idx_dists
                  if d > 0]
    else:
        # Remove query object from results
        result = [(int(i), int(timestep), float(d))
                  for i, d in idx_dists
                  if i != aso_idx]
    return result