Esempio n. 1
0
def process_subject(subdir, despike=False):
    _, sid = os.path.split(subdir)
    rawdir = os.path.join(subdir, "raw")
    workdir = utils.defaults["realign_ants"]
    if despike:
        workdir = utils.defaults["despike"] + workdir
    workdir, exists = utils.make_dir(subdir, workdir)

    if exists:
        raise IOError("{0}: skipping {1} exists".format(subdir, workdir))

    funcs = split(rawdir, workdir, sid, despike)
    aligned, move_arr = make_realign(funcs)

    ## Make aligned_4d
    aligned4d = os.path.join(workdir, "align4d_{0}.nii.gz".format(sid))
    aligned4d = utils.fsl_make4d(aligned, aligned4d)
    print "aligned_4d:", aligned4d
    plot_write_movement(workdir, sid, move_arr)
    utils.zip_files(funcs)
    utils.zip_files(aligned[1:])
    print "{0} : finished".format(sid)
Esempio n. 2
0
def process_subject(subdir, tr, logger, despike=False):
    """ process one subject despike (optional), realign and
    do slicetime correction via SPM tools"""
    globstr = 'B*func4d.nii*'
    workdirnme = utils.defaults['realign_spm']
    if despike:
        workdirnme = utils.defaults['despike'] + workdirnme
        globstr = 'ds' + globstr
    _, sid = os.path.split(subdir)
    rawdir = os.path.join(subdir, 'raw')

    workdir, exists = utils.make_dir(subdir, workdirnme)

    if exists:
        logger.error('{0}: skipping {1} exists'.format(subdir, workdir))
        return None

    funcs = split(rawdir, workdir, sid, logger, globstr)
    if funcs is None:
        logger.error('Raw dir missing data: {0}'.format(rawdir))
        return None

    staligned, move_arr = make_realignst(funcs, tr, logger)
    if staligned is None:
        return None

    ## Make aligned_4d
    aligned4d = os.path.join(workdir, 'align4d_{0}.nii.gz'.format(sid))
    aligned4d = utils.fsl_make4d(staligned, aligned4d)
    logger.info(aligned4d)
    ## spm only has 6 params, add empty 7th for plotting
    move_arr = np.hstack((move_arr,
                          np.zeros((move_arr.shape[0],1))))
    plot_write_movement(workdir, sid, move_arr, logger)
    ## zip files
    utils.zip_files(funcs)
    utils.zip_files(staligned)
    logger.info('{0} : finished'.format(sid))