def test_fetch_openneuro_dataset_index(): dataset_version = 'ds000030_R1.0.4' data_prefix = '{}/{}/uncompressed'.format( dataset_version.split('_')[0], dataset_version) data_dir = _get_dataset_dir(data_prefix, data_dir=tst.tmpdir, verbose=1) url_file = os.path.join(data_dir, 'urls.json') # Prepare url files for subject and filter tests file_list = [ data_prefix + '/stuff.html', data_prefix + '/sub-xxx.html', data_prefix + '/sub-yyy.html', data_prefix + '/sub-xxx/ses-01_task-rest.txt', data_prefix + '/sub-xxx/ses-01_task-other.txt', data_prefix + '/sub-xxx/ses-02_task-rest.txt', data_prefix + '/sub-xxx/ses-02_task-other.txt', data_prefix + '/sub-yyy/ses-01.txt', data_prefix + '/sub-yyy/ses-02.txt' ] json.dump(file_list, open(url_file, 'w')) # Only 1 subject and not subject specific files get downloaded datadir, dl_files = datasets.fetch_openneuro_dataset_index( tst.tmpdir, dataset_version) assert_true(isinstance(datadir, _basestring)) assert_true(isinstance(dl_files, list)) assert_true(len(dl_files) == 9)
def _fetch_bids_data(): # pragma: no cover _, urls = nistats_datasets.fetch_openneuro_dataset_index() exclusion_patterns = [ '*group*', '*phenotype*', '*mriqc*', '*parameter_plots*', '*physio_plots*', '*space-fsaverage*', '*space-T1w*', '*dwi*', '*beh*', '*task-bart*', '*task-rest*', '*task-scap*', '*task-task*' ] urls = nistats_datasets.select_from_index( urls, exclusion_filters=exclusion_patterns, n_subjects=1) data_dir, _ = nistats_datasets.fetch_openneuro_dataset(urls=urls) return data_dir
def test_fetch_openneuro_dataset_index(): with TemporaryDirectory() as tmpdir: dataset_version = 'ds000030_R1.0.4' subdir_names = ['ds000030', 'ds000030_R1.0.4', 'uncompressed'] tmp_list = [] for subdir in subdir_names: tmp_list.append(subdir) subdirpath = os.path.join(tmpdir, *tmp_list) os.mkdir(subdirpath) filepath = os.path.join(subdirpath, 'urls.json') mock_json_content = ['junk1', 'junk2'] with open(filepath, 'w') as f: json.dump(mock_json_content, f) urls_path, urls = fetch_openneuro_dataset_index( data_dir=tmpdir, dataset_version=dataset_version, verbose=1, ) urls_path = urls_path.replace('/', os.sep) assert urls_path == filepath assert urls == mock_json_content
def download_dataset(cfg): """ Download a dataset from OpenNeuro using nistats functions. """ dataset_version = cfg['version'] _, urls = fetch_openneuro_dataset_index(dataset_version=dataset_version) # Just download based on subject for now. # Don't want to accidentally ignore anats or field maps. sub = 'sub-{0}'.format(cfg['subject']) urls = select_from_index(urls) temp_urls1 = [ url for url in urls if ('derivatives' not in url) and (sub in url) ] temp_urls2 = [ url for url in urls if ('derivatives' not in url) and ('sub-' not in url) ] urls = sorted(list(set(temp_urls1 + temp_urls2))) _, _ = fetch_openneuro_dataset(urls=urls, dataset_version=dataset_version, data_dir=op.abspath('../data/'))
.. contents:: **Contents** :local: :depth: 1 """ ############################################################################## # Fetch openneuro BIDS dataset # ----------------------------- # We download one subject from the stopsignal task in the ds000030 V4 BIDS # dataset available in openneuro. # This dataset contains the necessary information to run a statistical analysis # using Nistats. The dataset also contains statistical results from a previous # FSL analysis that we can employ for comparison with the Nistats estimation. from nistats.datasets import (fetch_openneuro_dataset_index, fetch_openneuro_dataset, select_from_index) _, urls = fetch_openneuro_dataset_index() exclusion_patterns = [ '*group*', '*phenotype*', '*mriqc*', '*parameter_plots*', '*physio_plots*', '*space-fsaverage*', '*space-T1w*', '*dwi*', '*beh*', '*task-bart*', '*task-rest*', '*task-scap*', '*task-task*' ] urls = select_from_index(urls, exclusion_filters=exclusion_patterns, n_subjects=1) data_dir, _ = fetch_openneuro_dataset(urls=urls) ############################################################################## # Obtain FirstLevelModel objects automatically and fit arguments # ---------------------------------------------------------------
.. contents:: **Contents** :local: :depth: 1 """ ############################################################################## # Fetch openneuro BIDS dataset # ----------------------------- # We download one subject from the stopsignal task in the ds000030 V4 BIDS # dataset available in openneuro. # This dataset contains the necessary information to run a statistical analysis # using Nistats. The dataset also contains statistical results from a previous # FSL analysis that we can employ for comparison with the Nistats estimation. from nistats.datasets import (fetch_openneuro_dataset_index, fetch_openneuro_dataset, select_from_index) _, urls = fetch_openneuro_dataset_index() exclusion_patterns = ['*group*', '*phenotype*', '*mriqc*', '*parameter_plots*', '*physio_plots*', '*space-fsaverage*', '*space-T1w*', '*dwi*', '*beh*', '*task-bart*', '*task-rest*', '*task-scap*', '*task-task*'] urls = select_from_index( urls, exclusion_filters=exclusion_patterns, n_subjects=1) data_dir, _ = fetch_openneuro_dataset(urls=urls) ############################################################################## # Obtain automatically FirstLevelModel objects and fit arguments # --------------------------------------------------------------- # From the dataset directory we obtain automatically FirstLevelModel objects