Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 1 addition & 6 deletions cortex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
pass

# Create deprecated interface for database
class dep(object):
class dep:
def __getattr__(self, name):
warnings.warn("cortex.surfs is deprecated, use cortex.db instead", Warning)
return getattr(db, name)
Expand All @@ -41,8 +41,3 @@ def __dir__(self):
surfs = dep()

import sys
if sys.version_info < (3,):
stdout = sys.stdout
reload(sys)
sys.setdefaultencoding('utf8')
sys.stdout = stdout
1 change: 0 additions & 1 deletion cortex/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import subprocess as sp
import tempfile
import warnings
from builtins import input

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion cortex/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def user_log_dir(appname, appauthor=None, version=None, opinion=True):
return path


class AppDirs(object):
class AppDirs:
"""Convenience wrapper for getting application dirs."""
def __init__(self, appname, appauthor, version=None, roaming=False):
self.appname = appname
Expand Down
10 changes: 5 additions & 5 deletions cortex/brainctm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from . import polyutils
from .openctm import CTMfile

class BrainCTM(object):
class BrainCTM:
def __init__(self, subject, decimate=False):
self.subject = subject
self.types = []
Expand Down Expand Up @@ -196,7 +196,7 @@ def save(self, path, method='mg2', external_svg=None,
fp.write(svg.toxml())
return ptmap

class Hemi(object):
class Hemi:
def __init__(self, pts, polys, norms=None):
self.tf = tempfile.NamedTemporaryFile()
self.tf.name = bytes(self.tf.name, 'ascii')
Expand Down Expand Up @@ -258,16 +258,16 @@ def __init__(self, pts, polys, fpolys, pia=None):
idxmap[mask] = np.arange(mask.sum()).astype(np.uint32)
#norms = polyutils.Surface(pts, polys).normals[mask]
basepts = pts[mask] if pia is None else pia[mask]
super(DecimatedHemi, self).__init__(basepts, idxmap[allpolys])
super().__init__(basepts, idxmap[allpolys])
self.aux[idxmap[mwidx], 0] = 1
self.mask = mask
self.idxmap = idxmap

def setFlat(self, pts):
super(DecimatedHemi, self).setFlat(pts[self.mask])
super().setFlat(pts[self.mask])

def addSurf(self, pts, **kwargs):
super(DecimatedHemi, self).addSurf(pts[self.mask], **kwargs)
super().addSurf(pts[self.mask], **kwargs)

def make_pack(outfile, subj, types=("inflated",), method='raw', level=0,
decimate=False, disp_layers=['rois'],
Expand Down
19 changes: 9 additions & 10 deletions cortex/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import shutil
import tempfile
import warnings
from builtins import input
from hashlib import sha1

import numpy as np
Expand All @@ -33,7 +32,7 @@ def memofn(self, *args, **kwargs):

return memofn

class SubjectDB(object):
class SubjectDB:
def __init__(self, subj, filestore=default_filestore):
self.subject = subj
self._warning = None
Expand Down Expand Up @@ -61,7 +60,7 @@ def surfaces(self):
self._surfaces = SurfaceDB(self.subject, filestore=self.filestore)
return self._surfaces

class SurfaceDB(object):
class SurfaceDB:
def __init__(self, subj, filestore=default_filestore):
self.subject = subj
self.types = {}
Expand All @@ -80,7 +79,7 @@ def __getattr__(self, attr):
return self.types[attr]
raise AttributeError(attr)

class Surf(object):
class Surf:
def __init__(self, subject, surftype, filestore=default_filestore):
self.subject, self.surftype = subject, surftype
self.db = Database(filestore)
Expand All @@ -93,7 +92,7 @@ def show(self, hemisphere="both"):
pts, polys = self.db.get_surf(self.subject, self.surftype, hemisphere, merge=True, nudge=True)
return mlab.triangular_mesh(pts[:,0], pts[:,1], pts[:,2], polys)

class XfmDB(object):
class XfmDB:
def __init__(self, subj, filestore=default_filestore):
self.subject = subj
self.filestore = filestore
Expand All @@ -108,7 +107,7 @@ def __repr__(self):
xfms = "\n".join(sorted(self.xfms))
return f"Available transforms for {self.subject}:\n{xfms}"

class XfmSet(object):
class XfmSet:
def __init__(self, subj, name, filestore=default_filestore):
self.subject = subj
self.name = name
Expand All @@ -126,13 +125,13 @@ def __getattr__(self, attr):
def __repr__(self):
return "Types: {types}".format(types=", ".join(self._jsdat.keys()))

class MaskSet(object):
class MaskSet:
def __init__(self, subj, name, filestore=default_filestore):
self.subject = subj
self.xfmname = name
maskform = Database(filestore).get_paths(subj)['masks']
maskpath = maskform.format(xfmname=name, type='*')
self._masks = dict((os.path.split(path)[1][5:-7], path) for path in glob.glob(maskpath))
self._masks = {os.path.split(path)[1][5:-7]: path for path in glob.glob(maskpath)}

def __getitem__(self, item):
import nibabel
Expand All @@ -141,7 +140,7 @@ def __getitem__(self, item):
def __repr__(self):
return "Masks: [{types}]".format(types=', '.join(self._masks.keys()))

class Database(object):
class Database:
"""
Database()

Expand Down Expand Up @@ -180,7 +179,7 @@ def subjects(self):
subjs = os.listdir(os.path.join(self.filestore))
subjs = [s for s in subjs if os.path.isdir(os.path.join(self.filestore, s))]
subjs = sorted(subjs)
self._subjects = dict([(sname, SubjectDB(sname, filestore=self.filestore)) for sname in subjs])
self._subjects = {sname: SubjectDB(sname, filestore=self.filestore) for sname in subjs}
return self._subjects

def reload_subjects(self):
Expand Down
31 changes: 14 additions & 17 deletions cortex/dataset/braindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..database import db


class BrainData(object):
class BrainData:
"""
Abstract base class for brain data.

Expand All @@ -38,7 +38,7 @@ def __init__(self, data: Union[npt.NDArray, str], subject: str, **kwargs):
except NameError:
subject = subject if isinstance(subject, str) else subject.decode('utf-8')
self.subject = subject
super(BrainData, self).__init__(**kwargs)
super().__init__(**kwargs)

@property
def data(self):
Expand Down Expand Up @@ -86,7 +86,7 @@ def _write_hdf(self, h5, name=None):
def to_json(self, simple=False):
"""Creates JSON description of this brain data.
"""
sdict = super(BrainData, self).to_json(simple=simple)
sdict = super().to_json(simple=simple)
if simple:
sdict.update(dict(name=self.name,
subject=self.subject,
Expand Down Expand Up @@ -144,11 +144,8 @@ class VolumeData(BrainData):
def __init__(self, data: npt.NDArray, subject: str, xfmname: str, mask: Optional[npt.NDArray]=None, **kwargs):
if self.__class__ == VolumeData:
raise TypeError('Cannot directly instantiate VolumeData objects')
super(VolumeData, self).__init__(data, subject, **kwargs)
try:
basestring
except NameError:
xfmname = xfmname if isinstance(xfmname, str) else xfmname.decode('utf-8')
super().__init__(data, subject, **kwargs)
xfmname = xfmname if isinstance(xfmname, str) else xfmname.decode('utf-8')
self.xfmname = xfmname

self._check_size(mask)
Expand All @@ -158,13 +155,13 @@ def to_json(self, simple: bool=False):
"""Creates JSON description of this brain data.
"""
if simple:
sdict = super(VolumeData, self).to_json(simple=simple)
sdict = super().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])
sdict.update(super(VolumeData, self).to_json())
sdict.update(super().to_json())
return sdict

@classmethod
Expand Down Expand Up @@ -288,7 +285,7 @@ def __repr__(self):
return "<%s data for (%s, %s)>"%(maskstr, self.subject, self.xfmname)

def copy(self, data):
return super(VolumeData, self).copy(data, self.subject, self.xfmname, mask=self._mask)
return super().copy(data, self.subject, self.xfmname, mask=self._mask)

@property
def volume(self):
Expand Down Expand Up @@ -321,8 +318,8 @@ def save(self, filename, name=None):
elif isinstance(filename, h5py.Group):
self._write_hdf(filename, name=name)

def _write_hdf(self, h5, name=None):
node = super(VolumeData, self)._write_hdf(h5, name=name)
def _write_hdf(self, h5: Union[h5py.File, h5py.Group], name: Optional[str]=None) -> h5py.Dataset:
node = super()._write_hdf(h5, name=name)

#write the mask into the file, as necessary
if self._mask is not None:
Expand Down Expand Up @@ -367,7 +364,7 @@ class VertexData(BrainData):
def __init__(self, data: npt.NDArray, subject: str, **kwargs):
if self.__class__ == VertexData:
raise TypeError('Cannot directly instantiate VertexData objects')
super(VertexData, self).__init__(data, subject, **kwargs)
super().__init__(data, subject, **kwargs)
try:
left, right = db.get_surf(self.subject, "wm")
except IOError:
Expand Down Expand Up @@ -469,7 +466,7 @@ def copy(self, data: npt.NDArray) -> Self:
it doesn't require reloading the surfaces from the database to check
numbers of vertices, etc.
"""
return super(VertexData, self).copy(data, self.subject)
return super().copy(data, self.subject)

def volume(self, xfmname, projection='nearest', **kwargs):
"""
Expand Down Expand Up @@ -518,11 +515,11 @@ def __getitem__(self, idx):
def to_json(self, simple: bool = False):
if simple:
sdict = dict(split=self.llen, frames=self.vertices.shape[0])
sdict.update(super(VertexData, self).to_json(simple=simple))
sdict.update(super().to_json(simple=simple))
return sdict

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

@property
Expand Down
2 changes: 1 addition & 1 deletion cortex/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .views import normalize as _vnorm
from .views import Dataview, Vertex, Volume, _from_hdf_data

class Dataset(object):
class Dataset:
"""
Wrapper for multiple data objects. This often does not need to be used
explicitly--for example, if a dictionary of data objects is passed to
Expand Down
6 changes: 3 additions & 3 deletions cortex/dataset/view2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ def __init__(self, dim1: Union[npt.NDArray, Volume], dim2: Union[npt.NDArray, Vo
vmax = self.dim1.vmax if vmax is None else vmax
vmax2 = self.dim2.vmax if vmax2 is None else vmax2

super(Volume2D, self).__init__(description=description, cmap=cmap, vmin=vmin,
super().__init__(description=description, cmap=cmap, vmin=vmin,
vmax=vmax, vmin2=vmin2, vmax2=vmax2, **kwargs)

def __repr__(self):
return "<2D volumetric data for (%s, %s)>"%(self.dim1.subject, self.dim1.xfmname)

def _write_hdf(self, h5, name="data"):
viewnode = super(Volume2D, self)._write_hdf(h5, name)
viewnode = super()._write_hdf(h5, name)
viewnode[7] = json.dumps([[self.dim1.xfmname, self.dim2.xfmname]])
return viewnode

Expand Down Expand Up @@ -267,7 +267,7 @@ def __init__(self, dim1: Union[npt.NDArray, Vertex], dim2: Union[npt.NDArray, Ve
vmax = self.dim1.vmax if vmax is None else vmax
vmax2 = self.dim2.vmax if vmax2 is None else vmax2

super(Vertex2D, self).__init__(description=description, cmap=cmap,
super().__init__(description=description, cmap=cmap,
vmin=vmin, vmax=vmax, vmin2=vmin2,
vmax2=vmax2, **kwargs)

Expand Down
12 changes: 6 additions & 6 deletions cortex/dataset/viewRGB.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _write_hdf(self, h5, name="data", xfmname=None):
return viewnode

def to_json(self, simple=False):
sdict = super(DataviewRGB, self).to_json(simple=simple)
sdict = super().to_json(simple=simple)

if simple:
sdict["name"] = self.name
Expand Down Expand Up @@ -558,7 +558,7 @@ def __init__(
else:
raise ValueError("Cannot handle different transforms per volume")

super(VolumeRGB, self).__init__(
super().__init__(
subject, alpha, description=description, state=state, priority=priority
)

Expand Down Expand Up @@ -591,7 +591,7 @@ def alpha(self, alpha: Optional[Union[npt.NDArray, Volume]]):
self._alpha = alpha

def to_json(self, simple=False):
sdict = super(VolumeRGB, self).to_json(simple=simple)
sdict = super().to_json(simple=simple)
if simple:
sdict["shape"] = self.red.shape
else:
Expand Down Expand Up @@ -647,7 +647,7 @@ def name(self):
return "__%s" % _hash(self.volume)[:16]

def _write_hdf(self, h5, name="data"):
return super(VolumeRGB, self)._write_hdf(h5, name=name, xfmname=[self.xfmname])
return super()._write_hdf(h5, name=name, xfmname=[self.xfmname])

@property
def raw(self):
Expand Down Expand Up @@ -834,7 +834,7 @@ def __init__(
self.blue = Vertex(b, subject)
self.alpha = alpha

super(VertexRGB, self).__init__(
super().__init__(
subject, alpha, description=description, state=state, priority=priority
)

Expand Down Expand Up @@ -894,7 +894,7 @@ def vertices(self):
return np.array(verts).transpose([1, 2, 0])

def to_json(self, simple=False):
sdict = super(VertexRGB, self).to_json(simple=simple)
sdict = super().to_json(simple=simple)

if simple:
sdict.update(dict(split=self.red.llen, frames=self.vertices.shape[0]))
Expand Down
Loading