code: def which_bin(par, minpar, maxpar, nbins, log=False):
      
      assert (par >= minpar and par <= maxpar)
      if log:
          par, minpar, maxpar = numpy.log(par), numpy.log(minpar), numpy.log(maxpar)
      # par lies some fraction of the way between min and max
      frac = float(par - minpar) / float(maxpar - minpar)
      # binind then lies between 0 and nbins - 1
      binind = int(frac * nbins)
      # corner case
      if par == maxpar:
          binind = nbins - 1
      return binind
docs: Helper function
  
      Returns bin index where a parameter value belongs (from 0 through nbins-1)
      when dividing the range between minpar and maxpar equally into bins.
  
      Parameters
      ----------
      par : float
          Parameter value being binned
      minpar : float
          Minimum parameter value
      maxpar : float
          Maximum parameter value
      nbins : int
          Number of bins to use
      log : boolean
          If True, use log spaced bins
  
      Returns
      -------
      binind : int
          Bin index