@@ -330,6 +330,30 @@ def test_apply_transformchain(tmp_path, testdata_path):
330330 assert (np .abs (diff ) > 1e-3 ).sum () / diff .size < RMSE_TOL_LINEAR
331331
332332
333+ @pytest .mark .xfail (reason = "gh-281: applying a single 3D transform to 4D data" )
334+ def test_apply_single_3d_on_4d ():
335+ """Apply one 3D transform across all timepoints of a 4D dataset."""
336+ nvols = 5
337+ data = np .zeros ((10 , 5 , 5 , nvols ), dtype = np .float32 )
338+ for i in range (nvols ):
339+ data [i + 1 , 2 , 2 , i ] = i + 1
340+
341+ img = nb .Nifti1Image (data , np .eye (4 ))
342+
343+ mat = np .eye (4 )
344+ mat [0 , 3 ] = - 1.0
345+ ref = nb .Nifti1Image (np .zeros ((10 , 5 , 5 ), dtype = np .uint8 ), np .eye (4 ))
346+ xfm = nitl .Affine (mat , reference = ref )
347+
348+ moved = apply (xfm , img , order = 0 )
349+ moved_data = np .asanyarray (moved .dataobj )
350+
351+ assert moved_data .shape == data .shape
352+ for i in range (nvols ):
353+ assert moved_data [i + 2 , 2 , 2 , i ] == i + 1
354+ assert moved_data [i + 1 , 2 , 2 , i ] == 0
355+
356+
333357@pytest .mark .parametrize ("serialize_4d" , [True , False ])
334358def test_LinearTransformsMapping_apply (
335359 tmp_path , data_path , testdata_path , serialize_4d
0 commit comments