-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstimuli.py
More file actions
37 lines (31 loc) · 1.14 KB
/
stimuli.py
File metadata and controls
37 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
""" Functions to work with standard OpenFMRI stimulus files
The functions have docstrings according to the numpy docstring standard - see:
https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
"""
import numpy as np
def events2neural(task_fname, tr, n_trs):
""" Return predicted neural time course from event file `task_fname`
Parameters
----------
task_fname : str
Filename of event file
tr : float
TR in seconds
n_trs : int
Number of TRs in functional run
Returns
-------
time_course : array shape (n_trs,)
Predicted neural time course, one value per TR
"""
task = np.loadtxt(task_fname)
# Check that the file is plausibly a task file
if task.ndim != 2 or task.shape[1] != 3:
raise ValueError("Is {0} really a task file?", task_fname)
# Convert onset, duration seconds to TRs
task[:, :2] = task[:, :2] / tr
# Neural time course from onset, duration, amplitude for each event
time_course = np.zeros(n_trs)
for onset, duration, amplitude in task:
time_course[onset:onset + duration] = amplitude
return time_course