def test_AvScale_inputs(): input_map = dict( args=dict(argstr='%s', ), environ=dict( nohash=True, usedefault=True, ), ignore_exception=dict( nohash=True, usedefault=True, ), mat_file=dict( argstr='%s', position=0, ), output_type=dict(), terminal_output=dict( mandatory=True, nohash=True, ), ) inputs = AvScale.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
def rotate_bvecs(bvecs, motion_vecs, rotate): if not rotate: rotated_bvecs = bvecs else: import numpy as np import os from nipype.interfaces.fsl.utils import AvScale bvecs = np.genfromtxt(bvecs) rotated_bvecs = open(os.path.abspath('rotated_bvecs.txt'),'w') for i,r in enumerate(motion_vecs): avscale = AvScale() avscale.inputs.mat_file = r res = avscale.run() mat = np.asarray(res.outputs.rotation_translation_matrix) rot = np.dot(mat,np.hstack((bvecs[i,:],1))) for point in rot[:-1]: rotated_bvecs.write('%f '%point) rotated_bvecs.write('\n') rotated_bvecs.close() rotated_bvecs = os.path.abspath('rotated_bvecs.txt') return rotated_bvecs
def test_AvScale_outputs(): output_map = dict(average_scaling=dict(), backward_half_transform=dict(), determinant=dict(), forward_half_transform=dict(), left_right_orientation_preserved=dict(), rotation_translation_matrix=dict(), scales=dict(), skews=dict(), ) outputs = AvScale.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def test_AvScale_outputs(): output_map = dict( average_scaling=dict(), backward_half_transform=dict(), determinant=dict(), forward_half_transform=dict(), left_right_orientation_preserved=dict(), rotation_translation_matrix=dict(), scales=dict(), skews=dict(), ) outputs = AvScale.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def get_flirt_motion_parameters(flirt_out_mats): def get_params(A): """This is a copy of spm's spm_imatrix where we already know the rotations and translations matrix, shears and zooms (as outputs from fsl FLIRT/avscale) Let A = the 4x4 rotation and translation matrix R = [ c5*c6, c5*s6, s5] [-s4*s5*c6-c4*s6, -s4*s5*s6+c4*c6, s4*c5] [-c4*s5*c6+s4*s6, -c4*s5*s6-s4*c6, c4*c5] """ def rang(b): a = min(max(b, -1), 1) return a Ry = np.arcsin(A[0, 2]) # Rx = np.arcsin(A[1, 2] / np.cos(Ry)) # Rz = np.arccos(A[0, 1] / np.sin(Ry)) if (abs(Ry) - np.pi / 2)**2 < 1e-9: Rx = 0 Rz = np.arctan2(-rang(A[1, 0]), rang(-A[2, 0] / A[0, 2])) else: c = np.cos(Ry) Rx = np.arctan2(rang(A[1, 2] / c), rang(A[2, 2] / c)) Rz = np.arctan2(rang(A[0, 1] / c), rang(A[0, 0] / c)) rotations = [Rx, Ry, Rz] translations = [A[0, 3], A[1, 3], A[2, 3]] return rotations, translations motion_params = open(op.abspath('motion_parameters.par'), 'w') for mat in flirt_out_mats: res = AvScale(mat_file=mat).run() A = np.asarray(res.outputs.rotation_translation_matrix) rotations, translations = get_params(A) for i in rotations + translations: motion_params.write('%f ' % i) motion_params.write('\n') motion_params.close() motion_params = op.abspath('motion_parameters.par') return motion_params
def test_AvScale_inputs(): input_map = dict(args=dict(argstr='%s', ), environ=dict(nohash=True, usedefault=True, ), ignore_exception=dict(nohash=True, usedefault=True, ), mat_file=dict(argstr='%s', position=0, ), output_type=dict(), terminal_output=dict(nohash=True, ), ) inputs = AvScale.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value