class_docstr: Estimate contrast of a fitted model.
class_docstr_tok: ["Estimate","contrast","of","a","fitted","model","."]
code: def _run_interface(self, runtime):
      import nibabel as nb
      import numpy as np
      import nipy.modalities.fmri.glm as GLM
  
      beta_nii = nb.load(self.inputs.beta)
      if isdefined(self.inputs.mask):
          mask = np.asanyarray(nb.load(self.inputs.mask).dataobj) > 0
      else:
          mask = np.ones(beta_nii.shape[:3]) == 1
  
      glm = GLM.GeneralLinearModel()
      glm.beta = np.array(beta_nii.dataobj)[mask, :].T
      glm.nvbeta = self.inputs.nvbeta
      glm.s2 = np.array(nb.load(self.inputs.s2).dataobj)[mask]
      glm.dof = self.inputs.dof
      glm._axis = self.inputs.axis
      glm._constants = self.inputs.constants
  
      reg_names = self.inputs.reg_names
  
      self._stat_maps = []
      self._p_maps = []
      self._z_maps = []
      for contrast_def in self.inputs.contrasts:
          name = contrast_def[0]
          contrast = np.zeros(len(reg_names))
  
          for i, reg_name in enumerate(reg_names):
              if reg_name in contrast_def[2]:
                  idx = contrast_def[2].index(reg_name)
                  contrast[i] = contrast_def[3][idx]
  
          est_contrast = glm.contrast(contrast)
  
          stat_map = np.zeros(mask.shape)
          stat_map[mask] = est_contrast.stat().T
          stat_map_file = os.path.abspath(name + "_stat_map.nii")
          nb.save(
              nb.Nifti1Image(stat_map, beta_nii.affine), stat_map_file
          )
          self._stat_maps.append(stat_map_file)
  
          p_map = np.zeros(mask.shape)
          p_map[mask] = est_contrast.pvalue().T
          p_map_file = os.path.abspath(name + "_p_map.nii")
          nb.save(nb.Nifti1Image(p_map, nii.affine), p_map_file)
          self._p_maps.append(p_map_file)
  
          z_map = np.zeros(mask.shape)
          z_map[mask] = est_contrast.zscore().T
          z_map_file = os.path.abspath(name + "_z_map.nii")
          nb.save(nb.Nifti1Image(z_map, nii.affine), z_map_file)
          self._z_maps.append(z_map_file)
  
      return runtime
  
file_path: nipype/nipype/interfaces/nipy/model.py
imports: import os
  from .base import NipyBaseInterface
  from ..base import TraitedSpec, traits, File, OutputMultiPath, BaseInterfaceInputSpec, isdefined
label_desc: Use image node_id 1 for calling the EstimateContrast obj's underlying member method code with example usage: obj._run_interface(runtime) and returns: runtime