def has_no_dangling_branch(neuron):
    '''Check if the neuron has dangling neurites'''
    soma_center = neuron.soma.points[:, COLS.XYZ].mean(axis=0)
    recentered_soma = neuron.soma.points[:, COLS.XYZ] - soma_center
    radius = np.linalg.norm(recentered_soma, axis=1)
    soma_max_radius = radius.max()

    def is_dangling(neurite):
        '''Is the neurite dangling ?'''
        starting_point = neurite.points[1][COLS.XYZ]

        if np.linalg.norm(starting_point - soma_center) - soma_max_radius <= 12.:
            return False

        if neurite.type != NeuriteType.axon:
            return True

        all_points = list(chain.from_iterable(n.points[1:]
                                              for n in iter_neurites(neurite)
                                              if n.type != NeuriteType.axon))
        res = [np.linalg.norm(starting_point - p[COLS.XYZ]) >= 2 * p[COLS.R] + 2
               for p in all_points]
        return all(res)

    bad_ids = [(n.root_node.id, [n.root_node.points[1]])
               for n in iter_neurites(neuron) if is_dangling(n)]
    return CheckResult(len(bad_ids) == 0, bad_ids)
Check if the neuron has dangling neurites