def _find_K_cut(self, k):

        ## Find the lowest level to cut at that has k or more clusters
        starts = [v.start_level for v in self.nodes.itervalues()]
        ends = [v.end_level for v in self.nodes.itervalues()]
        crits = _np.unique(starts + ends)
        nclust = {}

        for c in crits:
            nclust[c] = len([e for e, v in self.nodes.iteritems()
                             if v.start_level <= c and v.end_level > c])

        width = _np.max(nclust.values())

        if k in nclust.values():
            cut = _np.min([e for e, v in nclust.iteritems() if v == k])
        else:
            if width < k:
                cut = _np.min([e for e, v in nclust.iteritems() if v == width])
            else:
                ktemp = _np.min([v for v in nclust.itervalues() if v > k])
                cut = _np.min([e for e, v in nclust.iteritems() if v == ktemp])

        return cut
Find the lowest level cut that has k connected components. If there are
dataset/ETHPy150Open CoAxLab/DeBaCl/debacl/level_set_tree.py/LevelSetTree._find_K_cut