code: def get_colorbar_and_data_ranges(
      stat_map_data,
      vmin=None,
      vmax=None,
      symmetric_cbar=True,
      force_min_stat_map_value=None,
  ):
      """Set colormap and colorbar limits.
  
      Used by plot_stat_map, plot_glass_brain and plot_img_on_surf.
  
      The limits for the colorbar depend on the symmetric_cbar argument. Please
      refer to docstring of plot_stat_map.
      """
      # handle invalid vmin/vmax inputs
      if (not isinstance(vmin, numbers.Number)) or (
          not np.isfinite(vmin)
      ):
          vmin = None
      if (not isinstance(vmax, numbers.Number)) or (
          not np.isfinite(vmax)
      ):
          vmax = None
  
      # avoid dealing with masked_array:
      if hasattr(stat_map_data, "_mask"):
          stat_map_data = np.asarray(
              stat_map_data[np.logical_not(stat_map_data._mask)]
          )
  
      if force_min_stat_map_value is None:
          stat_map_min = np.nanmin(stat_map_data)
      else:
          stat_map_min = force_min_stat_map_value
      stat_map_max = np.nanmax(stat_map_data)
  
      if symmetric_cbar == "auto":
          if (vmin is None) or (vmax is None):
              symmetric_cbar = stat_map_min < 0 and stat_map_max > 0
          else:
              symmetric_cbar = np.isclose(vmin, -vmax)
  
      # check compatibility between vmin, vmax and symmetric_cbar
      if symmetric_cbar:
          if vmin is None and vmax is None:
              vmax = max(-stat_map_min, stat_map_max)
              vmin = -vmax
          elif vmin is None:
              vmin = -vmax
          elif vmax is None:
              vmax = -vmin
          elif not np.isclose(vmin, -vmax):
              raise ValueError(
                  "vmin must be equal to -vmax unless symmetric_cbar is False."
              )
          cbar_vmin = vmin
          cbar_vmax = vmax
  
      # set colorbar limits
      else:
          negative_range = stat_map_max <= 0
          positive_range = stat_map_min >= 0
          if positive_range:
              if vmin is None:
                  cbar_vmin = 0
              else:
                  cbar_vmin = vmin
              cbar_vmax = vmax
          elif negative_range:
              if vmax is None:
                  cbar_vmax = 0
              else:
                  cbar_vmax = vmax
              cbar_vmin = vmin
          else:
              # limit colorbar to plotted values
              cbar_vmin = vmin
              cbar_vmax = vmax
  
      # set vmin/vmax based on data if they are not already set
      if vmin is None:
          vmin = stat_map_min
      if vmax is None:
          vmax = stat_map_max
  
      return cbar_vmin, cbar_vmax, vmin, vmax
  
imports: import collections.abc
  import functools
  import numbers
  import os
  import warnings
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from matplotlib import gridspec
  from matplotlib.colors import LinearSegmentedColormap
  from nibabel.spatialimages import SpatialImage
  from scipy import stats
  from scipy.ndimage import binary_fill_holes
  from nilearn.image.resampling import reorder_img
  from nilearn.maskers import NiftiMasker
  from nilearn.plotting.displays import get_projector, get_slicer
  from nilearn.plotting.displays._slicers import _get_cbar_ticks
  from ..None import _utils
  from .._utils import compare_version, fill_doc
  from .._utils.extmath import fast_abs_percentile
  from .._utils.ndimage import get_border_data
  from .._utils.niimg import safe_get_data
  from .._utils.numpy_conversions import as_ndarray
  from .._utils.param_validation import check_threshold
  from ..datasets import load_mni152_template
  from ..image import get_data, iter_img, math_img, new_img_like, resample_to_img
  from ..masking import apply_mask, compute_epi_mask
  from ..signal import clean
  from .None import cm
label_desc: Use image node_id 2 for calling a global function with example usage: get_colorbar_and_data_ranges(stat_map_data, vmin, vmax, symmetric_cbar, force_min_stat_map_value) and returns: cbar_vmin,  cbar_vmax,  vmin,  vmax