class_docstr: This class is meant to handle GLMs from a higher-level perspective
  i.e. by taking images as input and output
class_docstr_tok: ["This","class","is","meant","to","handle","GLMs","from","a","higher-level","perspective","i.e",".","by","taking","images","as","input","and","output"]
docstr: Estimation of a contrast as fixed effects on all sessions
  
  Parameters
  ----------
  contrasts : array or list of arrays of shape (n_col) or (n_dim, n_col)
      where ``n_col`` is the number of columns of the design matrix,
      numerical definition of the contrast (one array per run)
  con_id : str, optional
      name of the contrast
  contrast_type : {'t', 'F', 'tmin-conjunction'}, optional
      type of the contrast
  output_z : bool, optional
      Return or not the corresponding z-stat image
  output_stat : bool, optional
      Return or not the base (t/F) stat image
  output_effects : bool, optional
      Return or not the corresponding effect image
  output_variance : bool, optional
      Return or not the corresponding variance image
  
  Returns
  -------
  output_images : list of nibabel images
      The required output images, in the following order:
      z image, stat(t/F) image, effects image, variance image
docstr_tok: ["Estimation","of","a","contrast","as","fixed","effects","on","all","sessions","Parameters","--","--","--","--","--","contrasts",":","array","or","list","of","arrays","of","shape","(","n_col",")","or","(","n_dim",",","n_col",")","where","``","n_col","``","is","the","number","of","columns","of","the","design","matrix",",","numerical","definition","of","the","contrast","(","one","array","per","run",")","con_id",":","str",",","optional","name","of","the","contrast","contrast_type",":","{","'t","'",",","'","F","'",",","'tmin-conjunction","'","}",",","optional","type","of","the","contrast","output_z",":","bool",",","optional","Return","or","not","the","corresponding","z-stat","image","output_stat",":","bool",",","optional","Return","or","not","the","base","(","t\/F",")","stat","image","output_effects",":","bool",",","optional","Return","or","not","the","corresponding","effect","image","output_variance",":","bool",",","optional","Return","or","not","the","corresponding","variance","image","Returns","--","--","--","-","output_images",":","list","of","nibabel","images","The","required","output","images",",","in","the","following","order",":","z","image",",","stat","(","t\/F",")","image",",","effects","image",",","variance","image"]
code: def contrast(
      self,
      contrasts,
      con_id="",
      contrast_type=None,
      output_z=True,
      output_stat=False,
      output_effects=False,
      output_variance=False,
  ):
      """Estimation of a contrast as fixed effects on all sessions
  
      Parameters
      ----------
      contrasts : array or list of arrays of shape (n_col) or (n_dim, n_col)
          where ``n_col`` is the number of columns of the design matrix,
          numerical definition of the contrast (one array per run)
      con_id : str, optional
          name of the contrast
      contrast_type : {'t', 'F', 'tmin-conjunction'}, optional
          type of the contrast
      output_z : bool, optional
          Return or not the corresponding z-stat image
      output_stat : bool, optional
          Return or not the base (t/F) stat image
      output_effects : bool, optional
          Return or not the corresponding effect image
      output_variance : bool, optional
          Return or not the corresponding variance image
  
      Returns
      -------
      output_images : list of nibabel images
          The required output images, in the following order:
          z image, stat(t/F) image, effects image, variance image
      """
      if self.glms == []:
          raise ValueError("first run fit() to estimate the model")
      if isinstance(contrasts, np.ndarray):
          contrasts = [contrasts]
      if len(contrasts) != len(self.glms):
          raise ValueError(
              f"contrasts must be a sequence of {len(self.glms)} session contrasts"
          )
  
      contrast_ = None
      for i, (glm, con) in enumerate(zip(self.glms, contrasts)):
          if np.all(con == 0):
              warn("Contrast for session %d is null" % i)
          elif contrast_ is None:
              contrast_ = glm.contrast(con, contrast_type)
          else:
              contrast_ = contrast_ + glm.contrast(con, contrast_type)
      if output_z or output_stat:
          # compute the contrast and stat
          contrast_.z_score()
  
      # Prepare the returned images
      mask = self.mask.get_fdata().astype(np.bool_)
      do_outputs = [
          output_z,
          output_stat,
          output_effects,
          output_variance,
      ]
      estimates = ["z_score_", "stat_", "effect", "variance"]
      descrips = [
          "z statistic",
          "Statistical value",
          "Estimated effect",
          "Estimated variance",
      ]
      dims = [1, 1, contrast_.dim, contrast_.dim**2]
      n_vox = mask.sum()
      output_images = []
      for do_output, estimate, descrip, dim in zip(
          do_outputs, estimates, descrips, dims
      ):
          if do_output:
              if dim > 1:
                  result_map = np.tile(
                      mask.astype(np.float64)[:, :, :, np.newaxis], dim
                  )
                  result_map[mask] = np.reshape(
                      getattr(contrast_, estimate).T, (n_vox, dim)
                  )
              else:
                  result_map = mask.astype(np.float64)
                  result_map[mask] = np.squeeze(
                      getattr(contrast_, estimate)
                  )
              output = Nifti1Image(result_map, self.affine)
              get_header(output)[
                  "descrip"
              ] = f"{descrip} associated with contrast {con_id}"
              output_images.append(output)
      return output_images
  
imports: from warnings import warn
  import numpy
  import scipy.stats
  from nibabel import Nifti1Image, load
  from nipy.algorithms.statistics.models.regression import ARModel, OLSModel
  from nipy.algorithms.statistics.utils import multiple_mahalanobis, z_score
  from nipy.io.nibcompat import get_affine, get_header
  from nipy.labs.mask import compute_mask_sessions
label_desc: Use image node_id 3 for calling the FMRILinearModel obj's underlying member method code with example usage: obj.contrast(contrasts, con_id, contrast_type, output_z, output_stat, output_effects, output_variance) and returns: output_images