# Path: cogspaces/datasets/derivative.py
# 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']
# 
# def add_study_contrast(ys):
#     for study in ys:
#         ys[study]['study_contrast'] = ys[study]['study'] + '__' + ys[study]['task'] + '__' + \
#                                       ys[study]['contrast']
#     return ys


from os.path import join
from typing import List
from joblib import load
from nilearn.datasets import fetch_neurovault_ids
from cogspaces.datasets.derivative import STUDY_LIST, add_study_contrast
import pandas as pd
        if study == 'brainpedia':
            this_study = meta['study']
            subject = meta['name'].split('_')[-1]
            contrast = '_'.join(meta['task'].split('_')[1:])
            task = meta['task'].split('_')[0]
        else:
            this_study = study
            subject = meta['name'].split('_')[0]
            contrast = meta['contrast_definition']
            task = meta['task']
        records.append([image, this_study, subject, task, contrast])
    df = pd.DataFrame(records, columns=['z_map', 'study', 'subject', 'task', 'contrast'])
    return df


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)


def load_masked_contrasts(data_dir):
    Xs, ys = {}, {}

# Path: cogspaces/datasets/derivative.py
# 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']
# 
# def add_study_contrast(ys):
#     for study in ys:
#         ys[study]['study_contrast'] = ys[study]['study'] + '__' + ys[study]['task'] + '__' + \
#                                       ys[study]['contrast']
#     return ys


# Path: cogspaces/datasets/contrast.py
from os.path import join
from typing import List
from joblib import load
from nilearn.datasets import fetch_neurovault_ids
from cogspaces.datasets.derivative import STUDY_LIST, add_study_contrast
import pandas as pd

        if study == 'brainpedia':
            this_study = meta['study']
            subject = meta['name'].split('_')[-1]
            contrast = '_'.join(meta['task'].split('_')[1:])
            task = meta['task'].split('_')[0]
        else:
            this_study = study
            subject = meta['name'].split('_')[0]
            contrast = meta['contrast_definition']
            task = meta['task']
        records.append([image, this_study, subject, task, contrast])
    df = pd.DataFrame(records, columns=['z_map', 'study', 'subject', 'task', 'contrast'])
    return df


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)


def load_masked_contrasts(data_dir):
    Xs, ys = {}, {}

    for study in STUDY_LIST: