def test_fetch_openneuro_dataset(): 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 urls = [ 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(urls, open(url_file, 'w')) # Only 1 subject and not subject specific files get downloaded datadir, dl_files = datasets.fetch_openneuro_dataset( urls, 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 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/'))
# 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 # --------------------------------------------------------------- # From the dataset directory we automatically obtain FirstLevelModel objects # with their subject_id filled from the BIDS dataset. Moreover we obtain, # for each model, the list of run images and their respective events and # confound regressors. Those are inferred from the confounds.tsv files # available in the BIDS dataset. # To get the first level models we have to specify the dataset directory, # the task_label and the space_label as specified in the file names. # We also have to provide the folder with the desired derivatives, that in this # case were produced by the fmriprep BIDS app. from nistats.first_level_model import first_level_models_from_bids task_label = 'stopsignal'
# 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 # with their subject_id filled from the BIDS dataset. Moreover we obtain # for each model the list of run imgs and their respective events and # confounder regressors. Confounders are inferred from the confounds.tsv files # available in the BIDS dataset. # To get the first level models we have to specify the dataset directory, # the task_label and the space_label as specified in the file names. # We also have to provide the folder with the desired derivatives, that in this # case were produced by the fmriprep BIDS app. from nistats.first_level_model import first_level_models_from_bids task_label = 'stopsignal'