Skip to content

Use of "warn", "warnings.warn", "logger.warning" in the codebase #9432

@sappelhoff

Description

@sappelhoff

I recently got a warning raised by plot_compare_evokeds that I somehow couldn't switch off using mne.utils.use_log_level(0):

:50: RuntimeWarning: Only 1 channel in "picks"; cannot combine by method "mean".
cmap=cmap,
:50: RuntimeWarning: Cannot find channel coordinates in the supplied Evokeds. Not showing channel locations.
cmap=cmap,

That led me down a bit of a rabbit hole and I saw that within the code base, there are several ways how warnings are raised. Is each of those ways desirable for the particular situation? Or is that something to be unified, to consistently make use of a feature (such as setting a log level that all warning calls respect).

Examples:

--> should these all be just mne.utils.warn instead?

PS: I also didn't solve that issue of not being able to suppress the warning yet, so if somebody has an idea, please let me know. Here is a MWE:

import numpy as np
import mne

# create data
sampling_freq = 200
times = np.linspace(0, 1, sampling_freq, endpoint=False)
sine = np.sin(20 * np.pi * times)

info = mne.create_info(ch_names=['sine'],
                       ch_types=['misc'],
                       sfreq=sampling_freq)

data = np.array([[0.2 * sine],
                 [0.4 * sine],
                 [0.6 * sine],
                 [0.8 * sine],
                 [1.0 * sine]])
evoked_array = mne.EvokedArray(data.mean(axis=0), info, tmin=-0.5,
                               nave=data.shape[0], comment='simulated')

# This will still raise warnings ...
with mne.utils.use_log_level(0):
    mne.viz.plot_compare_evokeds([evoked_array] * 2, picks=0, combine="mean")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions