Skip to content
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
4 changes: 0 additions & 4 deletions brainiak/utils/fmrisim.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,6 @@ def generate_stimfunction(onsets,
# Store the weights
stimfunction[onset_idx:offset_idx, 0] = [weights[onset_counter]]

# Shorten the data if it's too long

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this is unnecessary as you say

if stimfunction.shape[0] > total_time * temporal_resolution:
stimfunction = stimfunction[0:int(total_time * temporal_resolution), 0]

return stimfunction


Expand Down
37 changes: 20 additions & 17 deletions brainiak/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL',
n_C = len(stimtime_files) # number of conditions
n_S = np.size(scan_duration) # number of scans
if n_S > 1:
design = [np.empty([int(np.floor(duration / TR)), n_C])
design = [np.empty([int(np.round(duration / TR)), n_C])
for duration in scan_duration]
else:
design = [np.empty([int(np.floor(scan_duration / TR)), n_C])]
design = [np.empty([int(np.round(scan_duration / TR)), n_C])]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

scan_onoff = np.insert(np.cumsum(scan_duration), 0, 0)
if style == 'FSL':
design_info = _read_stimtime_FSL(stimtime_files, n_C, n_S, scan_onoff)
Expand All @@ -445,21 +445,24 @@ def gen_design(stimtime_files, scan_duration, TR, style='FSL',
# generate design matrix
for i_s in range(n_S):
for i_c in range(n_C):
stimfunction = generate_stimfunction(
onsets=design_info[i_s][i_c]['onset'],
event_durations=design_info[i_s][i_c]['duration'],
total_time=scan_duration[i_s],
weights=design_info[i_s][i_c]['weight'],
temporal_resolution=1.0/temp_res)
hrf = _double_gamma_hrf(response_delay=response_delay,
undershoot_delay=undershoot_delay,
response_dispersion=response_disp,
undershoot_dispersion=undershoot_disp,
undershoot_scale=undershoot_scale,
temporal_resolution=1.0/temp_res)
design[i_s][:, i_c] = convolve_hrf(
stimfunction, TR, hrf_type=hrf, scale_function=0,
temporal_resolution=1.0 / temp_res).transpose() * temp_res
if len(design_info[i_s][i_c]['onset']) > 0:
stimfunction = generate_stimfunction(
onsets=design_info[i_s][i_c]['onset'],
event_durations=design_info[i_s][i_c]['duration'],
total_time=scan_duration[i_s],
weights=design_info[i_s][i_c]['weight'],
temporal_resolution=1.0/temp_res)
hrf = _double_gamma_hrf(response_delay=response_delay,
undershoot_delay=undershoot_delay,
response_dispersion=response_disp,
undershoot_dispersion=undershoot_disp,
undershoot_scale=undershoot_scale,
temporal_resolution=1.0/temp_res)
design[i_s][:, i_c] = convolve_hrf(
stimfunction, TR, hrf_type=hrf, scale_function=False,
temporal_resolution=1.0 / temp_res).transpose() * temp_res
else:
design[i_s][:, i_c] = 0.0
# We multiply the resulting design matrix with
# the temporal resolution to normalize it.
# We do not use the internal normalization
Expand Down
1 change: 1 addition & 0 deletions tests/utils/example_stimtime_2_AFNI.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-10.0
8 changes: 7 additions & 1 deletion tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def test_gen_design():
import os.path
files = {'FSL1': 'example_stimtime_1_FSL.txt',
'FSL2': 'example_stimtime_2_FSL.txt',
'AFNI1': 'example_stimtime_1_AFNI.txt'}
'AFNI1': 'example_stimtime_1_AFNI.txt',
'AFNI2': 'example_stimtime_2_AFNI.txt'}
for key in files.keys():
files[key] = os.path.join(os.path.dirname(__file__), files[key])
design1 = gen_design(stimtime_files=files['FSL1'], scan_duration=[48, 20],
Expand Down Expand Up @@ -130,6 +131,11 @@ def test_gen_design():
scan_duration=[48, 20], TR=2, style='AFNI')
assert np.all(np.isclose(design1, design6)), (
'design matrices generated from AFNI style and FSL style do not match')
design7 = gen_design(stimtime_files=[files['AFNI2']],
scan_duration=[48], TR=2, style='AFNI')
assert np.all(design7 == 0.0), (
'A negative stimulus onset of AFNI style should result in an all-zero'
+ ' design matrix')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good extra test to have



def test_center_mass_exp():
Expand Down