code: def _demean_confounds(confounds, sample_mask):
      """Demean the confounds.
  
      The mean is calculated on non-outlier values.
  
      Parameters
      ----------
      confounds : pandas.DataFrame
          Confound regressors loaded based on user's choice.
  
      sample_mask : None or numpy.ndarray
          When no volumns require removal, the value is None.
          Otherwise, the shape is \
              (number of scans - number of volumes removed, )
          The index of the niimgs along time/fourth dimension for valid
          volumes for subsequent analysis.
  
      Returns
      -------
      confounds : pandas.DataFrame
          Demeaned confounds.
      """
      confound_cols = confounds.columns
      if sample_mask is None:
          confounds = scale(confounds, axis=0, with_std=False)
      else:  # calculate the mean without outliers.
          confounds_mean = confounds.iloc[sample_mask, :].mean(axis=0)
          confounds -= confounds_mean
      return pd.DataFrame(confounds, columns=confound_cols)
  
imports: import itertools
  import json
  import os
  import re
  import numpy
  import pandas
  from sklearn.preprocessing import scale
  from nilearn._utils.fmriprep_confounds import flag_single_gifti, is_camel_case
  from nilearn.interfaces.bids import parse_bids_filename
  from .load_confounds_scrub import extract_outlier_regressors
label_desc: Use image node_id 14 for calling a global function with example usage: _demean_confounds(confounds, sample_mask) and returns: pd