コード例 #1
0
def cl_nsteps(coord,
              label_name,
              output_dir=os.getcwd(),
              subj_id="fsaverage",
              hemi="lh",
              map_surface="inflated",
              n_steps=10,
              update=False):
    """
    Create label by coord or vertex within its n_steps.

    Parameters
    ----------
        coord: coord(x, y, z) or vertex(number) that used for creating label.
        label_name: label name used for saving label, final label file name would be:
                    "%s-%s.label" % (label_name, hemi)
        output_dir: set dir to save label, default is current dir.
        subj_id: specify the subject, default is 'fsaverage'.
        hemi: set hemisphere, default is 'lh'.
        map_surface: set map surface, default is 'inflated'.
        n_steps: set to specify the label in n steps range of coord.
        update: set to overwrite output file or not.

    Returns
    -------
        boolean value, 'True' stands for successfully saving labels  into out_dir, 'False' for file exists.
    """
    if isinstance(coord, int):
        state = True
    elif isinstance(coord, list):
        state = False
    else:
        raise Exception("Please check your coord!")

    try:
        check_dir(output_dir, new=True)
        os.chdir(output_dir)
        print("Output dir is: %s" % output_dir)
    except:
        raise Exception("Please check output_dir: %s" % output_dir)

    label_file = "%s-%s.label" % (label_name, hemi)
    if (not update) and os.path.exists(label_file):
        print("Not updated: %s exists, file is not saved." % label_file)
        return False
    coord_to_label(subj_id,
                   coord,
                   hemi=hemi,
                   label=label_name,
                   n_steps=n_steps,
                   map_surface=map_surface,
                   coord_as_vert=state)
    return True
コード例 #2
0
subject_id = "fsaverage"
subjects_dir = os.environ["SUBJECTS_DIR"]
"""
Bring up the visualization.
"""
brain = Brain(subject_id, "lh", "inflated")
"""
First we'll get a set of stereotaxic foci in the MNI
coordinate system. These might be peak activations from
a volume based analysis.
"""
coord = [-43, 25, 24]

utils.coord_to_label(subject_id,
                     coord,
                     label='example_data/coord',
                     hemi='lh',
                     n_steps=50,
                     map_surface="white")
brain.add_label('example_data/coord-lh.label')
"""
Now we plot the foci on the inflated surface. We will map
the foci onto the surface by finding the vertex on the "white"
mesh that is closest to the coordinate of the point we want
to display.
"""
brain.add_foci([coord], map_surface="white", color="gold")
"""
or using a vertex index
"""
coord = 0
コード例 #3
0
subject = 'fsaverage'

# Plot brain in 3D with PySurfer if available
brain = new_stc.plot(subject, hemi='lh',
                     subjects_dir=subjects_dir, backend='mayavi')
brain.show_view('lateral')

# use peak getter to move vizualization to the time point of the peak
vertno_max, time_idx = new_stc.get_peak(hemi='lh', time_as_index=True)

brain.set_data_time_index(time_idx)

# draw marker at maximum peaking vertex
brain.add_foci(vertno_max, coords_as_verts=True, hemi='lh', color='blue',
               scale_factor=0.6, map_surface='white')

mni_coords = mne.vertex_to_mni(vertno_max, hemis=0, subject=subject,
                               subjects_dir=subjects_dir)
print('The MNI coords are ', mni_coords)

# my_trans = mne.read_trans(?)
# src_pts = apply_trans(trans, some_tgt_pts)

utils.coord_to_label(subject, mni_coords, label='mycoord',
                     hemi='lh', n_steps=25, map_surface="white")
brain.add_label('mycoord-lh.label', color="darkseagreen", alpha=.8)

# if the new mni_coords are computed
brain.add_foci(mni_coords, coords_as_verts=False, hemi='lh', color='red',
               map_surface='white', scale_factor=0.6)
コード例 #4
0
ファイル: plot_label_foci.py プロジェクト: Eric89GXL/PySurfer
"""
brain = Brain(subject_id, "lh", "inflated", cortex=("gray", -2, 7, True),
              units='m')

"""
First we'll identify a stereotaxic focus in the MNI coordinate system. This
might be a peak activations from a volume based analysis.
"""
coord = [-43, 25, 24]

"""
Next we grow a label along the surface around the neareset vertex to this
coordinate in the white surface mesh. The `n_steps` argument controls the size
of the resulting label.
"""
utils.coord_to_label(subject_id, coord, label='example_data/coord',
                     hemi='lh', n_steps=25, map_surface="white")
brain.add_label('example_data/coord-lh.label', color="darkseagreen", alpha=.8)

"""
Now we plot the focus on the inflated surface at the vertex identified in the
previous step.
"""
brain.add_foci([coord], map_surface="white", color="mediumseagreen")

"""
We can also do this using a vertex index, perhaps defined as the peak
activation in a surface analysis. This will be more accurate than using a
volume-based focus.
"""
coord = 0
コード例 #5
0
ファイル: plot_label_foci.py プロジェクト: akeshavan/PySurfer
subject_id = "fsaverage"
subjects_dir = os.environ["SUBJECTS_DIR"]

"""
Bring up the visualization.
"""
brain = Brain(subject_id, "lh", "inflated")

"""
First we'll get a set of stereotaxic foci in the MNI
coordinate system. These might be peak activations from
a volume based analysis.
"""
coord = [-43, 25, 24]

utils.coord_to_label(subject_id, coord, label='coord', hemi='lh', n_steps=50,
                     map_surface="white")
brain.add_label('coord-lh.label')

"""
Now we plot the foci on the inflated surface. We will map
the foci onto the surface by finding the vertex on the "white"
mesh that is closest to the coordinate of the point we want
to display.
"""
brain.add_foci([coord], map_surface="white", color="gold")

"""
or using a vertex index
"""
coord = 0
コード例 #6
0
subject = 'fsaverage'

# Plot brain in 3D with PySurfer if available
brain = new_stc.plot(subject, hemi='lh', subjects_dir=subjects_dir)
brain.show_view('lateral')

# use peak getter to move vizualization to the time point of the peak
vertno_max, time_idx = new_stc.get_peak(hemi='lh', time_as_index=True)

brain.set_data_time_index(time_idx)

# draw marker at maximum peaking vertex
brain.add_foci(vertno_max, coords_as_verts=True, hemi='lh', color='blue',
               scale_factor=0.6, map_surface='white')

mni_coords = mne.vertex_to_mni(vertno_max, hemis=0, subject=subject,
                               subjects_dir=subjects_dir)
print 'The MNI coords are ', mni_coords

#my_trans = mne.read_trans(?)
#src_pts = apply_trans(trans, some_tgt_pts)

from surfer import utils
utils.coord_to_label(subject, mni_coords[0], label='mycoord',
                     hemi='lh', n_steps=25, map_surface="white")
brain.add_label('mycoord-lh.label', color="darkseagreen", alpha=.8)

# if the new mni_coords are computed
brain.add_foci(mni_coords[0], coords_as_verts=False, hemi='lh', color='red',
               map_surface='white', scale_factor=0.6)