# Path: ephypype/preproc.py
# def _create_reject_dict(raw_info, data_type='meg'):
#     """Create reject dir."""
#     picks_eog, picks_eeg, picks_grad, picks_mag = [], [], [], []
#     picks_eog = pick_types(raw_info, meg=False, ref_meg=False, eog=True)
# 
#     if data_type == 'meg':
#         picks_mag = pick_types(raw_info, meg='mag', ref_meg=False)
#         picks_grad = pick_types(raw_info, meg='grad', ref_meg=False)
#     elif data_type == 'eeg':
#         picks_eeg = pick_types(raw_info, eeg=True)
# 
#     reject = dict()
#     if len(picks_mag) > 0:
#         reject['mag'] = 4e-12
#     if len(picks_grad) > 0:
#         reject['grad'] = 4000e-13
#     if len(picks_eog) > 0:
#         reject['eog'] = 250e-6
#     if len(picks_eeg) > 0:
#         reject['eeg'] = 150e-6
#     print(reject)
#     return reject
# 
# Path: ephypype/source_estimate.py
# def _process_stc(stc, basename, sbj_id, subjects_dir, parc, forward,
#                  aseg, is_fixed, all_src_space=False, ROIs_mean=True):
#     if not isinstance(stc, list):
#         print('***')
#         print(('stc dim ' + str(stc.shape)))
#         print('***')
# 
#         stc = [stc]
#     else:
#         print('***')
#         print(('len stc %d' % len(stc)))
#         print('***')
# 
#     print('**************************************************************')
#     print('all_src_space: {}'.format(all_src_space))
#     print('ROIs_mean: {}'.format(ROIs_mean))
#     print('**************************************************************')
#     if all_src_space:
#         stc_data = list()
#         stc_file = op.abspath(basename + '_stc.hdf5')
# 
#         for i in range(len(stc)):
#             stc_data.append(stc[i].data)
# 
#         write_hdf5(stc_file, stc_data, dataset_name='stc_data')
# 
#     if ROIs_mean:
#         label_ts, labels_file, label_names_file, label_coords_file = \
#             _compute_mean_ROIs(stc, sbj_id, subjects_dir, parc,
#                                forward, aseg, is_fixed)
# 
#         ts_file = op.abspath(basename + '_ROI_ts.npy')
#         np.save(ts_file, label_ts)
# 
#     else:
#         ts_file = stc_file
#         labels_file = ''
#         label_names_file = ''
#         label_coords_file = ''
# 
#     return ts_file, labels_file, label_names_file, label_coords_file


import mne
import glob
import os.path as op
import numpy as np
from mne.io import read_raw_fif, read_raw_ctf
from mne import read_epochs
from mne.evoked import write_evokeds, read_evokeds
from mne.minimum_norm import make_inverse_operator, apply_inverse_raw
from mne.minimum_norm import apply_inverse_epochs, apply_inverse
from mne.beamformer import apply_lcmv_raw, make_lcmv
from mne import compute_raw_covariance, pick_types, write_cov
from nipype.utils.filemanip import split_filename as split_f
from .preproc import _create_reject_dict
from .source_estimate import _process_stc
        if events_id != condition and condition:
            events_name = condition
        else:
            events_name = events_id

        stc = list()
        for evo, cond_name in zip(evokeds, events_name):
            print(evo.comment, cond_name)
            stc_evo = apply_inverse(evo, inverse_operator, lambda2,
                                    inv_method, pick_ori=pick_ori)
            print(('\n*** STC for event %s ***\n' % cond_name))
            print('***')
            print(('stc dim ' + str(stc_evo.shape)))
            print('***')

            stc_evo_file = op.join(subj_path, basename + '-%s' % cond_name)
            print(stc_evo_file)
            stc_evo.save(stc_evo_file)

            stc.append(stc_evo)
            stc_files.append(stc_evo_file)
    else:
        stc = apply_inverse_raw(raw, inverse_operator, lambda2, inv_method,
                                label=None,
                                start=None, stop=None,
                                buffer_size=1000,
                                pick_ori=pick_ori)  # None 'normal'


    ts_file, labels_file, label_names_file, label_coords_file = \

# Path: ephypype/preproc.py
# def _create_reject_dict(raw_info, data_type='meg'):
#     """Create reject dir."""
#     picks_eog, picks_eeg, picks_grad, picks_mag = [], [], [], []
#     picks_eog = pick_types(raw_info, meg=False, ref_meg=False, eog=True)
# 
#     if data_type == 'meg':
#         picks_mag = pick_types(raw_info, meg='mag', ref_meg=False)
#         picks_grad = pick_types(raw_info, meg='grad', ref_meg=False)
#     elif data_type == 'eeg':
#         picks_eeg = pick_types(raw_info, eeg=True)
# 
#     reject = dict()
#     if len(picks_mag) > 0:
#         reject['mag'] = 4e-12
#     if len(picks_grad) > 0:
#         reject['grad'] = 4000e-13
#     if len(picks_eog) > 0:
#         reject['eog'] = 250e-6
#     if len(picks_eeg) > 0:
#         reject['eeg'] = 150e-6
#     print(reject)
#     return reject
# 
# Path: ephypype/source_estimate.py
# def _process_stc(stc, basename, sbj_id, subjects_dir, parc, forward,
#                  aseg, is_fixed, all_src_space=False, ROIs_mean=True):
#     if not isinstance(stc, list):
#         print('***')
#         print(('stc dim ' + str(stc.shape)))
#         print('***')
# 
#         stc = [stc]
#     else:
#         print('***')
#         print(('len stc %d' % len(stc)))
#         print('***')
# 
#     print('**************************************************************')
#     print('all_src_space: {}'.format(all_src_space))
#     print('ROIs_mean: {}'.format(ROIs_mean))
#     print('**************************************************************')
#     if all_src_space:
#         stc_data = list()
#         stc_file = op.abspath(basename + '_stc.hdf5')
# 
#         for i in range(len(stc)):
#             stc_data.append(stc[i].data)
# 
#         write_hdf5(stc_file, stc_data, dataset_name='stc_data')
# 
#     if ROIs_mean:
#         label_ts, labels_file, label_names_file, label_coords_file = \
#             _compute_mean_ROIs(stc, sbj_id, subjects_dir, parc,
#                                forward, aseg, is_fixed)
# 
#         ts_file = op.abspath(basename + '_ROI_ts.npy')
#         np.save(ts_file, label_ts)
# 
#     else:
#         ts_file = stc_file
#         labels_file = ''
#         label_names_file = ''
#         label_coords_file = ''
# 
#     return ts_file, labels_file, label_names_file, label_coords_file


# Path: ephypype/compute_inv_problem.py
import mne
import glob
import os.path as op
import numpy as np
from mne.io import read_raw_fif, read_raw_ctf
from mne import read_epochs
from mne.evoked import write_evokeds, read_evokeds
from mne.minimum_norm import make_inverse_operator, apply_inverse_raw
from mne.minimum_norm import apply_inverse_epochs, apply_inverse
from mne.beamformer import apply_lcmv_raw, make_lcmv
from mne import compute_raw_covariance, pick_types, write_cov
from nipype.utils.filemanip import split_filename as split_f
from .preproc import _create_reject_dict
from .source_estimate import _process_stc

        if events_id != condition and condition:
            events_name = condition
        else:
            events_name = events_id

        stc = list()
        for evo, cond_name in zip(evokeds, events_name):
            print(evo.comment, cond_name)
            stc_evo = apply_inverse(evo, inverse_operator, lambda2,
                                    inv_method, pick_ori=pick_ori)
            print(('\n*** STC for event %s ***\n' % cond_name))
            print('***')
            print(('stc dim ' + str(stc_evo.shape)))
            print('***')

            stc_evo_file = op.join(subj_path, basename + '-%s' % cond_name)
            print(stc_evo_file)
            stc_evo.save(stc_evo_file)

            stc.append(stc_evo)
            stc_files.append(stc_evo_file)
    else:
        stc = apply_inverse_raw(raw, inverse_operator, lambda2, inv_method,
                                label=None,
                                start=None, stop=None,
                                buffer_size=1000,
                                pick_ori=pick_ori)  # None 'normal'


    ts_file, labels_file, label_names_file, label_coords_file = \

        _process_stc(stc, basename, sbj_id, subjects_dir, parc, forward,