# run 2
t2 = Term('t2') # Time within run 2
# Conditions 1 through 3 in run 2
c12 = utils.events([3.3, 7, 10], f=h2); c12 = c12.subs(t, t2)
c22 = utils.events([1, 3.2, 9], f=h2); c22 = c22.subs(t, t2)
c32 = utils.events([2, 4.2, 8], f=h2); c32 = c32.subs(t, t2)
d2 = utils.fourier_basis([0.3, 0.5, 0.7]); d2 = d2.subs(t, t2)

# Formula for run 2 signal in terms of time in run 2 (t2)
f2 = Formula([c12, c22, c32]) + d2

# Factor giving constant for run. The [1, 2] means that there are two levels to
# this factor, and that when we get to pass in values for this factor,
# instantiating an actual design matrix (see below), a value of 1 means level
# 1 and a value of 2 means level 2.
run_factor = Factor('run', [1, 2])
run_1_coder = run_factor.get_term(1) # Term coding for level 1
run_2_coder = run_factor.get_term(2) # Term coding for level 2

# The multi run formula will combine the indicator (dummy value) terms from the
# run factor with the formulae for the runs (which are functions of (run1, run2)
# time. The run_factor terms are step functions that are zero when not in the
# run, 1 when in the run.
f = Formula([run_1_coder]) * f1 + Formula([run_2_coder]) * f2 + run_factor

# Now, we evaluate the formula.  So far we've been entirely symbolic.  Now we
# start to think about the values at which we want to evaluate our symbolic
# formula.

# We'll use these values for time within run 1.  The times are in seconds from
# the beginning of run 1.  In our case run 1 was 20 seconds long. 101 below
c12 = c12.subs(t, t2)
c22 = utils.events([1, 3.2, 9], f=h2)
c22 = c22.subs(t, t2)
c32 = utils.events([2, 4.2, 8], f=h2)
c32 = c32.subs(t, t2)
d2 = utils.fourier_basis([0.3, 0.5, 0.7])
d2 = d2.subs(t, t2)

# Formula for run 2 signal in terms of time in run 2 (t2)
f2 = Formula([c12, c22, c32]) + d2

# Factor giving constant for run. The [1, 2] means that there are two levels to
# this factor, and that when we get to pass in values for this factor,
# instantiating an actual design matrix (see below), a value of 1 means level
# 1 and a value of 2 means level 2.
run_factor = Factor('run', [1, 2])
run_1_coder = run_factor.get_term(1)  # Term coding for level 1
run_2_coder = run_factor.get_term(2)  # Term coding for level 2

# The multi run formula will combine the indicator (dummy value) terms from the
# run factor with the formulae for the runs (which are functions of (run1, run2)
# time. The run_factor terms are step functions that are zero when not in the
# run, 1 when in the run.
f = Formula([run_1_coder]) * f1 + Formula([run_2_coder]) * f2 + run_factor

# Now, we evaluate the formula.  So far we've been entirely symbolic.  Now we
# start to think about the values at which we want to evaluate our symbolic
# formula.

# We'll use these values for time within run 1.  The times are in seconds from
# the beginning of run 1.  In our case run 1 was 20 seconds long. 101 below
Example #3
0
tval1 = np.linspace(0,20,101)

f1 = Formula([c11,c21,c31]) + d1

# Session 2

t2 = Term('t2')
c12 = utils.events([3.3,7,10], f=h2); c12 = c12.subs(t, t2)
c22 = utils.events([1,3.2,9], f=h2); c22 = c22.subs(t, t2)
c32 = utils.events([2,4.2,8], f=h2); c32 = c32.subs(t, t2)
d2 = utils.fourier_basis([0.3,0.5,0.7]); d2 = d2.subs(t, t2)
tval2 = np.linspace(0,10,51)

f2 = Formula([c12,c22,c32]) + d2

sess_factor = Factor('sess', [1,2])

# The multi session formula

f = Formula([sess_factor.terms[0]]) * f1 + Formula([sess_factor.terms[1]]) * f2

# Now, we evaluate the formula
# the arrays now have 152=101+51 rows...

ttval1 = np.hstack([tval1, np.zeros(tval2.shape)])
ttval2 = np.hstack([np.zeros(tval1.shape), tval2])
session = np.array([1]*tval1.shape[0] + [2]*tval2.shape[0])

f = f.subs(h1, hrf.glover)
f = f.subs(h2, hrf.glover)