code: def rate_to_mcs(rate, bw=20, long_gi=True):
      
      if bw not in [20, 40, 80, 160]:
          raise Exception("Unknown bandwidth: %d MHz" % (bw))
      idx = int((math.log(bw/10, 2)-1)*2)
      if not long_gi:
          idx += 1
  
      for mcs, rates in MCS_TABLE.items():
          if abs(rates[idx] - rate) < 1e-3:
              return mcs
  
      # failed. Try dot11a rates
      for idx, r in enumerate(DOT11A_RATES):
          if abs(r-rate) < 1e-3:
              return idx
  
      raise Exception("MCS not found: rate=%f, bw=%d, long_gi=%s" %
                      (rate, bw, long_gi))
docs: Convert bit rate to MCS index.
  
      Args:
          rate (float): bit rate in Mbps
          bw (int): bandwidth, 20, 40, 80, ...
          long_gi (bool): True if long GI is used.
  
      Returns:
          mcs (int): MCS index
  
      >>> rate_to_mcs(120, bw=40, long_gi=False)
      5