@@ -590,6 +590,11 @@ def _lite_src(folder, rel):
590590 "subjects/sample/surf/lh.inflated" ,
591591 "subjects/sample/surf/rh.curv" ,
592592 "subjects/sample/surf/lh.curv" ,
593+ # setup_source_space maps each hemisphere onto its sphere for any
594+ # ico/oct spacing, and _create_surf_spacing reads surf/{hemi}.sphere
595+ # by a path it builds itself (5.6 MB each)
596+ "subjects/sample/surf/lh.sphere" ,
597+ "subjects/sample/surf/rh.sphere" ,
593598 "subjects/sample/label/lh.aparc.annot" ,
594599 "subjects/sample/label/rh.aparc.annot" ,
595600 # the auditory/visual ROIs; about nine notebooks build these names with
@@ -1282,7 +1287,8 @@ def _lite_copy_tree(folder, rel_dir):
12821287 "# plot_alignment locates its head surface by probing the filesystem\n "
12831288 "# with os.path.exists before any reader runs, so a reader shim never\n "
12841289 "# fires. Fetch the candidates first and let MNE choose as it normally\n "
1285- "# would. mne.viz._3d binds the function at import time, so patch both.\n "
1290+ "# would. Several viz modules bind the name at import time, so rebind\n "
1291+ "# it wherever the original landed instead of in one known place.\n "
12861292 "import mne._freesurfer as _mne_fs\n "
12871293 "_orig_get_head_surface = _mne_fs._get_head_surface\n "
12881294 "def _lite_get_head_surface(surf, subject, subjects_dir, bem=None,\n "
@@ -1307,8 +1313,14 @@ def _lite_copy_tree(folder, rel_dir):
13071313 " surf, subject, subjects_dir, bem=bem, verbose=verbose\n "
13081314 " )\n "
13091315 "_mne_fs._get_head_surface = _lite_get_head_surface\n "
1310- "import mne.viz._3d as _mne_viz3d\n "
1311- "_mne_viz3d._get_head_surface = _lite_get_head_surface\n "
1316+ "# import the 3D module first so the sweep below is guaranteed to see\n "
1317+ "# it; anything imported later picks the patched name up on its own.\n "
1318+ "import mne.viz._3d # noqa: F401\n "
1319+ "for _m in list(sys.modules.values()):\n "
1320+ " if (getattr(_m, '__name__', '').startswith('mne')\n "
1321+ " and getattr(_m, '_get_head_surface', None)\n "
1322+ " is _orig_get_head_surface):\n "
1323+ " _m._get_head_surface = _lite_get_head_surface\n "
13121324 "# same story for the skull surfaces, which _check_fname insists\n "
13131325 "# already exist on disk\n "
13141326 "_orig_get_skull_surface = _mne_fs._get_skull_surface\n "
@@ -1327,7 +1339,35 @@ def _lite_copy_tree(folder, rel_dir):
13271339 " surf, subject, subjects_dir, bem=bem, verbose=verbose\n "
13281340 " )\n "
13291341 "_mne_fs._get_skull_surface = _lite_get_skull_surface\n "
1330- "_mne_viz3d._get_skull_surface = _lite_get_skull_surface\n "
1342+ "for _m in list(sys.modules.values()):\n "
1343+ " if (getattr(_m, '__name__', '').startswith('mne')\n "
1344+ " and getattr(_m, '_get_skull_surface', None)\n "
1345+ " is _orig_get_skull_surface):\n "
1346+ " _m._get_skull_surface = _lite_get_skull_surface\n "
1347+ "# dig_mri_distances reaches a second, unrelated _get_head_surface, the\n "
1348+ "# one in mne/surface.py: it takes a list of candidate sources and\n "
1349+ "# probes bem/ with os.path.exists and glob, raising if the directory\n "
1350+ "# is absent, so the candidates have to land before it runs.\n "
1351+ "import mne.surface as _mne_surface\n "
1352+ "_orig_surface_head = _mne_surface._get_head_surface\n "
1353+ "def _lite_surface_head_surface(subject, source, subjects_dir,\n "
1354+ " on_defects, raise_error=True):\n "
1355+ " _sd = str(subjects_dir) if subjects_dir is not None else ''\n "
1356+ " if subject and _sd.startswith(mne_data_path + '/'):\n "
1357+ " _rel = _sd[len(mne_data_path) + 1:] + '/' + str(subject)\n "
1358+ " _srcs = [source] if isinstance(source, str) else list(source)\n "
1359+ " for _s in _srcs:\n "
1360+ " try:\n "
1361+ " _lite_fetch_rel(\n "
1362+ " _rel + '/bem/' + str(subject) + '-' + _s + '.fif'\n "
1363+ " )\n "
1364+ " except Exception:\n "
1365+ " pass\n "
1366+ " return _orig_surface_head(\n "
1367+ " subject, source, subjects_dir, on_defects,\n "
1368+ " raise_error=raise_error\n "
1369+ " )\n "
1370+ "_mne_surface._get_head_surface = _lite_surface_head_surface\n "
13311371 "# plot_bem globs bem/*.surf and requires the bem directory to exist,\n "
13321372 "# so pull its three contours (plus the MRI it draws them on) down\n "
13331373 "# first; fetching creates the directory as a side effect.\n "
0 commit comments