def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-s", "--subject", dest="subject", help="Subject name", default=None) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", help="Subjects directory", default=None) parser.add_option("-3", "--noflash30", dest="noflash30", action="store_true", default=False, help=("Skip the 30-degree flip angle data"),) parser.add_option("-n", "--noconvert", dest="noconvert", action="store_true", default=False, help=("Assume that the Flash MRI images have already " "been converted to mgz files")) parser.add_option("-u", "--unwarp", dest="unwarp", action="store_true", default=False, help=("Run grad_unwarp with -unwarp <type> option on " "each of the converted data sets")) parser.add_option("-o", "--overwrite", dest="overwrite", action="store_true", default=False, help="Write over existing .surf files in bem folder") parser.add_option("-v", "--view", dest="show", action="store_true", help="Show BEM model in 3D for visual inspection", default=False) parser.add_option("--copy", dest="copy", help="Use copies instead of symlinks for surfaces", action="store_true") parser.add_option("-p", "--flash-path", dest="flash_path", default=None, help="The directory containing flash05.mgz and " "flash30.mgz files (defaults to " "$SUBJECTS_DIR/$SUBJECT/mri/flash/parameter_maps") options, args = parser.parse_args() subject = options.subject subjects_dir = options.subjects_dir flash30 = not options.noflash30 convert = not options.noconvert unwarp = options.unwarp overwrite = options.overwrite show = options.show flash_path = options.flash_path copy = options.copy if options.subject is None: parser.print_help() raise RuntimeError('The subject argument must be set') convert_flash_mris(subject=subject, subjects_dir=subjects_dir, flash30=flash30, convert=convert, unwarp=unwarp, verbose=True) make_flash_bem(subject=subject, subjects_dir=subjects_dir, overwrite=overwrite, show=show, flash_path=flash_path, copy=copy, verbose=True)
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-s", "--subject", dest="subject", help="Subject name", default=None) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", help="Subjects directory", default=None) parser.add_option("-3", "--noflash30", dest="noflash30", action="store_true", default=False, help=("Skip the 30-degree flip angle data"),) parser.add_option("-n", "--noconvert", dest="noconvert", action="store_true", default=False, help=("Assume that the Flash MRI images have already " "been converted to mgz files")) parser.add_option("-u", "--unwarp", dest="unwarp", action="store_true", default=False, help=("Run grad_unwarp with -unwarp <type> option on " "each of the converted data sets")) parser.add_option("-o", "--overwrite", dest="overwrite", action="store_true", default=False, help="Write over existing .surf files in bem folder") parser.add_option("-v", "--view", dest="show", action="store_true", help="Show BEM model in 3D for visual inspection", default=False) parser.add_option("-p", "--flash-path", dest="flash_path", default=None, help="The directory containing flash05.mgz and " "flash30.mgz files (defaults to " "$SUBJECTS_DIR/$SUBJECT/mri/flash/parameter_maps") options, args = parser.parse_args() subject = options.subject subjects_dir = options.subjects_dir flash30 = not options.noflash30 convert = not options.noconvert unwarp = options.unwarp overwrite = options.overwrite show = options.show flash_path = options.flash_path if options.subject is None: parser.print_help() raise RuntimeError('The subject argument must be set') convert_flash_mris(subject=subject, subjects_dir=subjects_dir, flash30=flash30, convert=convert, unwarp=unwarp, verbose=True) make_flash_bem(subject=subject, subjects_dir=subjects_dir, overwrite=overwrite, show=show, flash_path=flash_path, verbose=True)
def run(): """Run command.""" from mne.commands.utils import get_optparser parser = get_optparser(__file__) parser.add_option("-s", "--subject", dest="subject", help="Subject name", default=None) parser.add_option("-d", "--subjects-dir", dest="subjects_dir", help="Subjects directory", default=None) parser.add_option("-3", "--noflash30", dest="noflash30", action="store_true", default=False, help=("Skip the 30-degree flip angle data"),) parser.add_option("-n", "--noconvert", dest="noconvert", action="store_true", default=False, help=("Assume that the Flash MRI images have already " "been converted to mgz files")) parser.add_option("-u", "--unwarp", dest="unwarp", action="store_true", default=False, help=("Run grad_unwarp with -unwarp <type> option on " "each of the converted data sets")) parser.add_option("-o", "--overwrite", dest="overwrite", action="store_true", default=False, help="Write over existing .surf files in bem folder") parser.add_option("-v", "--view", dest="show", action="store_true", help="Show BEM model in 3D for visual inspection", default=False) options, args = parser.parse_args() subject = options.subject subjects_dir = options.subjects_dir flash30 = not options.noflash30 convert = not options.noconvert unwarp = options.unwarp overwrite = options.overwrite show = options.show if options.subject is None: parser.print_help() raise RuntimeError('The subject argument must be set') convert_flash_mris(subject=subject, subjects_dir=subjects_dir, flash30=flash30, convert=convert, unwarp=unwarp) make_flash_bem(subject=subject, subjects_dir=subjects_dir, overwrite=overwrite, show=show, flash_path='.')
def test_flash_bem(tmp_path): """Test mne flash_bem.""" check_usage(mne_flash_bem, force_help=True) # Copy necessary files to tempdir tempdir = Path(str(tmp_path)) mridata_path = Path(subjects_dir) / 'sample' / 'mri' subject_path_new = tempdir / 'sample' mridata_path_new = subject_path_new / 'mri' flash_path = mridata_path_new / 'flash' flash_path.mkdir(parents=True, exist_ok=True) bem_path = mridata_path_new / 'bem' bem_path.mkdir(parents=True, exist_ok=True) shutil.copyfile(op.join(mridata_path, 'T1.mgz'), op.join(mridata_path_new, 'T1.mgz')) shutil.copyfile(op.join(mridata_path, 'brain.mgz'), op.join(mridata_path_new, 'brain.mgz')) # Copy the available mri/flash/mef*.mgz files from the dataset for kind in (5, 30): in_fname = mridata_path / "flash" / f'mef{kind:02d}.mgz' in_fname_echo = flash_path / f'mef{kind:02d}_001.mgz' shutil.copyfile(in_fname, flash_path / in_fname_echo.name) # Test mne flash_bem with --noconvert option # (since there are no DICOM Flash images in dataset) for s in ('outer_skin', 'outer_skull', 'inner_skull'): assert not op.isfile(subject_path_new / 'bem' / f'{s}.surf') # First test without flash30 with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n', '-r', '-3'), disable_stdout=False, disable_stderr=False): mne_flash_bem.run() for s in ('outer_skin', 'outer_skull', 'inner_skull'): surf_path = subject_path_new / 'bem' / f'{s}.surf' assert surf_path.exists() surf_path.unlink() # cleanup shutil.rmtree(flash_path / "parameter_maps") # remove old files # Test synthesize flash5 with MEF flash5 and flash30 default locations flash5_img = convert_flash_mris(subject="sample", subjects_dir=tempdir, convert=False, unwarp=False) assert flash5_img == (flash_path / "parameter_maps" / "flash5.mgz") assert flash5_img.exists() shutil.rmtree(flash_path / "parameter_maps") # remove old files # Test with flash5 and flash30 shutil.rmtree(flash_path) # first remove old files with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n', '-3', str(mridata_path / "flash" / 'mef30.mgz'), '-5', str(mridata_path / "flash" / 'mef05.mgz')), disable_stdout=False, disable_stderr=False): mne_flash_bem.run() kwargs = dict(rtol=1e-5, atol=1e-5) for s in ('outer_skin', 'outer_skull', 'inner_skull'): rr, tris = read_surface(op.join(subject_path_new, 'bem', '%s.surf' % s)) assert_equal(len(tris), 5120) assert_equal(tris.min(), 0) assert_equal(rr.shape[0], tris.max() + 1) # compare to the testing flash surfaces rr_c, tris_c = read_surface( op.join(subjects_dir, 'sample', 'bem', '%s.surf' % s)) assert_allclose(rr, rr_c, **kwargs) assert_allclose(tris, tris_c, **kwargs)