code: def _merge_grad_data(data, method="rms"):
      """Merge data from channel pairs using the RMS or mean.
  
      Parameters
      ----------
      data : array, shape = (n_channels, ..., n_times)
          Data for channels, ordered in pairs.
      method : str
          Can be 'rms' or 'mean'.
  
      Returns
      -------
      data : array, shape = (n_channels / 2, ..., n_times)
          The root mean square or mean for each pair.
      """
      data, orig_shape = (
          data.reshape((len(data) // 2, 2, -1)),
          data.shape,
      )
      if method == "mean":
          data = np.mean(data, axis=1)
      elif method == "rms":
          data = np.sqrt(np.sum(data**2, axis=1) / 2)
      else:
          raise ValueError(
              'method must be "rms" or "mean", got %s.' % method
          )
      return data.reshape(data.shape[:1] + orig_shape[1:])
  
imports: import logging
  from collections import defaultdict
  from itertools import combinations
  from pathlib import Path
  import numpy
  from scipy.spatial.distance import pdist, squareform
  from .._fiff.constants import FIFF
  from .._fiff.meas_info import Info
  from .._fiff.pick import _FNIRS_CH_TYPES_SPLIT, _picks_to_idx, pick_types
  from ..transforms import _cart_to_sph, _pol_to_cart
  from ..utils import _check_ch_locs, _check_fname, _check_option, _check_sphere, _clean_names, fill_doc, logger, warn
  from ..viz.topomap import plot_layout
  from .channels import _get_ch_info
label_desc: Use image node_id 16 for calling a global function with example usage: _merge_grad_data(data, method) and returns: data