Exemple #1
0
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    N_SLICES = 40
    TR = 2.5
    # You need to work out slice times here
    subjects = get_subjects(DATA_PATH)
    for name, subject in subjects.items():
        for run in subject['functionals']:
            fname = run['filename']
            print("Running slice timing on " + fname)
            slice_time_file(fname, slice_times, TR)
Exemple #2
0
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    N_SLICES = 40
    TR = 2.5
    
    # Figure out slice times.
    slice_order = np.array(range(0, N_SLICES, 2) + range(1, N_SLICES, 2))
    space_to_order = np.argsort(slice_order)
    time_one_slice = TR / N_SLICES
    slice_times = space_to_order * time_one_slice + time_one_slice / 2.0
    
    subjects = get_subjects(DATA_PATH)
    for name, subject in subjects.items():
        for run in subject['functionals']:
            fname = run['filename']
            print("Running slice timing on " + fname)
            slice_time_file(fname, slice_times, TR, slice_axis=0)
def test_slice_time_file():
    # Test slice_time_file from slice_time_image
    n_slices = 5
    n_vols = 4
    TR = 2.0
    data = np.random.normal(size=(2, 3, n_slices, n_vols))
    img = nib.Nifti1Image(data, np.eye(4))
    slice_times = np.arange(n_slices) * TR / n_slices + 0.1
    tmpdir = tempfile.mkdtemp()
    try:
        fname = os.path.join(tmpdir, 'myfile.nii')
        a_fname = os.path.join(tmpdir, 'amyfile.nii')
        nib.save(img, fname)
        for order in ('linear', 'cubic', 1, 4):
            interped_img = slice_time_image(img, slice_times, TR, order)
            slice_time_file(fname, slice_times, TR, order)
            a_img = nib.load(a_fname)
            assert_almost_equal(interped_img.get_data(), a_img.get_data())
            del a_img
    finally:
        shutil.rmtree(tmpdir)
def test_slice_time_file():
    # Test slice_time_file from slice_time_image
    n_slices = 5
    n_vols = 4
    TR = 2.0
    data = np.random.normal(size=(2, 3, n_slices, n_vols))
    img = nib.Nifti1Image(data, np.eye(4))
    slice_times = np.arange(n_slices) * TR / n_slices + 0.1
    tmpdir = tempfile.mkdtemp()
    try:
        fname = os.path.join(tmpdir, 'myfile.nii')
        a_fname = os.path.join(tmpdir, 'amyfile.nii')
        nib.save(img, fname)
        for order in ('linear', 'cubic', 1, 4):
            interped_img = slice_time_image(img, slice_times, TR, order)
            slice_time_file(fname, slice_times, TR, order)
            a_img = nib.load(a_fname)
            assert_almost_equal(interped_img.get_data(), a_img.get_data())
            del a_img
    finally:
        shutil.rmtree(tmpdir)
Exemple #5
0
import numpy as np
import slicetime

fname = 'bold.nii.gz'

slice_order = np.array(range(0, 35, 2) + range(1, 35, 2))
TR = 3.0
n_slices = 35
time_one_slice = TR / n_slices
space_to_order = np.argsort(slice_order)
slice_times = space_to_order * time_one_slice + (time_one_slice / 2)

slicetime.slice_time_file(fname, slice_times, TR)