Exemplo n.º 1
0
def test_gen_design():
    from brainiak.utils.utils import gen_design
    import numpy as np
    import os.path
    files = {
        'FSL1': 'example_stimtime_1_FSL.txt',
        'FSL2': 'example_stimtime_2_FSL.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],
                         TR=2,
                         style='FSL')
    assert design1.shape == (34, 1), 'Returned design matrix has wrong shape'
    assert design1[24] == 0, (
        "gen_design should generated design matrix for each run separately "
        "and concatenate them.")
    design2 = gen_design(stimtime_files=[files['FSL1'], files['FSL2']],
                         scan_duration=[48, 20],
                         TR=2,
                         style='FSL')
    assert design2.shape == (34, 2), 'Returned design matrix has wrong shape'
    design3 = gen_design(stimtime_files=files['FSL1'],
                         scan_duration=68,
                         TR=2,
                         style='FSL')
    assert design3[24] != 0, (
        'design matrix should be non-zero 8 seconds after an event onset.')
    design4 = gen_design(stimtime_files=[files['FSL2']],
                         scan_duration=[48, 20],
                         TR=2,
                         style='FSL')
    assert np.all(np.isclose(
        design1 * 0.5,
        design4)), ('gen_design does not treat missing values correctly')
    design5 = gen_design(stimtime_files=[files['FSL2']],
                         scan_duration=[48, 20],
                         TR=1)
    assert (np.abs(design4 - design5[::2])).mean() < 0.1, (
        'design matrices sampled at different frequency do not match'
        ' at corresponding time points')
    design6 = gen_design(stimtime_files=[files['AFNI1']],
                         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')
Exemplo n.º 2
0
def test_gen_design():
    from brainiak.utils.utils import gen_design
    import numpy as np
    import os.path
    files = {'FSL1': 'example_stimtime_1_FSL.txt',
             'FSL2': 'example_stimtime_2_FSL.txt',
             'AFNI1': 'example_stimtime_1_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],
                         TR=2, style='FSL')
    assert design1.shape == (34, 1), 'Returned design matrix has wrong shape'
    assert design1[24] == 0, (
        "gen_design should generated design matrix for each run separately "
        "and concatenate them.")
    design2 = gen_design(stimtime_files=[files['FSL1'], files['FSL2']],
                         scan_duration=[48, 20], TR=2, style='FSL')
    assert design2.shape == (34, 2), 'Returned design matrix has wrong shape'
    design3 = gen_design(stimtime_files=files['FSL1'], scan_duration=68, TR=2,
                         style='FSL')
    assert design3[24] != 0, (
        'design matrix should be non-zero 8 seconds after an event onset.')
    design4 = gen_design(stimtime_files=[files['FSL2']],
                         scan_duration=[48, 20], TR=2, style='FSL')
    assert np.all(np.isclose(design1 * 0.5, design4)), (
        'gen_design does not treat missing values correctly')
    design5 = gen_design(stimtime_files=[files['FSL2']],
                         scan_duration=[48, 20], TR=1)
    assert np.all(np.isclose(design4, design5[::2])), (
        'design matrices sampled at different frequency do not match'
        ' at corresponding time points')
    design6 = gen_design(stimtime_files=[files['AFNI1']],
                         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')
Exemplo n.º 3
0
np.random.seed(10)

# In[2]:

# read FSL style event files
dir_design = '/home/tselab/studies/vr1_data/code/BIDS/brainiak/design/'
path_designs = [dir_design + 'e' + str(i + 1) for i in range(8)]

# In[3]:

# generate the design matrix
TR_per_run = 189
nruns = 6
scan_duration = TR_per_run * nruns
tr = 2
design = utils.gen_design(path_designs, scan_duration * tr, tr)

# In[4]:

# visulization of design
fig = plt.figure(num=None, figsize=(30, 8), facecolor='w', edgecolor='k')
plt.plot(design)
plt.ylim([-.5, 3])
plt.title('hypothetic fMRI response time courses '
          'of all conditions for one subject\n'
          '(design matrix)')
plt.xlabel('time')
plt.show()

# In[5]: