Skip to content

Commit 3014786

Browse files
wmvanvlietlarsoner
andauthored
BUG: Fix check_inside with spherical BEM (#13371)
Co-authored-by: Eric Larson <[email protected]>
1 parent befc418 commit 3014786

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
pytest:
5151
name: '${{ matrix.os }} / ${{ matrix.kind }} / ${{ matrix.python }}'
5252
needs: style
53-
timeout-minutes: 85
53+
timeout-minutes: 90
5454
runs-on: ${{ matrix.os }}
5555
defaults:
5656
run:

doc/changes/dev/13371.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the check in :func:`mne.make_forward_solution` that all MEG sensors are outside a spherical BEM model, by `Marijn van Vliet`_

mne/forward/_make_forward.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,8 @@ def check_inside(x):
553553
else:
554554

555555
def check_inside(x):
556-
return (
557-
np.linalg.norm(x - bem["r0"], axis=1) < bem["layers"][-1]["rad"]
558-
)
556+
r0 = apply_trans(invert_transform(mri_head_t), bem["r0"])
557+
return np.linalg.norm(x - r0, axis=1) < bem["layers"][-1]["rad"]
559558

560559
if "meg" in sensors:
561560
meg_loc = apply_trans(

mne/forward/tests/test_make_forward.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ def test_make_forward_solution_sphere(tmp_path, fname_src_small):
574574
1.0,
575575
rtol=1e-3,
576576
)
577+
577578
# Number of layers in the sphere model doesn't matter for MEG
578579
# (as long as no sources are omitted due to distance)
579580
assert len(sphere["layers"]) == 4
@@ -592,6 +593,14 @@ def test_make_forward_solution_sphere(tmp_path, fname_src_small):
592593
with pytest.raises(RuntimeError, match="zero shells.*EEG"):
593594
make_forward_solution(fname_raw, fname_trans, src, sphere)
594595

596+
# Since the spherical model is defined in head space, the head->MRI transform should
597+
# not matter for the check that MEG sensors are outside the sphere.
598+
custom_trans = Transform("head", "mri")
599+
custom_trans["trans"][0, 3] = 0.05 # move MEG sensors close to mesh
600+
sphere = make_sphere_model()
601+
fwd = make_forward_solution(fname_raw, custom_trans, src, sphere)
602+
assert fwd["mri_head_t"]["trans"][0, 3] == -0.05
603+
595604

596605
@pytest.mark.slowtest
597606
@testing.requires_testing_data

tools/github_actions_test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ if [[ ! -z "$CONDA_ENV" ]] && [[ "${RUNNER_OS}" != "Windows" ]] && [[ "${MNE_CI_
2121
INSTALL_PATH=$(python -c "import mne, pathlib; print(str(pathlib.Path(mne.__file__).parents[1]))")
2222
echo "Copying tests from ${PROJ_PATH}/mne-python/mne/ to ${INSTALL_PATH}/mne/"
2323
echo "::group::rsync mne"
24-
rsync -a --partial --progress --prune-empty-dirs --exclude="*.pyc" --include="**/" --include="**/tests/*" --include="**/tests/data/**" --exclude="**" ${PROJ_PATH}/mne/ ${INSTALL_PATH}/mne/
24+
set -x
25+
rsync -a --partial --progress --prune-empty-dirs --exclude="*.pyc" --include="*/" --include="tests/**" --include="**/tests/**" --exclude="**" ${PROJ_PATH}/mne/ ${INSTALL_PATH}/mne/
2526
echo "::endgroup::"
2627
echo "::group::rsync doc"
2728
mkdir -p ${INSTALL_PATH}/doc/
28-
rsync -a --partial --progress --prune-empty-dirs --include="**/" --include="**/api/*" --exclude="**" ${PROJ_PATH}/doc/ ${INSTALL_PATH}/doc/
29+
rsync -a --partial --progress --prune-empty-dirs --include="api/" --include="api/*.rst" --exclude="*" ${PROJ_PATH}/doc/ ${INSTALL_PATH}/doc/
2930
test -f ${INSTALL_PATH}/doc/api/reading_raw_data.rst
3031
cd $INSTALL_PATH
3132
cp -av $PROJ_PATH/pyproject.toml .
33+
set +x
3234
echo "::endgroup::"
3335
fi
3436

0 commit comments

Comments
 (0)