Skip to content

Commit

Permalink
MAINT: Warn when fitting cHPI amplitudes on Maxwell filtered data
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 30, 2023
1 parent d52a0d3 commit de62aee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mne/chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,16 @@ def _setup_hpi_amplitude_fitting(
on_missing = "raise" if not allow_empty else "ignore"
hpi_freqs, hpi_pick, hpi_ons = get_chpi_info(info, on_missing=on_missing)

# check for maxwell filtering
for ent in info["proc_history"]:
for key in ("sss_info", "max_st"):
if len(ent["max_info"]["sss_info"]) > 0:
warn(
"Fitting cHPI amplutudes after Maxwell filtering may not to work, "
"consider fitting on the original data"
)
break

_validate_type(t_window, (str, "numeric"), "t_window")
if info["line_freq"] is not None:
line_freqs = np.arange(
Expand Down
9 changes: 9 additions & 0 deletions mne/tests/test_chpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@ def test_calculate_chpi_positions_artemis():
)


@testing.requires_testing_data
def test_warn_maxwell_filtered():
"""Test that trying to compute locations on Maxwell filtered data warns."""
raw = read_raw_fif(sss_fif_fname).crop(0, 1)
with pytest.warns(RuntimeWarning, match="Maxwell filter"):
amps = compute_chpi_amplitudes(raw)
assert len(amps["times"]) > 0 # but for this file, it does work!


@testing.requires_testing_data
def test_initial_fit_redo():
"""Test that initial fits can be redone based on moments."""
Expand Down

0 comments on commit de62aee

Please sign in to comment.