Coverage for nilearn/image/tests/conftest.py: 0%
20 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 12:32 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 12:32 +0200
1"""Pytest fixtures for testing copied headers in nilearn.image functions."""
3import pytest
4from nibabel.nifti1 import Nifti1Image
6from nilearn import image
9@pytest.fixture
10def img_4d_ones_eye_default_header(img_4d_ones_eye):
11 """Return a 4D Nifti1Image with default header.
13 The header is created by new_img_like and is not modified. The image is
14 filled with ones and has an identity affine.
15 """
16 img = image.new_img_like(
17 img_4d_ones_eye,
18 data=img_4d_ones_eye.get_fdata(),
19 copy_header=False,
20 )
21 return img
24@pytest.fixture
25def img_4d_ones_eye_tr2(img_4d_ones_eye):
26 """Return a 4D Nifti1Image with otherwise default header, except TR 2.0.
28 The header is the default one created by new_img_like, but the TR is
29 changed to 2.0. The image is filled with ones and has an identity affine.
30 """
31 img = image.new_img_like(
32 img_4d_ones_eye,
33 data=img_4d_ones_eye.get_fdata(),
34 copy_header=True,
35 )
36 # Change the TR
37 header = img.header.copy()
38 header["pixdim"][4] = 2.0
39 return Nifti1Image(img.get_fdata(), img.affine, header=header)
42@pytest.fixture
43def img_4d_mni_tr2(img_4d_mni):
44 """Return a 4D Nifti1Image with MNI affine and header, and TR 2.0.
46 The header has the MNI affine, and the TR is changed to 2.0. The image is
47 filled with random numbers.
48 """
49 img = image.new_img_like(
50 img_4d_mni, data=img_4d_mni.get_fdata(), copy_header=True
51 )
52 # Add fake description
53 header = img.header.copy()
54 header["descrip"] = b"Fake description"
55 # Change the TR
56 header["pixdim"][4] = 2.0
57 return Nifti1Image(img.get_fdata(), img.affine, header=header)