Esempio n. 1
0
def MultiNiftiOverlap(niftiPath1, coordsPath, subject_id, subjects_dir):

    #for whatever reason, it seems that left and right are switched here.
    # at least this is what I infer from the nifti.  Right side niftis
    # have lower x values than left side niftis, which one wouldnt usualy
    # expect, but whatever.  It serves as the appropriate check
    niftiVol = nib.load(niftiPath1)
    niftiData = niftiVol.get_data()
    nonZeros = np.nonzero(niftiData)
    niftiDimensions = niftiData.shape
    xDim = niftiDimensions[1]
    averageXcoord = np.mean(nonZeros[0])
    if averageXcoord < xDim / 2:
        side = 'lh'
    else:
        side = 'rh'

    print(niftiPath1)

    brain = Brain(subject_id=subject_id,
                  hemi=side,
                  surf="inflated",
                  background="white",
                  subjects_dir=subjects_dir)

    #set this up for each system, I guess
    os.environ['FREESURFER_HOME'] = '/Applications/freesurfer/'
    os.environ['SUBJECTS_DIR'] = subjects_dir
    #print os.environ['SUBJECTS_DIR']

    steps = [float(i) for i in [0, 8, .1]]

    #NOTE:  FIBER 2 IS ACTUALLY THE ECOG PLOT HERE.

    epi_img = nib.load(niftiPath1)
    epi_img_data = epi_img.get_fdata()
    np.unique(epi_img_data.data)

    #unique, counts = np.unique(epi_img_data.data, return_counts=True)
    #dict(zip(unique, counts))

    fib1_surf_data = io.project_volume_data(filepath=niftiPath1,
                                            hemi=side,
                                            subject_id=subject_id,
                                            projsum='max',
                                            smooth_fwhm=5,
                                            projmeth='dist',
                                            projarg=steps)
    #fib1_surf_data = io.project_volume_data(filepath=niftiPath1, hemi=side,  subject_id=subject_id, projsum='max', smooth_fwhm=5)

    #Just scale the data I guess?  Something is being messed with in the data.

    #fib1Max=max(fib1_surf_data)

    #thresh1=np.median(fib1_surf_data[np.nonzero(fib1_surf_data)])
    #print(thresh1)
    #coords2=[]
    coords = readcsv(coordsPath)
    #padCoord=np.zeros((1,3))
    #coords2=np.concatenate((coords,padCoord),axis=0)

    fsPath = subjects_dir + subject_id + '/'
    interpolatedCoords = interpolate_coords_to_GM(fsPath, coords)
    #interpolatedCoords=rewarp_coords(fsPath,coords)

    brain.add_data(fib1_surf_data,
                   0,
                   1000,
                   150,
                   colormap="hsv",
                   alpha=.68,
                   hemi=side)

    #        colorwords=['red',
    #                     'blue',
    #                     'green',
    #                     'black',
    #                     'purple',
    #                     'cyan',
    #                     'yellow',
    #                     'pink'
    #                     'orange']

    #
    #        coordsSize=interpolatedCoords.shape
    #
    #        print(interpolatedCoords)

    #        for iCoords in range(coordsSize[0]):
    brain.add_foci(interpolatedCoords,
                   map_surface='white',
                   color="black",
                   scale_factor=.5)
    #            print(interpolatedCoords[iCoords])
    #            print(colorwords[iCoords])
    #            brain.add_foci(interpolatedCoords[iCoords], map_surface='white', color=colorwords[iCoords], scale_factor=.5)

    figdir = os.path.join(subjects_dir, subject_id, 'Figures/')
    filename1 = os.path.basename(niftiPath1)

    #i have no idea why this picks the first ., but it works.
    filedotIndex1 = filename1.index('.')

    coordName = os.path.basename(coordsPath)
    coordName = coordName.replace('.csv', '')

    filetitle1 = filename1[0:filedotIndex1] + '_' + coordName

    if not os.path.exists(figdir):
        os.makedirs(figdir)
        #views=[(-45,27.5),(-45,90),(45,90),(-90,135),(-225,27.5),(-315,27.5),(-45,-27.5),(-135,-27.5),(-225,-27.5),(-315,-27.5),(0,0),(0,-27.5),(0,27.5)]
    if side == 'rh':
        views = [(-45, 27.5), (-45, 110), (45, 90), (-90, 135), (-315, 27.5),
                 (90, -180), (0, 27.5), (-100, 80), (-120, 105), (0, 90),
                 (90, 90)]
    else:
        views = [(-135, 27.5), (-135, 110), (135, 90), (90, -135),
                 (315, -27.5), (90, -180), (0, -27.5), (100, -80), (120, -105),
                 (0, -90), (90, 90)]

    for iviews in np.arange(len(views)):

        mayavi.mlab.view(azimuth=views[iviews][0], elevation=views[iviews][1])
        figName = filetitle1 + str(iviews) + '.png'
        curFileName = os.path.join(figdir, figName)
        brain.save_single_image(curFileName)
Esempio n. 2
0
               labels[52], labels[53],
               labels[68], labels[69]]
    

subject_id = "fsaverage"
hemi = "lh"
surf = "inflated"
left_b = Brain(subject_id, hemi, surf)

# If the label lives in the normal place in the subjects directory,
# you can plot it by just using the name

for lbl in labels_list[::2]:
    left_b.add_label(lbl, color="#2E2E2E")
    left_b.add_label(lbl, borders=True, color="#F2F2F2")

left_b.save_single_image("left_hemi.png")

subject_id = "fsaverage"
hemi = "rh"
surf = "inflated"
right_b = Brain(subject_id, hemi, surf)

# If the label lives in the normal place in the subjects directory,
# you can plot it by just using the name

for lbl in labels_list[1::2]:
    right_b.add_label(lbl, color="#2E2E2E")
    right_b.add_label(lbl, borders=True, color="#F2F2F2")

right_b.save_single_image("right_hemi.png")