Skip to content

Commit 672bdf4

Browse files
Backport PR #13062 on branch maint/1.9 (BUG: Fix bug with interval calculation) (#13064)
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 9ef5c23 commit 672bdf4

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ repos:
7878
language: python
7979
entry: ./tools/hooks/sync_dependencies.py
8080
files: pyproject.toml
81-
additional_dependencies: ["mne"]
81+
additional_dependencies: ["mne==1.9.0"]
8282

8383
# zizmor
8484
- repo: https://github.com/woodruffw/zizmor-pre-commit

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The minimum required dependencies to run MNE-Python are:
7272

7373
.. ↓↓↓ BEGIN CORE DEPS LIST. DO NOT EDIT! HANDLED BY PRE-COMMIT HOOK ↓↓↓
7474
75-
- `Python <https://www.python.org>`__ ≥ 3.9
75+
- `Python <https://www.python.org>`__ ≥ 3.10
7676
- `NumPy <https://numpy.org>`__ ≥ 1.23
7777
- `SciPy <https://scipy.org>`__ ≥ 1.9
7878
- `Matplotlib <https://matplotlib.org>`__ ≥ 3.6

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ stages:
244244
PYTHONIOENCODING: 'utf-8'
245245
AZURE_CI_WINDOWS: 'true'
246246
PYTHON_ARCH: 'x64'
247-
timeoutInMinutes: 75
247+
timeoutInMinutes: 80
248248
strategy:
249249
maxParallel: 4
250250
matrix:

doc/changes/devel/13062.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix computation of time intervals in :func:`mne.preprocessing.compute_fine_calibration` by `Eric Larson`_.

mne/preprocessing/_fine_cal.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ def compute_fine_calibration(
156156
# 1. Rotate surface normals using magnetometer information (if present)
157157
#
158158
cals = np.ones(len(info["ch_names"]))
159-
time_idxs = raw.time_as_index(np.arange(0.0, raw.times[-1], t_window))
160-
if len(time_idxs) <= 1:
161-
time_idxs = np.array([0, len(raw.times)], int)
162-
else:
163-
time_idxs[-1] = len(raw.times)
159+
end = len(raw.times) + 1
160+
time_idxs = np.arange(0, end, int(round(t_window * raw.info["sfreq"])))
161+
if len(time_idxs) == 1:
162+
time_idxs = np.concatenate([time_idxs, [end]])
163+
if time_idxs[-1] != end:
164+
time_idxs[-1] = end
164165
count = 0
165166
locs = np.array([ch["loc"] for ch in info["chs"]])
166167
zs = locs[mag_picks, -3:].copy()
@@ -388,9 +389,11 @@ def _adjust_mag_normals(info, data, origin, ext_order, *, angle_limit, err_limit
388389
each_err = _data_err(data, S_tot, cals, axis=-1)[picks_mag]
389390
n_bad = (each_err > err_limit).sum()
390391
if n_bad:
392+
bad_max = np.argmax(each_err)
391393
reason.append(
392394
f"{n_bad} residual{_pl(n_bad)} > {err_limit:0.1f}% "
393-
f"(max: {each_err.max():0.2f}%)"
395+
f"(max: {each_err[bad_max]:0.2f}% @ "
396+
f"{info['ch_names'][picks_mag[bad_max]]})"
394397
)
395398
reason = ", ".join(reason)
396399
if reason:

mne/preprocessing/tests/test_fine_cal.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from mne.preprocessing.tests.test_maxwell import _assert_shielding
2222
from mne.transforms import _angle_dist_between_rigid
23-
from mne.utils import object_diff
23+
from mne.utils import catch_logging, object_diff
2424

2525
# Define fine calibration filepaths
2626
data_path = testing.data_path(download=False)
@@ -289,3 +289,15 @@ def test_fine_cal_systems(system, tmp_path):
289289
got_corrs = np.corrcoef([raw_data, raw_sss_data, raw_sss_cal_data])
290290
got_corrs = got_corrs[np.triu_indices(3, 1)]
291291
assert_allclose(got_corrs, corrs, atol=corr_tol)
292+
if system == "fil":
293+
with catch_logging(verbose=True) as log:
294+
compute_fine_calibration(
295+
raw.copy().crop(0, 0.12).pick(raw.ch_names[:12]),
296+
t_window=0.06, # 2 segments
297+
angle_limit=angle_limit,
298+
err_limit=err_limit,
299+
ext_order=2,
300+
verbose=True,
301+
)
302+
log = log.getvalue()
303+
assert "(averaging over 2 time intervals)" in log, log

0 commit comments

Comments
 (0)