Exemple #1
0
 def _load_subject(ppath, url, credentials, cache_directory, df, sid):
     '''
     Creates a pseudo-path for the given subject and loads that subject as an hcp subject then
     returns it.
     '''
     from neuropythy.hcp import subject
     from posixpath import join as urljoin
     pm    = ppath._path_data['pathmod']
     creds = ppath.credentials
     # Make the pseudo-path; if auto-downloading is set to false, we want to create a pseudo-path
     # from only the cache path
     if config['hcp_auto_download'] in [False, None]:
         ppath = pseudo_path(os.path.join(cache_directory, str(sid)), delete=False)
     else:
         ppath = pseudo_path((pm.s3fs, urljoin(url, str(sid))),
                             credentials=credentials,
                             cache_path=os.path.join(cache_directory, str(sid)),
                             delete=False) # the base dir will be deleted if needs be
     return subject(ppath, default_alignment=df, name=str(sid))
def calc_arguments(args):
    '''
    calc_arguments is a calculator that parses the command-line arguments for the registration
    command and produces the subject, the model, the log function, and the additional options.
    '''
    (args, opts) = _retinotopy_parser(args)
    # We do some of the options right here...
    if opts['help']:
        print(info, file=sys.stdout)
        sys.exit(1)
    # and if we are verbose, lets setup a note function
    verbose = opts['verbose']
    def note(s):
        if verbose:
            print(s, file=sys.stdout)
            sys.stdout.flush()
        return verbose
    def error(s):
        print(s, file=sys.stderr)
        sys.stderr.flush()
        sys.exit(1)
    if len(args) < 1: error('subject argument is required')
    try: # we try FreeSurfer first:
        import neuropythy.freesurfer as fs
        # Add the subjects directory, if there is one
        if 'subjects_dir' in opts and opts['subjects_dir'] is not None:
            fs.add_subject_path(opts['subjects_dir'])
        # Get the subject now
        sub = fs.subject(args[0])
    except Exception: sub = None
    if sub is None:
        try: # As an alternative, try HCP
            import neuropythy.hcp as hcp
            # Add the subjects directory, if there is one
            if 'subjects_dir' in opts and opts['subjects_dir'] is not None:
                hcp.add_subject_path(opts['subjects_dir'])
            sub = hcp.subject(args[0])
        except Exception: sub = None
    if sub is None: error('Failed to load subject %s' % args[0])
    # and the model
    if len(args) > 1:       mdl_name = args[1]
    elif opts['model_sym']: mdl_name = 'schira'
    else:                   mdl_name = 'benson17'
    try:
        if opts['model_sym']:
            model = {h:retinotopy_model(mdl_name).persist() for h in ['lh', 'rh']}
        else:
            model = {h:retinotopy_model(mdl_name, hemi=h).persist() for h in ['lh', 'rh']}
    except Exception: error('Could not load retinotopy model %s' % mdl_name)

    # Now, we want to run a few filters on the options
    # Parse the simple numbers
    for o in ['weight_min', 'scale', 'max_step_size', 'max_out_eccen',
              'max_in_eccen', 'min_in_eccen', 'field_sign_weight', 'radius_weight']:
        opts[o] = float(opts[o])
    opts['max_steps'] = int(opts['max_steps'])
    # Make a note:
    note('Processing subject: %s' % sub.name)
    del opts['help']
    del opts['verbose']
    del opts['subjects_dir']
    # That's all we need!
    return pimms.merge(opts,
                       {'subject': sub.persist(),
                        'model':   pyr.pmap(model),
                        'options': pyr.pmap(opts),
                        'note':    note,
                        'error':   error})