Python mne.set_log_level() Examples

The following are 5 code examples of mne.set_log_level(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mne , or try the search function .
Example #1
Source File: utils.py    From autoreject with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def interpolate_bads(inst, picks, dots=None, reset_bads=True, mode='accurate'):
    """Interpolate bad MEG and EEG channels."""
    import mne
    # to prevent cobyla printf error
    # XXX putting to critical for now unless better solution
    # emerges
    verbose = mne.set_log_level('CRITICAL', return_old_level=True)

    eeg_picks = set(pick_types(inst.info, meg=False, eeg=True, exclude=[]))
    eeg_picks_interp = [p for p in picks if p in eeg_picks]
    if len(eeg_picks_interp) > 0:
        _interpolate_bads_eeg(inst, picks=eeg_picks_interp)

    meg_picks = set(pick_types(inst.info, meg=True, eeg=False, exclude=[]))
    meg_picks_interp = [p for p in picks if p in meg_picks]
    if len(meg_picks_interp) > 0:
        _interpolate_bads_meg_fast(inst, picks=meg_picks_interp,
                                   dots=dots, mode=mode)

    if reset_bads is True:
        inst.info['bads'] = []

    mne.set_log_level(verbose)

    return inst 
Example #2
Source File: utils.py    From autoreject with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _fast_map_meg_channels(info, pick_from, pick_to,
                           dots=None, mode='fast'):
    from mne.io.pick import pick_info
    from mne.forward._field_interpolation import _setup_dots
    from mne.forward._field_interpolation import _compute_mapping_matrix
    from mne.forward._make_forward import _create_meg_coils, _read_coil_defs
    from mne.bem import _check_origin

    miss = 1e-4  # Smoothing criterion for MEG

    # XXX: hack to silence _compute_mapping_matrix
    verbose = mne.get_config('MNE_LOGGING_LEVEL', 'INFO')
    mne.set_log_level('WARNING')

    info_from = pick_info(info, pick_from, copy=True)
    templates = _read_coil_defs()
    coils_from = _create_meg_coils(info_from['chs'], 'normal',
                                   info_from['dev_head_t'], templates)
    my_origin = _check_origin((0., 0., 0.04), info_from)
    int_rad, noise, lut_fun, n_fact = _setup_dots(mode, coils_from, 'meg')

    # This function needs a clean input. It hates the presence of other
    # channels than MEG channels. Make sure all is picked.
    if dots is None:
        dots = self_dots, cross_dots = _compute_dots(info, mode=mode)
    else:
        self_dots, cross_dots = dots

    self_dots, cross_dots = _pick_dots(dots, pick_from, pick_to)

    ch_names = [c['ch_name'] for c in info_from['chs']]
    fmd = dict(kind='meg', ch_names=ch_names,
               origin=my_origin, noise=noise, self_dots=self_dots,
               surface_dots=cross_dots, int_rad=int_rad, miss=miss)

    fmd['data'] = _compute_mapping_matrix(fmd, info_from)
    mne.set_log_level(verbose)

    return fmd['data'] 
Example #3
Source File: conftest.py    From pyprep with MIT License 5 votes vote down vote up
def raw():
    """Fixture for physionet EEG subject 4, dataset 1."""
    mne.set_log_level("WARNING")
    # load in subject 1, run 1 dataset
    edf_fpath = eegbci.load_data(4, 1, update_path=True)[0]

    # using sample EEG data (https://physionet.org/content/eegmmidb/1.0.0/)
    raw = mne.io.read_raw_edf(edf_fpath, preload=True)

    # The eegbci data has non-standard channel names. We need to rename them:
    eegbci.standardize(raw)

    return raw 
Example #4
Source File: hcp.py    From alphacsc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def load_data(n_trials=10, data_type='rest', sfreq=150, epoch=None,
              filter_params=[5., None], equalize="zeropad", n_jobs=1,
              random_state=None):
    """Load and prepare the HCP dataset for multiCSC


    Parameters
    ----------
    n_trials : int
        Number of recordings that are loaded.
    data_type : str
        Type of recordings loaded. Should be in {'rest', 'task_working_memory',
        'task_motor', 'task_story_math', 'noise_empty_room', 'noise_subject'}.
    sfreq : float
        Sampling frequency of the signal. The data are resampled to match it.
    epoch : tuple or None
        If set to a tuple, extract epochs from the raw data, using
        t_min=epoch[0] and t_max=epoch[1]. Else, use the raw signal, divided
        in n_splits chunks.
    filter_params : tuple
        Frequency cut for a band pass filter applied to the signals. The
        default is a high-pass filter with frequency cut at 2Hz.
    n_jobs : int
        Number of jobs that can be used for preparing (filtering) the data.
    random_state : int | None
        State to seed the random number generator.

    Return
    ------
    X : ndarray, shape (n_trials, n_channels, n_times)
        Signals loaded from HCP.
    info : list of mne.Info
        List of the info related to each signals.
    """
    if data_type == "rest" and epoch is not None:
        raise ValueError("epoch != None is not valid with resting-state data.")

    rng = check_random_state(random_state)
    mne.set_log_level(30)

    db = get_all_records()
    records = [(subject, run_index)
               for subject, runs in db[data_type].items()
               for run_index in runs]

    X, info = [], []
    records = rng.permutation(records)[:n_trials]
    for i, (subject, run_index) in enumerate(records):
        print("\rLoading HCP subjects: {:7.2%}".format(i / n_trials),
              end='', flush=True)
        X_n, info_n = load_one_record(
            data_type, subject, int(run_index), sfreq=sfreq, epoch=epoch,
            filter_params=filter_params, n_jobs=n_jobs)
        X += [X_n]
        info += [info_n]

    print("\rLoading HCP subjects: done   ")
    X = make_array(X, equalize=equalize)
    X /= np.std(X)
    return X, info 
Example #5
Source File: hcp.py    From alphacsc with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def data_generator(n_trials=10, data_type='rest', sfreq=150, epoch=None,
                   filter_params=[5., None], equalize="zeropad", n_jobs=1,
                   random_state=None):
    """Generator loading subjects from the HCP dataset for multiCSC


    Parameters
    ----------
    n_trials : int
        Number of recordings that are loaded.
    data_type : str
        Type of recordings loaded. Should be in {'rest', 'task_working_memory',
        'task_motor', 'task_story_math', 'noise_empty_room', 'noise_subject'}.
    sfreq : float
        Sampling frequency of the signal. The data are resampled to match it.
    epoch : tuple or None
        If set to a tuple, extract epochs from the raw data, using
        t_min=epoch[0] and t_max=epoch[1]. Else, use the raw signal, divided
        in n_splits chunks.
    filter_params : tuple
        Frequency cut for a band pass filter applied to the signals. The
        default is a high-pass filter with frequency cut at 2Hz.
    n_jobs : int
        Number of jobs that can be used for preparing (filtering) the data.
    random_state : int | None
        State to seed the random number generator.

    Yields
    ------
    X : ndarray, shape (1, n_channels, n_times)
        Signals loaded from HCP.
    info : list of mne.Info
        info related to this signal.
    """
    if data_type == "rest" and epoch is not None:
        raise ValueError("epoch != None is not valid with resting-state data.")

    rng = check_random_state(random_state)
    mne.set_log_level(30)

    db = get_all_records()
    records = [(subject, run_index)
               for subject, runs in db[data_type].items()
               for run_index in runs]

    records = rng.permutation(records)[:n_trials]
    for i, (subject, run_index) in enumerate(records):
        try:
            X_n, info_n = load_one_record(
                data_type, subject, int(run_index), sfreq=sfreq, epoch=epoch,
                filter_params=filter_params, n_jobs=n_jobs)
            X_n /= X_n.std()
            yield X_n, info_n
        except UnicodeDecodeError:
            print("failed to load {}-{}-{}"
                  .format(subject, data_type, run_index))