def _get_fs_subjid(subject_id, subjects_dir=None): """ Gets fsaverage version `subject_id`, fetching if required Parameters ---------- subject_id : str FreeSurfer subject ID subjects_dir : str, optional Path to FreeSurfer subject directory. If not set, will inherit from the environmental variable $SUBJECTS_DIR. Default: None Returns ------- subject_id : str FreeSurfer subject ID subjects_dir : str Path to subject directory with `subject_id` """ from netneurotools.utils import check_fs_subjid # check for FreeSurfer install w/fsaverage; otherwise, fetch required try: subject_id, subjects_dir = check_fs_subjid(subject_id, subjects_dir) except FileNotFoundError: if 'fsaverage' not in subject_id: raise ValueError('Provided subject {} does not exist in provided ' 'subjects_dir {}'.format(subject_id, subjects_dir)) from netneurotools.datasets import fetch_fsaverage from netneurotools.datasets.utils import _get_data_dir fetch_fsaverage(subject_id) subjects_dir = os.path.join(_get_data_dir(), 'tpl-fsaverage') subject_id, subjects_dir = check_fs_subjid(subject_id, subjects_dir) return subject_id, subjects_dir
def test_get_data_dir(tmpdir): data_dir = utils._get_data_dir(tmpdir) assert os.path.isdir(data_dir)