Skip to content

Commit

Permalink
Merge 8bcb00f into acecabb
Browse files Browse the repository at this point in the history
  • Loading branch information
acse-wx319 committed Nov 9, 2015
2 parents acecabb + 8bcb00f commit 0796a52
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 2 deletions.
87 changes: 87 additions & 0 deletions code/convolving/behavdata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
onset gain loss PTval respnum respcat RT
0.00 20 15 5.15 0 -1 0.000
4.00 18 12 6.12 2 1 1.793
8.00 10 15 -4.85 3 0 1.637
18.00 34 16 18.16 1 1 1.316
24.00 18 5 13.05 1 1 1.670
28.00 26 13 13.13 2 1 1.232
38.00 32 17 15.17 2 1 1.502
42.00 16 5 11.05 2 1 1.925
46.00 22 7 15.07 1 1 1.061
52.00 36 8 28.08 1 1 1.079
56.00 16 10 6.10 2 1 1.477
62.00 30 13 17.13 1 1 1.599
74.00 14 17 -2.83 4 0 1.822
78.00 28 19 9.19 2 1 1.405
82.00 14 20 -5.80 4 0 1.206
86.00 26 16 10.16 2 1 1.272
90.00 40 5 35.05 1 1 0.900
94.00 28 12 16.12 2 1 1.318
98.00 20 16 4.16 2 1 1.367
102.00 26 5 21.05 1 1 1.566
106.00 32 20 12.20 2 1 1.360
110.00 18 17 1.17 3 0 1.321
116.00 20 6 14.06 1 1 1.433
120.00 20 18 2.18 3 0 1.215
126.00 40 7 33.07 1 1 0.824
130.00 36 6 30.06 1 1 0.903
134.00 16 20 -3.80 4 0 1.047
140.00 40 15 25.15 1 1 1.169
148.00 10 6 4.06 3 0 1.137
156.00 12 15 -2.85 4 0 1.082
160.00 34 17 17.17 2 1 1.096
164.00 18 14 4.14 2 1 2.200
170.00 40 13 27.13 1 1 0.776
174.00 32 19 13.19 2 1 1.336
178.00 14 12 2.12 3 0 1.585
182.00 32 10 22.10 2 1 1.362
192.00 36 17 19.17 2 1 1.786
202.00 28 13 15.13 2 1 1.107
208.00 34 13 21.13 1 1 1.243
212.00 38 14 24.14 1 1 1.112
220.00 32 11 21.11 1 1 1.235
224.00 32 9 23.09 1 1 0.866
234.00 30 16 14.16 2 1 1.627
238.00 34 10 24.10 1 1 1.000
246.00 18 8 10.08 2 1 1.526
250.00 34 20 14.20 2 1 1.251
256.00 32 16 16.16 2 1 2.280
260.00 24 12 12.12 2 1 1.242
266.00 38 12 26.12 1 1 1.011
272.00 38 10 28.10 1 1 1.043
280.00 24 7 17.07 1 1 1.172
284.00 16 13 3.13 2 1 1.115
296.00 36 19 17.19 2 1 1.750
310.00 32 5 27.05 1 1 0.918
316.00 34 9 25.09 1 1 0.734
320.00 28 7 21.07 1 1 1.067
324.00 24 13 11.13 2 1 1.600
330.00 38 5 33.05 1 1 0.805
336.00 22 9 13.09 1 1 1.390
342.00 10 11 -0.89 4 0 1.806
346.00 12 14 -1.86 4 0 1.600
350.00 34 19 15.19 2 1 1.237
360.00 38 7 31.07 1 1 0.957
364.00 30 6 24.06 1 1 0.877
368.00 26 18 8.18 2 1 1.454
374.00 14 6 8.06 2 1 1.904
378.00 16 12 4.12 2 1 1.486
382.00 22 20 2.20 3 0 1.598
386.00 12 17 -4.83 4 0 1.368
398.00 10 7 3.07 2 1 1.320
402.00 18 20 -1.80 4 0 2.302
408.00 12 6 6.06 2 1 1.433
412.00 32 6 26.06 1 1 0.999
416.00 18 7 11.07 2 1 1.071
420.00 40 10 30.10 1 1 0.783
424.00 14 14 0.14 3 0 1.687
428.00 30 19 11.19 2 1 1.167
436.00 24 18 6.18 2 1 1.145
440.00 10 12 -1.88 3 0 1.383
444.00 40 19 21.19 1 1 0.862
448.00 24 9 15.09 1 1 0.834
458.00 16 18 -1.82 4 0 1.785
462.00 36 12 24.12 2 1 1.280
466.00 26 9 17.09 1 1 1.394
470.00 20 12 8.12 2 1 1.249
474.00 24 14 10.14 2 1 1.266
Binary file added code/convolving/bold.nii
Binary file not shown.
86 changes: 86 additions & 0 deletions code/convolving/cond001.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
0.0000 3 1
4.0000 3 1
8.0000 3 1
18.0000 3 1
24.0000 3 1
28.0000 3 1
38.0000 3 1
42.0000 3 1
46.0000 3 1
52.0000 3 1
56.0000 3 1
62.0000 3 1
74.0000 3 1
78.0000 3 1
82.0000 3 1
86.0000 3 1
90.0000 3 1
94.0000 3 1
98.0000 3 1
102.0000 3 1
106.0000 3 1
110.0000 3 1
116.0000 3 1
120.0000 3 1
126.0000 3 1
130.0000 3 1
134.0000 3 1
140.0000 3 1
148.0000 3 1
156.0000 3 1
160.0000 3 1
164.0000 3 1
170.0000 3 1
174.0000 3 1
178.0000 3 1
182.0000 3 1
192.0000 3 1
202.0000 3 1
208.0000 3 1
212.0000 3 1
220.0000 3 1
224.0000 3 1
234.0000 3 1
238.0000 3 1
246.0000 3 1
250.0000 3 1
256.0000 3 1
260.0000 3 1
266.0000 3 1
272.0000 3 1
280.0000 3 1
284.0000 3 1
296.0000 3 1
310.0000 3 1
316.0000 3 1
320.0000 3 1
324.0000 3 1
330.0000 3 1
336.0000 3 1
342.0000 3 1
346.0000 3 1
350.0000 3 1
360.0000 3 1
364.0000 3 1
368.0000 3 1
374.0000 3 1
378.0000 3 1
382.0000 3 1
386.0000 3 1
398.0000 3 1
402.0000 3 1
408.0000 3 1
412.0000 3 1
416.0000 3 1
420.0000 3 1
424.0000 3 1
428.0000 3 1
436.0000 3 1
440.0000 3 1
444.0000 3 1
448.0000 3 1
458.0000 3 1
462.0000 3 1
466.0000 3 1
470.0000 3 1
474.0000 3 1
42 changes: 42 additions & 0 deletions code/convolving/convolve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Creating convolved

import numpy as np # the Python array package
import matplotlib.pyplot as plt # the Python plotting package
from scipy.stats import gamma
import nibabel as nib
img = nib.load('bold.nii')
data = img.get_data()
data = data[...,1:]


def hrf(times):
# Gamma pdf for the peak
peak_values = gamma.pdf(times, 6)
# Gamma pdf for the undershoot
undershoot_values = gamma.pdf(times, 12)
# Combine them
values = peak_values - 0.35 * undershoot_values
# Scale max to 0.6
return values / np.max(values) * 0.6

def get_behave(filename):
# Read in behave.txt to get repetition times
df = [line.strip().split('\t') for line in open(filename)]
return df

names = get_task('behavdata.txt')[0]
# names = ['onset', 'gain', 'loss', 'PTval', 'respnum', 'respcat', 'RT']
behave = get_behave('behavdata.txt')[1:]

tr_times = [float(p[6]) for p in behave] # list of repetition times
n_vol = data.shape[3] # number of volumes

from stimuli_v1 import events2neural # a new version of stimuli that deals with nonconstant TR
neural_prediction = events2neural('cond001.txt', tr_times, n_vol)

hrf_at_trs = hrf(tr_times)
convolved = np.convolve(neural_prediction, hrf_at_trs)
n_to_remove = len(hrf_at_trs) - 1
convolved = convolved[:-n_to_remove]


42 changes: 42 additions & 0 deletions code/convolving/stimuli_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
""" 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(taskfname, 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 = [line.strip().split('\t') for line in open(taskfname)][1:]
# 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
for i in range(len(task)):
if tr[i] == 0:
tr[i] = 1
task[i][0] = int(float(task[i][0])/tr[i])
task[i][1] = int(float(task[i][1])/tr[i])

# Neural time course from onset, duration, amplitude for each event
time_course = np.zeros(n_trs)
for line in task:
time_course[line[0]:(line[0] + line[1])] = line[2]
return time_course
4 changes: 2 additions & 2 deletions slides/progress.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
% Project Aleph Progress Report
% Ross Barnowski, Matthew Brett, Jarrod Millman
% Project Eta Progress Report
% Jon Jara, Will Sanderson, Juan Shishido, Paul Wu, Wendy Xu
% November 12, 2015

# Background
Expand Down

0 comments on commit 0796a52

Please sign in to comment.