Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated test file for stimuli and cond_test1 #247

Merged
merged 2 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions code/utils/tests/test_stimuli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from __future__ import print_function # print('me') instead of print 'me'
from __future__ import division # 1/2 == 0.5, not 0
from __future__ import absolute_import

""" Test stimuli module
Run tests with::
nosetests test_stimuli.py
"""

import numpy as np
import numpy.testing as npt
import scipy.stats
from scipy.stats import gamma
import numpy as np
import matplotlib.pyplot as plt
import nibabel as nib


import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), "../functions/"))

import stimuli

data_location=os.path.join(os.path.dirname(__file__), '../../../data/')

def test_hrf():
time = np.arange(0,24, 1.0/100)
peak_values = gamma.pdf(time,6)
undershoot_values = gamma.pdf(time, 12)
values = peak_values - 0.35 * undershoot_values
hrf_totest = values/np.max(values) * 0.6
npt.assert_array_equal(hrf_totest,stimuli.hrf(np.arange(0,24,1.0/100)))



def test_events2neural():
# test events2neural function
cond_test1 = np.loadtxt(data_location+'cond_test1.txt')
neural = stimuli.events2neural(cond_test1, 2, 16)
# cond_test1.txt file is:
"""
10 5.0 1
20 4.0 2
24 3.0 0.1
"""
# Expected values for tr=2, n_trs=16
expected = np.zeros(16)
expected[5:7] = 1
expected[10:12] = 2
expected[12] = 0.1
npt.assert_array_equal(neural, expected)


def test_events2neural_high():
"""test with gain condition from subject 3's run 001

"""
TR=2
n_trs=240
tr_div=100
condfile = np.loadtxt(data_location+'ds005/sub003/model/model001/onsets/task001_run001/cond002.txt')
onsets = condfile[:, 0]
durations_seconds = condfile[:, 1]
amplitudes = condfile[:, 2]
onsets_in_scans = onsets / TR
high_res_times = np.arange(0, n_trs, 1.0/tr_div) * TR
high_res_neural = np.zeros(high_res_times.shape)
high_res_onset_indices = onsets_in_scans * tr_div
high_res_durations = durations_seconds / TR * tr_div
for hr_onset, hr_duration, amplitude in list(zip(high_res_onset_indices,high_res_durations,amplitudes)):
hr_onset = int(round(hr_onset))
hr_duration = int(round(hr_duration))
high_res_neural[hr_onset:hr_onset+hr_duration] = amplitude

cond = np.loadtxt(data_location+'ds005/sub003/model/model001/onsets/task001_run001/cond002.txt')
test_high_res_times, test_high_res_neural = stimuli.events2neural_high(cond)
npt.assert_array_equal(high_res_times, test_high_res_times)
npt.assert_array_equal(high_res_neural, test_high_res_neural)

3 changes: 3 additions & 0 deletions data/cond_test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
10 5.0 1
20 4.0 2
24 3.0 0.1
86 changes: 86 additions & 0 deletions data/ds005/sub003/model/model001/onsets/task001_run001/cond002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
0.0000 3 -0.1390
4.0000 3 -0.1890
8.0000 3 -0.3890
18.0000 3 0.2110
24.0000 3 -0.1890
28.0000 3 0.0110
38.0000 3 0.1610
42.0000 3 -0.2390
46.0000 3 -0.0890
52.0000 3 0.2610
56.0000 3 -0.2390
62.0000 3 0.1110
74.0000 3 -0.2890
78.0000 3 0.0610
82.0000 3 -0.2890
86.0000 3 0.0110
90.0000 3 0.3610
94.0000 3 0.0610
98.0000 3 -0.1390
102.0000 3 0.0110
106.0000 3 0.1610
110.0000 3 -0.1890
116.0000 3 -0.1390
120.0000 3 -0.1390
126.0000 3 0.3610
130.0000 3 0.2610
134.0000 3 -0.2390
140.0000 3 0.3610
148.0000 3 -0.3890
156.0000 3 -0.3390
160.0000 3 0.2110
164.0000 3 -0.1890
170.0000 3 0.3610
174.0000 3 0.1610
178.0000 3 -0.2890
182.0000 3 0.1610
192.0000 3 0.2610
202.0000 3 0.0610
208.0000 3 0.2110
212.0000 3 0.3110
220.0000 3 0.1610
224.0000 3 0.1610
234.0000 3 0.1110
238.0000 3 0.2110
246.0000 3 -0.1890
250.0000 3 0.2110
256.0000 3 0.1610
260.0000 3 -0.0390
266.0000 3 0.3110
272.0000 3 0.3110
280.0000 3 -0.0390
284.0000 3 -0.2390
296.0000 3 0.2610
310.0000 3 0.1610
316.0000 3 0.2110
320.0000 3 0.0610
324.0000 3 -0.0390
330.0000 3 0.3110
336.0000 3 -0.0890
342.0000 3 -0.3890
346.0000 3 -0.3390
350.0000 3 0.2110
360.0000 3 0.3110
364.0000 3 0.1110
368.0000 3 0.0110
374.0000 3 -0.2890
378.0000 3 -0.2390
382.0000 3 -0.0890
386.0000 3 -0.3390
398.0000 3 -0.3890
402.0000 3 -0.1890
408.0000 3 -0.3390
412.0000 3 0.1610
416.0000 3 -0.1890
420.0000 3 0.3610
424.0000 3 -0.2890
428.0000 3 0.1110
436.0000 3 -0.0390
440.0000 3 -0.3890
444.0000 3 0.3610
448.0000 3 -0.0390
458.0000 3 -0.2390
462.0000 3 0.2610
466.0000 3 0.0110
470.0000 3 -0.1390
474.0000 3 -0.0390