Skip to content

Commit 08be9de

Browse files
committed
TEST: Verify legacy dtseries.json hack
1 parent 0a0b659 commit 08be9de

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

niworkflows/interfaces/tests/test_bids.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests on BIDS compliance."""
22
import os
33
from pathlib import Path
4+
import json
45

56
import numpy as np
67
import nibabel as nb
@@ -278,6 +279,46 @@ def test_DerivativesDataSink_build_path(
278279
assert Path(out).relative_to(tmp_path) == Path(base) / exp
279280

280281

282+
def test_DerivativesDataSink_dtseries_json_hack(tmp_path):
283+
cifti_fname = str(tmp_path / "test.dtseries.nii")
284+
285+
axes = (nb.cifti2.SeriesAxis(start=0, step=2, size=20),
286+
nb.cifti2.BrainModelAxis.from_mask(np.ones((5, 5, 5))))
287+
hdr = nb.cifti2.cifti2_axes.to_header(axes)
288+
cifti = nb.Cifti2Image(np.zeros(hdr.matrix.get_data_shape(), dtype=np.float32),
289+
header=hdr)
290+
cifti.nifti_header.set_intent("ConnDenseSeries")
291+
cifti.to_filename(cifti_fname)
292+
293+
source_file = tmp_path / "bids" / "sub-01" / "func" / "sub-01_task-rest_bold.nii.gz"
294+
source_file.parent.mkdir(parents=True)
295+
source_file.touch()
296+
297+
dds = bintfs.DerivativesDataSink(
298+
in_file=cifti_fname,
299+
base_directory=str(tmp_path),
300+
source_file=str(source_file),
301+
compress=False,
302+
out_path_base="",
303+
space="fsLR",
304+
grayordinates="91k",
305+
RepetitionTime=2.0,
306+
)
307+
308+
res = dds.run()
309+
310+
out_path = Path(res.outputs.out_file)
311+
312+
assert out_path.name == "sub-01_task-rest_space-fsLR_bold.dtseries.nii"
313+
old_sidecar = out_path.with_name("sub-01_task-rest_space-fsLR_bold.dtseries.json")
314+
new_sidecar = out_path.with_name("sub-01_task-rest_space-fsLR_bold.json")
315+
316+
assert old_sidecar.exists()
317+
assert "grayordinates" in json.loads(old_sidecar.read_text())
318+
assert new_sidecar.exists()
319+
assert "RepetitionTime" in json.loads(new_sidecar.read_text())
320+
321+
281322
@pytest.mark.parametrize(
282323
"space, size, units, xcodes, zipped, fixed, data_dtype",
283324
[

0 commit comments

Comments
 (0)