Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ def make_version(app, exception):
try:
stdout, _ = run_subprocess(["git", "rev-parse", "HEAD"], verbose=False)
except Exception as exc:
sphinx_logger.warning(f"Failed to write _version.txt: {exc}")
sphinx_logger.warning("Failed to write _version.txt: %s", exc)
return
with open(os.path.join(app.outdir, "_version.txt"), "w") as fid:
fid.write(stdout)
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinxext/related_software.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _get_packages() -> dict[str, str]:
packages = _get_installer_packages()
except urllib.error.URLError as exc: # e.g., bad internet connection
if not REQUIRE_METADATA:
sphinx_logger.warning(f"Could not fetch package list, got: {exc}")
sphinx_logger.warning("Could not fetch package list, got: %s", exc)
return dict()
raise
# There can be duplicates in manual and installer packages because some of the
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ def _read_extended_ch_info(chs, parent, fid):
except KeyError:
# This shouldn't happen if we're up to date with the FIFF
# spec
warn(f"Discarding extra channel information kind {kind}")
warn("Discarding extra channel information kind %s" % (kind,))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drammock I think these we probably don't want to change... our warn function is really a wrapper around warnings.warn which doesn't use *args or delayed % formatting

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we only want % for errors and for logger.info and logger.debug, but not for warn()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's the idea

continue
assert key in ch
data = read_tag(fid, new["directory"][k].pos).data
Expand Down
2 changes: 1 addition & 1 deletion mne/_fiff/proc_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _read_proc_history(fid, tree):
record[key] = cast(tag.data)
break
else:
warn(f"Unknown processing history item {kind}")
warn("Unknown processing history item %s" % (kind,))
record["max_info"] = _read_maxfilter_record(fid, proc_record)
iass = dir_tree_find(proc_record, FIFF.FIFFB_IAS)
if len(iass) > 0:
Expand Down
4 changes: 3 additions & 1 deletion mne/_fiff/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,9 @@ def _has_eeg_average_ref_proj(
missing = [name for name in want_names if name not in found_names]
if missing:
if found_names: # found some but not all: warn
warn(f"Incomplete {ch_type} projector, missing channel(s) {missing}")
warn(
"Incomplete %s projector, missing channel(s) %s" % (ch_type, missing)
)
return False
return True

Expand Down
4 changes: 3 additions & 1 deletion mne/_fiff/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def _check_before_dict_reference(inst, ref_dict):
if any(self_ref):
which = np.array(list(_refdict))[np.nonzero(self_ref)]
for ch in which:
warn(f"Channel {ch} is self-referenced, which will nullify the channel.")
warn(
"Channel %s is self-referenced, which will nullify the channel." % (ch,)
)

# Check that channel types match. First unpack list-like vals into separate items:
pairs = [(k, v) for k in _refdict for v in _refdict[k]]
Expand Down
5 changes: 4 additions & 1 deletion mne/_fiff/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def _read_tag_header(fid, pos):
if len(s) != 16:
where = fid.tell() - len(s)
extra = f" in file {fid.name}" if hasattr(fid, "name") else ""
warn(f"Invalid tag with only {len(s)}/16 bytes at position {where}{extra}")
warn(
"Invalid tag with only %s/16 bytes at position %s%s"
% (len(s), where, extra)
)
return None
# struct.unpack faster than np.frombuffer, saves ~10% of time some places
kind, type_, size, next_ = struct.unpack(">iIii", s)
Expand Down
4 changes: 3 additions & 1 deletion mne/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,9 @@ def crop(
if emit_warning:
omitted = np.array(out_of_bounds).sum()
if omitted > 0:
warn(f"Omitted {omitted} annotation(s) that were outside data range.")
warn(
"Omitted %s annotation(s) that were outside data range." % (omitted,)
)
limited = (np.array(clip_left_elem) | np.array(clip_right_elem)).sum()
if limited > 0:
warn(
Expand Down
31 changes: 10 additions & 21 deletions mne/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ def compute_raw_covariance(
_check_n_samples(n_samples, len(picks), on_few_samples)
data -= mu[:, None] * (mu[None, :] / n_samples)
data /= n_samples - 1.0
logger.info("Number of samples used : %d", n_samples)
logger.info(f"Number of samples used : {n_samples}")
logger.info("[done]")
ch_names = [raw.info["ch_names"][k] for k in picks]
bads = [b for b in raw.info["bads"] if b in ch_names]
Expand Down Expand Up @@ -1196,7 +1196,7 @@ def _unpack_epochs(epochs):
# add extra info
cov.update(method=this_method, **data)
covs.append(cov)
logger.info("Number of samples used : %d", n_samples_tot)
logger.info(f"Number of samples used : {n_samples_tot}")
covs.sort(key=lambda c: c["loglik"], reverse=True)

if len(covs) > 1:
Expand Down Expand Up @@ -1849,7 +1849,7 @@ def _smart_eigh(
if isinstance(C, Covariance):
C = C["data"]
if ncomp > 0:
logger.info(" Created an SSP operator (subspace dimension = %d)", ncomp)
logger.info(f" Created an SSP operator (subspace dimension = {ncomp})")
C = np.dot(proj, np.dot(C, proj.T))

noise_cov = Covariance(C, ch_names, [], projs, 0)
Expand Down Expand Up @@ -2297,10 +2297,8 @@ def compute_whitener(
C = np.sqrt(eig) * noise_cov["eigvec"].conj().T # C ** 0.5
n_nzero = nzero.sum()
logger.info(
" Created the whitener using a noise covariance matrix "
"with rank %d (%d small eigenvalues omitted)",
n_nzero,
noise_cov["dim"] - n_nzero,
f" Created the whitener using a noise covariance matrix "
f"with rank {n_nzero} ({noise_cov["dim"] - n_nzero} small eigenvalues omitted)"
)

# Do the requested projection
Expand Down Expand Up @@ -2428,10 +2426,7 @@ def _read_cov(fid, node, cov_kind, limited=False, verbose=None):
data = tag.data
diag = True
logger.info(
" %d x %d diagonal covariance (kind = %d) found.",
dim,
dim,
cov_kind,
f" {dim} x {dim} diagonal covariance (kind = {cov_kind}) found."
)

else:
Expand All @@ -2444,20 +2439,14 @@ def _read_cov(fid, node, cov_kind, limited=False, verbose=None):
data.flat[:: dim + 1] /= 2.0
diag = False
logger.info(
" %d x %d full covariance (kind = %d) found.",
dim,
dim,
cov_kind,
f" {dim} x {dim} full covariance (kind = {cov_kind}) found."
)
else:
diag = False
data = tag.data
logger.info(
" %d x %d sparse covariance (kind = %d) found.",
dim,
dim,
cov_kind,
)
f" {dim} x {dim} sparse covariance (kind = {cov_kind}) found."
)

# Read the possibly precomputed decomposition
tag1 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVALUES)
Expand Down Expand Up @@ -2499,7 +2488,7 @@ def _read_cov(fid, node, cov_kind, limited=False, verbose=None):

return cov

logger.info(" Did not find the desired covariance matrix (kind = %d)", cov_kind)
logger.info(f" Did not find the desired covariance matrix (kind = {cov_kind})")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one I think was okay in main. These are logging.logger calls so delayed repr calls using % and *args can be useful


return None

Expand Down
10 changes: 5 additions & 5 deletions mne/dipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def _read_dipole_text(fname):
assert len(handled_fields) == len(required_fields) + len(optional_fields)
ignored_fields = sorted(set(fields) - set(handled_fields) - {"end/ms"})
if len(ignored_fields) > 0:
warn(f"Ignoring extra fields in dipole file: {ignored_fields}")
warn("Ignoring extra fields in dipole file: %s" % (ignored_fields,))
if len(fields) != data.shape[1]:
raise OSError(
f"More data fields ({len(fields)}) found than data columns ({data.shape[1]}"
Expand Down Expand Up @@ -1322,7 +1322,7 @@ def _fit_dipole(
# Find a good starting point (find_best_guess in C)
B2 = np.dot(B, B)
if B2 == 0:
warn(f"Zero field found for time {t}")
warn("Zero field found for time %s" % (t,))
return np.zeros(3), 0, np.zeros(3), 0, B

idx = np.argmin(
Expand Down Expand Up @@ -1387,12 +1387,12 @@ def _fit_dipole(
sensors=sensors, rd=rd_final, Q=Q, ori=ori, whitener=whitener, fwd_data=fwd_data
)

msg = "---- Fitted : %7.1f ms" % (1000.0 * t)
msg = f"---- Fitted : {1000.0 * t:7.1f} ms"
if surf is not None:
dist_to_inner_skull = _compute_nearest(
surf["rr"], rd_final[np.newaxis, :], return_dists=True
)[1][0]
msg += ", distance to inner skull : %2.4f mm" % (dist_to_inner_skull * 1000.0)
msg += f", distance to inner skull : {dist_to_inner_skull * 1000.0:2.4f} mm"

logger.info(msg)
return rd_final, amp, ori, gof, conf, khi2, nfree, residual_noproj
Expand All @@ -1417,7 +1417,7 @@ def _fit_dipole_fixed(
B = np.dot(whitener, B_orig)
B2 = np.dot(B, B)
if B2 == 0:
warn(f"Zero field found for time {t}")
warn("Zero field found for time %s" % (t,))
return np.zeros(3), 0, np.zeros(3), 0, np.zeros(6)
# Compute the dipole moment
Q, gof, residual_noproj = _fit_Q(
Expand Down
5 changes: 4 additions & 1 deletion mne/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ def read_events(
event_list = _mask_trigs(event_list, mask, mask_type)
masked_len = event_list.shape[0]
if masked_len < unmasked_len:
warn(f"{unmasked_len - masked_len} of {unmasked_len} events masked")
warn(
"%d of %d events masked"
% (unmasked_len - masked_len, unmasked_len)
)
out = event_list
if return_event_id:
if event_id is None:
Expand Down
4 changes: 3 additions & 1 deletion mne/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,9 @@ def resample(
if axis < 0:
axis = x.ndim + axis
if x.shape[axis] == 0:
warn(f"x has zero length along axis={axis}, returning a copy of x")
warn(
"x has zero length along axis=%s, returning a copy of x" % (axis,)
)
return x.copy()

# prep for resampling along the last axis (swap axis with last then reshape)
Expand Down
4 changes: 3 additions & 1 deletion mne/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def _safe_svd(A, **kwargs):
except np.linalg.LinAlgError as exp:
from .utils import warn

warn(f"SVD error ({exp}), attempting to use GESVD instead of GESDD")
warn(
"SVD error (%s), attempting to use GESVD instead of GESDD" % (exp,)
)
return linalg.svd(A, lapack_driver="gesvd", **kwargs)


Expand Down
2 changes: 1 addition & 1 deletion mne/inverse_sparse/mxne_optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def mixed_norm_solver(
idx = np.searchsorted(idx_active_set, idx_old_active_set)
X_init[idx] = X
else:
warn(f"Did NOT converge ! (gap: {gap} > {tol})")
warn("Did NOT converge ! (gap: %s > %s)" % (gap, tol))
else:
X, active_set, E = l21_solver(
M, G, alpha, lc, maxit=maxit, tol=tol, n_orient=n_orient, init=None
Expand Down
2 changes: 1 addition & 1 deletion mne/io/artemis123/artemis123.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def _get_artemis123_info(fname, pos_fname=None):
"Spatial Filter Active?",
]:
if header_info[k] != "FALSE":
warn(f"{k} - set to but is not supported")
warn("%s - set to but is not supported" % (k,))
if header_info["filter_hist"]:
warn("Non-Empty Filter history found, BUT is not supported")

Expand Down
2 changes: 1 addition & 1 deletion mne/io/brainvision/brainvision.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def _check_bv_version(header, kind):
return version
else:
if header == "":
warn(f"Missing header in {kind} file.")
warn("Missing header in %s file." % (kind,))
else:
warn(_data_err % (kind, header))

Expand Down
2 changes: 1 addition & 1 deletion mne/io/edf/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def _read_edf_header(
logger.debug(err)
continue
else:
warn(f"Invalid patient information {key}")
warn("Invalid patient information %s" % (key,))

# Recording ID
rec_info = fid.read(80).decode("latin-1").rstrip().split(" ")
Expand Down
2 changes: 1 addition & 1 deletion mne/io/egi/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _parse_xml(xml_file: str) -> list[dict[str, str]] | None:
try:
xml = defusedxml.ElementTree.parse(xml_file)
except defusedxml.ElementTree.ParseError as e:
warn(f"Could not parse the XML file {xml_file}: {e}")
warn("Could not parse the XML file %s: %s" % (xml_file, e))
return
root = xml.getroot()
return _xml2list(root)
Expand Down
5 changes: 4 additions & 1 deletion mne/io/eyelink/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,10 @@ def _make_eyelink_annots(df_dict, create_annots, apply_offsets):
elif annots:
annots += this_annot
if not annots:
warn(f"Annotations for {descs} were requested but none could be made.")
warn(
"Annotations for %s were requested but none could be made."
% (descs,)
)
return

return annots
Expand Down
2 changes: 1 addition & 1 deletion mne/io/fil/fil.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __init__(self, binfile, precision="single", preload=False):
elif key.lower().startswith("nas"):
nas = np.asarray(hc[key])
else:
warn(f"{key} is not a valid fiducial name!")
warn("%s is not a valid fiducial name!" % (key,))

size = np.linalg.norm(nas - rpa)
unit, sf = _size2units(size)
Expand Down
2 changes: 1 addition & 1 deletion mne/io/kit/kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def get_kit_info(rawfile, allow_unknown_format, standardize_names=None, verbose=
version_string = f"V{version}R{revision:03d}"
if allow_unknown_format:
unsupported_format = True
warn(f"Force loading KIT format {version_string}")
warn("Force loading KIT format %s" % (version_string,))
else:
raise UnsupportedKITFormat(
version_string,
Expand Down
2 changes: 1 addition & 1 deletion mne/io/nihon/nihon.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def _read_nihon_annotations(fname, encoding="utf-8"):
try:
t_desc = t_desc.decode(encoding)
except UnicodeDecodeError:
warn(f"Could not decode log as {encoding}")
warn("Could not decode log as %s" % (encoding,))
continue

all_onsets.append(t_onset)
Expand Down
2 changes: 1 addition & 1 deletion mne/minimum_norm/_eloreta.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def _compute_eloreta(inv, lambda2, options):
)
break
else:
warn(f"eLORETA weight fitting did not converge (>= {eps})")
warn("eLORETA weight fitting did not converge (>= %s)" % (eps,))
del G_R_Gt
logger.info(" Updating inverse with weighted eigen leads")
G /= source_std # undo our biasing
Expand Down
5 changes: 4 additions & 1 deletion mne/preprocessing/artifact_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ def compute_average_dev_head_t(raw, pos, *, verbose=None):
trans[:3, 3] = dt @ hp[:, 4:7]
dist = np.linalg.norm(trans[:3, 3])
if dist > 1: # less than 1 meter is sane
warn(f"Implausible head position detected: {dist} meters from device origin")
warn(
"Implausible head position detected: %s meters from device origin"
% (dist,)
)
dev_head_t = Transform("meg", "head", trans)
return dev_head_t

Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/eyetracking/_pupillometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def interpolate_blinks(raw, buffer=0.05, match="BAD_blink", interpolate_gaze=Fal
# get the blink annotations
blink_annots = [annot for annot in raw.annotations if annot["description"] in match]
if not blink_annots:
warn(f"No annotations matching {match} found. Aborting.")
warn("No annotations matching %s found. Aborting." % (match,))
return raw
_interpolate_blinks(raw, buffer, blink_annots, interpolate_gaze=interpolate_gaze)

Expand Down
7 changes: 5 additions & 2 deletions mne/preprocessing/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,10 @@ def _prep_fine_cal(info, fine_cal, *, ignore_ref):
f"Not all MEG channels found in fine calibration file, missing:\n{bad}"
)
if len(missing):
warn(f"Found cal channel{_pl(missing)} not in data: {missing}")
warn(
"Found cal channel%s not in data: %s"
% (_pl(missing), missing)
)
return info_to_cal, fine_cal, ch_names


Expand Down Expand Up @@ -2912,7 +2915,7 @@ def _read_cross_talk(cross_talk, ch_names):
raise RuntimeError(f"Missing MEG channels in cross-talk matrix:\n{missing}")
missing = sorted(list(set(ctc_chs) - set(ch_names)))
if len(missing) > 0:
warn(f"Not all cross-talk channels in raw:\n{missing}")
warn("Not all cross-talk channels in raw:\n%s" % (missing,))
ctc_picks = [ctc_chs.index(name) for name in ch_names]
ctc = sss_ctc["decoupler"][ctc_picks][:, ctc_picks]
# I have no idea why, but MF transposes this for storage..
Expand Down
2 changes: 1 addition & 1 deletion mne/preprocessing/ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _compute_exg_proj(

# Check to make sure we actually got at least one usable event
if events.shape[0] < 1:
warn(f"No {mode} events found")
warn("No %s events found" % (mode,))
return ([], events) + (([],) if return_drop_log else ())

logger.info("Computing projector")
Expand Down
Loading
Loading