def fa(self): r""" Fractional anisotropy (FA) calculated from cached eigenvalues. Returns --------- fa : array (V, 1) Calculated FA. Note: range is 0 <= FA <= 1. Notes -------- FA is calculated with the following equation: .. math:: FA = \sqrt{\frac{1}{2}\frac{(\lambda_1-\lambda_2)^2+(\lambda_1- \lambda_3)^2+(\lambda_2-lambda_3)^2}{\lambda_1^2+ \lambda_2^2+\lambda_3^2} } """ evals, wrap = _makearray(self.model_params[..., :3]) ev1 = evals[..., 0] ev2 = evals[..., 1] ev3 = evals[..., 2] fa = np.sqrt(0.5 * ((ev1 - ev2)**2 + (ev2 - ev3)**2 + (ev3 - ev1)**2) / (ev1*ev1 + ev2*ev2 + ev3*ev3)) fa = wrap(np.asarray(fa)) return _filled(fa)
def evecs(self): """ Returns the eigenvectors of teh tensor as an array """ evecs = _filled(self.model_params[..., 3:]) return evecs.reshape(self.shape + (3, 3))
def evals(self): """ Returns the eigenvalues of the tensor as an array """ return _filled(self.model_params[..., :3])
def _getD(self): """Calculates the 3x3 diffusion tensor for each voxel""" params, wrap = _makearray(self.model_params) evals = params[..., :3] evecs = params[..., 3:] evals_flat = evals.reshape((-1, 3)) evecs_flat = evecs.reshape((-1, 3, 3)) D_flat = np.empty(evecs_flat.shape) for ii in xrange(len(D_flat)): Q = evecs_flat[ii] L = evals_flat[ii] D_flat[ii] = np.dot(Q * L, Q.T) D = _filled(wrap(D_flat)) D.shape = self.shape + (3, 3) return D
def fa(self, fill_value=0, nonans=True): r""" Fractional anisotropy (FA) calculated from cached eigenvalues. Parameters ---------- fill_value : float value of fa where self.mask == True. nonans : Bool When True, fa is 0 when all eigenvalues are 0, otherwise fa is nan Returns --------- fa : array (V, 1) Calculated FA. Note: range is 0 <= FA <= 1. Notes -------- FA is calculated with the following equation: .. math:: FA = \sqrt{\frac{1}{2}\frac{(\lambda_1-\lambda_2)^2+(\lambda_1- \lambda_3)^2+(\lambda_2-lambda_3)^2}{\lambda_1^2+ \lambda_2^2+\lambda_3^2} } """ evals, wrap = _makearray(self.model_params[..., :3]) ev1 = evals[..., 0] ev2 = evals[..., 1] ev3 = evals[..., 2] if nonans: all_zero = (ev1 == 0) & (ev2 == 0) & (ev3 == 0) else: all_zero = 0.0 fa = np.sqrt( 0.5 * ((ev1 - ev2) ** 2 + (ev2 - ev3) ** 2 + (ev3 - ev1) ** 2) / (ev1 * ev1 + ev2 * ev2 + ev3 * ev3 + all_zero) ) fa = wrap(np.asarray(fa)) return _filled(fa, fill_value)
def fa(self, fill_value=0, nonans=True): r""" Fractional anisotropy (FA) calculated from cached eigenvalues. Parameters ---------- fill_value : float value of fa where self.mask == True. nonans : Bool When True, fa is 0 when all eigenvalues are 0, otherwise fa is nan Returns --------- fa : array (V, 1) Calculated FA. Note: range is 0 <= FA <= 1. Notes -------- FA is calculated with the following equation: .. math:: FA = \sqrt{\frac{1}{2}\frac{(\lambda_1-\lambda_2)^2+(\lambda_1- \lambda_3)^2+(\lambda_2-lambda_3)^2}{\lambda_1^2+ \lambda_2^2+\lambda_3^2} } """ evals, wrap = _makearray(self.model_params[..., :3]) ev1 = evals[..., 0] ev2 = evals[..., 1] ev3 = evals[..., 2] if nonans: all_zero = (ev1 == 0) & (ev2 == 0) & (ev3 == 0) else: all_zero = 0. fa = np.sqrt(0.5 * ((ev1 - ev2)**2 + (ev2 - ev3)**2 + (ev3 - ev1)**2) / (ev1 * ev1 + ev2 * ev2 + ev3 * ev3 + all_zero)) fa = wrap(np.asarray(fa)) return _filled(fa, fill_value)