code: def add_reference_channels(inst, ref_channels, copy=True):
      """Add reference channels to data that consists of all zeros.
  
      Adds reference channels to data that were not included during recording.
      This is useful when you need to re-reference your data to different
      channels. These added channels will consist of all zeros.
  
      Parameters
      ----------
      inst : instance of Raw | Epochs | Evoked
          Instance of Raw or Epochs with EEG channels and reference channel(s).
      %(ref_channels)s
      copy : bool
          Specifies whether the data will be copied (True) or modified in-place
          (False). Defaults to True.
  
      Returns
      -------
      inst : instance of Raw | Epochs | Evoked
          Data with added EEG reference channels.
  
      Notes
      -----
      .. warning::
          When :ref:`re-referencing <tut-set-eeg-ref>`,
          make sure to apply the montage using :meth:`mne.io.Raw.set_montage`
          only after calling this function. Applying a montage will only set
          locations of channels that exist at the time it is applied.
      """
      from ..epochs import BaseEpochs
      from ..evoked import Evoked
      from ..io import BaseRaw
  
      # Check to see that data is preloaded
      _check_preload(inst, "add_reference_channels")
      _validate_type(ref_channels, (list, tuple, str), "ref_channels")
      if isinstance(ref_channels, str):
          ref_channels = [ref_channels]
      for ch in ref_channels:
          if ch in inst.info["ch_names"]:
              raise ValueError(
                  "Channel %s already specified in inst." % ch
              )
  
      # Once CAR is applied (active), don't allow adding channels
      if _has_eeg_average_ref_proj(inst.info, check_active=True):
          raise RuntimeError(
              "Average reference already applied to data."
          )
  
      if copy:
          inst = inst.copy()
  
      if isinstance(inst, (BaseRaw, Evoked)):
          data = inst._data
          refs = np.zeros((len(ref_channels), data.shape[1]))
          data = np.vstack((data, refs))
          inst._data = data
      elif isinstance(inst, BaseEpochs):
          data = inst._data
          x, y, z = data.shape
          refs = np.zeros((x * len(ref_channels), z))
          data = np.vstack((data.reshape((x * y, z), order="F"), refs))
          data = data.reshape(x, y + len(ref_channels), z, order="F")
          inst._data = data
      else:
          raise TypeError(
              "inst should be Raw, Epochs, or Evoked instead of %s."
              % type(inst)
          )
      nchan = len(inst.info["ch_names"])
  
      # only do this if we actually have digitisation points
      if inst.info.get("dig", None) is not None:
          # "zeroth" EEG electrode dig points is reference
          ref_dig_loc = [
              dl
              for dl in inst.info["dig"]
              if (
                  dl["kind"] == FIFF.FIFFV_POINT_EEG
                  and dl["ident"] == 0
              )
          ]
          if len(ref_channels) > 1 or len(ref_dig_loc) != len(
              ref_channels
          ):
              ref_dig_array = np.full(12, np.nan)
              warn(
                  "The locations of multiple reference channels are ignored."
              )
          else:  # n_ref_channels == 1 and a single ref digitization exists
              ref_dig_array = np.concatenate(
                  (
                      ref_dig_loc[0]["r"],
                      ref_dig_loc[0]["r"],
                      np.zeros(6),
                  )
              )
              # Replace the (possibly new) Ref location for each channel
              for idx in pick_types(
                  inst.info, meg=False, eeg=True, exclude=[]
              ):
                  inst.info["chs"][idx]["loc"][3:6] = ref_dig_loc[0][
                      "r"
                  ]
      else:
          # Ideally we'd fall back on getting the location from a montage, but
          # locations for non-present channels aren't stored, so location is
          # unknown. Users can call set_montage() again if needed.
          ref_dig_array = np.full(12, np.nan)
          logger.info(
              "Location for this channel is unknown; consider calling "
              "set_montage() after adding new reference channels if needed. "
              "Applying a montage will only set locations of channels that "
              "exist at the time it is applied."
          )
  
      for ch in ref_channels:
          chan_info = {
              "ch_name": ch,
              "coil_type": FIFF.FIFFV_COIL_EEG,
              "kind": FIFF.FIFFV_EEG_CH,
              "logno": nchan + 1,
              "scanno": nchan + 1,
              "cal": 1,
              "range": 1.0,
              "unit_mul": FIFF.FIFF_UNITM_NONE,
              "unit": FIFF.FIFF_UNIT_V,
              "coord_frame": FIFF.FIFFV_COORD_HEAD,
              "loc": ref_dig_array,
          }
          inst.info["chs"].append(chan_info)
          inst.info._update_redundant()
      range_ = np.arange(1, len(ref_channels) + 1)
      if isinstance(inst, BaseRaw):
          inst._cals = np.hstack((inst._cals, [1] * len(ref_channels)))
          for pi, picks in enumerate(inst._read_picks):
              inst._read_picks[pi] = np.concatenate(
                  [picks, np.max(picks) + range_]
              )
      elif isinstance(inst, BaseEpochs):
          picks = inst.picks
          inst.picks = np.concatenate([picks, np.max(picks) + range_])
      inst.info._check_consistency()
      set_eeg_reference(
          inst, ref_channels=ref_channels, copy=False, verbose=False
      )
      return inst
  
file_path: mne-python/mne/_fiff/reference.py
imports: import numpy
  from ..defaults import DEFAULTS
  from ..fixes import pinv
  from ..utils import _check_option, _check_preload, _on_missing, _validate_type, fill_doc, logger, verbose, warn
  from .constants import FIFF
  from .meas_info import _check_ch_keys
  from .pick import _ELECTRODE_CH_TYPES, pick_channels, pick_channels_forward, pick_types
  from .proj import _has_eeg_average_ref_proj, make_eeg_average_ref_proj, setup_proj
label_desc: Use image node_id 4 for calling a global function with example usage: add_reference_channels(inst, ref_channels, copy) and returns: inst