Creating flash5.mgz files for BEM segmentation

Dear MNE users,

I have both a regular T1w MPRAGE and multi-echo flash (5 and 30°) sequences along with my MEG-EEG data. I would like to use the flash sequences to improve the creation of my 3-layers BEM.

I understood that I need to use the mne command flash_bem but this command requires a specific data organization. According to the doc, it needs as inputs two files flash5.mgz and flash30.mgz, that should be created by the command mne_organize_dicom. However, I didn’t manage to find this script anywhere, so is it now deprecated? Is there another way to get these mgz files to run flash_bem from the dicom (or niftii) files?

  • MNE version: 0.23.0
  • operating system: Debian GNU Linux/buster

Thank you very much for your help!

Best,

Laetitia G.

Salut @LaetitiaG !

first flash30.mgz is not mandatory. You should be fine with just the flash5.
If the two files are aligned in the same scanner coordinate system it should be rather simple.
if you already have the flash image in .nii (not in dicom anymore) you need to convert
this file to .mgz and call it flash05.mgz. Then pass to mne flash_bem command the path to the folder containing the file. Use option --noflash30 to only require the flash05.

let us know if it works
Alex

1 Like

Hi Alex!

So, first point : I have not only 1 but 8 niftii files for flash05, corresponding to the 8 echos used in this sequence (the same for flash30 sequence). So is it enough to convert only the first echo into mgz? Anyway, I tried to do that, using mri_convert. Then I used mne flash_bem with the folder where I put my flash05.mgz and flash30.mgz files as argument. Yet, I get an error, indicating a problem with the organization of the data folder (see below). So it seems that I need this particular organization of files that I can’t find described anywhere…

mne flash_bem -s $SUBJECT -p ${SUBJECTS_DIR}/${SUBJECT}/mri/flash/parameter_maps
---- Converting Flash images ----
Traceback (most recent call last):
File “/home/lgrabot/.conda/envs/mne/bin/mne”, line 10, in
sys.exit(main())
File “/home/lgrabot/.conda/envs/mne/lib/python3.9/site-packages/mne/commands/utils.py”, line 107, in main
cmd.run()
File “/home/lgrabot/.conda/envs/mne/lib/python3.9/site-packages/mne/commands/mne_flash_bem.py”, line 100, in run
convert_flash_mris(subject=subject, subjects_dir=subjects_dir,
File “”, line 22, in convert_flash_mris
File “/home/lgrabot/.conda/envs/mne/lib/python3.9/site-packages/mne/bem.py”, line 1766, in convert_flash_mris
raise RuntimeError(“Directory %s is missing.”
RuntimeError: Directory flash05/002 is missing.

Thanks again for the help!
Laetitia

can you add the -n option? From the doc:

-n, --noconvert Assume that the Flash MRI images have already been
converted to mgz files

Alex

I have another error when I add the -n option (the error is the same even when I’m putting the flash05.mgz and flash30.mgz files directly in the indicated flash folder):

mne flash_bem -n -s $SUBJECT -p ${SUBJECTS_DIR}/${SUBJECT}/mri/flash/parameter_maps

Traceback (most recent call last):
File “/home/lgrabot/.conda/envs/mne/bin/mne”, line 10, in
sys.exit(main())
File “/home/lgrabot/.conda/envs/mne/lib/python3.9/site-packages/mne/commands/utils.py”, line 107, in main
cmd.run()
File “/home/lgrabot/.conda/envs/mne/lib/python3.9/site-packages/mne/commands/mne_flash_bem.py”, line 100, in run
convert_flash_mris(subject=subject, subjects_dir=subjects_dir,
File “”, line 22, in convert_flash_mris
File “/home/lgrabot/.conda/envs/mne/lib/python3.9/site-packages/mne/bem.py”, line 1789, in convert_flash_mris
raise ValueError(‘No suitable source files found (%s)’ % template)
ValueError: No suitable source files found (/home/lgrabot/wave_model/data_MRI/preproc/freesurfer/XZJ7KI/mri/flash/mef*.mgz)

@LaetitiaG can you share your recon folder privately with me?

Alex

Hi Laetitia,

I think the mne_organize_dicom script only exists in classic MNE-C, from http://www.nmr.mgh.harvard.edu/martinos/userInfo/data/MNE_register/.

But that’s more of a last resort. You can use freesurfer’s mri_average to combine your 8 echoes from the flash05, and then run flash_bem to get your BEM. E.g. navigate to the directory where the mgz files for your 8 echoes are located and do:

mri_average -noconform mef05_001.mgz mef05_002.mgz mef05_003.mgz mef05_004.mgz mef05_005.mgz mef05_006.mgz mef05_007.mgz mef05_008.mgz flash5.mgz (or however your 8 echoes are named).

This saves the average image into flash5.mgz. Then you can do:

mne flash_bem -s $SUBJECT -d $SUBJECTS_DIR -n -3 -p /absolute/path/to/wherever/you/saved/the/average/from/the/previous/step

This does not use the flash30 images but as Alex said you don’t really need them. You could skip the averaging step and would probably get a reasonable result from a single echo but since you have the 8 echoes you may as well use them. :slight_smile:

Jon

1 Like

Hi Jon,

Thanks a lot for your suggestion, I was missing this step!

Thanks to Alex’s help, I finally manage to get my BEM model from flash sequences. Here is a summary pipeline for people who will run into the same problems in the future:

# Convert each echo into mgz files for flash5 and flash30 sequences
mri_convert your_nifti_file_name_megre5_echoX.nii.gz megre5_X.mgz

# Average echos and store the average files into mri/flash/parameter_maps folder of your freesurfer directory of the subject
mri_average -noconform megre5_1.mgz megre5_2.mgz megre5_3.mgz megre5_4.mgz megre5_5.mgz megre5_6.mgz megre5_7.mgz megre5_8.mgz ${SUBJECTS_DIR}/${SUBJECT}/mri/flash/parameter_maps/flash5.mgz
mri_average -noconform megre30_1.mgz megre30_2.mgz megre30_3.mgz megre30_4.mgz megre30_5.mgz megre30_6.mgz megre30_7.mgz megre30_8.mgz ${SUBJECTS_DIR}/${SUBJECT}/mri/flash/parameter_maps/flash30.mgz

# In python terminal, make the BEM models
from mne.bem import make_flash_bem
subject = "XZJ7KI"
subjects_dir = "your_freesurfer_directory"
make_flash_bem(subject, overwrite=False, show=True, subjects_dir=subjects_dir,
               flash_path=None, copy=True, verbose=None)

Note!!! It is not working with freesurfer version 7 as they remove the required command mri_make_bem_surfaces. However, this command was added back in the last development version, so it should work with the next releases.

Thanks a lot for your help!
Cheers,
Laetitia