From 4cdf90c70b18081ae0c82ce87a69d5331cd1463a Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 15 Nov 2024 19:54:15 -0500 Subject: [PATCH] FIX: Check --- mne/preprocessing/_fine_cal.py | 5 +++++ mne/preprocessing/tests/test_fine_cal.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/mne/preprocessing/_fine_cal.py b/mne/preprocessing/_fine_cal.py index adc2b9bdb7e..41d20539ce0 100644 --- a/mne/preprocessing/_fine_cal.py +++ b/mne/preprocessing/_fine_cal.py @@ -129,6 +129,11 @@ def compute_fine_calibration( ext_order = _ensure_int(ext_order, "ext_order") origin = _check_origin(origin, raw.info, "meg", disp=True) _check_option("raw.info['bads']", raw.info["bads"], ([],)) + _validate_type(err_limit, "numeric", "err_limit") + _validate_type(angle_limit, "numeric", "angle_limit") + for key, val in dict(err_limit=err_limit, angle_limit=angle_limit).items(): + if val < 0: + raise ValueError(f"{key} must be greater than or equal to 0, got {val}") # Fine cal should not include ref channels picks = pick_types(raw.info, meg=True, ref_meg=False) if raw.info["dev_head_t"] is not None: diff --git a/mne/preprocessing/tests/test_fine_cal.py b/mne/preprocessing/tests/test_fine_cal.py index 696261fd6f1..b25b824bae0 100644 --- a/mne/preprocessing/tests/test_fine_cal.py +++ b/mne/preprocessing/tests/test_fine_cal.py @@ -94,6 +94,10 @@ def test_compute_fine_cal(kind): cl3 = [-0.3, -0.1] raw = read_raw_fif(erm) want_cal = read_fine_calibration(cal) + with pytest.raises(ValueError, match="err_limit.*greater.*0"): + compute_fine_calibration(raw, err_limit=-1) + with pytest.raises(ValueError, match="angle_limit.*greater.*0"): + compute_fine_calibration(raw, angle_limit=-1) got_cal, counts = compute_fine_calibration( raw, cross_talk=ctc,