code: def fixed_effects(subj, design):
      """Fixed effects (within subject) for OpenfMRI ds105 model
  
      Finds run by run estimated model results, creates fixed effects results
      image per subject.
  
      Parameters
      ----------
      subj : int
          subject number 1..6 inclusive
      design : {'standard'}
          design type
      """
      # First, find all the effect and standard deviation images
      # for the subject and this design type
      path_dict = futil.path_info_design(subj, design)
      rootdir = path_dict["rootdir"]
      # The output directory
      fixdir = pjoin(rootdir, "fixed")
      # Fetch results images from run estimations
      results = futil.results_table(path_dict)
      # Get our hands on the relevant coordmap to save our results
      coordmap = futil.load_image_ds105(
          "_%02d" % subj, "wanatomical.nii"
      ).coordmap
      # Compute the "fixed" effects for each type of contrast
      for con in results:
          fixed_effect = 0
          fixed_var = 0
          for effect, sd in results[con]:
              effect = load_image(effect).get_fdata()
              sd = load_image(sd).get_fdata()
              var = sd**2
  
              # The optimal, in terms of minimum variance, combination of the
              # effects has weights 1 / var
              #
              # XXX regions with 0 variance are set to 0
              # XXX do we want this or np.nan?
              ivar = np.nan_to_num(1.0 / var)
              fixed_effect += effect * ivar
              fixed_var += ivar
  
          # Now, compute the fixed effects variance and t statistic
          fixed_sd = np.sqrt(fixed_var)
          isd = np.nan_to_num(1.0 / fixed_sd)
          fixed_t = fixed_effect * isd
  
          # Save the results
          odir = futil.ensure_dir(fixdir, con)
          for a, n in zip(
              [fixed_effect, fixed_sd, fixed_t], ["effect", "sd", "t"]
          ):
              im = api.Image(a, copy(coordmap))
              save_image(im, pjoin(odir, f"{n}.nii"))
  
imports: import warnings
  from copy import copy
  from imp import reload
  from os.path import join
  from tempfile import NamedTemporaryFile
  import ds105_util
  import numpy
  from nipy.algorithms.statistics import onesample
  from nipy.algorithms.statistics.api import ARModel, OLSModel, isestimable, make_recarray
  from nipy.core import api
  from nipy.core.api import Image
  from nipy.core.image.image import rollimg
  from nipy.io.api import load_image, save_image
  from nipy.modalities.fmri import design
  from nipy.modalities.fmri.fmristat import hrf
label_desc: Use image node_id 2 for calling a global function with example usage: fixed_effects(subj, design) without return types