Example #1
0
def get_raw(subdir, globstr, logger):
    files, nfiles = utils.get_files(subdir, globstr)
    logger.info('SUBID: {0}, nfiles: {1}'.format(subdir, nfiles))
    if not nfiles == 1:
        logger.error('Raw functional not found: {0}'.format(globstr))
        return None
    return files[0]
Example #2
0
def run_despike(datadir, globstr, taskid):
    gstr = os.path.join(datadir, 'B*')
    subjects = sorted(glob(gstr))
    subdir = subjects[taskid]
    _, sid = os.path.split(subdir)
    rawdir, exists = utils.make_dir(subdir, 'raw')
    if not exists:
        return None
    files, nfiles = utils.get_files(rawdir, 'ds*func*nii*')
    if nfiles > 0:
        print files, 'exists skipping'
        return None
    logger = logging.getLogger('despike')
    logger.setLevel(logging.DEBUG)
    ts = reg.timestr()
    fname = os.path.split(__file__)[-1].replace('.py', '')
    logfile = os.path.join(rawdir,
                           '{0}_{1}_{2}.log'.format(sid, fname, ts))
    fh = logging.FileHandler(logfile)
    fh.setLevel(logging.DEBUG)
    logger.addHandler(fh)
    logger.info(ts)
    logger.info(__file__)
    logger.info(os.getenv('USER'))
    in4d = get_raw(rawdir, globstr, logger)
    if in4d is None:
        logger.error('in4d is None')
        return
    returncode, result = utils.afni_despike(in4d)
    if returncode == 0:
        logger.info('Despike finished')
        logger.info(result.outputs.out_file)
        return
    logger.error(result.runtime.stderr)
def get_file(workdir, type_glob, logger=None):
    files, nfiles = utils.get_files(workdir, type_glob)
    ## type_glob eg 'align4d_{0}.nii.gz'.format(sid) from utils.defaults)
    if logger:
        logger.info(' glob ({0}) yields nfiles: {1}'.format(type_glob, nfiles))
    if nfiles == 1:
        return files[0]
    raise IOError('{0} in {1} not found'.format(type_glob, workdir))
def split(rawdir, destdir, sid, logger, globstr='B*func4d.nii*'):
    """ split files into 3D vols,
    return is None if it fails"""
    files, nfiles = utils.get_files(rawdir, globstr)
    logger.info('SUBID: {0}, nfiles: {1}'.format(sid, nfiles))
    if not nfiles == 1:
        logger.error('Raw functional not found: {0}'.format(globstr))
        return None
    rawfunc = files[0]
    funcs =  utils.fsl_split4d(rawfunc, destdir, sid)
    return funcs
Example #5
0
def split(rawdir, destdir, sid, despike=False):
    globstr = "B*func4d.nii*"
    if despike:
        globstr = "ds" + globstr

    files, nfiles = utils.get_files(rawdir, globstr)
    if not nfiles == 1:
        raise IOError("raw functional not found unexpected {0}".format(globstr))
    rawfunc = files[0]
    funcs = utils.fsl_split4d(rawfunc, destdir, sid)
    if funcs is None:
        raise IOError("splitting {0} failed".format(rawfunc))
    return funcs