Skip to content

Merge latest from gallantlab #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e07b603
fixed css relative path to minicolors sprite
Oct 27, 2014
0b9ae05
reverting bug I introduced, woops
alexhuth Nov 1, 2014
8f2ab43
Merge pull request #115 from infocortex/fix_minicolors
jamesgao Nov 4, 2014
d0024b9
added fa reference to surface_gradient()
sslivkoff Nov 4, 2014
e5cf7f3
refactored hatch overlay code in quickflat, added option for extra_hatch
alexhuth Nov 5, 2014
3fd1b9e
updated quickflat docstring
alexhuth Nov 5, 2014
484ae69
BF: fixed roi line opacity
alexhuth Nov 5, 2014
649979c
fixed some bugs, but more to go..?
alexhuth Nov 5, 2014
6c203f4
Fixed non-existent normalization for raw (RGB) volumes, small steps t…
marklescroart Nov 5, 2014
0fd3086
Merge branch 'master' of https://github.com/gallantlab/pycortex w/ ad…
marklescroart Nov 5, 2014
4906f5f
made html asset embedding a configurable option for make_static()
infocortex Nov 5, 2014
875a3f3
fixed vmin/vmax for VertexRGB
alexhuth Nov 5, 2014
1c5efa4
made copying of ctm content to static view dir optional
infocortex Nov 6, 2014
a0166cd
Merge branch 'master' of https://github.com/gallantlab/pycortex into …
infocortex Nov 9, 2014
c8e6db1
fix 2d colormap mapping
Nov 11, 2014
2d36e4e
New colormap: Blue to Green
marklescroart Nov 13, 2014
68ee2cd
Merge branch 'master' of github.com:gallantlab/pycortex
Nov 15, 2014
08dad9e
minor 2d colormap fix
anwarnunez Nov 15, 2014
834ae13
Add a read_stl function to formats
Nov 15, 2014
05450a2
minor edit
Nov 15, 2014
4bedcbc
Merge pull request #116 from infocortex/enh/static_options
jamesgao Dec 1, 2014
ac0acb3
Merge branch 'master' of github.com:gallantlab/pycortex
Dec 4, 2014
5bf0384
add bbr options
jamesgao Dec 8, 2014
406fc35
Updated gitignore to correctly exclude formats.c, openctm.c
marklescroart Mar 6, 2015
6bb57ff
Merge branch 'master' of https://github.com/gallantlab/pycortex
marklescroart Mar 6, 2015
ea1781f
Merge in vertexdata fix
jamesgao Mar 11, 2015
e22555c
Merge branch 'master' of https://github.com/gallantlab/pycortex
marklescroart Mar 11, 2015
7471c10
Why is openctm.c still tracked?
jamesgao Mar 11, 2015
0532445
Addition of a few 2D colormaps, update of help to db.get_surfinfo()
marklescroart Mar 12, 2015
5befcd5
Merge branch 'master' of https://github.com/gallantlab/pycortex
marklescroart Mar 12, 2015
a4bb9cd
Merge with addition of colormaps, addition of help fo realz
marklescroart Mar 12, 2015
f4f2fe9
Add colorbar ticks for quickflat
jamesgao Apr 7, 2015
7233679
Merge branch 'master' of github.com:jamesgao/pycortex
jamesgao Apr 7, 2015
d2d207c
New colormaps
marklescroart Apr 14, 2015
e73efed
Merge branch 'master' of https://github.com/gallantlab/pycortex
marklescroart Apr 14, 2015
7558ef4
made non-binary dropout (and other hatch) maps possible
alexhuth Apr 14, 2015
110bc6e
Merge branch 'master' of https://github.com/gallantlab/pycortex
alexhuth Apr 14, 2015
589746d
fix: memory issue in quickflat figures
anwarnunez Apr 18, 2015
e5a0eb0
Merge branch 'master' of https://github.com/jamesgao/pycortex
anwarnunez Apr 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ scripts

# C extensions
*.so
cortex/formats.c
cortex/openctm.c

# Packages
*.egg
Expand Down
13 changes: 7 additions & 6 deletions cortex/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def save_callback(aligner):

return m

def automatic(subject, xfmname, reference, noclean=False):
def automatic(subject, xfmname, reference, noclean=False, bbrtype="signed"):
"""Create an automatic alignment using the FLIRT boundary-based alignment (BBR) from FSL.

If `noclean`, intermediate files will not be removed from /tmp. The `reference` image and resulting
Expand Down Expand Up @@ -121,16 +121,17 @@ def automatic(subject, xfmname, reference, noclean=False):
raw = db.get_anat(subject, type='raw').get_filename()
bet = db.get_anat(subject, type='brainmask').get_filename()
wmseg = db.get_anat(subject, type='whitematter').get_filename()
# Compute anatomical-to-epi transform
#Compute anatomical-to-epi transform
print('FLIRT pre-alignment')
cmd = '{fslpre}flirt -in {epi} -ref {bet} -dof 6 -omat {cache}/init.mat'.format(
fslpre=fsl_prefix, cache=cache, epi=absreference, bet=bet)
fslpre=fsl_prefix, cache=cache, epi=absreference, bet=bet)
if sp.call(cmd, shell=True) != 0:
raise IOError('Error calling initial FLIRT')
raise IOError('Error calling initial FLIRT')

print('Running BBR')
# Run epi-to-anat transform (this is more stable than anat-to-epi in FSL!)
cmd = '{fslpre}flirt -in {epi} -ref {raw} -dof 6 -cost bbr -wmseg {wmseg} -init {cache}/init.mat -omat {cache}/out.mat -schedule {schfile}'
cmd = cmd.format(fslpre=fsl_prefix, cache=cache, raw=raw, wmseg=wmseg, epi=absreference, schfile=schfile)
cmd = '{fslpre}flirt -in {epi} -ref {raw} -dof 6 -cost bbr -wmseg {wmseg} -init {cache}/init.mat -omat {cache}/out.mat -schedule {schfile} -bbrtype {bbrtype}'
cmd = cmd.format(fslpre=fsl_prefix, cache=cache, raw=bet, wmseg=wmseg, epi=absreference, schfile=schfile, bbrtype=bbrtype)
if sp.call(cmd, shell=True) != 0:
raise IOError('Error calling BBR flirt')

Expand Down
3 changes: 3 additions & 0 deletions cortex/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ def get_surfinfo(self, subject, type="curvature", recache=False, **kwargs):
-------
verts : Vertex class
If the surface information has "left" and "right" entries, a Vertex class is returned

- OR -

npz : npzfile
Otherwise, an npz object is returned. Remember to close it!
"""
Expand Down
13 changes: 6 additions & 7 deletions cortex/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Module for maintaining brain data and their masks

Three basic classes, with child classes:
Four basic classes:
1. Dataset
2. BrainData
a. VolumeData
b. VertexData
3. View
a. DataView
2. Volume/Vertex
3. VolumeRGB/VertexRGB
4. Volume2D/Vertex2D

Dataset holds a collection of View and BrainData objects. It provides a thin
wrapper around h5py to store data. Datasets will store all View and BrainData
Expand Down Expand Up @@ -93,7 +91,8 @@ def from_file(cls, filename):
try:
ds.views[name] = Dataview.from_hdf(node)
except:
warnings.warn("Could not load view '%s'"%node.name)
import traceback
traceback.print_exc()

db.auxfile = None

Expand Down
27 changes: 21 additions & 6 deletions cortex/dataset/braindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def to_json(self, simple=False):
subject=self.subject,
min=float(np.nan_to_num(self.data).min()),
max=float(np.nan_to_num(self.data).max()),
shape=self.shape))
))
return sdict

@classmethod
Expand Down Expand Up @@ -112,7 +112,9 @@ def __init__(self, data, subject, xfmname, mask=None, **kwargs):

def to_json(self, simple=False):
if simple:
return super(VolumeData, self).to_json(simple=simple)
sdict = super(VolumeData, self).to_json(simple=simple)
sdict["shape"] = self.shape
return sdict

xfm = db.get_xfm(self.subject, self.xfmname, 'coord').xfm
sdict = dict(xfm=[list(np.array(xfm).ravel())], data=[self.name])
Expand Down Expand Up @@ -201,9 +203,10 @@ def volume(self):
def save(self, filename, name=None):
"""Save the dataset into an hdf file with the provided name
"""
import os
if isinstance(filename, str):
fname, ext = os.path.splitext(filename)
if ext in (".hdf", ".h5"):
if ext in (".hdf", ".h5",".hf5"):
h5 = h5py.File(filename, "a")
self._write_hdf(h5, name=name)
h5.close()
Expand Down Expand Up @@ -331,6 +334,16 @@ def __getitem__(self, idx):
#return VertexData(self.data[idx], self.subject, **self.attrs)
return self.copy(self.data[idx])

def to_json(self, simple=False):
if simple:
sdict = dict(split=self.llen, frames=self.vertices.shape[0])
sdict.update(super(VertexData, self).to_json(simple=simple))
return sdict

sdict = dict(data=[self.name])
sdict.update(super(VertexData, self).to_json())
return sdict

@property
def vertices(self):
verts = self.data
Expand Down Expand Up @@ -378,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
8 changes: 5 additions & 3 deletions cortex/dataset/view2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def raw(self):
if self.dim1.xfmname != self.dim2.xfmname:
raise ValueError("Both Volumes must have same xfmname to generate single raw volume")

if self.dim1.linear and self.dim2.linear and self.dim1.mask == self.dim2.mask:
if ((self.dim1.linear and self.dim2.linear) and
(self.dim1.mask.shape == self.dim2.mask.shape) and
np.all(self.dim1.mask == self.dim2.mask)):
r, g, b, a = self._to_raw(self.dim1.data, self.dim2.data)
else:
r, g, b, a = self._to_raw(self.dim1.volume, self.dim2.volume)
Expand All @@ -128,7 +130,7 @@ def raw(self):
def xfmname(self):
return self.dim1.xfmname

class Vertex2D(Dataview):
class Vertex2D(Dataview2D):
_cls = VertexData
def __init__(self, dim1, dim2, subject=None, description="", cmap=None,
vmin=None, vmax=None, vmin2=None, vmax2=None, **kwargs):
Expand All @@ -155,4 +157,4 @@ def __repr__(self):
@property
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)
return VertexRGB(r, g, b, alpha=a, subject=self.dim1.subject)
20 changes: 14 additions & 6 deletions cortex/dataset/viewRGB.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,21 @@ def vertices(self):

verts = []
for dv in (self.red, self.green, self.blue, alpha):
vert = dv.vertices
vert = dv.vertices.copy()
if vert.dtype != np.uint8:
if vert.min() < 0:
vert -= vert.min()
if vert.max() > 1:
vert /= vert.max()
vert = (vert * 255).astype(np.uint8)
if dv.vmin is None:
if vert.min() < 0:
vert -= vert.min()
else:
vert -= dv.vmin

if dv.vmax is None:
if vert.max() > 1:
vert /= vert.max()
else:
vert /= dv.vmax - dv.vmin

vert = (np.clip(vert, 0, 1) * 255).astype(np.uint8)
verts.append(vert)

return np.array(verts).transpose([1, 2, 0])
Expand Down
10 changes: 8 additions & 2 deletions cortex/dataset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,14 @@ def raw(self):
cm.register_cmap(self.cmap,cmap)
else:
cmap = cm.get_cmap(self.cmap)
norm = colors.Normalize(self.vmin, self.vmax) # Does this do anything?
return np.rollaxis(cmap(self.data), -1)
elif isinstance(self.cmap,colors.Colormap):
cmap = self.cmap
# Normalize colors according to vmin, vmax
norm = colors.Normalize(self.vmin, self.vmax)
cmapper = cm.ScalarMappable(norm=norm, cmap=cmap)
color_data = cmapper.to_rgba(self.data.flatten()).reshape(self.data.shape+(4,))
# rollaxis puts the last color dimension first, to allow output of separate channels: r,g,b,a = dataset.raw
return np.rollaxis(color_data, -1)

class Multiview(Dataview):
def __init__(self, views, description=""):
Expand Down
Loading