Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
pytest:
name: '${{ matrix.os }} / ${{ matrix.kind }} / ${{ matrix.python }}'
needs: style
timeout-minutes: 85
timeout-minutes: 90
runs-on: ${{ matrix.os }}
defaults:
run:
Expand Down
1 change: 1 addition & 0 deletions doc/changes/dev/13371.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the check in :func:`mne.make_forward_solution` that all MEG sensors are outside a spherical BEM model, by `Marijn van Vliet`_
1 change: 1 addition & 0 deletions doc/changes/dev/13376.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure auto-computed plot scalings are always non-zero, by `Daniel McCloy`_.
5 changes: 2 additions & 3 deletions mne/forward/_make_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,8 @@ def check_inside(x):
else:

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

if "meg" in sensors:
meg_loc = apply_trans(
Expand Down
9 changes: 9 additions & 0 deletions mne/forward/tests/test_make_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def test_make_forward_solution_sphere(tmp_path, fname_src_small):
1.0,
rtol=1e-3,
)

# Number of layers in the sphere model doesn't matter for MEG
# (as long as no sources are omitted due to distance)
assert len(sphere["layers"]) == 4
Expand All @@ -592,6 +593,14 @@ def test_make_forward_solution_sphere(tmp_path, fname_src_small):
with pytest.raises(RuntimeError, match="zero shells.*EEG"):
make_forward_solution(fname_raw, fname_trans, src, sphere)

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


@pytest.mark.slowtest
@testing.requires_testing_data
Expand Down
6 changes: 6 additions & 0 deletions mne/viz/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def test_auto_scale():
raw = read_raw_fif(raw_fname)
epochs = Epochs(raw, read_events(ev_fname))
rand_data = np.random.randn(10, 100)
# make a stim channel all zeros (gh 13376)
ix = raw.get_channel_types().index("stim")
raw.load_data()
raw._data[ix] = 0.0

for inst in [raw, epochs]:
scale_grad = 1e10
Expand All @@ -142,6 +146,8 @@ def test_auto_scale():
scalings_new = _compute_scalings(scalings_def, inst)
assert scale_grad == scalings_new["grad"]
assert scalings_new["eeg"] != "auto"
# make sure an all-zero channel doesn't cause scaling=0 (gh 13376)
assert scalings_new["stim"] > 0

with pytest.raises(ValueError, match="Must supply either Raw or Epochs"):
_compute_scalings(scalings_def, rand_data)
Expand Down
2 changes: 2 additions & 0 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,8 @@ def _compute_scalings(scalings, inst, remove_dc=False, duration=10):
this_data = this_data[np.isfinite(this_data)]
if this_data.size:
iqr = np.diff(np.percentile(this_data, [25, 75]))[0]
if iqr == 0: # e.g. sparse stim channels, flat channels
iqr = 1.0
else:
iqr = 1.0
scalings[key] = iqr
Expand Down
6 changes: 4 additions & 2 deletions tools/github_actions_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ if [[ ! -z "$CONDA_ENV" ]] && [[ "${RUNNER_OS}" != "Windows" ]] && [[ "${MNE_CI_
INSTALL_PATH=$(python -c "import mne, pathlib; print(str(pathlib.Path(mne.__file__).parents[1]))")
echo "Copying tests from ${PROJ_PATH}/mne-python/mne/ to ${INSTALL_PATH}/mne/"
echo "::group::rsync mne"
rsync -a --partial --progress --prune-empty-dirs --exclude="*.pyc" --include="**/" --include="**/tests/*" --include="**/tests/data/**" --exclude="**" ${PROJ_PATH}/mne/ ${INSTALL_PATH}/mne/
set -x
rsync -a --partial --progress --prune-empty-dirs --exclude="*.pyc" --include="*/" --include="tests/**" --include="**/tests/**" --exclude="**" ${PROJ_PATH}/mne/ ${INSTALL_PATH}/mne/
echo "::endgroup::"
echo "::group::rsync doc"
mkdir -p ${INSTALL_PATH}/doc/
rsync -a --partial --progress --prune-empty-dirs --include="**/" --include="**/api/*" --exclude="**" ${PROJ_PATH}/doc/ ${INSTALL_PATH}/doc/
rsync -a --partial --progress --prune-empty-dirs --include="api/" --include="api/*.rst" --exclude="*" ${PROJ_PATH}/doc/ ${INSTALL_PATH}/doc/
test -f ${INSTALL_PATH}/doc/api/reading_raw_data.rst
cd $INSTALL_PATH
cp -av $PROJ_PATH/pyproject.toml .
set +x
echo "::endgroup::"
fi

Expand Down
Loading