code: def tail_threshold(vals, N=1000):
      
      vals = numpy.array(vals)
      if len(vals) < N:
          raise RuntimeError('Not enough input values to determine threshold')
      vals.sort()
      return min(vals[-N:])
docs: Determine a threshold above which there are N louder values