Skip to content

Commit adf71da

Browse files
authored
Merge pull request #299 from jhlegarreta/tst/add-brainmask-to-pet-load
TST: Test loading PET data with brainmask
2 parents 83a8b65 + a197e9f commit adf71da

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

test/test_data_pet.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,30 @@ def test_pet_set_transform_updates_motion_affines(random_dataset):
184184

185185

186186
@pytest.mark.random_uniform_spatial_data((2, 2, 2, 2), 0.0, 1.0)
187-
def test_pet_load(setup_random_uniform_spatial_data, tmp_path):
187+
def test_pet_load(request, tmp_path, setup_random_uniform_spatial_data):
188188
data, affine = setup_random_uniform_spatial_data
189189
img = nb.Nifti1Image(data, affine)
190190
fname = tmp_path / "pet.nii.gz"
191191
img.to_filename(fname)
192192

193+
brainmask_dataobj = request.node.rng.choice([True, False], size=data.shape[:3]).astype(
194+
np.uint8
195+
)
196+
brainmask = nb.Nifti1Image(brainmask_dataobj, affine)
197+
brainmask_fname = tmp_path / "brainmask.nii.gz"
198+
brainmask.to_filename(brainmask_fname)
199+
193200
json_file = tmp_path / "pet.json"
194201
metadata = {
195202
"FrameDuration": [1.0, 1.0],
196203
"FrameTimesStart": [0.0, 1.0],
197204
}
198205
json_file.write_text(json.dumps(metadata))
199206

200-
pet_obj = PET.load(fname, json_file)
207+
pet_obj = PET.load(fname, json_file, brainmask_fname)
201208

202209
assert pet_obj.dataobj.shape == data.shape
203210
assert np.allclose(pet_obj.midframe, [0.5, 1.5])
204211
assert pet_obj.total_duration == 2.0
212+
if pet_obj.brainmask is not None:
213+
assert pet_obj.brainmask.shape == brainmask_dataobj.shape

0 commit comments

Comments
 (0)