示例#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
    SLICE_AXIS=0

    # 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
    # This time, don't add half a slice - nifti won't accept it.
    slice_times = space_to_order * time_one_slice

    subjects = get_subjects(DATA_PATH)
    for name, subject in subjects.items():
        for run in subject['functionals']:
            fname = run['filename']
            print("Fixing functional " + fname)
            fixnifti.fixup_nifti_file(fname, 'f', TR, SLICE_AXIS, slice_times)
        for anat_fname in subject['anatomicals']:
            print("Fixing anatomical " + anat_fname)
            fixnifti.fixup_nifti_file(anat_fname)
示例#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
    SLICE_AXIS = 0

    # 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
    # This time, don't add half a slice - nifti won't accept it.
    slice_times = space_to_order * time_one_slice

    subjects = get_subjects(DATA_PATH)
    for name, subject in subjects.items():
        for run in subject['functionals']:
            fname = run['filename']
            print("Fixing functional " + fname)
            fixnifti.fixup_nifti_file(fname, 'f', TR, SLICE_AXIS,
                                      slice_times)  # changed filename to fname
        for anat_fname in subject['anatomicals']:
            print("Fixing anatomical " + anat_fname)
            fixnifti.fixup_nifti_file(anat_fname)
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    TR = 2.5
    subjects = get_subjects(DATA_PATH)
    for name, subject in subjects.items():
        run_fnames = []
        for run in subject['functionals']:
            run_fnames.append(run['filename'])
        print("Realigning subject " + name)
        time_space_realign(run_fnames, TR, 'ascending', slice_axis=0)
示例#4
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)
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    for name, subject in get_subjects(DATA_PATH).items():
        for run in subject['functionals']:
            fname = run['filename']
            print("Diagnosing functional " + fname)
            img = nipy.load_image(fname)
            res = screens.screen(img, slice_axis=0)
            pth, fname = os.path.split(fname)
            froot, ext = os.path.splitext(fname)
            if ext in ('.gz', '.bz2'): # discard compressed exts
                froot, ext = os.path.splitext(froot)
            screens.write_screen_res(res, pth, froot)
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    subjects = get_subjects(DATA_PATH)
    for name in sorted(subjects):
        subject = subjects[name]
        print("Smoothing subject " + name)
        for run in subject['functionals']:
            fname = run['filename']
            pth, fpart = os.path.split(fname)
            ra_fname = os.path.join(pth, 'ra' + fpart)
            sra_fname = os.path.join(pth, 'sra' + fpart)
            img = load_image(ra_fname)
            save_image(smooth_image(img, 8.), sra_fname)
示例#7
0
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    subjects = get_subjects(DATA_PATH)
    for name in sorted(subjects):
        subject = subjects[name]
        print("Smoothing subject " + name)
        for run in subject['functionals']:
            fname = run['filename']
            pth, fpart = os.path.split(fname)
            ra_fname = os.path.join(pth, 'ra' + fpart)
            sra_fname = os.path.join(pth, 'sra' + fpart)
            img = load_image(ra_fname)
            save_image(smooth_image(img, 8.), sra_fname)
示例#8
0
def main():
    try:
        DATA_PATH = sys.argv[1]
    except IndexError:
        raise RuntimeError("Pass data path on command line")
    for name, subject in get_subjects(DATA_PATH).items():
        for run in subject['functionals']:
            fname = run['filename']
            print("Diagnosing functional " + fname)
            img = nipy.load_image(fname)
            res = screens.screen(img, slice_axis=0)
            pth, fname = os.path.split(fname)
            froot, ext = os.path.splitext(fname)
            if ext in ('.gz', '.bz2'):  # discard compressed exts
                froot, ext = os.path.splitext(froot)
            screens.write_screen_res(res, pth, froot)
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
    space_to_time = list(range(0, N_SLICES, 2)) + list(range(1, N_SLICES, 2))
    time_to_space = np.argsort(space_to_time)
    subjects = get_subjects(DATA_PATH)
    for name, subject in subjects.items():
        run_fnames = []
        for run in subject['functionals']:
            run_fnames.append(run['filename'])
        print("Realigning subject " + name)
        time_space_realign(run_fnames, TR, time_to_space, slice_axis=0)
示例#10
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)
示例#11
0
def test_big_picture():
    subjects = get_subjects(FILEROOT)
    assert_equal(len(subjects), 6)
    assert_equal(sorted(subjects.keys()), SUBJ_NAMES)
    for name, subject in subjects.items():
        assert_equal(len(subject['anatomicals']), 1)
        assert_equal(subject['tasks'], [1])
        if name == 'sub005':
            assert_equal(len(subject['functionals']), 11)
        else:
            assert_equal(len(subject['functionals']), 12)
        for i, rundef in enumerate(subject['functionals']):
            assert_true(rundef['filename'].endswith('bold.nii.gz'))
            assert_equal(rundef['task_no'], 1)
            assert_equal(rundef['run_no'], i+1)
            assert_true('task001_run%03d' % (i + 1,) in rundef['filename'])
            img = nib.load(rundef['filename'])
            assert_equal(img.shape, (40, 64, 64, 121))
            hdr = img.get_header()
            assert_almost_equal(hdr['pixdim'][1:4], (3.5, 3.75, 3.75))
示例#12
0
def main():
    hash_dict = {}
    subjects = get_subjects(sys.argv[1])
    for name, subject in subjects.items():
        for run in subject['functionals']:
            check_store_hash(run['filename'], hash_dict)
示例#13
0
import os

import nipy
from nipy.algorithms.diagnostics import screens
from openfmri import get_subjects

for name, subject in get_subjects('ds105').items():
    for run in subject['functionals']:
        fname = run['filename']
        img = nipy.load_image(fname)
        res = screens.screen(img, slice_axis=0)
        pth, fname = os.path.split(fname)
        froot, ext = os.path.splitext(fname)
        screens.write_screen_res(res, pth, froot)
示例#14
0
import os

import nipy
from nipy.algorithms.diagnostics import screens
from openfmri import get_subjects

for name, subject in get_subjects("ds105").items():
    for run in subject["functionals"]:
        fname = run["filename"]
        img = nipy.load_image(fname)
        res = screens.screen(img, slice_axis=0)
        pth, fname = os.path.split(fname)
        froot, ext = os.path.splitext(fname)
        screens.write_screen_res(res, pth, froot)
示例#15
0
def main():
    hash_dict = {}
    subjects = get_subjects(sys.argv[1])
    for name, subject in subjects.items():
        for run in subject['functionals']:
            check_store_hash(run['filename'], hash_dict)