# Path: ephypype/import_data.py
# def write_hdf5(filename, data, dataset_name='dataset', dtype='f'):
#     """
#     Create hdf5 file
# 
#     Inputs
#         filename : str
#             hdf5 filename
#         data : array, shape (n_vertices, n_times)
#             raw data for whose the dataset is created
#         dataset_name : str
#             name of dataset to create
#         dtype : str
#             data type for new dataset
# 
#     """
# 
#     hf = h5py.File(filename, 'w')
#     hf.create_dataset(dataset_name, data=data, dtype=dtype)
#     hf.close()
# 
# Path: ephypype/source_space.py
# def _create_MNI_label_files(fwd, labels_cortex, labels_aseg, sbj,
#                             subjects_dir):
#     """Create MNI label files."""
#     print(('*** n labels cortex: {} ***'.format(len(labels_cortex))))
#     if labels_aseg:
#         print(('*** n labels aseg: {} ***'.format(len(labels_aseg))))
#     else:
#         print('*** no deep regions ***')
#     label_names_file = op.abspath('label_names.txt')
#     label_coords_file = op.abspath('label_coords.txt')
#     label_centroid_file = op.abspath('label_centroid.txt')
# 
#     label_names = list()
#     label_centroids = list()
# 
#     vertno_left = fwd['src'][0]['vertno']
#     vertno_right = fwd['src'][1]['vertno']
# 
#     roi_cortex = convert_cortex_mri_to_mni(labels_cortex, vertno_left,
#                                            vertno_right, sbj, subjects_dir)
#     roi_cortex_name = roi_cortex['ROI_name']
#     roi_cortex_mni_coords = roi_cortex['ROI_MNI_coords']
#     roi_cortex_color = roi_cortex['ROI_color']
# 
#     if labels_aseg:
#         roi_aseg = convert_aseg_head_to_mni(labels_aseg, fwd['mri_head_t'],
#                                             sbj, subjects_dir)
#         roi_aseg_mni_coords = roi_aseg['ROI_aseg_MNI_coords']
#         roi_aseg_name = roi_aseg['ROI_aseg_name']
#         roi_aseg_color = roi_aseg['ROI_aseg_color']
#     else:
#         roi_aseg_name = []
#         roi_aseg_mni_coords = []
#         roi_aseg_color = []
# 
#     # ROI names
#     roi_names = roi_cortex_name + roi_aseg_name
#     for name in roi_names:
#         label_names.append(name)
#     np.savetxt(label_names_file, np.array(label_names, dtype=str),
#                fmt="%s")
# 
#     # ROI centroids
#     roi_coords = roi_cortex_mni_coords + roi_aseg_mni_coords
#     for coo in roi_coords:
#         label_centroids.append(np.mean(coo, axis=0))
#     np.savetxt(label_centroid_file, np.array(label_centroids, dtype=float),
#                fmt="%f %f %f")
# 
#     # ROI MNI coords
#     label_coo_mni_matrix = np.vstack(roi_coords)
#     np.savetxt(label_coords_file, np.array(label_coo_mni_matrix, dtype=float),
#                fmt="%f %f %f")
# 
#     roi_colors = roi_cortex_color + roi_aseg_color
# 
#     roi = dict(ROI_names=roi_names, ROI_coords=roi_coords,
#                ROI_colors=roi_colors)
# 
#     print(('*** written {} labels in a pickle ***'.format(len(roi_names))))
#     labels_file = op.abspath('labels.pkl')
#     with open(labels_file, "wb") as f:
#         pickle.dump(roi, f)
# 
#     return labels_file, label_names_file, label_coords_file


import mne
import numpy as np
import os.path as op
from mne import get_volume_labels_from_src
from .import_data import write_hdf5
from .source_space import _create_MNI_label_files

    # allow_empty : bool -> Instead of emitting an error, return all-zero time
    # courses for labels that do not have any vertices in the source estimate

    if is_fixed:
        mode = 'mean_flip'
    else:
        mode = 'mean'

    label_ts = mne.extract_label_time_course(stc, labels_cortex, src,
                                             mode=mode,
                                             allow_empty=True,
                                             return_generator=False)

    # save results in .npy file that will be the input for spectral node
    print('\n*** SAVE ROI TS ***\n')
    print((len(label_ts)))

    if aseg:
        print(sbj_id)
        labels_aseg = get_volume_labels_from_src(src, sbj_id, subjects_dir)
        labels = labels_cortex + labels_aseg
    else:
        labels = labels_cortex
        labels_aseg = None

    print((labels[0].pos))
    print((len(labels)))

    labels_file, label_names_file, label_coords_file = \

# Path: ephypype/import_data.py
# def write_hdf5(filename, data, dataset_name='dataset', dtype='f'):
#     """
#     Create hdf5 file
# 
#     Inputs
#         filename : str
#             hdf5 filename
#         data : array, shape (n_vertices, n_times)
#             raw data for whose the dataset is created
#         dataset_name : str
#             name of dataset to create
#         dtype : str
#             data type for new dataset
# 
#     """
# 
#     hf = h5py.File(filename, 'w')
#     hf.create_dataset(dataset_name, data=data, dtype=dtype)
#     hf.close()
# 
# Path: ephypype/source_space.py
# def _create_MNI_label_files(fwd, labels_cortex, labels_aseg, sbj,
#                             subjects_dir):
#     """Create MNI label files."""
#     print(('*** n labels cortex: {} ***'.format(len(labels_cortex))))
#     if labels_aseg:
#         print(('*** n labels aseg: {} ***'.format(len(labels_aseg))))
#     else:
#         print('*** no deep regions ***')
#     label_names_file = op.abspath('label_names.txt')
#     label_coords_file = op.abspath('label_coords.txt')
#     label_centroid_file = op.abspath('label_centroid.txt')
# 
#     label_names = list()
#     label_centroids = list()
# 
#     vertno_left = fwd['src'][0]['vertno']
#     vertno_right = fwd['src'][1]['vertno']
# 
#     roi_cortex = convert_cortex_mri_to_mni(labels_cortex, vertno_left,
#                                            vertno_right, sbj, subjects_dir)
#     roi_cortex_name = roi_cortex['ROI_name']
#     roi_cortex_mni_coords = roi_cortex['ROI_MNI_coords']
#     roi_cortex_color = roi_cortex['ROI_color']
# 
#     if labels_aseg:
#         roi_aseg = convert_aseg_head_to_mni(labels_aseg, fwd['mri_head_t'],
#                                             sbj, subjects_dir)
#         roi_aseg_mni_coords = roi_aseg['ROI_aseg_MNI_coords']
#         roi_aseg_name = roi_aseg['ROI_aseg_name']
#         roi_aseg_color = roi_aseg['ROI_aseg_color']
#     else:
#         roi_aseg_name = []
#         roi_aseg_mni_coords = []
#         roi_aseg_color = []
# 
#     # ROI names
#     roi_names = roi_cortex_name + roi_aseg_name
#     for name in roi_names:
#         label_names.append(name)
#     np.savetxt(label_names_file, np.array(label_names, dtype=str),
#                fmt="%s")
# 
#     # ROI centroids
#     roi_coords = roi_cortex_mni_coords + roi_aseg_mni_coords
#     for coo in roi_coords:
#         label_centroids.append(np.mean(coo, axis=0))
#     np.savetxt(label_centroid_file, np.array(label_centroids, dtype=float),
#                fmt="%f %f %f")
# 
#     # ROI MNI coords
#     label_coo_mni_matrix = np.vstack(roi_coords)
#     np.savetxt(label_coords_file, np.array(label_coo_mni_matrix, dtype=float),
#                fmt="%f %f %f")
# 
#     roi_colors = roi_cortex_color + roi_aseg_color
# 
#     roi = dict(ROI_names=roi_names, ROI_coords=roi_coords,
#                ROI_colors=roi_colors)
# 
#     print(('*** written {} labels in a pickle ***'.format(len(roi_names))))
#     labels_file = op.abspath('labels.pkl')
#     with open(labels_file, "wb") as f:
#         pickle.dump(roi, f)
# 
#     return labels_file, label_names_file, label_coords_file


# Path: ephypype/source_estimate.py
import mne
import numpy as np
import os.path as op
from mne import get_volume_labels_from_src
from .import_data import write_hdf5
from .source_space import _create_MNI_label_files


    # allow_empty : bool -> Instead of emitting an error, return all-zero time
    # courses for labels that do not have any vertices in the source estimate

    if is_fixed:
        mode = 'mean_flip'
    else:
        mode = 'mean'

    label_ts = mne.extract_label_time_course(stc, labels_cortex, src,
                                             mode=mode,
                                             allow_empty=True,
                                             return_generator=False)

    # save results in .npy file that will be the input for spectral node
    print('\n*** SAVE ROI TS ***\n')
    print((len(label_ts)))

    if aseg:
        print(sbj_id)
        labels_aseg = get_volume_labels_from_src(src, sbj_id, subjects_dir)
        labels = labels_cortex + labels_aseg
    else:
        labels = labels_cortex
        labels_aseg = None

    print((labels[0].pos))
    print((len(labels)))

    labels_file, label_names_file, label_coords_file = \

        _create_MNI_label_files(forward, labels_cortex, labels_aseg,