Skip to content

Commit

Permalink
more import defers, maybe fix python3 errors?
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgao committed Feb 7, 2018
1 parent 974c986 commit 9dc7861
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cortex/anat.py
Expand Up @@ -5,7 +5,6 @@
import subprocess as sp

import numpy as np
import nibabel

#from . import utils
from .database import db
Expand All @@ -28,6 +27,7 @@ def whitematter(outfile, subject, do_voxelize=False):
else:
voxelize(outfile, subject, surf="wm")
except IOError:
import nibabel
bet = db.get_anat(subject, type='brainmask').get_filename()
try:
cache = tempfile.mkdtemp()
Expand Down Expand Up @@ -56,6 +56,7 @@ def whitematter(outfile, subject, do_voxelize=False):

def voxelize(outfile, subject, surf='wm', mp=True):
'''Voxelize the whitematter surface to generate the white matter mask'''
import nibabel
from . import polyutils
nib = db.get_anat(subject, "raw")
shape = nib.get_shape()
Expand Down
2 changes: 1 addition & 1 deletion cortex/dataset/views.py
Expand Up @@ -125,7 +125,7 @@ def to_json(self, simple=False):
sdict = dict(
state=self.state,
attrs=self.attrs.copy(),
desc=self.description)
desc=self.description.decode())
try:
sdict.update(dict(
cmap=[self.cmap],
Expand Down
6 changes: 3 additions & 3 deletions cortex/openctm.pyx
Expand Up @@ -28,7 +28,7 @@ attrmaps = [
cdef class CTMfile:
cdef CTMcontext ctx

cdef public bytes filename
cdef public object filename
cdef public str mode

cdef unsigned int length
Expand All @@ -38,7 +38,7 @@ cdef class CTMfile:
cdef public dict attribs
cdef public dict uvs

def __cinit__(self, bytes filename, str mode='r'):
def __cinit__(self, object filename, str mode='r'):
cdef openctm.CTMenum err
cdef char* name
self.filename = filename
Expand Down Expand Up @@ -145,7 +145,7 @@ cdef class CTMfile:

return pts, polys, norms

def save(self, str method='mg2', int level=9):
def save(self, method='mg2', int level=9):
cdef char* cname = NULL
cdef float* cnorms = NULL
cdef openctm.CTMenum err
Expand Down
6 changes: 5 additions & 1 deletion cortex/quickflat/composite.py
Expand Up @@ -3,7 +3,6 @@
from .. import dataset
from ..database import db
from ..options import config
from ..svgoverlay import get_overlay
from .utils import _get_height, _get_extents, _convert_svg_kwargs, _has_cmap, _get_images, _parse_defaults
from .utils import make_flatmap_image, _make_hatch_image

Expand Down Expand Up @@ -194,6 +193,7 @@ def add_rois(fig, dataview, extents=None, height=None, with_labels=True, roi_lis
img : matplotlib.image.AxesImage
matplotlib axes image object for plotted data
"""
from ..svgoverlay import get_overlay
if extents is None:
extents = _get_extents(fig)
if height is None:
Expand Down Expand Up @@ -240,6 +240,7 @@ def add_sulci(fig, dataview, extents=None, height=1024, with_labels=True, **kwar
img : matplotlib.image.AxesImage
matplotlib axes image object for plotted data
"""
from ..svgoverlay import get_overlay
svgobject = db.get_overlay(dataview.subject)
svg_kws = _convert_svg_kwargs(kwargs)
layer_kws = _parse_defaults('sulci_paths')
Expand Down Expand Up @@ -292,6 +293,7 @@ def add_hatch(fig, hatch_data, extents=None, height=None, hatch_space=4, hatch_c
-----
Possibly to add: add hatch_width, hatch_offset arguments.
"""
from ..svgoverlay import get_overlay
if extents is None:
extents = _get_extents(fig)
if height is None:
Expand Down Expand Up @@ -370,6 +372,7 @@ def add_custom(fig, dataview, svgfile, layer, extents=None, height=None, with_la
matplotlib axes image object for plotted data
"""
from ..svgoverlay import get_overlay
if height is None:
height = _get_height(fig)
if extents is None:
Expand Down Expand Up @@ -417,6 +420,7 @@ def add_cutout(fig, name, dataview, layers=None, height=None, extents=None):
-------
"""
from ..svgoverlay import get_overlay
if layers is None:
layers = _get_images(fig)
if height is None:
Expand Down
1 change: 0 additions & 1 deletion cortex/quickflat/utils.py
Expand Up @@ -11,7 +11,6 @@
from .. import dataset
from ..database import db
from ..options import config
from ..svgoverlay import get_overlay


def make_flatmap_image(braindata, height=1024, recache=False, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion cortex/utils.py
Expand Up @@ -11,7 +11,6 @@
from .database import db
from .volume import anat2epispace
from .options import config
from .freesurfer import fs_aseg_dict

class DocLoader(object):
def __init__(self, func, mod, package):
Expand Down Expand Up @@ -416,6 +415,7 @@ def get_aseg_mask(subject, aseg_name, xfmname=None, order=1, threshold=None, **k
See also get_anat(subject, type='aseg')
"""
from .freesurfer import fs_aseg_dict
aseg = db.get_anat(subject, type="aseg").get_data().T

if not isinstance(aseg_name, (list, tuple)):
Expand Down

0 comments on commit 9dc7861

Please sign in to comment.