def test_iter_img(): img_3d = nibabel.Nifti1Image(np.ones((3, 4, 5)), np.eye(4)) testing.assert_raises_regex(TypeError, '4D Niimg-like', image.iter_img, img_3d) affine = np.array([[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.], [0., 0., 0., 1.]]) img_4d, _ = testing.generate_fake_fmri(affine=affine) for i, img in enumerate(image.iter_img(img_4d)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(img.get_affine(), img_4d.get_affine()) with testing.write_tmp_imgs(img_4d) as img_4d_filename: for i, img in enumerate(image.iter_img(img_4d_filename)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(img.get_affine(), img_4d.get_affine()) # enables to delete "img_4d_filename" on windows del img img_3d_list = list(image.iter_img(img_4d)) for i, img in enumerate(image.iter_img(img_3d_list)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(img.get_affine(), img_4d.get_affine()) with testing.write_tmp_imgs(*img_3d_list) as img_3d_filenames: for i, img in enumerate(image.iter_img(img_3d_filenames)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(img.get_affine(), img_4d.get_affine()) # enables to delete "img_3d_filename" on windows del img
def test_iter_img(): img_3d = nibabel.Nifti1Image(np.ones((3, 4, 5)), np.eye(4)) testing.assert_raises_regex(TypeError, "Input data has incompatible dimensionality: " "Expected dimension is 4D and you provided " "a 3D image.", image.iter_img, img_3d) affine = np.array([[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.], [0., 0., 0., 1.]]) img_4d, _ = testing.generate_fake_fmri(affine=affine) for i, img in enumerate(image.iter_img(img_4d)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(compat.get_affine(img), compat.get_affine(img_4d)) with testing.write_tmp_imgs(img_4d) as img_4d_filename: for i, img in enumerate(image.iter_img(img_4d_filename)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(compat.get_affine(img), compat.get_affine(img_4d)) # enables to delete "img_4d_filename" on windows del img img_3d_list = list(image.iter_img(img_4d)) for i, img in enumerate(image.iter_img(img_3d_list)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(compat.get_affine(img), compat.get_affine(img_4d)) with testing.write_tmp_imgs(*img_3d_list) as img_3d_filenames: for i, img in enumerate(image.iter_img(img_3d_filenames)): expected_data_3d = img_4d.get_data()[..., i] assert_array_equal(img.get_data(), expected_data_3d) assert_array_equal(compat.get_affine(img), compat.get_affine(img_4d)) # enables to delete "img_3d_filename" on windows del img