code: def events(times, amplitudes=None, f=DiracDelta, g=Symbol("a")):
      """Return a sum of functions based on a sequence of times.
  
      Parameters
      ----------
      times : sequence
         vector of onsets length $N$
      amplitudes : None or sequence length $N$, optional
         Optional sequence of amplitudes. None (default) results in
         sequence length $N$ of 1s
      f : sympy.Function, optional
         Optional function. Defaults to DiracDelta, can be replaced with
         another function, f, in which case the result is the convolution
         with f.
      g : sympy.Basic, optional
         Optional sympy expression function of amplitudes.  The
         amplitudes, should be represented by the symbol 'a', which will
         be substituted, by the corresponding value in `amplitudes`.
  
      Returns
      -------
      sum_expression : Sympy.Add
         Sympy expression of time $t$, where onsets, as a function of $t$,
         have been symbolically convolved with function `f`, and any
         function `g` of corresponding amplitudes.
  
      Examples
      --------
      We import some sympy stuff so we can test if we've got what we
      expected
  
      >>> from sympy import DiracDelta, Symbol, Function
      >>> from nipy.modalities.fmri.utils import T
      >>> evs = events([3,6,9])
      >>> evs == DiracDelta(-9 + T) + DiracDelta(-6 + T) + DiracDelta(-3 + T)
      True
      >>> hrf = Function('hrf')
      >>> evs = events([3,6,9], f=hrf)
      >>> evs == hrf(-9 + T) + hrf(-6 + T) + hrf(-3 + T)
      True
      >>> evs = events([3,6,9], amplitudes=[2,1,-1])
      >>> evs == -DiracDelta(-9 + T) + 2*DiracDelta(-3 + T) + DiracDelta(-6 + T)
      True
      """
      e = 0
      asymb = Symbol("a")
      if amplitudes is None:
          amplitudes = itertools.cycle([1])
      for time, a in zip(times, amplitudes):
          e = e + g.subs(asymb, a) * f(T - time)
      return e
  
imports: import itertools
  import numpy
  import sympy
  from scipy.interpolate import interp1d
  from sympy import DiracDelta, Symbol
  from sympy.utilities.lambdify import implemented_function, lambdify
  from nipy.algorithms.statistics.formula.formulae import Formula, Term
label_desc: Use image node_id 7 for calling a global function with example usage: events(times, amplitudes, f, g) and returns: e