code: def _threshold_maps_ratio(maps_img, threshold):
      """Automatic thresholding of atlas maps image.
  
      Considers the given threshold as a ratio to the total number of voxels
      in the brain volume. This gives a certain number within the data
      voxel size which means that nonzero voxels which fall above than this
      size will be kept across all the maps.
  
      Parameters
      ----------
      maps_img : Niimg-like object
          An image of brain atlas maps.
  
      threshold : float
          If float, value is used as a ratio to n_voxels
          to get a certain threshold size in number to threshold the image.
          The value should be positive and
          within the range of number of maps (i.e. n_maps in 4th dimension).
  
      Returns
      -------
      threshold_maps_img : Nifti1Image
          Gives us thresholded image.
  
      """
      maps = check_niimg(maps_img)
      n_maps = maps.shape[-1]
      if (
          not isinstance(threshold, numbers.Real)
          or threshold <= 0
          or threshold > n_maps
      ):
          raise ValueError(
              "threshold given as ratio to the number of voxels must "
              "be Real number and should be positive and between 0 and "
              f"total number of maps i.e. n_maps={n_maps}. "
              f"You provided {threshold}"
          )
      else:
          ratio = threshold
  
      # Get a copy of the data
      maps_data = safe_get_data(
          maps, ensure_finite=True, copy_data=True
      )
  
      abs_maps = np.abs(maps_data)
      # thresholding
      cutoff_threshold = scoreatpercentile(
          abs_maps, 100.0 - (100.0 / n_maps) * ratio
      )
      maps_data[abs_maps < cutoff_threshold] = 0.0
  
      threshold_maps_img = new_img_like(maps, maps_data)
  
      return threshold_maps_img
  
imports: import collections.abc
  import numbers
  import numpy
  from joblib import Memory
  from scipy.ndimage import label
  from scipy.stats import scoreatpercentile
  from nilearn.maskers import NiftiMapsMasker
  from ..None import masking
  from .._utils import check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.ndimage import peak_local_max
  from .._utils.niimg import safe_get_data
  from .._utils.niimg_conversions import check_same_fov
  from .._utils.segmentation import random_walker
  from ..image import new_img_like, resample_img
  from ..image.image import concat_imgs, smooth_array, threshold_img
label_desc: Use image node_id 1 for calling a global function with example usage: _threshold_maps_ratio(maps_img, threshold) and returns: threshold_maps_img