Create an average brain subject for subjects without structural MRI. Create a copy of fsaverage from the FreeSurfer directory in subjects_dir and add auxiliary files from the mne package. Parameters ---------- fs_home : None | str The FreeSurfer home directory (only nee
(fs_home=None, update=False, subjects_dir=None, verbose=None)
| 179 | |
| 180 | @verbose |
| 181 | def create_default_subject(fs_home=None, update=False, subjects_dir=None, verbose=None): |
| 182 | """Create an average brain subject for subjects without structural MRI. |
| 183 | |
| 184 | Create a copy of fsaverage from the FreeSurfer directory in subjects_dir |
| 185 | and add auxiliary files from the mne package. |
| 186 | |
| 187 | Parameters |
| 188 | ---------- |
| 189 | fs_home : None | str |
| 190 | The FreeSurfer home directory (only needed if ``FREESURFER_HOME`` is |
| 191 | not specified as environment variable). |
| 192 | update : bool |
| 193 | In cases where a copy of the fsaverage brain already exists in the |
| 194 | subjects_dir, this option allows to only copy files that don't already |
| 195 | exist in the fsaverage directory. |
| 196 | subjects_dir : None | path-like |
| 197 | Override the ``SUBJECTS_DIR`` environment variable |
| 198 | (``os.environ['SUBJECTS_DIR']``) as destination for the new subject. |
| 199 | %(verbose)s |
| 200 | |
| 201 | Notes |
| 202 | ----- |
| 203 | When no structural MRI is available for a subject, an average brain can be |
| 204 | substituted. FreeSurfer comes with such an average brain model, and MNE |
| 205 | comes with some auxiliary files which make coregistration easier. |
| 206 | :py:func:`create_default_subject` copies the relevant |
| 207 | files from FreeSurfer into the current subjects_dir, and also adds the |
| 208 | auxiliary files provided by MNE. |
| 209 | """ |
| 210 | subjects_dir = get_subjects_dir(subjects_dir, raise_error=True) |
| 211 | if fs_home is None: |
| 212 | fs_home = _check_freesurfer_home() |
| 213 | |
| 214 | # make sure FreeSurfer files exist |
| 215 | fs_src = os.path.join(fs_home, "subjects", "fsaverage") |
| 216 | if not os.path.exists(fs_src): |
| 217 | raise OSError( |
| 218 | f"fsaverage not found at {fs_src!r}. Is fs_home specified correctly?" |
| 219 | ) |
| 220 | for name in ("label", "mri", "surf"): |
| 221 | dirname = os.path.join(fs_src, name) |
| 222 | if not os.path.isdir(dirname): |
| 223 | raise OSError( |
| 224 | "FreeSurfer fsaverage seems to be incomplete: No directory named " |
| 225 | f"{name} found in {fs_src}" |
| 226 | ) |
| 227 | |
| 228 | # make sure destination does not already exist |
| 229 | dest = subjects_dir / "fsaverage" |
| 230 | if dest == fs_src: |
| 231 | raise OSError( |
| 232 | "Your subjects_dir points to the FreeSurfer subjects_dir " |
| 233 | f"({repr(subjects_dir)}). The default subject can not be created in the " |
| 234 | "FreeSurfer installation directory; please specify a different " |
| 235 | "subjects_dir." |
| 236 | ) |
| 237 | elif (not update) and dest.exists(): |
| 238 | raise OSError( |