@@ -781,33 +781,9 @@ def test_itk_h5_field_order_fortran(tmp_path):
781
781
assert np .allclose (img .get_fdata (), expected )
782
782
783
783
784
- def test_composite_h5_map_against_ants (tmp_path ):
784
+ def test_composite_h5_map_against_ants (testdata_path , tmp_path ):
785
785
"""Map points with NiTransforms and compare to ANTs."""
786
- shape = (2 , 2 , 2 )
787
- disp = np .zeros (shape + (3 ,), dtype = float )
788
- disp += np .array ([0.2 , - 0.3 , 0.4 ])
789
-
790
- params = np .moveaxis (disp , - 1 , 0 ).reshape (- 1 , order = "F" )
791
- fixed = np .array (
792
- list (shape ) + [0 , 0 , 0 ] + [1 , 1 , 1 ] + list (np .eye (3 ).ravel ()), dtype = float
793
- )
794
- fname = tmp_path / "test.h5"
795
- with H5File (fname , "w" ) as f :
796
- grp = f .create_group ("TransformGroup" )
797
- grp .create_group ("0" )["TransformType" ] = np .array (
798
- [b"CompositeTransform_double_3_3" ]
799
- )
800
- g1 = grp .create_group ("1" )
801
- g1 ["TransformType" ] = np .array ([b"DisplacementFieldTransform_float_3_3" ])
802
- g1 ["TransformFixedParameters" ] = fixed
803
- g1 ["TransformParameters" ] = params
804
- g2 = grp .create_group ("2" )
805
- g2 ["TransformType" ] = np .array ([b"AffineTransform_double_3_3" ])
806
- g2 ["TransformFixedParameters" ] = np .zeros (3 , dtype = float )
807
- g2 ["TransformParameters" ] = np .array (
808
- [1 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 , 0.1 , 0.2 , - 0.1 ], dtype = float
809
- )
810
-
786
+ h5file , _ = _load_composite_testdata (testdata_path )
811
787
points = np .array ([[0.0 , 0.0 , 0.0 ], [1.0 , 2.0 , 3.0 ]])
812
788
csvin = tmp_path / "points.csv"
813
789
with open (csvin , "w" ) as f :
@@ -816,9 +792,7 @@ def test_composite_h5_map_against_ants(tmp_path):
816
792
f .write ("," .join (map (str , row )) + "\n " )
817
793
818
794
csvout = tmp_path / "out.csv"
819
- cmd = (
820
- f"antsApplyTransformsToPoints -d 3 -i { csvin } -o { csvout } -t { fname } "
821
- )
795
+ cmd = f"antsApplyTransformsToPoints -d 3 -i { csvin } -o { csvout } -t { h5file } "
822
796
exe = cmd .split ()[0 ]
823
797
if not shutil .which (exe ):
824
798
pytest .skip (f"Command { exe } not found on host" )
@@ -827,9 +801,11 @@ def test_composite_h5_map_against_ants(tmp_path):
827
801
ants_res = np .genfromtxt (csvout , delimiter = "," , names = True )
828
802
ants_pts = np .vstack ([ants_res [n ] for n in ("x" , "y" , "z" )]).T
829
803
830
- xforms = itk .ITKCompositeH5 .from_filename (fname )
831
- dfield = nitnl .DenseFieldTransform (xforms [0 ])
832
- affine = nitl .Affine (xforms [1 ].to_ras ())
833
- mapped = (affine @ dfield ).map (points )
804
+ xforms = itk .ITKCompositeH5 .from_filename (h5file )
805
+ chain = (
806
+ nitl .Affine (xforms [0 ].to_ras ())
807
+ + nitnl .DenseFieldTransform (xforms [1 ])
808
+ )
809
+ mapped = chain .map (points )
834
810
835
811
assert np .allclose (mapped , ants_pts , atol = 1e-6 )
0 commit comments