[med-svn] [python-mne] 260/376: ENH : adding script to generate BEM models from flash sequences (mne_flash_bem_model.py)
Yaroslav Halchenko
debian at onerussian.com
Fri Nov 27 17:23:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
yoh pushed a commit to annotated tag v0.1
in repository python-mne.
commit d1736577a4cbe265b38ea7981764f05c20332c60
Author: Alexandre Gramfort <alexandre.gramfort at inria.fr>
Date: Fri May 20 10:33:13 2011 -0400
ENH : adding script to generate BEM models from flash sequences (mne_flash_bem_model.py)
---
bin/mne_flash_bem_model.py | 131 +++++++++++++++++++++++++++++++++++++++++++++
mne/__init__.py | 2 +-
mne/surface.py | 1 +
setup.py | 2 +-
4 files changed, 134 insertions(+), 2 deletions(-)
diff --git a/bin/mne_flash_bem_model.py b/bin/mne_flash_bem_model.py
new file mode 100644
index 0000000..eff60ff
--- /dev/null
+++ b/bin/mne_flash_bem_model.py
@@ -0,0 +1,131 @@
+#!/usr/bin/env python
+"""Create 3-Layers BEM model from Flash MRI images
+
+This function extracts the BEM surfaces (outer skull, inner skull, and
+outer skin) from multiecho FLASH MRI data with spin angles of 5 and 30
+degrees. The multiecho FLASH data are inputted in NIFTI format.
+It was developed to work for Phillips MRI data, but could probably be
+used for data from other scanners that have been converted to NIFTI format
+(e.g., using MRIcron's dcm2nii). However,it has been tested only for
+data from the Achieva scanner). This function assumes that the Freesurfer
+segmentation of the subject has been completed. In particular, the T1.mgz
+and brain.mgz MRI volumes should be, as usual, in the subject's mri
+directory.
+
+"""
+
+# Authors: Rey Rene Ramirez, Ph.D. e-mail: rrramir at uw.edu
+# Alexandre Gramfort, Ph.D.
+
+
+import math
+import os
+import mne
+
+def make_flash_bem(subject, subjects_dir, flash05, flash30, show=False):
+ """Create 3-Layers BEM model from Flash MRI images
+
+ Parameters
+ ----------
+ subject : string
+ Subject name
+ subjects_dir : string
+ Directory containing subjects data (Freesurfer SUBJECTS_DIR)
+ flash05: string
+ Full path of the NIFTI file for the
+ FLASH sequence with a spin angle of 5 degrees
+ flash30: string
+ Full path of the NIFTI file for the
+ FLASH sequence with a spin angle of 30 degrees
+ show : bool
+ Show surfaces in 3D to visually inspect all three BEM
+ surfaces (recommended)
+
+ Notes
+ -----
+ This program assumes that both Freesurfer/FSL, and MNE,
+ including MNE's Matlab Toolbox, are installed properly.
+ For reference please read the MNE manual and wiki, and Freesurfer's wiki:
+ http://www.nmr.mgh.harvard.edu/meg/manuals/
+ http://www.nmr.mgh.harvard.edu/martinos/userInfo/data/sofMNE.php
+ http://www.nmr.mgh.harvard.edu/martinos/userInfo/data/MNE_register/index.php
+ http://surfer.nmr.mgh.harvard.edu/
+ http://surfer.nmr.mgh.harvard.edu/fswiki
+
+ References:
+ B. Fischl, D. H. Salat, A. J. van der Kouwe, N. Makris, F. Segonne,
+ B. T. Quinn, and A. M. Dale, "Sequence-independent segmentation of magnetic
+ resonance images," Neuroimage, vol. 23 Suppl 1, pp. S69-84, 2004.
+ J. Jovicich, S. Czanner, D. Greve, E. Haley, A. van der Kouwe, R. Gollub,
+ D. Kennedy, F. Schmitt, G. Brown, J. Macfall, B. Fischl, and A. Dale,
+ "Reliability in multi-site structural MRI studies: effects of gradient
+ non-linearity correction on phantom and human data," Neuroimage,
+ vol. 30, Epp. 436-43, 2006.
+ """
+ os.environ['SUBJECT'] = subject
+ os.chdir(os.path.join(subjects_dir, subject, "mri"))
+ if not os.path.exists('flash'):
+ os.mkdir("flash")
+ os.chdir("flash")
+ # flash_dir = os.getcwd()
+ if not os.path.exists('parameter_maps'):
+ os.mkdir("parameter_maps")
+ print "--- Converting Flash 5"
+ os.system('mri_convert -flip_angle %s -tr 25 %s mef05.mgz' %
+ (5*math.pi/180, flash05))
+ print "--- Converting Flash 30"
+ os.system('mri_convert -flip_angle %s -tr 25 %s mef30.mgz' %
+ (30*math.pi/180, flash30))
+ print "--- Running mne_flash_bem"
+ os.system('mne_flash_bem --noconvert')
+ os.chdir(os.path.join(subjects_dir, subject, 'bem'))
+ if not os.path.exists('flash'):
+ os.mkdir("flash")
+ os.chdir("flash")
+ print "[done]"
+
+ if show:
+ fnames = ['outer_skin.surf', 'outer_skull.surf', 'inner_skull.surf']
+ head_col = (0.95, 0.83, 0.83) # light pink
+ skull_col = (0.91, 0.89, 0.67)
+ brain_col = (0.67, 0.89, 0.91) # light blue
+ colors = [head_col, skull_col, brain_col]
+ from enthought.mayavi import mlab
+ mlab.clf()
+ for fname, c in zip(fnames, colors):
+ points, faces = mne.read_surface(fname)
+ mlab.triangular_mesh(points[:, 0], points[:, 1], points[:, 2], faces,
+ color=c, opacity=0.3)
+ mlab.show()
+
+if __name__ == '__main__':
+
+ from optparse import OptionParser
+
+ subject = os.environ.get('SUBJECT')
+ subjects_dir = os.environ.get('SUBJECTS_DIR')
+
+ parser = OptionParser()
+ parser.add_option("-s", "--subject", dest="subject",
+ help="Subject name", default=subject)
+ parser.add_option("-d", "--subjects-dir", dest="subjects_dir",
+ help="Subjects directory", default=subjects_dir)
+ parser.add_option("-5", "--flash05", dest="flash05",
+ help=("Path to FLASH sequence with a spin angle of 5 "
+ "degrees in Nifti format"), metavar="FILE")
+ parser.add_option("-3", "--flash30", dest="flash30",
+ help=("Path to FLASH sequence with a spin angle of 30 "
+ "degrees in Nifti format"), metavar="FILE")
+ 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
+ flash05 = os.path.abspath(options.flash05)
+ flash30 = os.path.abspath(options.flash30)
+ show = options.show
+
+ make_flash_bem(subject, subjects_dir, flash05, flash30, show=show)
diff --git a/mne/__init__.py b/mne/__init__.py
index 64c4a42..03b5cb5 100644
--- a/mne/__init__.py
+++ b/mne/__init__.py
@@ -5,7 +5,7 @@ from .cov import read_cov, write_cov, write_cov_file, Covariance, \
from .event import read_events, write_events, find_events
from .forward import read_forward_solution
from .source_estimate import read_stc, write_stc, SourceEstimate, morph_data
-from .surface import read_bem_surfaces
+from .surface import read_bem_surfaces, read_surface
from .source_space import read_source_spaces
from .epochs import Epochs
from .label import label_time_courses, read_label
diff --git a/mne/surface.py b/mne/surface.py
index fed41f5..085daa5 100644
--- a/mne/surface.py
+++ b/mne/surface.py
@@ -247,4 +247,5 @@ def read_surface(filepath):
fnum = np.fromfile(fobj, ">i4", 1)[0]
vertex_coords = np.fromfile(fobj, ">f4", vnum * 3).reshape(vnum, 3)
faces = np.fromfile(fobj, ">i4", fnum * 3).reshape(fnum, 3)
+ vertex_coords = vertex_coords.astype(np.float) # XXX : due to mayavi bug
return vertex_coords, faces
diff --git a/setup.py b/setup.py
index 17c511d..439b0af 100755
--- a/setup.py
+++ b/setup.py
@@ -81,5 +81,5 @@ if __name__ == "__main__":
'mne.minimum_norm', 'mne.minimum_norm.tests',
'mne.layouts',
'mne.time_frequency', 'mne.time_frequency.tests'],
- scripts=['bin/mne_clean_eog_ecg.py'],
+ scripts=['bin/mne_clean_eog_ecg.py', 'bin/mne_flash_bem_model.py'],
**extra_setuptools_args)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git
More information about the debian-med-commit
mailing list