@@ -77,6 +77,13 @@ def test_displacements_within_mask(simple_mask_img, test_xfm, reference_xfm, exp
7777 np .testing .assert_allclose (disp , expected )
7878
7979
80+ def test_compute_fd_from_transform_exceptions ():
81+ img = nb .Nifti1Image (np .zeros ((5 , 5 , 5 ), dtype = float ), np .eye (4 ))
82+ xfm = Affine (np .eye (4 ))
83+ with pytest .raises (ValueError , match = r"n_vertices must be >= 1" ):
84+ compute_fd_from_transform (img = img , xfm = xfm , n_vertices = 0 )
85+
86+
8087@pytest .mark .parametrize (
8188 "test_xfm, expected" ,
8289 [
@@ -94,7 +101,13 @@ def test_compute_fd_from_transform(simple_mask_img, test_xfm, expected):
94101 assert np .isclose (fd , expected , atol = 1e-4 , rtol = 1e-6 )
95102
96103
97- def test_single_vertex_fd_computation_variants ():
104+ def test_compute_fd_from_motion_exceptions ():
105+ bad = np .zeros ((10 , 5 ), dtype = float ) # must be (T, 6)
106+ with pytest .raises (ValueError , match = r"motion_parameters must have shape \(T, 6\)\." ):
107+ compute_fd_from_motion (bad )
108+
109+
110+ def test_compute_fd_from_motion_single_vertex_variants ():
98111 """For n_vertices=1, FD equals the L1 displacement of the single sampled point."""
99112 radius = 50.0
100113
@@ -148,6 +161,38 @@ def test_compute_fd_from_motion(motion_params, radius, expected):
148161 np .testing .assert_allclose (fd , expected , atol = 1e-4 )
149162
150163
164+ @pytest .mark .parametrize (
165+ "shape" ,
166+ [
167+ (2 , 2 ), # square but invalid
168+ (3 , 4 ), # rectangular
169+ (4 , 3 ), # rectangular
170+ (5 , 5 ), # wrong square size
171+ (1 , 3 , 4 ), # last dims (3,4)
172+ (2 , 4 , 3 ), # last dims (4,3)
173+ (2 , 3 , 3 , 4 ), # last dims (3,4)
174+ (2 , 4 , 4 , 3 ), # last dims (4,3)
175+ ],
176+ )
177+ def test_euler_from_matrix_exceptions (shape ):
178+ bad = np .zeros (shape , dtype = float )
179+ with pytest .raises (
180+ ValueError ,
181+ match = r"affine must end with shape \(3, 3\) or \(4, 4\)\." ,
182+ ):
183+ euler_from_matrix (bad )
184+
185+
186+ @pytest .mark .parametrize ("shape" , [(3 , 3 ), (4 , 4 ), (7 , 3 , 3 ), (5 , 4 , 4 )])
187+ def test_euler_from_matrix_valid_shapes (shape ):
188+ good = np .eye (shape [- 1 ], dtype = float )
189+ if len (shape ) > 2 :
190+ good = np .broadcast_to (good , shape ).copy ()
191+
192+ out = euler_from_matrix (good )
193+ assert out .shape == shape [:- 2 ] + (3 ,)
194+
195+
151196def test_euler_from_matrix_matches_scipy_xyz ():
152197 expected = np .array ([
153198 [10.0 , - 5.0 , 2.0 ],
0 commit comments