code: def check_levels(imls, imt, min_iml=1E-10):
      
      if len(imls) < 1:
          raise ValueError('No imls for %s: %s' % (imt, imls))
      elif imls != sorted(imls):
          raise ValueError('The imls for %s are not sorted: %s' % (imt, imls))
      elif len(distinct(imls)) < len(imls):
          raise ValueError("Found duplicated levels for %s: %s" % (imt, imls))
      elif imls[0] == 0 and imls[1] <= min_iml:  # apply the cutoff
          raise ValueError("The min_iml %s=%s is larger than the second level "
                           "for %s" % (imt, min_iml, imls))
      elif imls[0] == 0 and imls[1] > min_iml:  # apply the cutoff
          imls[0] = min_iml
docs: Raise a ValueError if the given levels are invalid.
  
      :param imls: a list of intensity measure and levels
      :param imt: the intensity measure type
      :param min_iml: minimum intensity measure level (default 1E-10)
  
      >>> check_levels([0.1, 0.2], 'PGA')  # ok
      >>> check_levels([], 'PGA')
      Traceback (most recent call last):
         ...
      ValueError: No imls for PGA: []
      >>> check_levels([0.2, 0.1], 'PGA')
      Traceback (most recent call last):
         ...
      ValueError: The imls for PGA are not sorted: [0.2, 0.1]
      >>> check_levels([0.2, 0.2], 'PGA')
      Traceback (most recent call last):
         ...
      ValueError: Found duplicated levels for PGA: [0.2, 0.2]