def subject_filemap(sid, subject_path=None):
<EOL>if pimms.is_int(sid):<EOL><INDENT>if subject_path is None: sdir = find_subject_path(sid)<EOL>else: sdir = os.path.expanduser(os.path.join(subject_path, str(sid)))<EOL><DEDENT>elif pimms.is_str(sid):<EOL><INDENT>try: sid = os.path.expanduser(sid)<EOL>except Exception: pass<EOL>sdir = sid if os.path.isdir(sid) else find_subject_path(sid)<EOL>sid  = int(sdir.split(os.sep)[-<NUM_LIT:1>])<EOL><DEDENT>else: raise ValueError('<STR_LIT>' % sid)<EOL>if sdir is None:<EOL><INDENT>if _auto_download_options is not None and _auto_download_options['<STR_LIT>']and _auto_downloadable(sid):<EOL><INDENT>sdir = _auto_download_options['<STR_LIT>']<EOL>sdir = os.path.join(sdir, str(sid))<EOL>if not os.path.isdir(sdir): os.makedirs(os.path.abspath(sdir), <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>' % sid)<EOL><DEDENT><DEDENT>ff = {'<STR_LIT:id>':sid}<EOL>def _make_lambda(flnm, dat): return lambda:_load(flnm, dat)<EOL>dats = {}<EOL>fls = {}<EOL>for (k,v) in six.iteritems(subject_structure['<STR_LIT>']):<EOL><INDENT>flnm = os.path.join(sdir, k.format(ff))<EOL>dat  = pimms.merge(v, ff)<EOL>fls[flnm]  = _make_lambda(flnm, dat)<EOL>dats[flnm] = dat<EOL><DEDENT>fls = pimms.lazy_map(fls)<EOL>def _lookup_fl(flnm):<EOL><INDENT>def _f():<EOL><INDENT>obj = fls[flnm]<EOL>dat = dats[flnm]<EOL>if '<STR_LIT>' in dat and dat['<STR_LIT>']:<EOL><INDENT>(ldat,rdat) = _cifti_to_hemis(np.asarray(obj), sid)<EOL>obj = ldat if dat['<STR_LIT>'][<NUM_LIT:0>:<NUM_LIT:2>] == '<STR_LIT>' else rdat<EOL>obj.setflags(write=False)<EOL><DEDENT>return obj<EOL><DEDENT>return _f<EOL><DEDENT>hems = pyr.pmap(<EOL>{h: pyr.pmap(<EOL>{k: pimms.lazy_map({nm: _lookup_fl(fnm)<EOL>for (nm,fl) in six.iteritems(v)<EOL>for fnm in [os.path.join(sdir, fl.format(ff))]})<EOL>for (k,v) in six.iteritems(entries)})<EOL>for (h,entries) in six.iteritems(subject_structure['<STR_LIT>'])})<EOL>imgs = pimms.lazy_map({k: _lookup_fl(os.path.join(sdir, v.format(ff)))<EOL>for (k,v) in six.iteritems(subject_structure['<STR_LIT>'])})<EOL>for size in [<NUM_LIT:32>, <NUM_LIT>]:<EOL><INDENT>retsubs = _retinotopy_submap(size=size)<EOL>if retsubs is not None and sid in retsubs:<EOL><INDENT>def _make_loader(sz):<EOL><INDENT>rp = retinotopy_prefix if sz == <NUM_LIT> else lowres_retinotopy_prefix<EOL>ldr = pimms.lazy_map({<NUM_LIT:0>:lambda:_retinotopy_data('<STR_LIT>', sid, size=sz)})<EOL>return pyr.pmap(<EOL>{('<STR_LIT>' % sz):pimms.lazy_map(<EOL>{(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:0>],<EOL>(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:0>],<EOL>(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:0>],<EOL>(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:0>]}),<EOL>('<STR_LIT>' % sz):pimms.lazy_map(<EOL>{(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:1>],<EOL>(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:1>],<EOL>(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:1>],<EOL>(rp+'<STR_LIT>'):lambda:ldr[<NUM_LIT:0>]['<STR_LIT>'][<NUM_LIT:1>]})})<EOL><DEDENT>ret = _make_loader(size)<EOL>for h in six.iterkeys(ret):<EOL><INDENT>hdat = hems[h]<EOL>prop = pimms.merge(hdat['<STR_LIT>'], ret[h])<EOL>hems = hems.set(h, hdat.set('<STR_LIT>', prop))<EOL><DEDENT><DEDENT><DEDENT>return pyr.pmap({'<STR_LIT>': imgs, '<STR_LIT>': hems})<EOL>
subject_filemap(sid) yields a persistent lazy map structure that loads the relevant files as
  requested for the given subject. The sid may be a subject id or the path of a subject
  directory. If a subject id is given, then the subject is searched for in the known subject
  paths.

The optional argument subject_path may be set to a specific path to ensure that the subject
id is only searched for in the given path.