def test_trans_distances(tmpdir): from ...interfaces.vtkbase import tvtk in_surf = example_data('surf01.vtk') warped_surf = tmpdir.join('warped.vtk') inc = np.array([0.7, 0.3, -0.2]) r1 = tvtk.PolyDataReader(file_name=in_surf) vtk1 = VTKInfo.vtk_output(r1) r1.update() vtk1.points = np.array(vtk1.points) + inc writer = tvtk.PolyDataWriter(file_name=warped_surf) VTKInfo.configure_input_data(writer, vtk1) writer.write() dist = m.ComputeMeshWarp() dist.inputs.surface1 = in_surf dist.inputs.surface2 = warped_surf dist.inputs.out_file = tmpdir.join('distance.npy') res = dist.run() assert np.allclose(res.outputs.distance, np.linalg.norm(inc), 4) dist.inputs.weighting = 'area' res = dist.run() assert np.allclose(res.outputs.distance, np.linalg.norm(inc), 4)
def test_trans_distances(): tempdir = mkdtemp() in_surf = example_data('surf01.vtk') warped_surf = os.path.join(tempdir, 'warped.vtk') curdir = os.getcwd() os.chdir(tempdir) inc = np.array([0.7, 0.3, -0.2]) r1 = tvtk.PolyDataReader(file_name=in_surf) vtk1 = r1.output r1.update() vtk1.points = np.array(vtk1.points) + inc writer = tvtk.PolyDataWriter(file_name=warped_surf) writer.set_input_data(vtk1) writer.write() dist = m.ComputeMeshWarp() dist.inputs.surface1 = in_surf dist.inputs.surface2 = warped_surf dist.inputs.out_file = os.path.join(tempdir, 'distance.npy') res = dist.run() yield assert_almost_equal, res.outputs.distance, np.linalg.norm(inc), 4 dist.inputs.weighting = 'area' res = dist.run() yield assert_almost_equal, res.outputs.distance, np.linalg.norm(inc), 4 os.chdir(curdir) rmtree(tempdir)
def test_importerror(): with pytest.raises(ImportError): m.ComputeMeshWarp() with pytest.raises(ImportError): m.WarpPoints() with pytest.raises(ImportError): m.MeshWarpMaths()
def test_ident_distances(tmpdir): tmpdir.chdir() in_surf = example_data('surf01.vtk') dist_ident = m.ComputeMeshWarp() dist_ident.inputs.surface1 = in_surf dist_ident.inputs.surface2 = in_surf dist_ident.inputs.out_file = tmpdir.join('distance.npy') res = dist_ident.run() assert res.outputs.distance == 0.0 dist_ident.inputs.weighting = 'area' res = dist_ident.run() assert res.outputs.distance == 0.0
def test_ident_distances(tmpdir): tmpdir.chdir() in_surf = example_data("surf01.vtk") dist_ident = m.ComputeMeshWarp() dist_ident.inputs.surface1 = in_surf dist_ident.inputs.surface2 = in_surf dist_ident.inputs.out_file = tmpdir.join("distance.npy").strpath res = dist_ident.run() assert res.outputs.distance == 0.0 dist_ident.inputs.weighting = "area" res = dist_ident.run() assert res.outputs.distance == 0.0
def test_ident_distances(): tempdir = mkdtemp() curdir = os.getcwd() os.chdir(tempdir) in_surf = example_data('surf01.vtk') dist_ident = m.ComputeMeshWarp() dist_ident.inputs.surface1 = in_surf dist_ident.inputs.surface2 = in_surf dist_ident.inputs.out_file = os.path.join(tempdir, 'distance.npy') res = dist_ident.run() yield assert_equal, res.outputs.distance, 0.0 dist_ident.inputs.weighting = 'area' res = dist_ident.run() yield assert_equal, res.outputs.distance, 0.0 os.chdir(curdir) rmtree(tempdir)
def map_energy(name='EnergyMapping', out_csv='energiesmapping.csv'): out_csv = op.abspath(out_csv) inputnode = pe.Node(niu.IdentityInterface(fields=[ 'reference', 'surfaces0', 'surfaces1', 'in_mask', 'subject_id' ]), name='inputnode') outputnode = pe.Node( niu.IdentityInterface(fields=['desc_zero', 'out_diff']), name='outputnode') ref_e = pe.Node(ComputeEnergy(), name='ComputeZeroEnergy') diff = pe.MapNode(namesh.ComputeMeshWarp(), name='ComputeError', iterfield=['surface1', 'surface2']) getval = pe.Node(nio.JSONFileGrabber(), name='GetZeroEnergy') csv = pe.Node(namisc.AddCSVRow(in_file=out_csv), name="AddReferenceRow") csv.inputs.error = 0.0 mapper = warp_n_map(out_csv=out_csv) wf = pe.Workflow(name=name) wf.connect([(inputnode, ref_e, [('reference', 'reference'), ('surfaces0', 'surfaces'), ('in_mask', 'in_mask')]), (ref_e, outputnode, [('out_file', 'desc_zero')]), (ref_e, getval, [('out_file', 'in_file')]), (inputnode, csv, [('subject_id', 'subject_id')]), (getval, csv, [('total', 'total')]), (inputnode, diff, [('surfaces0', 'surface1'), ('surfaces1', 'surface2')]), (diff, outputnode, [('out_warp', 'out_diff')]), (inputnode, mapper, [('subject_id', 'inputnode.subject_id'), ('reference', 'inputnode.reference'), ('in_mask', 'inputnode.in_mask')]), (diff, mapper, [('out_warp', 'inputnode.surf_warp')]), (ref_e, mapper, [('out_desc', 'inputnode.descriptors')])]) return wf
def test_trans_distances(): tempdir = mkdtemp() curdir = os.getcwd() os.chdir(tempdir) if VTKInfo.no_tvtk(): yield assert_raises, ImportError, m.ComputeMeshWarp else: from ...interfaces.vtkbase import tvtk in_surf = example_data('surf01.vtk') warped_surf = os.path.join(tempdir, 'warped.vtk') inc = np.array([0.7, 0.3, -0.2]) r1 = tvtk.PolyDataReader(file_name=in_surf) vtk1 = VTKInfo.vtk_output(r1) r1.update() vtk1.points = np.array(vtk1.points) + inc writer = tvtk.PolyDataWriter(file_name=warped_surf) VTKInfo.configure_input_data(writer, vtk1) writer.write() dist = m.ComputeMeshWarp() dist.inputs.surface1 = in_surf dist.inputs.surface2 = warped_surf dist.inputs.out_file = os.path.join(tempdir, 'distance.npy') res = dist.run() yield assert_almost_equal, res.outputs.distance, np.linalg.norm(inc), 4 dist.inputs.weighting = 'area' res = dist.run() yield assert_almost_equal, res.outputs.distance, np.linalg.norm(inc), 4 os.chdir(curdir) rmtree(tempdir)