class_docstr: Implement the General Linear Model for single run :term:`fMRI` data.
  
  Parameters
  ----------
  t_r : float
      This parameter indicates :term:`repetition times<TR>`
      of the experimental runs.
      In seconds. It is necessary to correctly consider times in the design
      matrix. This parameter is also passed to :func:`nilearn.signal.clean`.
      Please see the related documentation for details.
  
  slice_time_ref : float, default=0
      This parameter indicates the time of the reference slice used in the
      slice timing preprocessing step of the experimental runs.
      It is expressed as a fraction of the ``t_r`` (repetition time),
      so it can have values between 0. and 1.
  %(hrf_model)s
      Default='glover'.
  drift_model : string, default='cosine'
      This parameter specifies the desired drift model for the design
      matrices. It can be 'polynomial', 'cosine' or None.
  
  high_pass : float, default=0.01
      This parameter specifies the cut frequency of the high-pass filter in
      Hz for the design matrices. Used only if drift_model is 'cosine'.
  
  drift_order : int, default=1
      This parameter specifies the order of the drift model (in case it is
      polynomial) for the design matrices.
  
  fir_delays : array of shape(n_onsets) or list, default=[0]
      In case of :term:`FIR` design,
      yields the array of delays used in the :term:`FIR` model,
      in scans.
  
  min_onset : float, default=-24
      This parameter specifies the minimal onset relative to the design
      (in seconds). Events that start before (slice_time_ref * t_r +
      min_onset) are not considered.
  
  mask_img : Niimg-like, NiftiMasker object or False, optional
      Mask to be used on data. If an instance of masker is passed,
      then its mask will be used. If no mask is given,
      it will be computed automatically by a NiftiMasker with default
      parameters. If False is given then the data will not be masked.
  
  target_affine : 3x3 or 4x4 matrix, optional
      This parameter is passed to nilearn.image.resample_img.
      Please see the related documentation for details.
  
  target_shape : 3-tuple of integers, optional
      This parameter is passed to nilearn.image.resample_img.
      Please see the related documentation for details.
  %(smoothing_fwhm)s
  memory : string or pathlib.Path, optional
      Path to the directory used to cache the masking process and the glm
      fit. By default, no caching is done.
      Creates instance of joblib.Memory.
  
  memory_level : integer, optional
      Rough estimator of the amount of memory used by caching. Higher value
      means more memory for caching.
  
  standardize : boolean, default=False
      If standardize is True, the time-series are centered and normed:
      their variance is put to 1 in the time dimension.
  
  signal_scaling : False, int or (int, int), default=0
      If not False, fMRI signals are
      scaled to the mean value of scaling_axis given,
      which can be 0, 1 or (0, 1).
      0 refers to mean scaling each voxel with respect to time,
      1 refers to mean scaling each time point with respect to all voxels &
      (0, 1) refers to scaling with respect to voxels and time,
      which is known as grand mean scaling.
      Incompatible with standardize (standardize=False is enforced when
      signal_scaling is not False).
  
  noise_model : {'ar1', 'ols'}, default='ar1'
      The temporal variance model.
  
  verbose : integer, default=0
      Indicate the level of verbosity. By default, nothing is printed.
      If 0 prints nothing. If 1 prints progress by computation of
      each run. If 2 prints timing details of masker and GLM. If 3
      prints masker computation details.
  
  n_jobs : integer, default=1
      The number of CPUs to use to do the computation. -1 means
      'all CPUs', -2 'all CPUs but one', and so on.
  
  minimize_memory : boolean, default=True
      Gets rid of some variables on the model fit results that are not
      necessary for contrast computation and would only be useful for
      further inspection of model details. This has an important impact
      on memory consumption.
  
  subject_label : string, optional
      This id will be used to identify a `FirstLevelModel` when passed to
      a `SecondLevelModel` object.
  
  random_state : int or numpy.random.RandomState, default=None.
      Random state seed to sklearn.cluster.KMeans
      for autoregressive models
      of order at least 2 ('ar(N)' with n >= 2).
  
      .. versionadded:: 0.9.1
  
  Attributes
  ----------
  labels_ : array of shape (n_voxels,),
      a map of values on voxels used to identify the corresponding model
  
  results_ : dict,
      with keys corresponding to the different labels values.
      Values are SimpleRegressionResults corresponding to the voxels,
      if minimize_memory is True,
      RegressionResults if minimize_memory is False
class_docstr_tok: ["Implement","the","General","Linear","Model","for","single","run",":","term",":","`","fMRI","`","data",".","Parameters","--","--","--","--","--","t_r",":","float","This","parameter","indicates",":","term",":","`","repetition","times","<","TR",">","`","of","the","experimental","runs",".","In","seconds",".","It","is","necessary","to","correctly","consider","times","in","the","design","matrix",".","This","parameter","is","also","passed","to",":","func",":","`","nilearn.signal.clean","`",".","Please","see","the","related","documentation","for","details",".","slice_time_ref",":","float",",","default=0","This","parameter","indicates","the","time","of","the","reference","slice","used","in","the","slice","timing","preprocessing","step","of","the","experimental","runs",".","It","is","expressed","as","a","fraction","of","the","``","t_r","``","(","repetition","time",")",",","so","it","can","have","values","between","0.","and","1",".","%","(","hrf_model",")","s","Default='glover","'",".","drift_model",":","string",",","default='cosine'","This","parameter","specifies","the","desired","drift","model","for","the","design","matrices",".","It","can","be","'polynomial","'",",","'cosine","'","or","None",".","high_pass",":","float",",","default=0.01","This","parameter","specifies","the","cut","frequency","of","the","high-pass","filter","in","Hz","for","the","design","matrices",".","Used","only","if","drift_model","is","'cosine","'",".","drift_order",":","int",",","default=1","This","parameter","specifies","the","order","of","the","drift","model","(","in","case","it","is","polynomial",")","for","the","design","matrices",".","fir_delays",":","array","of","shape","(","n_onsets",")","or","list",",","default=","[","0","]","In","case","of",":","term",":","`","FIR","`","design",",","yields","the","array","of","delays","used","in","the",":","term",":","`","FIR","`","model",",","in","scans",".","min_onset",":","float",",","default=-24","This","parameter","specifies","the","minimal","onset","relative","to","the","design","(","in","seconds",")",".","Events","that","start","before","(","slice_time_ref","*","t_r","+","min_onset",")","are","not","considered",".","mask_img",":","Niimg-like",",","NiftiMasker","object","or","False",",","optional","Mask","to","be","used","on","data",".","If","an","instance","of","masker","is","passed",",","then","its","mask","will","be","used",".","If","no","mask","is","given",",","it","will","be","computed","automatically","by","a","NiftiMasker","with","default","parameters",".","If","False","is","given","then","the","data","will","not","be","masked",".","target_affine",":","3x3","or","4x4","matrix",",","optional","This","parameter","is","passed","to","nilearn.image.resample_img",".","Please","see","the","related","documentation","for","details",".","target_shape",":","3-tuple","of","integers",",","optional","This","parameter","is","passed","to","nilearn.image.resample_img",".","Please","see","the","related","documentation","for","details",".","%","(","smoothing_fwhm",")","s","memory",":","string","or","pathlib.Path",",","optional","Path","to","the","directory","used","to","cache","the","masking","process","and","the","glm","fit",".","By","default",",","no","caching","is","done",".","Creates","instance","of","joblib.Memory",".","memory_level",":","integer",",","optional","Rough","estimator","of","the","amount","of","memory","used","by","caching",".","Higher","value","means","more","memory","for","caching",".","standardize",":","boolean",",","default=False","If","standardize","is","True",",","the","time-series","are","centered","and","normed",":","their","variance","is","put","to","1","in","the","time","dimension",".","signal_scaling",":","False",",","int","or","(","int",",","int",")",",","default=0","If","not","False",",","fMRI","signals","are","scaled","to","the","mean","value","of","scaling_axis","given",",","which","can","be","0",",","1","or","(","0",",","1",")",".","0","refers","to","mean","scaling","each","voxel","with","respect","to","time",",","1","refers","to","mean","scaling","each","time","point","with","respect","to","all","voxels","&","(","0",",","1",")","refers","to","scaling","with","respect","to","voxels","and","time",",","which","is","known","as","grand","mean","scaling",".","Incompatible","with","standardize","(","standardize=False","is","enforced","when","signal_scaling","is","not","False",")",".","noise_model",":","{","'ar1","'",",","'ols","'","}",",","default='ar1'","The","temporal","variance","model",".","verbose",":","integer",",","default=0","Indicate","the","level","of","verbosity",".","By","default",",","nothing","is","printed",".","If","0","prints","nothing",".","If","1","prints","progress","by","computation","of","each","run",".","If","2","prints","timing","details","of","masker","and","GLM",".","If","3","prints","masker","computation","details",".","n_jobs",":","integer",",","default=1","The","number","of","CPUs","to","use","to","do","the","computation",".","-1","means","'all","CPUs","'",",","-2","'all","CPUs","but","one","'",",","and","so","on",".","minimize_memory",":","boolean",",","default=True","Gets","rid","of","some","variables","on","the","model","fit","results","that","are","not","necessary","for","contrast","computation","and","would","only","be","useful","for","further","inspection","of","model","details",".","This","has","an","important","impact","on","memory","consumption",".","subject_label",":","string",",","optional","This","id","will","be","used","to","identify","a","`","FirstLevelModel","`","when","passed","to","a","`","SecondLevelModel","`","object",".","random_state",":","int","or","numpy.random.RandomState",",","default=None",".","Random","state","seed","to","sklearn.cluster.KMeans","for","autoregressive","models","of","order","at","least","2","(","'ar","(","N",")","'","with","n",">","=","2",")",".","..","versionadded",":",":","0.9.1","Attributes","--","--","--","--","--","labels_",":","array","of","shape","(","n_voxels",",",")",",","a","map","of","values","on","voxels","used","to","identify","the","corresponding","model","results_",":","dict",",","with","keys","corresponding","to","the","different","labels","values",".","Values","are","SimpleRegressionResults","corresponding","to","the","voxels",",","if","minimize_memory","is","True",",","RegressionResults","if","minimize_memory","is","False"]
docstr: Generate different outputs corresponding to         the contrasts provided e.g. z_map, t_map, effects and variance.
  
  In multi-run case, outputs the fixed effects map.
  
  Parameters
  ----------
  contrast_def : str or array of shape (n_col) or list of (string or
                 array of shape (n_col))
  
      where ``n_col`` is the number of columns of the design matrix,
      (one array per run). If only one array is provided when there
      are several runs, it will be assumed that
      the same :term:`contrast` is
      desired for all runs. One can use the name of the conditions as
      they appear in the design matrix of the fitted model combined with
      operators +- and combined with numbers with operators +-`*`/. In
      this case, the string defining the contrasts must be a valid
      expression for compatibility with :meth:`pandas.DataFrame.eval`.
  
  stat_type : {'t', 'F'}, optional
      Type of the contrast.
  
  output_type : str, default='z_score'
      Type of the output map. Can be 'z_score', 'stat', 'p_value',
      :term:`'effect_size'<Parameter Estimate>`, 'effect_variance' or
      'all'.
  
  
  Returns
  -------
  output : Nifti1Image or dict
      The desired output image(s). If ``output_type == 'all'``, then
      the output is a dictionary of images, keyed by the type of image.
docstr_tok: ["Generate","different","outputs","corresponding","to","the","contrasts","provided","e.g",".","z_map",",","t_map",",","effects","and","variance",".","In","multi-run","case",",","outputs","the","fixed","effects","map",".","Parameters","--","--","--","--","--","contrast_def",":","str","or","array","of","shape","(","n_col",")","or","list","of","(","string","or","array","of","shape","(","n_col",")",")","where","``","n_col","``","is","the","number","of","columns","of","the","design","matrix",",","(","one","array","per","run",")",".","If","only","one","array","is","provided","when","there","are","several","runs",",","it","will","be","assumed","that","the","same",":","term",":","`","contrast","`","is","desired","for","all","runs",".","One","can","use","the","name","of","the","conditions","as","they","appear","in","the","design","matrix","of","the","fitted","model","combined","with","operators","+-","and","combined","with","numbers","with","operators","+-","`","*","`","\/",".","In","this","case",",","the","string","defining","the","contrasts","must","be","a","valid","expression","for","compatibility","with",":","meth",":","`","pandas.DataFrame.eval","`",".","stat_type",":","{","'t","'",",","'","F","'","}",",","optional","Type","of","the","contrast",".","output_type",":","str",",","default='z_score'","Type","of","the","output","map",".","Can","be","'z_score","'",",","'stat","'",",","'p_value","'",",",":","term",":","`","'effect_size","'","<","Parameter","Estimate",">","`",",","'effect_variance","'","or","'all","'",".","Returns","--","--","--","-","output",":","Nifti1Image","or","dict","The","desired","output","image","(","s",")",".","If","``","output_type","==","'all","'","``",",","then","the","output","is","a","dictionary","of","images",",","keyed","by","the","type","of","image","."]
code: def compute_contrast(
      self, contrast_def, stat_type=None, output_type="z_score"
  ):
      """Generate different outputs corresponding to \
          the contrasts provided e.g. z_map, t_map, effects and variance.
  
          In multi-run case, outputs the fixed effects map.
  
          Parameters
          ----------
          contrast_def : str or array of shape (n_col) or list of (string or
                         array of shape (n_col))
  
              where ``n_col`` is the number of columns of the design matrix,
              (one array per run). If only one array is provided when there
              are several runs, it will be assumed that
              the same :term:`contrast` is
              desired for all runs. One can use the name of the conditions as
              they appear in the design matrix of the fitted model combined with
              operators +- and combined with numbers with operators +-`*`/. In
              this case, the string defining the contrasts must be a valid
              expression for compatibility with :meth:`pandas.DataFrame.eval`.
  
          stat_type : {'t', 'F'}, optional
              Type of the contrast.
  
          output_type : str, default='z_score'
              Type of the output map. Can be 'z_score', 'stat', 'p_value',
              :term:`'effect_size'<Parameter Estimate>`, 'effect_variance' or
              'all'.
  
  
          Returns
          -------
          output : Nifti1Image or dict
              The desired output image(s). If ``output_type == 'all'``, then
              the output is a dictionary of images, keyed by the type of image.
  
          """
      if self.labels_ is None or self.results_ is None:
          raise ValueError("The model has not been fit yet.")
  
      if isinstance(contrast_def, (np.ndarray, str)):
          con_vals = [contrast_def]
      elif isinstance(contrast_def, (list, tuple)):
          con_vals = contrast_def
      else:
          raise ValueError(
              "contrast_def must be an array or str or list of"
              " (array or str)."
          )
  
      n_runs = len(self.labels_)
      n_contrasts = len(con_vals)
      if n_contrasts == 1 and n_runs > 1:
          warn(
              f"One contrast given, assuming it for all {n_runs} runs",
              category=UserWarning,
              stacklevel=2,
          )
          con_vals = con_vals * n_runs
      elif n_contrasts != n_runs:
          raise ValueError(
              f"{n_contrasts} contrasts given, "
              f"while there are {n_runs} runs."
          )
  
      # Translate formulas to vectors
      for cidx, (con, design_mat) in enumerate(
          zip(con_vals, self.design_matrices_)
      ):
          design_columns = design_mat.columns.tolist()
          if isinstance(con, str):
              con_vals[cidx] = expression_to_contrast_vector(
                  con, design_columns
              )
  
      valid_types = [
          "z_score",
          "stat",
          "p_value",
          "effect_size",
          "effect_variance",
      ]
      valid_types.append("all")  # ensuring 'all' is the final entry.
      if output_type not in valid_types:
          raise ValueError(f"output_type must be one of {valid_types}")
      contrast = compute_fixed_effect_contrast(
          self.labels_, self.results_, con_vals, stat_type
      )
      output_types = (
          valid_types[:-1] if output_type == "all" else [output_type]
      )
      outputs = {}
      for output_type_ in output_types:
          estimate_ = getattr(contrast, output_type_)()
          # Prepare the returned images
          output = self.masker_.inverse_transform(estimate_)
          contrast_name = str(con_vals)
          output.header[
              "descrip"
          ] = f"{output_type_} of contrast {contrast_name}"
          outputs[output_type_] = output
  
      return outputs if output_type == "all" else output
  
imports: from __future__ import annotations
  import csv
  import glob
  import os
  import sys
  import time
  from pathlib import Path
  from warnings import warn
  import numpy
  import pandas
  from joblib import Memory, Parallel, delayed
  from nibabel import Nifti1Image
  from sklearn.base import clone
  from sklearn.cluster import KMeans
  from nilearn._utils import fill_doc, stringify_path
  from nilearn._utils.niimg_conversions import check_niimg
  from nilearn._utils.param_validation import check_run_sample_masks
  from nilearn.glm._base import BaseGLM
  from nilearn.glm.contrasts import compute_fixed_effect_contrast, expression_to_contrast_vector
  from nilearn.glm.first_level.design_matrix import make_first_level_design_matrix
  from nilearn.glm.regression import ARModel, OLSModel, RegressionResults, SimpleRegressionResults
  from nilearn.image import get_data
  from nilearn.interfaces.bids import get_bids_files, parse_bids_filename
  from nilearn.interfaces.bids.query import infer_repetition_time_from_dataset, infer_slice_timing_start_time_from_dataset
  from nilearn.interfaces.bids.utils import bids_entities, check_bids_label
  from nilearn.interfaces.fmriprep.load_confounds import load_confounds
label_desc: Use image node_id 4 for calling the FirstLevelModel obj's underlying member method code with example usage: obj.compute_contrast(contrast_def, stat_type, output_type) and returns: unknown