code: def _set_montage_fnirs(info, montage):
      """Set the montage for fNIRS data.
  
      This needs to be different to electrodes as each channel has three
      coordinates that need to be set. For each channel there is a source optode
      location, a detector optode location, and a channel midpoint that must be
      stored. This function modifies info['chs'][#]['loc'] and info['dig'] in
      place.
      """
      from ..preprocessing.nirs import _validate_nirs_info
  
      # Validate that the fNIRS info is correctly formatted
      picks = _validate_nirs_info(info)
  
      # Modify info['chs'][#]['loc'] in place
      num_ficiduals = len(montage.dig) - len(montage.ch_names)
      for ch_idx in picks:
          ch = info["chs"][ch_idx]["ch_name"]
          source, detector = ch.split(" ")[0].split("_")
          source_pos = montage.dig[
              montage.ch_names.index(source) + num_ficiduals
          ]["r"]
          detector_pos = montage.dig[
              montage.ch_names.index(detector) + num_ficiduals
          ]["r"]
  
          info["chs"][ch_idx]["loc"][3:6] = source_pos
          info["chs"][ch_idx]["loc"][6:9] = detector_pos
          midpoint = (source_pos + detector_pos) / 2
          info["chs"][ch_idx]["loc"][:3] = midpoint
          info["chs"][ch_idx]["coord_frame"] = FIFF.FIFFV_COORD_HEAD
  
      # Modify info['dig'] in place
      with info._unlock():
          info["dig"] = montage.dig
  
imports: import os.path
  import re
  from collections import OrderedDict
  from copy import deepcopy
  from dataclasses import dataclass
  import numpy
  from .._fiff._digitization import _coord_frame_const, _count_points_by_type, _ensure_fiducials_head, _format_dig_points, _get_data_as_dict_from_dig, _get_dig_eeg, _get_fid_coords, _make_dig_points, _read_dig_fif, write_dig
  from .._fiff.constants import CHANNEL_LOC_ALIASES, FIFF
  from .._fiff.meas_info import create_info
  from .._fiff.open import fiff_open
  from .._fiff.pick import _picks_to_idx, channel_type, pick_types
  from .._freesurfer import get_mni_fiducials
  from ..defaults import HEAD_SIZE_DEFAULT
  from ..transforms import Transform, _ensure_trans, _fit_matched_points, _frame_to_str, _quat_to_affine, _sph_to_cart, _topo_to_sph, _verbose_frames, apply_trans, get_ras_to_neuromag_trans
  from ..utils import _check_fname, _check_option, _on_missing, _pl, _validate_type, copy_function_doc_to_method_doc, fill_doc, verbose, warn
  from ..utils.docs import docdict
  from ..viz import plot_montage
  from ._dig_montage_utils import _parse_brainvision_dig_montage, _read_dig_montage_egi
label_desc: Use image node_id 13 for calling a global function with example usage: _set_montage_fnirs(info, montage) without return types