code: def img_to_signals_maps(
      imgs, maps_img, mask_img=None, keep_masked_maps=True
  ):
      """Extract region signals from image.
  
      This function is applicable to regions defined by maps.
  
      Parameters
      ----------
      %(imgs)s
          Input images.
  
      maps_img : Niimg-like object
          See :ref:`extracting_data`.
          Regions definition as maps (array of weights).
          shape: imgs.shape + (region number, )
  
      mask_img : Niimg-like object, optional
          See :ref:`extracting_data`.
          Mask to apply to regions before extracting signals.
          Every point outside the mask is considered
          as background (i.e. outside of any region).
      %(keep_masked_maps)s
  
      Returns
      -------
      region_signals : :class:`numpy.ndarray`
          Signals extracted from each region.
          Shape is: (scans number, number of regions intersecting mask)
  
      labels : :obj:`list`
          maps_img[..., labels[n]] is the region that has been used to extract
          signal region_signals[:, n].
  
      See Also
      --------
      nilearn.regions.img_to_signals_labels
      nilearn.regions.signals_to_img_maps
      nilearn.maskers.NiftiMapsMasker : Signal extraction on probabilistic
          maps e.g. ICA
  
      """
      maps_img = _utils.check_niimg_4d(maps_img)
      imgs = _utils.check_niimg_4d(imgs)
  
      _check_shape_and_affine_compatibility(imgs, maps_img, 3)
  
      maps_data = safe_get_data(maps_img, ensure_finite=True)
      maps_mask = np.ones(maps_data.shape[:3], dtype=bool)
      labels = np.arange(maps_data.shape[-1], dtype=int)
  
      use_mask = _check_shape_and_affine_compatibility(imgs, mask_img)
      if use_mask:
          mask_img = _utils.check_niimg_3d(mask_img)
          labels_before_mask = {int(label) for label in labels}
          maps_data, maps_mask, labels = _trim_maps(
              maps_data,
              safe_get_data(mask_img, ensure_finite=True),
              keep_empty=keep_masked_maps,
          )
          maps_mask = _utils.as_ndarray(maps_mask, dtype=bool)
          if keep_masked_maps:
              warnings.warn(
                  'Applying "mask_img" before '
                  "signal extraction may result in empty region signals in the "
                  "output. These are currently kept. "
                  "Starting from version 0.13, the default behavior will be "
                  "changed to remove them by setting "
                  '"keep_masked_maps=False". '
                  '"keep_masked_maps" parameter will be removed '
                  "in version 0.15.",
                  DeprecationWarning,
                  stacklevel=2,
              )
          else:
              labels_after_mask = {int(label) for label in labels}
              labels_diff = labels_before_mask.difference(
                  labels_after_mask
              )
              # Raising a warning if any map is removed due to the mask
              if len(labels_diff) > 0:
                  warnings.warn(
                      "After applying mask to the maps image, "
                      "maps with the following indices were "
                      f"removed: {labels_diff}. "
                      f"Out of {len(labels_before_mask)} maps, the "
                      "masked map image only contains "
                      f"{len(labels_after_mask)} maps.",
                      stacklevel=2,
                  )
  
      data = safe_get_data(imgs, ensure_finite=True)
      region_signals = linalg.lstsq(
          maps_data[maps_mask, :], data[maps_mask, :]
      )[0].T
  
      return region_signals, list(labels)
  
file_path: nilearn/nilearn/regions/signal_extraction.py
imports: import warnings
  import numpy
  from nibabel import Nifti1Image
  from scipy import linalg, ndimage
  from ..None import _utils, masking
  from .._utils.niimg import safe_get_data
  from ..image import new_img_like
label_desc: Use image node_id 8 for calling a global function with example usage: img_to_signals_maps(imgs, maps_img, mask_img, keep_masked_maps) and returns: region_signals,  list