def test_flash_bem(): """Test mne flash_bem.""" check_usage(mne_flash_bem, force_help=True) # Using the sample dataset subjects_dir = op.join(sample.data_path(download=False), 'subjects') # Copy necessary files to tempdir tempdir = _TempDir() mridata_path = op.join(subjects_dir, 'sample', 'mri') mridata_path_new = op.join(tempdir, 'sample', 'mri') os.makedirs(op.join(mridata_path_new, 'flash')) os.makedirs(op.join(tempdir, 'sample', 'bem')) 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 files = glob.glob(op.join(mridata_path, 'flash', 'mef*.mgz')) for infile in files: shutil.copyfile( infile, op.join(mridata_path_new, 'flash', op.basename(infile))) # Test mne flash_bem with --noconvert option # (since there are no DICOM Flash images in dataset) currdir = os.getcwd() with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n'), disable_stdout=False, disable_stderr=False): mne_flash_bem.run() os.chdir(currdir)
def test_flash_bem(): """Test mne flash_bem.""" check_usage(mne_flash_bem, force_help=True) # Using the sample dataset subjects_dir = op.join(sample.data_path(download=False), 'subjects') # Copy necessary files to tempdir tempdir = _TempDir() mridata_path = op.join(subjects_dir, 'sample', 'mri') subject_path_new = op.join(tempdir, 'sample') mridata_path_new = op.join(subject_path_new, 'mri') os.makedirs(op.join(mridata_path_new, 'flash')) os.makedirs(op.join(subject_path_new, 'bem')) 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 flash_path = op.join(mridata_path_new, 'flash') for kind in (5, 30): in_fname = op.join(mridata_path, 'flash', 'mef%02d.mgz' % kind) shutil.copyfile(in_fname, op.join(flash_path, op.basename(in_fname))) # Test mne flash_bem with --noconvert option # (since there are no DICOM Flash images in dataset) out_fnames = list() for kind in ('outer_skin', 'outer_skull', 'inner_skull'): out_fnames.append(op.join(subject_path_new, 'bem', 'outer_skin.surf')) assert not any(op.isfile(out_fname) for out_fname in out_fnames) with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n'), disable_stdout=False, disable_stderr=False): mne_flash_bem.run() # do they exist and are expected size for out_fname in out_fnames: _, tris = read_surface(out_fname) assert len(tris) == 5120
def test_flash_bem(tmpdir): """Test mne flash_bem.""" check_usage(mne_flash_bem, force_help=True) # Using the sample dataset subjects_dir = op.join(sample.data_path(download=False), 'subjects') # Copy necessary files to tempdir tempdir = str(tmpdir) mridata_path = op.join(subjects_dir, 'sample', 'mri') subject_path_new = op.join(tempdir, 'sample') mridata_path_new = op.join(subject_path_new, 'mri') os.makedirs(op.join(mridata_path_new, 'flash')) os.makedirs(op.join(subject_path_new, 'bem')) 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 flash_path = op.join(mridata_path_new, 'flash') for kind in (5, 30): in_fname = op.join(mridata_path, 'flash', 'mef%02d.mgz' % kind) shutil.copyfile(in_fname, op.join(flash_path, op.basename(in_fname))) # Test mne flash_bem with --noconvert option # (since there are no DICOM Flash images in dataset) out_fnames = list() for kind in ('outer_skin', 'outer_skull', 'inner_skull'): out_fnames.append(op.join(subject_path_new, 'bem', 'outer_skin.surf')) assert not any(op.isfile(out_fname) for out_fname in out_fnames) with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n'), disable_stdout=False, disable_stderr=False): mne_flash_bem.run() # do they exist and are expected size for out_fname in out_fnames: _, tris = read_surface(out_fname) assert len(tris) == 5120
def test_flash_bem(): """Test mne flash_bem.""" check_usage(mne_flash_bem, force_help=True) # Using the sample dataset subjects_dir = op.join(sample.data_path(download=False), 'subjects') # Copy necessary files to tempdir tempdir = _TempDir() mridata_path = op.join(subjects_dir, 'sample', 'mri') mridata_path_new = op.join(tempdir, 'sample', 'mri') os.makedirs(op.join(mridata_path_new, 'flash')) os.makedirs(op.join(tempdir, 'sample', 'bem')) 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 files = glob.glob(op.join(mridata_path, 'flash', 'mef*.mgz')) for infile in files: shutil.copyfile(infile, op.join(mridata_path_new, 'flash', op.basename(infile))) # Test mne flash_bem with --noconvert option # (since there are no DICOM Flash images in dataset) currdir = os.getcwd() with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n'), disable_stdout=False, disable_stderr=False): mne_flash_bem.run() os.chdir(currdir)
def test_flash_bem(tmp_path): """Test mne flash_bem.""" check_usage(mne_flash_bem, force_help=True) # Copy necessary files to tempdir tempdir = str(tmp_path) mridata_path = op.join(subjects_dir, 'sample', 'mri') subject_path_new = op.join(tempdir, 'sample') mridata_path_new = op.join(subject_path_new, 'mri') os.makedirs(op.join(mridata_path_new, 'flash')) os.makedirs(op.join(subject_path_new, 'bem')) 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 flash_path = op.join(mridata_path_new, 'flash') for kind in (5, 30): in_fname = op.join(mridata_path, 'flash', 'mef%02d.mgz' % kind) shutil.copyfile(in_fname, op.join(flash_path, op.basename(in_fname))) # 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(op.join(subject_path_new, 'bem', '%s.surf' % s)) with ArgvSetter(('-d', tempdir, '-s', 'sample', '-n'), 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)
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)