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: Load the data
  
  Parameters
  ----------
  fmri_data : Image or str or sequence of Images / str
      fmri images / paths of the (4D) fmri images
  design_matrices : arrays or str or sequence of arrays / str
      design matrix arrays / paths of .npz files
  mask : str or Image or None, optional
      string can be 'compute' or a path to an image
      image is an input (assumed binary) mask image(s),
      if 'compute', the mask is computed
      if None, no masking will be applied
  m, M, threshold: float, optional
      parameters of the masking procedure.  Should be within [0, 1]
  
  Notes
  -----
  The only computation done here is mask computation (if required)
  
  Examples
  --------
  We need the example data package for this example::
  
      from nipy.utils import example_data
      from nipy.modalities.fmri.glm import FMRILinearModel
      fmri_files = [example_data.get_filename('fiac', 'fiac0', run)
          for run in ['run1.nii.gz', 'run2.nii.gz']]
      design_files = [example_data.get_filename('fiac', 'fiac0', run)
          for run in ['run1_design.npz', 'run2_design.npz']]
      mask = example_data.get_filename('fiac', 'fiac0', 'mask.nii.gz')
      multi_session_model = FMRILinearModel(fmri_files,
                                            design_files,
                                            mask)
      multi_session_model.fit()
      z_image, = multi_session_model.contrast([np.eye(13)[1]] * 2)
  
      # The number of voxels with p < 0.001 given by ...
      print(np.sum(z_image.get_fdata() > 3.09))
docstr_tok: ["Load","the","data","Parameters","--","--","--","--","--","fmri_data",":","Image","or","str","or","sequence","of","Images","\/","str","fmri","images","\/","paths","of","the","(","4D",")","fmri","images","design_matrices",":","arrays","or","str","or","sequence","of","arrays","\/","str","design","matrix","arrays","\/","paths","of",".npz","files","mask",":","str","or","Image","or","None",",","optional","string","can","be","'compute","'","or","a","path","to","an","image","image","is","an","input","(","assumed","binary",")","mask","image","(","s",")",",","if","'compute","'",",","the","mask","is","computed","if","None",",","no","masking","will","be","applied","m",",","M",",","threshold",":","float",",","optional","parameters","of","the","masking","procedure",".","Should","be","within","[","0",",","1","]","Notes","--","--","-","The","only","computation","done","here","is","mask","computation","(","if","required",")","Examples","--","--","--","--","We","need","the","example","data","package","for","this","example",":",":","from","nipy.utils","import","example_data","from","nipy.modalities.fmri.glm","import","FMRILinearModel","fmri_files","=","[","example_data.get_filename","(","'fiac","'",",","'fiac0","'",",","run",")","for","run","in","[","'run1.nii.gz","'",",","'run2.nii.gz","'","]","]","design_files","=","[","example_data.get_filename","(","'fiac","'",",","'fiac0","'",",","run",")","for","run","in","[","'run1_design.npz","'",",","'run2_design.npz","'","]","]","mask","=","example_data.get_filename","(","'fiac","'",",","'fiac0","'",",","'mask.nii.gz","'",")","multi_session_model","=","FMRILinearModel","(","fmri_files",",","design_files",",","mask",")","multi_session_model.fit","(",")","z_image",",","=","multi_session_model.contrast","(","[","np.eye","(","13",")","[","1","]","]","*","2",")","#","The","number","of","voxels","with","p","<","0.001","given","by","...","print","(","np.sum","(","z_image.get_fdata","(",")",">","3.09",")",")"]
code: def __init__(
      self,
      fmri_data,
      design_matrices,
      mask="compute",
      m=0.2,
      M=0.9,
      threshold=0.5,
  ):
      """Load the data
  
      Parameters
      ----------
      fmri_data : Image or str or sequence of Images / str
          fmri images / paths of the (4D) fmri images
      design_matrices : arrays or str or sequence of arrays / str
          design matrix arrays / paths of .npz files
      mask : str or Image or None, optional
          string can be 'compute' or a path to an image
          image is an input (assumed binary) mask image(s),
          if 'compute', the mask is computed
          if None, no masking will be applied
      m, M, threshold: float, optional
          parameters of the masking procedure.  Should be within [0, 1]
  
      Notes
      -----
      The only computation done here is mask computation (if required)
  
      Examples
      --------
      We need the example data package for this example::
  
          from nipy.utils import example_data
          from nipy.modalities.fmri.glm import FMRILinearModel
          fmri_files = [example_data.get_filename('fiac', 'fiac0', run)
              for run in ['run1.nii.gz', 'run2.nii.gz']]
          design_files = [example_data.get_filename('fiac', 'fiac0', run)
              for run in ['run1_design.npz', 'run2_design.npz']]
          mask = example_data.get_filename('fiac', 'fiac0', 'mask.nii.gz')
          multi_session_model = FMRILinearModel(fmri_files,
                                                design_files,
                                                mask)
          multi_session_model.fit()
          z_image, = multi_session_model.contrast([np.eye(13)[1]] * 2)
  
          # The number of voxels with p < 0.001 given by ...
          print(np.sum(z_image.get_fdata() > 3.09))
      """
      # manipulate the arguments
      if isinstance(fmri_data, str) or hasattr(fmri_data, "get_fdata"):
          fmri_data = [fmri_data]
      if isinstance(design_matrices, (str, np.ndarray)):
          design_matrices = [design_matrices]
      if len(fmri_data) != len(design_matrices):
          raise ValueError(
              "Incompatible number of fmri runs and "
              "design matrices were provided"
          )
      self.fmri_data, self.design_matrices = [], []
      self.glms, self.means = [], []
  
      # load the fmri data
      for fmri_run in fmri_data:
          if isinstance(fmri_run, str):
              self.fmri_data.append(load(fmri_run))
          else:
              self.fmri_data.append(fmri_run)
      # set self.affine as the affine of the first image
      self.affine = get_affine(self.fmri_data[0])
  
      # load the designs
      for design_matrix in design_matrices:
          if isinstance(design_matrix, str):
              loaded = np.load(design_matrix)
              self.design_matrices.append(loaded[loaded.files[0]])
          else:
              self.design_matrices.append(design_matrix)
  
      # load the mask
      if mask == "compute":
          mask = compute_mask_sessions(
              fmri_data, m=m, M=M, cc=1, threshold=threshold, opening=0
          )
          self.mask = Nifti1Image(mask.astype(np.int8), self.affine)
      elif mask is None:
          mask = np.ones(self.fmri_data[0].shape[:3]).astype(np.int8)
          self.mask = Nifti1Image(mask, self.affine)
      else:
          if isinstance(mask, str):
              self.mask = load(mask)
          else:
              self.mask = mask
  
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 1 to create a new FMRILinearModel object  with example: obj = FMRILinearModel(fmri_data, design_matrices, mask, m, M, threshold)