code: def prepare_output(confounds, demean):
      """Demean and create sample mask for the selected confounds.
  
      Parameters
      ----------
      confounds : pandas.DataFrame
          Confound regressors loaded based on user's choice.
  
      demean : bool
          True if the confounds should be demeaned, False otherwise.
  
      Returns
      -------
      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.
  
      confounds : pandas.DataFrame
          Demeaned confounds ready for subsequent analysis.
      """
      sample_mask, confounds, _ = extract_outlier_regressors(confounds)
      if (
          confounds.size != 0
      ):  # ica_aroma = "full" generate empty output
          # Derivatives have NaN on the first row
          # Replace them by estimates at second time point,
          # otherwise nilearn will crash.
          mask_nan = np.isnan(confounds.values[0, :])
          confounds.iloc[0, mask_nan] = confounds.iloc[1, mask_nan]
          if demean:
              confounds = _demean_confounds(confounds, sample_mask)
      return sample_mask, confounds
  
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 13 for calling a global function with example usage: prepare_output(confounds, demean) and returns: sample_mask,  confounds