Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, data, subject, **kwargs):
if self.__class__ == VertexData:
raise TypeError('Cannot directly instantiate VertexData objects')
super(VertexData, self).__init__(data, subject, **kwargs)
try:
left, right = db.get_surf(self.subject, "wm")
except IOError:
left, right = db.get_surf(self.subject, "fiducial")
self.llen = len(left[0])
self.rlen = len(right[0])
self._set_data(data)
def get_aligner(subject, xfmname, epifile=None, xfm=None, xfmtype="magnet", decimate=False):
from .database import db
dbxfm = None
try:
dbxfm = db.get_xfm(subject, xfmname, xfmtype='magnet')
epifile = dbxfm.reference.get_filename()
dbxfm = dbxfm.xfm
except IOError:
pass
try:
wpts, wpolys = db.get_surf(subject, 'wm', merge=True, nudge=False)
ppts, ppolys = db.get_surf(subject, 'pia', merge=True, nudge=False)
pts = np.vstack([wpts, ppts])
polys = np.vstack([wpolys, ppolys+len(wpts)])
except IOError:
pts, polys = db.get_surf(subject, 'fiducial', merge=True, nudge=False)
if decimate:
pts, polys = polyutils.decimate(pts, polys)
return Align(pts, polys, epifile, xfm=dbxfm if xfm is None else xfm, xfmtype=xfmtype)
max_dist : nonnegative float, optional
Limit computation to only voxels within `max_dist` mm of the surface.
Makes computation orders of magnitude faster for high-resolution
volumes.
Returns
-------
dist : ndarray
Distance (in mm) to the closest point on the surface
argdist : ndarray
Point index for the closest point
"""
from scipy.spatial import cKDTree
fiducial, polys = db.get_surf(subject, surface, merge=True)
xfm = db.get_xfm(subject, xfmname)
z, y, x = xfm.shape
idx = np.mgrid[:x, :y, :z].reshape(3, -1).T
mm = xfm.inv(idx)
tree = cKDTree(fiducial)
dist, argdist = tree.query(mm, distance_upper_bound=max_dist)
dist.shape = (x,y,z)
argdist.shape = (x,y,z)
return dist.T, argdist.T
def thickness(outfile, subject):
pl, pr = db.get_surf(subject, "pia")
wl, wr = db.get_surf(subject, "wm")
left = np.sqrt(((pl[0] - wl[0])**2).sum(1))
right = np.sqrt(((pr[0] - wr[0])**2).sum(1))
np.savez(outfile, left=left, right=right)
dbxfm = None
try:
dbxfm = db.get_xfm(subject, xfmname, xfmtype='magnet')
epifile = dbxfm.reference.get_filename()
dbxfm = dbxfm.xfm
except IOError:
pass
try:
wpts, wpolys = db.get_surf(subject, 'wm', merge=True, nudge=False)
ppts, ppolys = db.get_surf(subject, 'pia', merge=True, nudge=False)
pts = np.vstack([wpts, ppts])
polys = np.vstack([wpolys, ppolys+len(wpts)])
except IOError:
pts, polys = db.get_surf(subject, 'fiducial', merge=True, nudge=False)
if decimate:
pts, polys = polyutils.decimate(pts, polys)
return Align(pts, polys, epifile, xfm=dbxfm if xfm is None else xfm, xfmtype=xfmtype)
def _cache(cls, filename, subject, xfmname, **kwargs):
print('Caching mapper...')
from ..database import db
masks = []
xfm = db.get_xfm(subject, xfmname, xfmtype='coord')
fid = db.get_surf(subject, 'fiducial', merge=False, nudge=False)
try:
flat = db.get_surf(subject, 'flat', merge=False, nudge=False)
except IOError:
flat = fid
for (pts, _), (_, polys) in zip(fid, flat):
masks.append(cls._getmask(xfm(pts), polys, xfm.shape, **kwargs))
_savecache(filename, masks[0], masks[1], xfm.shape)
return cls(masks[0], masks[1], xfm.shape, subject, xfmname)
fleft, fright = db.get_surf(subject, "flat", nudge=True, merge=False)
except IOError:
fleft = None
if decimate:
try:
pleft, pright = db.get_surf(subject, "pia")
self.left = DecimatedHemi(left[0], left[1], fleft[1], pia=pleft[0])
self.right = DecimatedHemi(right[0], right[1], fright[1], pia=pright[0])
self.addSurf("wm", addtype=False, renorm=False)
except IOError:
self.left = DecimatedHemi(left[0], left[1], fleft[1])
self.right = DecimatedHemi(right[0], right[1], fright[1])
else:
try:
pleft, pright = db.get_surf(subject, "pia")
wleft, wright = db.get_surf(subject, "wm")
self.left = Hemi(pleft[0], left[1])
self.right = Hemi(pright[0], right[1])
self.addSurf("wm", addtype=False, renorm=False)
except IOError:
self.left = Hemi(left[0], left[1])
self.right = Hemi(right[0], right[1])
if fleft is not None:
#set medial wall
for hemi, ptpoly in ([self.left, fleft], [self.right, fright]):
# fidpolys = set(tuple(f) for f in polyutils.sort_polys(hemi.polys))
# flatpolys = set(tuple(f) for f in polyutils.sort_polys(ptpoly[1]))
# medial_verts = set(np.ravel(list(fidpolys - flatpolys)))
medial_verts = set(hemi.polys.ravel()) - set(ptpoly[1].ravel())
hemi.aux[list(medial_verts), 0] = 1