|
| 1 | +import json |
1 | 2 | from pathlib import Path
|
2 | 3 |
|
3 | 4 | import nibabel as nb
|
@@ -52,3 +53,41 @@ def test_datasink_datatype(tmp_path: Path):
|
52 | 53 | assert wf.get_node('ds_pet').inputs.datatype == 'pet'
|
53 | 54 | assert wf.get_node('ds_ref').inputs.datatype == 'pet'
|
54 | 55 | assert wf.get_node('ds_mask').inputs.datatype == 'pet'
|
| 56 | + |
| 57 | + |
| 58 | +def test_refmask_sources(tmp_path: Path): |
| 59 | + bids_dir = _prep_bids(tmp_path) |
| 60 | + out_dir = tmp_path / 'out' |
| 61 | + gm_file = bids_dir / 'sub-01' / 'anat' / 'sub-01_label-GM_probseg.nii.gz' |
| 62 | + seg_file = bids_dir / 'sub-01' / 'anat' / 'sub-01_desc-aparcaseg_dseg.nii.gz' |
| 63 | + refmask_file = tmp_path / 'refmask.nii.gz' |
| 64 | + |
| 65 | + img = nb.Nifti1Image(np.zeros((2, 2, 2)), np.eye(4)) |
| 66 | + for path in (gm_file, seg_file, refmask_file): |
| 67 | + path.parent.mkdir(parents=True, exist_ok=True) |
| 68 | + img.to_filename(path) |
| 69 | + |
| 70 | + t1_file = bids_dir / 'sub-01' / 'anat' / 'sub-01_T1w.nii.gz' |
| 71 | + |
| 72 | + with mock_config(bids_dir=bids_dir): |
| 73 | + wf = init_ds_refmask_wf(output_dir=out_dir, ref_name='test') |
| 74 | + wf.base_dir = tmp_path / 'work' |
| 75 | + |
| 76 | + inputnode = wf.get_node('inputnode') |
| 77 | + inputnode.inputs.source_files = str(gm_file) |
| 78 | + inputnode.inputs.anat_sources = str(t1_file) |
| 79 | + inputnode.inputs.segmentation = str(seg_file) |
| 80 | + inputnode.inputs.refmask = str(refmask_file) |
| 81 | + |
| 82 | + wf.run() |
| 83 | + |
| 84 | + out_files = list(out_dir.rglob('*desc-refmask*_mask.nii.gz')) |
| 85 | + assert out_files, 'Reference mask derivative was not generated' |
| 86 | + out_file = Path(out_files[0]) |
| 87 | + metadata = json.loads(out_file.with_suffix('').with_suffix('.json').read_text()) |
| 88 | + sources = metadata.get('Sources', []) |
| 89 | + |
| 90 | + assert any('label-GM_probseg' in src for src in sources) |
| 91 | + assert any('T1w' in src for src in sources) |
| 92 | + assert any('dseg' in src for src in sources) |
| 93 | + assert all('/pet/' not in src for src in sources) |
0 commit comments