Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gallantlab/pycortex
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgao committed Jul 9, 2015
2 parents e421842 + 934470d commit 98c71d6
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 15 deletions.
8 changes: 5 additions & 3 deletions cortex/dataset/braindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,11 @@ def __init__(self, dv):
self.data = dv.data

def __getitem__(self, masktype):
s, x = self.dv.subject, self.dv.xfmname
mask = db.get_mask(s, x, masktype)
return self.dv.copy(self.dv.volume[:,mask].squeeze())
try:
mask = db.get_mask(self.dv.subject, self.dv.xfmname, masktype)
return self.dv.copy(self.dv.volume[:,mask].squeeze())
except:
self.dv.copy(self.dv.volume[:, mask].squeeze())

def _hash(array):
'''A simple numpy hash function'''
Expand Down
4 changes: 4 additions & 0 deletions cortex/dataset/view2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ def __repr__(self):
def raw(self):
r, g, b, a = self._to_raw(self.dim1.data, self.dim2.data)
return VertexRGB(r, g, b, alpha=a, subject=self.dim1.subject)

@property
def vertices(self):
return self.raw.vertices
6 changes: 4 additions & 2 deletions cortex/formats.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ from libc.stdlib cimport atoi, atof
np.import_array()

def read(str globname):
readers = OrderedDict([('gii', read_gii), ('npz', read_npz), ('vtk', read_vtk), ('off', read_off)])
readers = OrderedDict([('gii', read_gii), ('npz', read_npz), ('vtk', read_vtk), ('off', read_off), ('stl', read_stl)])
for ext, func in readers.items():
try:
return func(globname+"."+ext)
Expand Down Expand Up @@ -63,13 +63,15 @@ def read_stl(str filename):

idx = dict()
polys = np.empty((npolys,3), dtype=np.uint32)
points = []
for i, pts in enumerate(data['f1']):
for j, pt in enumerate(pts):
if tuple(pt) not in idx:
idx[tuple(pt)] = len(idx)
points.append(tuple(pt))
polys[i, j] = idx[tuple(pt)]

return np.array(idx.keys()), polys
return np.array(points), polys

@cython.boundscheck(False)
def read_vtk(str filename):
Expand Down
2 changes: 1 addition & 1 deletion cortex/mapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __call__(self, data):
right = right[..., self.idxmap[1]]
return left, right

volume = data.volume
volume = np.ascontiguousarray(data.volume)
volume.shape = len(volume), -1
volume = volume.T

Expand Down
4 changes: 4 additions & 0 deletions cortex/mapper/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def collapse(j, data):

def nearest(coords, shape, **kwargs):
valid = ~(np.isnan(coords).all(1))
valid = np.logical_and(valid, np.logical_and(coords[:,0] > -.5, coords[:,0] < shape[2]+.5))
valid = np.logical_and(valid, np.logical_and(coords[:,1] > -.5, coords[:,1] < shape[1]+.5))
valid = np.logical_and(valid, np.logical_and(coords[:,2] > -.5, coords[:,2] < shape[0]+.5))

rcoords = coords[valid].round().astype(int)
j = np.ravel_multi_index(rcoords.T[::-1], shape, mode='clip')
#return np.nonzero(valid)[0], j, (rcoords > 0).all(1) #np.ones((valid.sum(),))
Expand Down
17 changes: 10 additions & 7 deletions cortex/quickflat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def make_figure(braindata, recache=False, pixelwise=True, thick=32, sampler='nea
with_dropout=False, with_curvature=False, extra_disp=None,
linewidth=None, linecolor=None, roifill=None, shadow=None,
labelsize=None, labelcolor=None, cutout=None, cvmin=None,
cvmax=None, cvthr=None, fig=None, extra_hatch=None, **kwargs):
cvmax=None, cvthr=None, fig=None, extra_hatch=None,
colorbar_ticks=None, **kwargs):
"""Show a Volume or Vertex on a flatmap with matplotlib. Additional kwargs are passed on to
matplotlib's imshow command.
Expand Down Expand Up @@ -134,7 +135,7 @@ def make_figure(braindata, recache=False, pixelwise=True, thick=32, sampler='nea
iy,ix = ((0,-1),(0,-1))

if with_curvature:
curv,ee = make(db.get_surfinfo(dataview.subject))
curv,ee = make(db.get_surfinfo(dataview.subject),recache=recache)
if cutout: curv[co==0] = np.nan
axcv = fig.add_axes((0,0,1,1))
# Option to use thresholded curvature
Expand Down Expand Up @@ -188,9 +189,10 @@ def make_figure(braindata, recache=False, pixelwise=True, thick=32, sampler='nea
ax.set_ylim(extents[2], extents[3])


if with_colorbar:
if with_colorbar and not isinstance(dataview, dataset.Volume2D):
cbar = fig.add_axes((.4, .07, .2, .04))
fig.colorbar(cimg, cax=cbar, orientation='horizontal')
fig.colorbar(cimg, cax=cbar, orientation='horizontal',
ticks=colorbar_ticks)

if with_dropout is not False:
if isinstance(with_dropout, dataset.Dataview):
Expand Down Expand Up @@ -262,7 +264,7 @@ def make_figure(braindata, recache=False, pixelwise=True, thick=32, sampler='nea
svgfile=svgfile)
overlays.append(disp)
for oo in overlays:
roitex = oo.get_texture(height, labels=with_labels)
roitex = oo.get_texture(height, labels=with_labels, size=labelsize)
roitex.seek(0)
oax = fig.add_axes((0,0,1,1))
roi_im = plt.imread(roitex)
Expand Down Expand Up @@ -342,7 +344,8 @@ def make_png(fname, braindata, recache=False, pixelwise=True, sampler='nearest',
fig.savefig(fname, transparent=True, dpi=dpi)
else:
fig.savefig(fname, facecolor=bgcolor, transparent=False, dpi=dpi)
plt.close()
fig.clf()
plt.close(fig)

def make_svg(fname, braindata, recache=False, pixelwise=True, sampler='nearest', height=1024, thick=32, depth=0.5, **kwargs):
dataview = dataset.normalize(braindata)
Expand Down Expand Up @@ -532,7 +535,7 @@ def _make_hatch_image(dropout_data, height, sampler):
hatchpat = (hx+hy)%(2*hatchspace) < 2
hatchpat = np.logical_or(hatchpat, hatchpat[:,::-1]).astype(float)
hatchim = np.dstack([1-hatchpat]*3 + [hatchpat])
hatchim[:,:,3] *= (dmap>0.5).astype(float)
hatchim[:,:,3] *= np.clip(dmap, 0, 1).astype(float)

return hatchim

Expand Down
2 changes: 1 addition & 1 deletion cortex/webgl/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def makeMovie(self, animation, filename="brainmovie%07d.png", offset=0,
for i, sec in enumerate(np.arange(0, anim[-1][1]['idx']+1./fps, 1./fps)):
for start, end in anim:
if start['idx'] < sec <= end['idx']:
idx = (sec - start['idx']) / (end['idx'] - start['idx'])
idx = (sec - start['idx']) / float(end['idx'] - start['idx'])
if start['state'] == 'frame':
func = mixes['linear']
else:
Expand Down
9 changes: 8 additions & 1 deletion cortex/xfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def from_fsl(cls, xfm, func_nii, anat_nii):
----------
xfm : array
4x4 transformation matrix, loaded from an FSL .mat file, for a transform computed
FROM the func_nii volume TO the anat_nii volume.
FROM the func_nii volume TO the anat_nii volume. Alternatively, a string file name
for the FSL .mat file.
anat_nii : str or nibabel.Nifti1Image
nibabel image object (or path to nibabel-readable image) for anatomical volume from
which cortical surface was created
Expand All @@ -99,6 +100,12 @@ def from_fsl(cls, xfm, func_nii, anat_nii):
import numpy.linalg as npl
inv = npl.inv

# Load transform from text file, if string is provided
if isinstance(xfm,(str,unicode)):
with open(xfm,'r') as fid:
L = fid.readlines()
xfm = np.array([[np.float(s) for s in ll.split() if s] for ll in L])

# Internally, pycortex computes the OPPOSITE transform: from anatomical volume to functional volume.
# Thus, assign anat to "infile" (starting point for transform)
infile = anat_nii
Expand Down
Binary file added filestore/colormaps/autumn_blkmin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added filestore/colormaps/autumn_blkmin_alpha_2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 98c71d6

Please sign in to comment.