class_docstr: Applying a mask to extract time-series from Niimg-like objects.
  
  NiftiMasker is useful when preprocessing (detrending, standardization,
  resampling, etc.) of in-mask :term:`voxels<voxel>` is necessary.
  Use case: working with time series of :term:`resting-state` or task maps.
  
  Parameters
  ----------
  mask_img : Niimg-like object, optional
      See :ref:`extracting_data`.
      Mask for the data. If not given, a mask is computed in the fit step.
      Optional parameters (mask_args and mask_strategy) can be set to
      fine tune the mask extraction.
      If the mask and the images have different resolutions, the images
      are resampled to the mask resolution.
      If target_shape and/or target_affine are provided, the mask is
      resampled first. After this, the images are resampled to the
      resampled mask.
  
  runs : :obj:`numpy.ndarray`, optional
      Add a run level to the preprocessing. Each run will be
      detrended independently. Must be a 1D array of n_samples elements.
  %(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
  target_affine : 3x3 or 4x4 :obj:`numpy.ndarray`, optional
      This parameter is passed to image.resample_img. Please see the
      related documentation for details.
  
  target_shape : 3-:obj:`tuple` of :obj:`int`, optional
      This parameter is passed to image.resample_img. Please see the
      related documentation for details.
  %(mask_strategy)s
  
          .. note::
              Depending on this value, the mask will be computed from
              :func:`nilearn.masking.compute_background_mask`,
              :func:`nilearn.masking.compute_epi_mask`, or
              :func:`nilearn.masking.compute_brain_mask`.
  
      Default='background'.
  
  mask_args : :obj:`dict`, optional
      If mask is None, these are additional parameters passed to
      masking.compute_background_mask or masking.compute_epi_mask
      to fine-tune mask computation. Please see the related documentation
      for details.
  
  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.
  %(memory)s
  %(memory_level1)s
  %(verbose0)s
  reports : :obj:`bool`, default=True
      If set to True, data is saved in order to produce a report.
  
  %(masker_kwargs)s
  
  Attributes
  ----------
  mask_img_ : :obj:`nibabel.nifti1.Nifti1Image`
      The mask of the data, or the computed one.
  
  affine_ : 4x4 :obj:`numpy.ndarray`
      Affine of the transformed image.
  
  n_elements_ : :obj:`int`
      The number of voxels in the mask.
  
      .. versionadded:: 0.9.2
  
  See Also
  --------
  nilearn.masking.compute_background_mask
  nilearn.masking.compute_epi_mask
  nilearn.image.resample_img
  nilearn.image.high_variance_confounds
  nilearn.masking.apply_mask
  nilearn.signal.clean
class_docstr_tok: ["Applying","a","mask","to","extract","time-series","from","Niimg-like","objects",".","NiftiMasker","is","useful","when","preprocessing","(","detrending",",","standardization",",","resampling",",","etc",".",")","of","in-mask",":","term",":","`","voxels","<","voxel",">","`","is","necessary",".","Use","case",":","working","with","time","series","of",":","term",":","`","resting-state","`","or","task","maps",".","Parameters","--","--","--","--","--","mask_img",":","Niimg-like","object",",","optional","See",":","ref",":","`","extracting_data","`",".","Mask","for","the","data",".","If","not","given",",","a","mask","is","computed","in","the","fit","step",".","Optional","parameters","(","mask_args","and","mask_strategy",")","can","be","set","to","fine","tune","the","mask","extraction",".","If","the","mask","and","the","images","have","different","resolutions",",","the","images","are","resampled","to","the","mask","resolution",".","If","target_shape","and\/or","target_affine","are","provided",",","the","mask","is","resampled","first",".","After","this",",","the","images","are","resampled","to","the","resampled","mask",".","runs",":",":","obj",":","`","numpy.ndarray","`",",","optional","Add","a","run","level","to","the","preprocessing",".","Each","run","will","be","detrended","independently",".","Must","be","a","1D","array","of","n_samples","elements",".","%","(","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","target_affine",":","3x3","or","4x4",":","obj",":","`","numpy.ndarray","`",",","optional","This","parameter","is","passed","to","image.resample_img",".","Please","see","the","related","documentation","for","details",".","target_shape",":","3-",":","obj",":","`","tuple","`","of",":","obj",":","`","int","`",",","optional","This","parameter","is","passed","to","image.resample_img",".","Please","see","the","related","documentation","for","details",".","%","(","mask_strategy",")","s","..","note",":",":","Depending","on","this","value",",","the","mask","will","be","computed","from",":","func",":","`","nilearn.masking.compute_background_mask","`",",",":","func",":","`","nilearn.masking.compute_epi_mask","`",",","or",":","func",":","`","nilearn.masking.compute_brain_mask","`",".","Default='background","'",".","mask_args",":",":","obj",":","`","dict","`",",","optional","If","mask","is","None",",","these","are","additional","parameters","passed","to","masking.compute_background_mask","or","masking.compute_epi_mask","to","fine-tune","mask","computation",".","Please","see","the","related","documentation","for","details",".","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",".","%","(","memory",")","s","%","(","memory_level1",")","s","%","(","verbose0",")","s","reports",":",":","obj",":","`","bool","`",",","default=True","If","set","to","True",",","data","is","saved","in","order","to","produce","a","report",".","%","(","masker_kwargs",")","s","Attributes","--","--","--","--","--","mask_img_",":",":","obj",":","`","nibabel.nifti1.Nifti1Image","`","The","mask","of","the","data",",","or","the","computed","one",".","affine_",":","4x4",":","obj",":","`","numpy.ndarray","`","Affine","of","the","transformed","image",".","n_elements_",":",":","obj",":","`","int","`","The","number","of","voxels","in","the","mask",".","..","versionadded",":",":","0.9.2","See","Also","--","--","--","--","nilearn.masking.compute_background_mask","nilearn.masking.compute_epi_mask","nilearn.image.resample_img","nilearn.image.high_variance_confounds","nilearn.masking.apply_mask","nilearn.signal.clean"]
docstr: Compute the mask corresponding to the data.
  
  Parameters
  ----------
  imgs : :obj:`list` of Niimg-like objects
      See :ref:`extracting_data`.
      Data on which the mask must be calculated. If this is a list,
      the affine is considered the same for all.
  
  y : None
      This parameter is unused. It is solely included for scikit-learn
      compatibility.
docstr_tok: ["Compute","the","mask","corresponding","to","the","data",".","Parameters","--","--","--","--","--","imgs",":",":","obj",":","`","list","`","of","Niimg-like","objects","See",":","ref",":","`","extracting_data","`",".","Data","on","which","the","mask","must","be","calculated",".","If","this","is","a","list",",","the","affine","is","considered","the","same","for","all",".","y",":","None","This","parameter","is","unused",".","It","is","solely","included","for","scikit-learn","compatibility","."]
code: def fit(self, imgs=None, y=None):
      """Compute the mask corresponding to the data.
  
      Parameters
      ----------
      imgs : :obj:`list` of Niimg-like objects
          See :ref:`extracting_data`.
          Data on which the mask must be calculated. If this is a list,
          the affine is considered the same for all.
  
      y : None
          This parameter is unused. It is solely included for scikit-learn
          compatibility.
  
      """
      # Load data (if filenames are given, load them)
      if self.verbose > 0:
          print(
              f"[{self.__class__.__name__}.fit] "
              f"Loading data from {_utils._repr_niimgs(imgs, shorten=False)}"
          )
  
      # Compute the mask if not given by the user
      if self.mask_img is None:
          if imgs is None:
              raise ValueError(
                  "Parameter 'imgs' must be provided to "
                  f"{self.__class__.__name__}.fit() "
                  "if no mask is passed to mask_img."
              )
          mask_args = (
              self.mask_args if self.mask_args is not None else {}
          )
          compute_mask = _get_mask_strategy(self.mask_strategy)
          if self.verbose > 0:
              print(
                  f"[{self.__class__.__name__}.fit] Computing the mask"
              )
          self.mask_img_ = self._cache(
              compute_mask, ignore=["verbose"]
          )(imgs, verbose=max(0, self.verbose - 1), **mask_args)
      else:
          self.mask_img_ = _utils.check_niimg_3d(self.mask_img)
  
      if self.reports:  # save inputs for reporting
          self._reporting_data = {
              "mask": self.mask_img_,
              "dim": None,
              "images": imgs,
          }
          if imgs is not None:
              imgs, dims = compute_middle_image(imgs)
              self._reporting_data["images"] = imgs
              self._reporting_data["dim"] = dims
      else:
          self._reporting_data = None
  
      # If resampling is requested, resample also the mask
      # Resampling: allows the user to change the affine, the shape or both
      if self.verbose > 0:
          print(f"[{self.__class__.__name__}.fit] Resampling mask")
  
      self.mask_img_ = self._cache(image.resample_img)(
          self.mask_img_,
          target_affine=self.target_affine,
          target_shape=self.target_shape,
          copy=False,
          interpolation="nearest",
      )
  
      if (
          self.target_affine is not None
      ):  # resample image to target affine
          self.affine_ = self.target_affine
      else:  # resample image to mask affine
          self.affine_ = self.mask_img_.affine
  
      # Load data in memory, while also checking that mask is binary/valid
      data, _ = masking.load_mask_img(self.mask_img_, allow_empty=True)
  
      # Infer the number of elements (voxels) in the mask
      self.n_elements_ = int(data.sum())
  
      if self.verbose > 10:
          print(f"[{self.__class__.__name__}.fit] Finished fit")
  
      if (
          (self.target_shape is not None)
          or (self.target_affine is not None)
          and self.reports
      ):
          if imgs is not None:
              resampl_imgs = self._cache(image.resample_img)(
                  imgs,
                  target_affine=self.affine_,
                  copy=False,
                  interpolation="nearest",
              )
              resampl_imgs, _ = compute_middle_image(resampl_imgs)
          else:  # imgs not provided to fit
              resampl_imgs = None
  
          self._reporting_data["transform"] = [
              resampl_imgs,
              self.mask_img_,
          ]
  
      return self
  
imports: import warnings
  from copy import copy
  from functools import partial
  from joblib import Memory
  from nilearn import _utils, image, masking
  from nilearn.maskers._utils import compute_middle_image
  from nilearn.maskers.base_masker import BaseMasker, _filter_and_extract
label_desc: Use image node_id 5 for calling the NiftiMasker obj's underlying member method code with example usage: obj.fit(imgs, y) and returns: self