code: def _interpolate_bads_nirs(inst, exclude=(), verbose=None):
      from mne.preprocessing.nirs import _validate_nirs_info
  
      if len(pick_types(inst.info, fnirs=True, exclude=())) == 0:
          return
  
      # Returns pick of all nirs and ensures channels are correctly ordered
      picks_nirs = _validate_nirs_info(inst.info)
      nirs_ch_names = [inst.info["ch_names"][p] for p in picks_nirs]
      nirs_ch_names = [ch for ch in nirs_ch_names if ch not in exclude]
      bads_nirs = [
          ch for ch in inst.info["bads"] if ch in nirs_ch_names
      ]
      if len(bads_nirs) == 0:
          return
      picks_bad = pick_channels(
          inst.info["ch_names"], bads_nirs, exclude=[]
      )
      bads_mask = [p in picks_bad for p in picks_nirs]
  
      chs = [inst.info["chs"][i] for i in picks_nirs]
      locs3d = np.array([ch["loc"][:3] for ch in chs])
  
      dist = pdist(locs3d)
      dist = squareform(dist)
  
      for bad in picks_bad:
          dists_to_bad = dist[bad]
          # Ignore distances to self
          dists_to_bad[dists_to_bad == 0] = np.inf
          # Ignore distances to other bad channels
          dists_to_bad[bads_mask] = np.inf
          # Find closest remaining channels for same frequency
          closest_idx = np.argmin(dists_to_bad) + (bad % 2)
          inst._data[bad] = inst._data[closest_idx]
  
      # TODO: this seems like a bug because it does not respect reset_bads
      inst.info["bads"] = [
          ch for ch in inst.info["bads"] if ch in exclude
      ]
  
      return inst
  
imports: import numpy
  from numpy.polynomial.legendre import legval
  from scipy.interpolate import RectBivariateSpline
  from scipy.linalg import pinv
  from scipy.spatial.distance import pdist, squareform
  from .._fiff.meas_info import _simplify_info
  from .._fiff.pick import pick_channels, pick_info, pick_types
  from ..surface import _normalize_vectors
  from ..utils import _validate_type, logger, verbose, warn
label_desc: Use image node_id 10 for calling a global function with example usage: _interpolate_bads_nirs(inst, exclude, verbose) and returns: inst