Skip to content

Commit 618932d

Browse files
pmolfesepre-commit-ci[bot]drammocklarsoner
authored
FIX make_watershed_bem to handle missing talairach_with_skull.lta courtesy Freesurfer 8 (#13172)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel McCloy <dan@mccloy.info> Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 9b93f03 commit 618932d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

doc/changes/devel/13172.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug in :func:`mne.bem.make_watershed_bem` where function would fail if ``talairach_with_skull.lta`` did not exist due to changes in Freesurfer by `Peter Molfese`_.

mne/bem.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,25 @@ def make_watershed_bem(
12561256
if gcaatlas:
12571257
fname = op.join(env["FREESURFER_HOME"], "average", "RB_all_withskull_*.gca")
12581258
fname = sorted(glob.glob(fname))[::-1][0]
1259+
1260+
# check if FS>8 didn't generate talairach_with_skull.lta
1261+
talairach_with_skull_path = os.path.join(
1262+
subject_dir, "mri/transforms/talairach_with_skull.lta"
1263+
)
1264+
if not os.path.exists(talairach_with_skull_path):
1265+
logger.info(
1266+
f"{talairach_with_skull_path} does not exist. Running mri_em_register."
1267+
)
1268+
em_reg_cmd = [
1269+
"mri_em_register",
1270+
"-skull",
1271+
subject_dir + "/mri/nu.mgz",
1272+
fname,
1273+
talairach_with_skull_path,
1274+
]
1275+
1276+
run_subprocess_env(em_reg_cmd)
1277+
12591278
logger.info(f"Using GCA atlas: {fname}")
12601279
cmd += [
12611280
"-atlas",

mne/preprocessing/tests/test_fine_cal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_compute_fine_cal(kind):
185185
assert got_cal["ch_names"] == got_cal_redo["ch_names"]
186186
assert_allclose(got_cal["imb_cals"], got_cal_redo["imb_cals"], atol=5e-5)
187187
assert_allclose(got_cal["locs"], got_cal_redo["locs"], atol=1e-6)
188-
assert sum([(ic == 1.0).any() for ic in got_cal["imb_cals"]]) == 0
188+
assert sum((ic == 1.0).any() for ic in got_cal["imb_cals"]) < 2
189189

190190
# redoing with 3 imlabance parameters should improve the shielding factor
191191
grad_subpicks = np.searchsorted(meg_picks, pick_types(raw.info, meg="grad"))

0 commit comments

Comments
 (0)