code: def rewrite_spec(subj, run, root="/home/jtaylo/FIAC-HBM2009"):
      """
      Take a FIAC specification file and get two specifications
      (experiment, begin).
  
      This creates two new .csv files, one for the experimental
      conditions, the other for the "initial" confounding trials that
      are to be modelled out.
  
      For the block design, the "initial" trials are the first
      trials of each block. For the event designs, the
      "initial" trials are made up of just the first trial.
  
      """
  
      if exists(
          pjoin(
              "%(root)s",
              "fiac%(subj)d",
              "subj%(subj)d_evt_fonc%(run)d.txt",
          )
          % {"root": root, "subj": subj, "run": run}
      ):
          designtype = "evt"
      else:
          designtype = "bloc"
  
      # Fix the format of the specification so it is
      # more in the form of a 2-way ANOVA
  
      eventdict = {
          1: "SSt_SSp",
          2: "SSt_DSp",
          3: "DSt_SSp",
          4: "DSt_DSp",
      }
      s = StringIO()
      w = csv.writer(s)
      w.writerow(["time", "sentence", "speaker"])
  
      specfile = pjoin(
          "%(root)s",
          "fiac%(subj)d",
          "subj%(subj)d_%(design)s_fonc%(run)d.txt",
      ) % {"root": root, "subj": subj, "run": run, "design": designtype}
      d = np.loadtxt(specfile)
      for row in d:
          w.writerow([row[0]] + eventdict[row[1]].split("_"))
      s.seek(0)
      d = csv2rec(s)
  
      # Now, take care of the 'begin' event
      # This is due to the FIAC design
  
      if designtype == "evt":
          b = np.array(
              [(d[0]["time"], 1)],
              np.dtype([("time", np.float64), ("initial", np.int_)]),
          )
          d = d[1:]
      else:
          k = np.equal(np.arange(d.shape[0]) % 6, 0)
          b = np.array(
              [(tt, 1) for tt in d[k]["time"]],
              np.dtype([("time", np.float64), ("initial", np.int_)]),
          )
          d = d[~k]
  
      designtype = {"bloc": "block", "evt": "event"}[designtype]
  
      fname = pjoin(
          DATADIR,
          "fiac_%(subj)02d",
          "%(design)s",
          "experiment_%(run)02d.csv",
      ) % {"root": root, "subj": subj, "run": run, "design": designtype}
      rec2csv(d, fname)
      experiment = csv2rec(fname)
  
      fname = pjoin(
          DATADIR,
          "fiac_%(subj)02d",
          "%(design)s",
          "initial_%(run)02d.csv",
      ) % {"root": root, "subj": subj, "run": run, "design": designtype}
      rec2csv(b, fname)
      initial = csv2rec(fname)
  
      return d, b
  
imports: import csv
  import os
  from io import StringIO
  from os import listdir, makedirs
  from os.path import abspath, exists, isdir, splitext
  from os.path import join
  import numpy
  import pandas
  from nipy.io.api import load_image
label_desc: Use image node_id 13 for calling a global function with example usage: rewrite_spec(subj, run, root) and returns: d,  b