From f4f2fe942194d8af32cf00df9204e655659e8941 Mon Sep 17 00:00:00 2001 From: James Gao Date: Mon, 6 Apr 2015 20:41:40 -0700 Subject: [PATCH 01/10] Add colorbar ticks for quickflat --- cortex/dataset/braindata.py | 8 +++++--- cortex/quickflat.py | 8 +++++--- cortex/webgl/view.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cortex/dataset/braindata.py b/cortex/dataset/braindata.py index e277a0c5a..6338edc0b 100644 --- a/cortex/dataset/braindata.py +++ b/cortex/dataset/braindata.py @@ -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''' diff --git a/cortex/quickflat.py b/cortex/quickflat.py index 654568ca1..695d00322 100644 --- a/cortex/quickflat.py +++ b/cortex/quickflat.py @@ -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. @@ -190,7 +191,8 @@ def make_figure(braindata, recache=False, pixelwise=True, thick=32, sampler='nea if with_colorbar: 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): @@ -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) diff --git a/cortex/webgl/view.py b/cortex/webgl/view.py index 70c8ce38d..83db638b9 100755 --- a/cortex/webgl/view.py +++ b/cortex/webgl/view.py @@ -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: From d2d207c6222a0c697640fc976ec8f79179e8b53c Mon Sep 17 00:00:00 2001 From: MarkLescroart Date: Tue, 14 Apr 2015 08:57:11 -0700 Subject: [PATCH 02/10] New colormaps --- filestore/colormaps/autumn_blkmin.png | Bin 0 -> 133 bytes filestore/colormaps/autumn_blkmin_alpha_2D.png | Bin 0 -> 967 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 filestore/colormaps/autumn_blkmin.png create mode 100644 filestore/colormaps/autumn_blkmin_alpha_2D.png diff --git a/filestore/colormaps/autumn_blkmin.png b/filestore/colormaps/autumn_blkmin.png new file mode 100644 index 0000000000000000000000000000000000000000..5f6e8d4eb020533dc04cf60968f24ecf94f74e46 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K57&+L0q+w)1Igny0cJd720D>Bhlnx-Dv%n*= zn1O*m5ri36*e}ln3aWd$IEGmCCZ{AM{P;hAVq;^Xf*~^yTxR%G*x9R68FaPxmAu$5 Z#&3p9|9$R;cLTLBc)I$ztaD0e0stBOBLV;b literal 0 HcmV?d00001 diff --git a/filestore/colormaps/autumn_blkmin_alpha_2D.png b/filestore/colormaps/autumn_blkmin_alpha_2D.png new file mode 100644 index 0000000000000000000000000000000000000000..59c89fc3b4ef1f1bbddf0fb740a793cdd7ccde50 GIT binary patch literal 967 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6%N?Bp530R%N1DIGvQXMsm# zF#`jCA_z0CuwS0Zz`&g8>EaktG3V_a>n>(T0oH@&N$=`Ydi@lf!7wi*v1iZp~fae82v8gy>5Qn}qD4eNg5O~JHkjO+Fy2spL@Sf3OhB8A7Cvm8fpW)CRc80`01_3qV&@)>G zj?Z!oEtb^th#8~e88rnA6SEySjDem3+6SW00?k!{V>70^pGgTE@?j821NsU`q4_9H zkmJxB%+T4%)?y&c&~g(Pc0dX(+#*?;46ww(I-rYL7!tn$V+cs0#g14bSQJXZC82tN md@S0aiqU20tA~L>Q~qSj+taJfA`O5!k-^i|&t;ucLK6UOmF|52 literal 0 HcmV?d00001 From 7558ef48e4633b3fed0d3c4143f59ad1a552a9c8 Mon Sep 17 00:00:00 2001 From: Alex Huth Date: Tue, 14 Apr 2015 14:34:14 -0700 Subject: [PATCH 03/10] made non-binary dropout (and other hatch) maps possible --- cortex/quickflat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex/quickflat.py b/cortex/quickflat.py index 654568ca1..a4b7a4dcf 100644 --- a/cortex/quickflat.py +++ b/cortex/quickflat.py @@ -532,7 +532,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 From 589746d3659b0eec735bfaca78a659eb146a0d14 Mon Sep 17 00:00:00 2001 From: Anwar Nunez-Elizalde Date: Sat, 18 Apr 2015 02:12:31 -0700 Subject: [PATCH 04/10] fix: memory issue in quickflat figures --- cortex/quickflat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cortex/quickflat.py b/cortex/quickflat.py index 654568ca1..a7016fb31 100644 --- a/cortex/quickflat.py +++ b/cortex/quickflat.py @@ -342,7 +342,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) From 75c09c6028b630bdde1d22baee35942b15d470d0 Mon Sep 17 00:00:00 2001 From: Alex Huth Date: Mon, 8 Jun 2015 12:18:26 -0700 Subject: [PATCH 05/10] fixed issue with 2D vertex data, now works correctly in quickflat --- cortex/dataset/view2D.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cortex/dataset/view2D.py b/cortex/dataset/view2D.py index 93a824daa..38069d1e4 100644 --- a/cortex/dataset/view2D.py +++ b/cortex/dataset/view2D.py @@ -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 From 1ce189b8aef10c055732d2da1607526a458b362e Mon Sep 17 00:00:00 2001 From: Mark Lescroart Date: Wed, 17 Jun 2015 16:23:37 -0700 Subject: [PATCH 06/10] Fixed curvature underlay in quickflat to correctly recache if told to do so --- cortex/quickflat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex/quickflat.py b/cortex/quickflat.py index 0a50b6f0e..8b3c4a022 100644 --- a/cortex/quickflat.py +++ b/cortex/quickflat.py @@ -135,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 From a7b9e22012a5a9e1f71291b5cc342cb61f4c38ca Mon Sep 17 00:00:00 2001 From: Mark Lescroart Date: Wed, 24 Jun 2015 08:51:36 -0700 Subject: [PATCH 07/10] Small change to xfm.from_fsl, to allow input of a filename string (for a .mat file created by FSL) in the xfm input argument (4x4 transform matrices are still accepted, too) --- cortex/xfm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cortex/xfm.py b/cortex/xfm.py index 5386d6e03..6bc947563 100644 --- a/cortex/xfm.py +++ b/cortex/xfm.py @@ -99,6 +99,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 From 12830a9ce4ca1471aeb25a19917cc774ab35c470 Mon Sep 17 00:00:00 2001 From: Mark Lescroart Date: Wed, 24 Jun 2015 08:52:35 -0700 Subject: [PATCH 08/10] Updated docstring to reflect change, too --- cortex/xfm.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cortex/xfm.py b/cortex/xfm.py index 6bc947563..e3d5bad66 100644 --- a/cortex/xfm.py +++ b/cortex/xfm.py @@ -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 From f39381b89c437c8686ff49892e87dec44a65bd9c Mon Sep 17 00:00:00 2001 From: James Gao Date: Thu, 25 Jun 2015 18:34:09 -0700 Subject: [PATCH 09/10] Fix read_stl, limit nearest sampler to ignore outside voxels --- cortex/formats.pyx | 6 ++++-- cortex/mapper/__init__.py | 2 +- cortex/mapper/samplers.py | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cortex/formats.pyx b/cortex/formats.pyx index f1df7c08a..ec8ea5a21 100644 --- a/cortex/formats.pyx +++ b/cortex/formats.pyx @@ -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) @@ -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): diff --git a/cortex/mapper/__init__.py b/cortex/mapper/__init__.py index 32e1af6b3..da88908aa 100644 --- a/cortex/mapper/__init__.py +++ b/cortex/mapper/__init__.py @@ -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 diff --git a/cortex/mapper/samplers.py b/cortex/mapper/samplers.py index 23ca1f927..fbac57d7f 100644 --- a/cortex/mapper/samplers.py +++ b/cortex/mapper/samplers.py @@ -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(),)) From 934470d312f81f74414157c0534c9d6c414804a5 Mon Sep 17 00:00:00 2001 From: James Gao Date: Thu, 9 Jul 2015 15:27:25 -0700 Subject: [PATCH 10/10] Fix fatma's bug, no colorbar with 2d colormaps --- cortex/quickflat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex/quickflat.py b/cortex/quickflat.py index 8b3c4a022..0fd45bc6d 100644 --- a/cortex/quickflat.py +++ b/cortex/quickflat.py @@ -189,7 +189,7 @@ 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', ticks=colorbar_ticks)