# Path: cogspaces/datasets/derivative.py
# 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]


import os
import numpy as np
from itertools import repeat
from os.path import join
from cogspaces.datasets import fetch_mask
from joblib import Parallel, delayed
from matplotlib.colors import LinearSegmentedColormap, rgb_to_hsv, hsv_to_rgb
from nilearn._utils import check_niimg
from nilearn.datasets import fetch_surf_fsaverage5
from nilearn.image import iter_img
from nilearn.input_data import NiftiMasker
    from nilearn.plotting import plot_stat_map, find_xyz_cut_coords, plot_glass_brain
    i = 0
    while True:
        yield '%s_%i' % (name, i)
        i += 1


def plot_4d_image(img, names=None, output_dir=None,
                  colors=None,
                  view_types=['stat_map'],
                  threshold=True,
                  n_jobs=1, verbose=10):
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    if colors is None:
        colors = repeat(None)

    if 'surf_stat_map_right' in view_types or 'surf_stat_map_left' in view_types:
        fetch_surf_fsaverage5()
    filename = img
    img = check_niimg(img, ensure_ndim=4)
    img.get_data()
    if names is None or isinstance(names, str):
        if names is None:
            dirname, filename = os.path.split(filename)
            names = filename.replace('.nii.gz', '')
        names = numbered_names(names)
    else:
        assert len(names) == img.get_shape()[3]


# Path: cogspaces/datasets/derivative.py
# 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]


# Path: cogspaces/plotting/volume.py
import os
import numpy as np
from itertools import repeat
from os.path import join
from cogspaces.datasets import fetch_mask
from joblib import Parallel, delayed
from matplotlib.colors import LinearSegmentedColormap, rgb_to_hsv, hsv_to_rgb
from nilearn._utils import check_niimg
from nilearn.datasets import fetch_surf_fsaverage5
from nilearn.image import iter_img
from nilearn.input_data import NiftiMasker
    from nilearn.plotting import plot_stat_map, find_xyz_cut_coords, plot_glass_brain

    i = 0
    while True:
        yield '%s_%i' % (name, i)
        i += 1


def plot_4d_image(img, names=None, output_dir=None,
                  colors=None,
                  view_types=['stat_map'],
                  threshold=True,
                  n_jobs=1, verbose=10):
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)

    if colors is None:
        colors = repeat(None)

    if 'surf_stat_map_right' in view_types or 'surf_stat_map_left' in view_types:
        fetch_surf_fsaverage5()
    filename = img
    img = check_niimg(img, ensure_ndim=4)
    img.get_data()
    if names is None or isinstance(names, str):
        if names is None:
            dirname, filename = os.path.split(filename)
            names = filename.replace('.nii.gz', '')
        names = numbered_names(names)
    else:
        assert len(names) == img.get_shape()[3]


    mask = fetch_mask()