code: def interpolate_bridged_electrodes(inst, bridged_idx, bad_limit=4):
      """Interpolate bridged electrode pairs.
  
      Because bridged electrodes contain brain signal, it's just that the
      signal is spatially smeared between the two electrodes, we can
      make a virtual channel midway between the bridged pairs and use
      that to aid in interpolation rather than completely discarding the
      data from the two channels.
  
      Parameters
      ----------
      inst : instance of Epochs, Evoked, or Raw
          The data object with channels that are to be interpolated.
      bridged_idx : list of tuple
          The indices of channels marked as bridged with each bridged
          pair stored as a tuple.
      bad_limit : int
          The maximum number of electrodes that can be bridged together
          (included) and interpolated. Above this number, an error will be
          raised.
  
          .. versionadded:: 1.2
  
      Returns
      -------
      inst : instance of Epochs, Evoked, or Raw
          The modified data object.
  
      See Also
      --------
      mne.preprocessing.compute_bridged_electrodes
      """
      _validate_type(inst, (BaseRaw, BaseEpochs, Evoked))
      bad_limit = _ensure_int(bad_limit, "bad_limit")
      if bad_limit <= 0:
          raise ValueError(
              "Argument 'bad_limit' should be a strictly positive "
              f"integer. Provided {bad_limit} is invalid."
          )
      montage = inst.get_montage()
      if montage is None:
          raise RuntimeError("No channel positions found in ``inst``")
      pos = montage.get_positions()
      if pos["coord_frame"] != "head":
          raise RuntimeError(
              f"Montage channel positions must be in ``head`` got {pos['coord_frame']}"
          )
      # store bads orig to put back at the end
      bads_orig = inst.info["bads"]
      inst.info["bads"] = list()
  
      # look for group of bad channels
      nodes = sorted(set(chain(*bridged_idx)))
      G_dense = np.zeros((len(nodes), len(nodes)))
      # fill the edges with a weight of 1
      for bridge in bridged_idx:
          idx0 = np.searchsorted(nodes, bridge[0])
          idx1 = np.searchsorted(nodes, bridge[1])
          G_dense[idx0, idx1] = 1
          G_dense[idx1, idx0] = 1
      # look for connected components
      _, labels = connected_components(G_dense, directed=False)
      groups_idx = [
          [nodes[j] for j in np.where(labels == k)[0]]
          for k in set(labels)
      ]
      groups_names = [
          [inst.info.ch_names[k] for k in group_idx]
          for group_idx in groups_idx
      ]
  
      # warn for all bridged areas that include too many electrodes
      for group_names in groups_names:
          if len(group_names) > bad_limit:
              raise RuntimeError(
                  f"The channels {', '.join(group_names)} are bridged together "
                  "and form a large area of bridged electrodes. Interpolation "
                  "might be inaccurate."
              )
  
      # make virtual channels
      virtual_chs = dict()
      bads = set()
      for k, group_idx in enumerate(groups_idx):
          group_names = [inst.info.ch_names[k] for k in group_idx]
          bads = bads.union(group_names)
          # compute centroid position in spherical "head" coordinates
          pos_virtual = _find_centroid_sphere(
              pos["ch_pos"], group_names
          )
          # create the virtual channel info and set the position
          virtual_info = create_info(
              [f"virtual {k + 1}"], inst.info["sfreq"], "eeg"
          )
          virtual_info["chs"][0]["loc"][:3] = pos_virtual
          # create virtual channel
          data = inst.get_data(picks=group_names)
          if isinstance(inst, BaseRaw):
              data = np.average(data, axis=0).reshape(1, -1)
              virtual_ch = RawArray(
                  data, virtual_info, first_samp=inst.first_samp
              )
          elif isinstance(inst, BaseEpochs):
              data = np.average(data, axis=1).reshape(len(data), 1, -1)
              virtual_ch = EpochsArray(
                  data, virtual_info, tmin=inst.tmin
              )
          else:  # evoked
              data = np.average(data, axis=0).reshape(1, -1)
              virtual_ch = EvokedArray(
                  np.average(data, axis=0).reshape(1, -1),
                  virtual_info,
                  tmin=inst.tmin,
                  nave=inst.nave,
                  kind=inst.kind,
              )
          virtual_chs[f"virtual {k + 1}"] = virtual_ch
  
      # add the virtual channels
      inst.add_channels(
          list(virtual_chs.values()), force_update_info=True
      )
  
      # use the virtual channels to interpolate
      inst.info["bads"] = list(bads)
      inst.interpolate_bads()
  
      # drop virtual channels
      inst.drop_channels(list(virtual_chs.keys()))
  
      inst.info["bads"] = bads_orig
      return inst
  
file_path: mne-python/mne/preprocessing/interpolate.py
imports: from itertools import chain
  import numpy
  from scipy.sparse.csgraph import connected_components
  from .._fiff.meas_info import create_info
  from ..epochs import BaseEpochs, EpochsArray
  from ..evoked import Evoked, EvokedArray
  from ..io import BaseRaw, RawArray
  from ..transforms import _cart_to_sph, _sph_to_cart
  from ..utils import _ensure_int, _validate_type
label_desc: Use image node_id 2 for calling a global function with example usage: interpolate_bridged_electrodes(inst, bridged_idx, bad_limit) and returns: inst