# Path: cogspaces/datasets/contrast.py
# def fetch_contrasts(studies: str or List[str] = 'all', data_dir=None):
#     dfs = []
#     if studies == 'all':
#         studies = nv_ids.keys()
#     for study in studies:
#         if study not in nv_ids:
#             return ValueError('Wrong dataset.')
#         data = fetch_neurovault_ids([nv_ids[study]], data_dir=data_dir, verbose=10,
#                                     mode='download_new')
#         dfs.append(_assemble(data['images'], data['images_meta'], study))
#     return pd.concat(dfs)
# 
# Path: cogspaces/datasets/derivative.py
# def fetch_reduced_loadings(data_dir=None, url=None, verbose=False,
#                            resume=True):
#     if url is None:
#         url = 'http://cogspaces.github.io/assets/data/loadings/'
# 
#     data_dir = get_data_dir(data_dir)
#     dataset_name = 'loadings'
#     data_dir = _get_dataset_dir(dataset_name, data_dir=data_dir,
#                                 verbose=verbose)
# 
#     keys = STUDY_LIST
# 
#     paths = ['data_%s.pt' % key for key in keys]
#     urls = [url + path for path in paths]
#     files = [(path, url, {}) for path, url in zip(paths, urls)]
# 
#     files = _fetch_files(data_dir, files, resume=resume,
#                          verbose=verbose)
# 
#     params = {key: file for key, file in zip(keys, files)}
# 
#     fdescr = (
#         "Z-statistic loadings over a dictionary of 453 components covering "
#         "grey-matter `modl_atlas['components_512_gm']` "
#         "for 35 different task fMRI studies.")
# 
#     params['description'] = fdescr
#     params['data_dir'] = data_dir
# 
#     return params
# 
# def fetch_atlas_modl(data_dir=None,
#                      url=None,
#                      resume=True, verbose=1):
#     """Download and load a multi-scale atlas computed using MODL over HCP900.
# 
#     Parameters
#     ----------
#     data_dir: string, optional
#         Path of the data directory. Used to force data storage in a non-
#         standard location. Default: None (meaning: default)
#     url: string, optional
#         Download URL of the dataset. Overwrite the default URL.
#     """
# 
#     if url is None:
#         url = 'http://cogspaces.github.io/assets/data/modl/'
# 
#     data_dir = get_data_dir(data_dir)
#     dataset_name = 'modl'
#     data_dir = _get_dataset_dir(dataset_name, data_dir=data_dir,
#                                 verbose=verbose)
# 
#     keys = ['components_64',
#             'components_128',
#             'components_453_gm',
#             'loadings_128_gm'
#             ]
# 
#     paths = [
#         'components_64.nii.gz',
#         'components_128.nii.gz',
#         'components_453_gm.nii.gz',
#         'loadings_128_gm.npy',
#     ]
#     urls = [url + path for path in paths]
#     files = [(path, url, {}) for path, url in zip(paths, urls)]
# 
#     files = _fetch_files(data_dir, files, resume=resume,
#                          verbose=verbose)
# 
#     params = {key: file for key, file in zip(keys, files)}
# 
#     fdescr = 'Components computed using the MODL package, at various scale,' \
#              'from HCP900 data'
# 
#     params['description'] = fdescr
#     params['data_dir'] = data_dir
# 
#     return Bunch(**params)
# 
# def fetch_mask(data_dir=None, url=None, resume=True, verbose=1):
#     if url is None:
#         url = 'http://cogspaces.github.io/assets/data/hcp_mask.nii.gz'
#     files = [('hcp_mask.nii.gz', url, {})]
# 
#     dataset_name = 'mask'
#     data_dir = get_data_dir(data_dir)
#     dataset_dir = _get_dataset_dir(dataset_name, data_dir=data_dir,
#                                    verbose=verbose)
#     files = _fetch_files(dataset_dir, files, resume=resume,
#                          verbose=verbose)
#     return files[0]
# 
# STUDY_LIST = ['knops2009recruitment', 'ds009', 'gauthier2010resonance',
#               'ds017B', 'ds110', 'vagharchakian2012temporal', 'ds001',
#               'devauchelle2009sentence', 'camcan', 'archi',
#               'henson2010faces', 'ds052', 'ds006A', 'ds109', 'ds108', 'la5c',
#               'gauthier2009resonance', 'ds011', 'ds107', 'ds116', 'ds101',
#               'ds002', 'ds003', 'ds051', 'ds008', 'pinel2009twins', 'ds017A',
#               'ds105', 'ds007', 'ds005', 'amalric2012mathematicians', 'ds114',
#               'brainomics', 'cauvet2009muslang', 'hcp']


import os
from cogspaces.datasets import fetch_atlas_modl, fetch_mask, \
    fetch_reduced_loadings, STUDY_LIST, fetch_contrasts



def test_atlas_modl():
    """Download the dataset in default directory and check success.

    """
    atlas = fetch_atlas_modl()
    keys = ['components_64',
            'components_128',
            'components_453_gm',
            ]

    assert all(os.path.exists(atlas[key]) for key in keys)


def test_fetch_mask():
    fetch_mask()


def test_reduced_loadings():

# Path: cogspaces/datasets/contrast.py
# def fetch_contrasts(studies: str or List[str] = 'all', data_dir=None):
#     dfs = []
#     if studies == 'all':
#         studies = nv_ids.keys()
#     for study in studies:
#         if study not in nv_ids:
#             return ValueError('Wrong dataset.')
#         data = fetch_neurovault_ids([nv_ids[study]], data_dir=data_dir, verbose=10,
#                                     mode='download_new')
#         dfs.append(_assemble(data['images'], data['images_meta'], study))
#     return pd.concat(dfs)
# 
# Path: cogspaces/datasets/derivative.py
# def fetch_reduced_loadings(data_dir=None, url=None, verbose=False,
#                            resume=True):
#     if url is None:
#         url = 'http://cogspaces.github.io/assets/data/loadings/'
# 
#     data_dir = get_data_dir(data_dir)
#     dataset_name = 'loadings'
#     data_dir = _get_dataset_dir(dataset_name, data_dir=data_dir,
#                                 verbose=verbose)
# 
#     keys = STUDY_LIST
# 
#     paths = ['data_%s.pt' % key for key in keys]
#     urls = [url + path for path in paths]
#     files = [(path, url, {}) for path, url in zip(paths, urls)]
# 
#     files = _fetch_files(data_dir, files, resume=resume,
#                          verbose=verbose)
# 
#     params = {key: file for key, file in zip(keys, files)}
# 
#     fdescr = (
#         "Z-statistic loadings over a dictionary of 453 components covering "
#         "grey-matter `modl_atlas['components_512_gm']` "
#         "for 35 different task fMRI studies.")
# 
#     params['description'] = fdescr
#     params['data_dir'] = data_dir
# 
#     return params
# 
# def fetch_atlas_modl(data_dir=None,
#                      url=None,
#                      resume=True, verbose=1):
#     """Download and load a multi-scale atlas computed using MODL over HCP900.
# 
#     Parameters
#     ----------
#     data_dir: string, optional
#         Path of the data directory. Used to force data storage in a non-
#         standard location. Default: None (meaning: default)
#     url: string, optional
#         Download URL of the dataset. Overwrite the default URL.
#     """
# 
#     if url is None:
#         url = 'http://cogspaces.github.io/assets/data/modl/'
# 
#     data_dir = get_data_dir(data_dir)
#     dataset_name = 'modl'
#     data_dir = _get_dataset_dir(dataset_name, data_dir=data_dir,
#                                 verbose=verbose)
# 
#     keys = ['components_64',
#             'components_128',
#             'components_453_gm',
#             'loadings_128_gm'
#             ]
# 
#     paths = [
#         'components_64.nii.gz',
#         'components_128.nii.gz',
#         'components_453_gm.nii.gz',
#         'loadings_128_gm.npy',
#     ]
#     urls = [url + path for path in paths]
#     files = [(path, url, {}) for path, url in zip(paths, urls)]
# 
#     files = _fetch_files(data_dir, files, resume=resume,
#                          verbose=verbose)
# 
#     params = {key: file for key, file in zip(keys, files)}
# 
#     fdescr = 'Components computed using the MODL package, at various scale,' \
#              'from HCP900 data'
# 
#     params['description'] = fdescr
#     params['data_dir'] = data_dir
# 
#     return Bunch(**params)
# 
# def fetch_mask(data_dir=None, url=None, resume=True, verbose=1):
#     if url is None:
#         url = 'http://cogspaces.github.io/assets/data/hcp_mask.nii.gz'
#     files = [('hcp_mask.nii.gz', url, {})]
# 
#     dataset_name = 'mask'
#     data_dir = get_data_dir(data_dir)
#     dataset_dir = _get_dataset_dir(dataset_name, data_dir=data_dir,
#                                    verbose=verbose)
#     files = _fetch_files(dataset_dir, files, resume=resume,
#                          verbose=verbose)
#     return files[0]
# 
# STUDY_LIST = ['knops2009recruitment', 'ds009', 'gauthier2010resonance',
#               'ds017B', 'ds110', 'vagharchakian2012temporal', 'ds001',
#               'devauchelle2009sentence', 'camcan', 'archi',
#               'henson2010faces', 'ds052', 'ds006A', 'ds109', 'ds108', 'la5c',
#               'gauthier2009resonance', 'ds011', 'ds107', 'ds116', 'ds101',
#               'ds002', 'ds003', 'ds051', 'ds008', 'pinel2009twins', 'ds017A',
#               'ds105', 'ds007', 'ds005', 'amalric2012mathematicians', 'ds114',
#               'brainomics', 'cauvet2009muslang', 'hcp']


# Path: cogspaces/tests/test_datasets.py
import os
from cogspaces.datasets import fetch_atlas_modl, fetch_mask, \
    fetch_reduced_loadings, STUDY_LIST, fetch_contrasts




def test_atlas_modl():
    """Download the dataset in default directory and check success.

    """
    atlas = fetch_atlas_modl()
    keys = ['components_64',
            'components_128',
            'components_453_gm',
            ]

    assert all(os.path.exists(atlas[key]) for key in keys)


def test_fetch_mask():
    fetch_mask()


def test_reduced_loadings():

    loadings = fetch_reduced_loadings()