class_docstr: Class for masking of Niimg-like objects.
  
  NiftiMapsMasker is useful when data from overlapping volumes should be
  extracted (contrarily to :class:`nilearn.maskers.NiftiLabelsMasker`).
  Use case: Summarize brain signals from large-scale networks obtained by
  prior PCA or :term:`ICA`.
  
  Note that, Inf or NaN present in the given input images are automatically
  put to zero rather than considered as missing data.
  
  Parameters
  ----------
  maps_img : 4D niimg-like object
      See :ref:`extracting_data`.
      Set of continuous maps. One representative time course per map is
      extracted using least square regression.
  
  mask_img : 3D niimg-like object, optional
      See :ref:`extracting_data`.
      Mask to apply to regions before extracting signals.
  
  allow_overlap : :obj:`bool`, default=True
      If False, an error is raised if the maps overlaps (ie at least two
      maps have a non-zero value for the same voxel).
  %(smoothing_fwhm)s
  %(standardize_maskers)s
  %(standardize_confounds)s
  high_variance_confounds : :obj:`bool`, default=False
      If True, high variance confounds are computed on provided image with
      :func:`nilearn.image.high_variance_confounds` and default parameters
      and regressed out.
  %(detrend)s
  %(low_pass)s
  %(high_pass)s
  %(t_r)s
  dtype : {dtype, "auto"}, optional
      Data type toward which the data should be converted. If "auto", the
      data will be converted to int32 if dtype is discrete and float32 if it
      is continuous.
  
  resampling_target : {"data", "mask", "maps", None}, default="data"
      Gives which image gives the final shape/size. For example, if
      `resampling_target` is "mask" then maps_img and images provided to
      fit() are resampled to the shape and affine of mask_img. "None" means
      no resampling: if shapes and affines do not match, a ValueError is
      raised.
  %(memory)s
  %(memory_level)s
  %(verbose0)s
  %(keep_masked_maps)s
  
  reports : :obj:`bool`, default=True
      If set to True, data is saved in order to produce a report.
  
  %(masker_kwargs)s
  
  Attributes
  ----------
  maps_img_ : :obj:`nibabel.nifti1.Nifti1Image`
      The maps mask of the data.
  
  n_elements_ : :obj:`int`
      The number of overlapping maps in the mask.
      This is equivalent to the number of volumes in the mask image.
  
      .. versionadded:: 0.9.2
  
  Notes
  -----
  If resampling_target is set to "maps", every 3D image processed by
  transform() will be resampled to the shape of maps_img. It may lead to a
  very large memory consumption if the voxel number in maps_img is large.
  
  See Also
  --------
  nilearn.maskers.NiftiMasker
  nilearn.maskers.NiftiLabelsMasker
class_docstr_tok: ["Class","for","masking","of","Niimg-like","objects",".","NiftiMapsMasker","is","useful","when","data","from","overlapping","volumes","should","be","extracted","(","contrarily","to",":","class",":","`","nilearn.maskers.NiftiLabelsMasker","`",")",".","Use","case",":","Summarize","brain","signals","from","large-scale","networks","obtained","by","prior","PCA","or",":","term",":","`","ICA","`",".","Note","that",",","Inf","or","NaN","present","in","the","given","input","images","are","automatically","put","to","zero","rather","than","considered","as","missing","data",".","Parameters","--","--","--","--","--","maps_img",":","4D","niimg-like","object","See",":","ref",":","`","extracting_data","`",".","Set","of","continuous","maps",".","One","representative","time","course","per","map","is","extracted","using","least","square","regression",".","mask_img",":","3D","niimg-like","object",",","optional","See",":","ref",":","`","extracting_data","`",".","Mask","to","apply","to","regions","before","extracting","signals",".","allow_overlap",":",":","obj",":","`","bool","`",",","default=True","If","False",",","an","error","is","raised","if","the","maps","overlaps","(","ie","at","least","two","maps","have","a","non-zero","value","for","the","same","voxel",")",".","%","(","smoothing_fwhm",")","s","%","(","standardize_maskers",")","s","%","(","standardize_confounds",")","s","high_variance_confounds",":",":","obj",":","`","bool","`",",","default=False","If","True",",","high","variance","confounds","are","computed","on","provided","image","with",":","func",":","`","nilearn.image.high_variance_confounds","`","and","default","parameters","and","regressed","out",".","%","(","detrend",")","s","%","(","low_pass",")","s","%","(","high_pass",")","s","%","(","t_r",")","s","dtype",":","{","dtype",",","``","auto","''","}",",","optional","Data","type","toward","which","the","data","should","be","converted",".","If","``","auto","''",",","the","data","will","be","converted","to","int32","if","dtype","is","discrete","and","float32","if","it","is","continuous",".","resampling_target",":","{","``","data","''",",","``","mask","''",",","``","maps","''",",","None","}",",","default=","''","data","''","Gives","which","image","gives","the","final","shape\/size",".","For","example",",","if","`","resampling_target","`","is","``","mask","''","then","maps_img","and","images","provided","to","fit","(",")","are","resampled","to","the","shape","and","affine","of","mask_img",".","``","None","''","means","no","resampling",":","if","shapes","and","affines","do","not","match",",","a","ValueError","is","raised",".","%","(","memory",")","s","%","(","memory_level",")","s","%","(","verbose0",")","s","%","(","keep_masked_maps",")","s","reports",":",":","obj",":","`","bool","`",",","default=True","If","set","to","True",",","data","is","saved","in","order","to","produce","a","report",".","%","(","masker_kwargs",")","s","Attributes","--","--","--","--","--","maps_img_",":",":","obj",":","`","nibabel.nifti1.Nifti1Image","`","The","maps","mask","of","the","data",".","n_elements_",":",":","obj",":","`","int","`","The","number","of","overlapping","maps","in","the","mask",".","This","is","equivalent","to","the","number","of","volumes","in","the","mask","image",".","..","versionadded",":",":","0.9.2","Notes","--","--","-","If","resampling_target","is","set","to","``","maps","''",",","every","3D","image","processed","by","transform","(",")","will","be","resampled","to","the","shape","of","maps_img",".","It","may","lead","to","a","very","large","memory","consumption","if","the","voxel","number","in","maps_img","is","large",".","See","Also","--","--","--","--","nilearn.maskers.NiftiMasker","nilearn.maskers.NiftiLabelsMasker"]
docstr: Extract signals from a single 4D niimg.
  
  Parameters
  ----------
  imgs : 3D/4D Niimg-like object
      See :ref:`extracting_data`.
      Images to process.
      If a 3D niimg is provided, a singleton dimension will be added to
      the output to represent the single scan in the niimg.
  
  confounds : CSV file or array-like, optional
      This parameter is passed to signal.clean. Please see the related
      documentation for details.
      shape: (number of scans, number of confounds)
  
  sample_mask : Any type compatible with numpy-array indexing, optional
      shape: (number of scans - number of volumes removed, )
      Masks the niimgs along time/fourth dimension to perform scrubbing
      (remove volumes with high motion) and/or non-steady-state volumes.
      This parameter is passed to signal.clean.
  
          .. versionadded:: 0.8.0
  
  Returns
  -------
  region_signals : 2D numpy.ndarray
      Signal for each map.
      shape: (number of scans, number of maps)
  
  Warns
  -----
  DeprecationWarning
      If a 3D niimg input is provided, the current behavior
      (adding a singleton dimension to produce a 2D array) is deprecated.
      Starting in version 0.12, a 1D array will be returned for 3D
      inputs.
docstr_tok: ["Extract","signals","from","a","single","4D","niimg",".","Parameters","--","--","--","--","--","imgs",":","3D\/4D","Niimg-like","object","See",":","ref",":","`","extracting_data","`",".","Images","to","process",".","If","a","3D","niimg","is","provided",",","a","singleton","dimension","will","be","added","to","the","output","to","represent","the","single","scan","in","the","niimg",".","confounds",":","CSV","file","or","array-like",",","optional","This","parameter","is","passed","to","signal.clean",".","Please","see","the","related","documentation","for","details",".","shape",":","(","number","of","scans",",","number","of","confounds",")","sample_mask",":","Any","type","compatible","with","numpy-array","indexing",",","optional","shape",":","(","number","of","scans","-","number","of","volumes","removed",",",")","Masks","the","niimgs","along","time\/fourth","dimension","to","perform","scrubbing","(","remove","volumes","with","high","motion",")","and\/or","non-steady-state","volumes",".","This","parameter","is","passed","to","signal.clean",".","..","versionadded",":",":","0.8.0","Returns","--","--","--","-","region_signals",":","2D","numpy.ndarray","Signal","for","each","map",".","shape",":","(","number","of","scans",",","number","of","maps",")","Warns","--","--","-","DeprecationWarning","If","a","3D","niimg","input","is","provided",",","the","current","behavior","(","adding","a","singleton","dimension","to","produce","a","2D","array",")","is","deprecated",".","Starting","in","version","0.12",",","a","1D","array","will","be","returned","for","3D","inputs","."]
code: def transform_single_imgs(
      self, imgs, confounds=None, sample_mask=None
  ):
      """Extract signals from a single 4D niimg.
  
      Parameters
      ----------
      imgs : 3D/4D Niimg-like object
          See :ref:`extracting_data`.
          Images to process.
          If a 3D niimg is provided, a singleton dimension will be added to
          the output to represent the single scan in the niimg.
  
      confounds : CSV file or array-like, optional
          This parameter is passed to signal.clean. Please see the related
          documentation for details.
          shape: (number of scans, number of confounds)
  
      sample_mask : Any type compatible with numpy-array indexing, optional
          shape: (number of scans - number of volumes removed, )
          Masks the niimgs along time/fourth dimension to perform scrubbing
          (remove volumes with high motion) and/or non-steady-state volumes.
          This parameter is passed to signal.clean.
  
              .. versionadded:: 0.8.0
  
      Returns
      -------
      region_signals : 2D numpy.ndarray
          Signal for each map.
          shape: (number of scans, number of maps)
  
      Warns
      -----
      DeprecationWarning
          If a 3D niimg input is provided, the current behavior
          (adding a singleton dimension to produce a 2D array) is deprecated.
          Starting in version 0.12, a 1D array will be returned for 3D
          inputs.
  
      """
      # We handle the resampling of maps and mask separately because the
      # affine of the maps and mask images should not impact the extraction
      # of the signal.
  
      if not hasattr(self, "_resampled_maps_img_"):
          self._resampled_maps_img_ = self.maps_img_
      if not hasattr(self, "_resampled_mask_img_"):
          self._resampled_mask_img_ = self.mask_img_
  
      if self.resampling_target is None:
          imgs_ = _utils.check_niimg(imgs, atleast_4d=True)
          images = dict(maps=self.maps_img_, data=imgs_)
          if self.mask_img_ is not None:
              images["mask"] = self.mask_img_
          _utils.niimg_conversions.check_same_fov(
              raise_error=True,
              **images,
          )
      else:
          if self.resampling_target == "data":
              imgs_ = _utils.check_niimg(imgs, atleast_4d=True)
              ref_img = imgs_
          elif self.resampling_target == "mask":
              self._resampled_mask_img_ = self.mask_img_
              ref_img = self.mask_img_
          elif self.resampling_target == "maps":
              self._resampled_maps_img_ = self.maps_img_
              ref_img = self.maps_img_
  
          if not _utils.niimg_conversions.check_same_fov(
              ref_img,
              self._resampled_maps_img_,
          ):
              if self.verbose > 0:
                  print("Resampling maps")
              self._resampled_maps_img_ = self._cache(
                  image.resample_img
              )(
                  self.maps_img_,
                  interpolation="continuous",
                  target_shape=ref_img.shape[:3],
                  target_affine=ref_img.affine,
              )
  
          if (
              self.mask_img_ is not None
              and not _utils.niimg_conversions.check_same_fov(
                  ref_img,
                  self.mask_img_,
              )
          ):
              if self.verbose > 0:
                  print("Resampling mask")
              self._resampled_mask_img_ = self._cache(
                  image.resample_img
              )(
                  self.mask_img_,
                  interpolation="nearest",
                  target_shape=ref_img.shape[:3],
                  target_affine=ref_img.affine,
              )
  
      if not self.allow_overlap:
          # Check if there is an overlap.
  
          # If float, we set low values to 0
          data = image.get_data(self._resampled_maps_img_)
          dtype = data.dtype
          if dtype.kind == "f":
              data[data < np.finfo(dtype).eps] = 0.0
  
          # Check the overlaps
          if np.any(np.sum(data > 0.0, axis=3) > 1):
              raise ValueError(
                  "Overlap detected in the maps. The overlap may be "
                  "due to the atlas itself or possibly introduced by "
                  "resampling."
              )
  
      target_shape = None
      target_affine = None
      if self.resampling_target != "data":
          target_shape = self._resampled_maps_img_.shape[:3]
          target_affine = self._resampled_maps_img_.affine
  
      params = _utils.class_inspect.get_params(
          NiftiMapsMasker,
          self,
          ignore=["resampling_target"],
      )
      params["target_shape"] = target_shape
      params["target_affine"] = target_affine
      params["clean_kwargs"] = self.clean_kwargs
  
      region_signals, labels_ = self._cache(
          _filter_and_extract,
          ignore=["verbose", "memory", "memory_level"],
      )(
          # Images
          imgs,
          _ExtractionFunctor(
              self._resampled_maps_img_,
              self._resampled_mask_img_,
              self.keep_masked_maps,
          ),
          # Pre-treatments
          params,
          confounds=confounds,
          sample_mask=sample_mask,
          dtype=self.dtype,
          # Caching
          memory=self.memory,
          memory_level=self.memory_level,
          # kwargs
          verbose=self.verbose,
      )
      self.labels_ = labels_
      return region_signals
  
file_path: nilearn/nilearn/maskers/nifti_maps_masker.py
imports: import warnings
  import numpy
  from joblib import Memory
  from nilearn import _utils, image
  from nilearn.maskers._utils import compute_middle_image
  from nilearn.maskers.base_masker import BaseMasker, _filter_and_extract
label_desc: Use image node_id 7 for calling the NiftiMapsMasker obj's underlying member method code with example usage: obj.transform_single_imgs(imgs, confounds, sample_mask) and returns: region_signals