code: def unique_bvals_tolerance(bvals, tol=20):
      """Gives the unique b-values of the data, within a tolerance gap
  
      The b-values must be regrouped in clusters easily separated by a
      distance greater than the tolerance gap. If all the b-values of a
      cluster fit within the tolerance gap, the highest b-value is kept.
  
      Parameters
      ----------
      bvals : ndarray
          Array containing the b-values
  
      tol : int
          The tolerated gap between the b-values to extract
          and the actual b-values.
  
      Returns
      -------
      ubvals : ndarray
          Array containing the unique b-values using the median value
          for each cluster
      """
      b = np.unique(bvals)
      ubvals = []
      lower_part = np.where(b <= b[0] + tol)[0]
      upper_part = np.where(
          np.logical_and(
              b <= b[lower_part[-1]] + tol, b > b[lower_part[-1]]
          )
      )[0]
      ubvals.append(b[lower_part[-1]])
      if len(upper_part) != 0:
          b_index = upper_part[-1] + 1
      else:
          b_index = lower_part[-1] + 1
      while b_index != len(b):
          lower_part = np.where(
              np.logical_and(b <= b[b_index] + tol, b > b[b_index - 1])
          )[0]
          upper_part = np.where(
              np.logical_and(
                  b <= b[lower_part[-1]] + tol, b > b[lower_part[-1]]
              )
          )[0]
          ubvals.append(b[lower_part[-1]])
          if len(upper_part) != 0:
              b_index = upper_part[-1] + 1
          else:
              b_index = lower_part[-1] + 1
  
      # Checking for overlap with get_bval_indices
      for i, ubval in enumerate(ubvals[:-1]):
          indices_1 = get_bval_indices(bvals, ubval, tol)
          indices_2 = get_bval_indices(bvals, ubvals[i + 1], tol)
          if len(np.intersect1d(indices_1, indices_2)) != 0:
              msg = """There is overlap in clustering of b-values.
              The tolerance factor might be too high."""
              warn(msg, UserWarning)
  
      return np.asarray(ubvals)
  
imports: import logging
  from warnings import warn
  import numpy
  from scipy.linalg import inv, polar
  from dipy.io import gradients
  from dipy.core.onetime import auto_attr
  from dipy.core.geometry import vector_norm, vec2vec_rotmat
  from dipy.core.sphere import disperse_charges, HemiSphere
  from dipy.utils.deprecator import deprecate_with_version
label_desc: Use image node_id 12 for calling a global function with example usage: unique_bvals_tolerance(bvals, tol) and returns: np