code: def load_paradigm_from_csv_file(path, session=None):
      """
      Read a (.csv) paradigm file consisting of values yielding
      (occurrence time, (duration), event ID, modulation)
      and returns a paradigm instance or a dictionary of paradigm instances
  
      Parameters
      ----------
      path: string,
            path to a .csv file that describes the paradigm
      session: string, optional, session identifier
               by default the output is a dictionary
               of session-level dictionaries indexed by session
  
      Returns
      -------
      paradigm, paradigm instance (if session is provided), or
                dictionary of paradigm instances otherwise,
                the resulting session-by-session paradigm
  
      Notes
      -----
      It is assumed that the csv file contains the following columns:
      (session id, condition id, onset),
      plus possibly (duration) and/or (amplitude).
      If all the durations are 0, the paradigm will be handled as event-related.
  
      FIXME: would be much clearer if amplitude was put before duration in the
      .csv
      """
      import csv
  
      with open(path, newline="") as csvfile:
          dialect = csv.Sniffer().sniff(csvfile.read())
          csvfile.seek(0)
          reader = csv.reader(csvfile, dialect)
  
          # load the csv as a paradigm array
          sess, cid, onset, amplitude, duration = [], [], [], [], []
          for row in reader:
              sess.append(row[0])
              cid.append(row[1])
              onset.append(float(row[2]))
              if len(row) > 3:
                  duration.append(float(row[3]))
              if len(row) > 4:
                  amplitude.append(row[4])
  
          paradigm_info = [
              np.array(sess),
              np.array(cid),
              np.array(onset),
              np.array(duration),
              np.array(amplitude),
          ]
          paradigm_info = paradigm_info[: len(row)]
  
      def read_session(paradigm_info, session):
          """return a paradigm instance corresponding to session"""
          ps = paradigm_info[0] == session
          if np.sum(ps) == 0:
              return None
          ampli = np.ones(np.sum(ps))
          if len(paradigm_info) > 4:
              _, cid, onset, duration, ampli = (
                  lp[ps] for lp in paradigm_info
              )
              if (duration == 0).all():
                  paradigm = EventRelatedParadigm(cid, onset, ampli)
              else:
                  paradigm = BlockParadigm(cid, onset, duration, ampli)
          elif len(paradigm_info) > 3:
              _, cid, onset, duration = (lp[ps] for lp in paradigm_info)
              paradigm = BlockParadigm(cid, onset, duration, ampli)
          else:
              _, cid, onset = (lp[ps] for lp in paradigm_info)
              paradigm = EventRelatedParadigm(cid, onset, ampli)
          return paradigm
  
      sessions = np.unique(paradigm_info[0])
      if session is None:
          paradigm = {}
          for session in sessions:
              paradigm[session] = read_session(paradigm_info, session)
      else:
          paradigm = read_session(paradigm_info, session)
      return paradigm
  
file_path: nipy/nipy/modalities/fmri/experimental_paradigm.py
imports: import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: load_paradigm_from_csv_file(path, session) and returns: paradigm, paradigm, None