Skip to content

Conversation

@nordme
Copy link
Contributor

@nordme nordme commented Oct 29, 2025

What does this implement/fix?

This is a PR to simplify an overly long and complicated test in the testing suite for #D visualization. This refactor breaks testing of the function mne.viz.plot_alignment into manageable chunks, separating tests of different parameters, and separating error checking from test plots (except where doing so would add extra up front instantiations).

Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

very nice! a few suggestions below (terse, because @nordme and I were reviewing this together in real time)

def test_plot_alignment_cframe(renderer):
"""Test varying the coordinate frame for alignment plot."""
info = read_info(evoked_fname)
for coord_frame in ("meg", "head", "mri"):
Copy link
Member

Choose a reason for hiding this comment

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

parametrize this

surfaces="white",
coord_frame="head",
)
fwd = convert_forward_solution(fwd, force_fixed=True)
Copy link
Member

Choose a reason for hiding this comment

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

add comment before this line, e.g. "now test a fwd with fixed source ori"

surfaces="white",
coord_frame="head",
)
fwd["coord_frame"] = FIFF.FIFFV_COORD_MRI # check required to get to MRI
Copy link
Member

Choose a reason for hiding this comment

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

better comment (e.g. "hack fwd coordframe, to make sure plot_alignment raises error")

@testing.requires_testing_data
def test_plot_alignment_fwd(renderer):
"""Test plotting forward solution."""
info = read_info(evoked_fname)
Copy link
Member

Choose a reason for hiding this comment

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

replace with info=evoked.info and use evoked fixture

sample_vsrc.plot(subjects_dir=subjects_dir, head=True, skull=True, brain="white")
renderer.backend._close_all()

# test mixed src
Copy link
Member

Choose a reason for hiding this comment

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

split this to its own test

bem=sphere,
)
# but you can ask for a specific brain surface, and
# no info is permitted
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# no info is permitted
# then omitting info is permitted

Comment on lines +698 to +701
info,
trans=trans_fname,
subject="sample",
subjects_dir=subjects_dir,
Copy link
Member

Choose a reason for hiding this comment

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

pull out a shared_kwargs dict with these 4 params, to make clearer which params are different between each call to plot_alignment in this test



@testing.requires_testing_data
def test_plot_alignment_trans_erros(renderer, evoked):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_plot_alignment_trans_erros(renderer, evoked):
def test_plot_alignment_trans_errors(renderer, evoked):


@testing.requires_testing_data
def test_plot_alignment_info(renderer, evoked):
"""Test basic alignment plotting with info, but no trans or other."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""Test basic alignment plotting with info, but no trans or other."""
"""Test plotting with info, but no trans, fwd, bem, or src."""

Comment on lines 545 to 549
info,
trans,
subject="foo",
subjects_dir=subjects_dir,
surfaces=["brain"],
Copy link
Member

Choose a reason for hiding this comment

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

see if you can dedup these param lists by pulling out a shared params dict and overriding / augmenting it as needed for each call.

@nordme
Copy link
Contributor Author

nordme commented Nov 12, 2025

@larsoner @drammock Hey Eric, something I noticed while doing this refactor is that our volumetric source space example in our testing data set does not have a value for the subject field, i.e. src._subject is blank. I can hack it to make it work for this PR, but I wondered if perhaps we should update the volumetric source space in the testing data (MNE-testing-data/subjects/sample/bem/sample-volume-7mm-src.fif), since plotting functions want the subject field filled. What do you think?

@larsoner
Copy link
Member

We could, but it's also pretty easy to add a

@pytest.fixture
@testing.requires_testing_data
def vol_src():
    src = mne.read_source_spaces(...)
    src._subject = "sample"
    return src

instead, which might be preferable anyway since it avoids some boilerplate. There are some similar things here already

def fwd_volume_small(_fwd_subvolume):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants