|
1 | 1 | """Tests on BIDS compliance.""" |
2 | 2 | import os |
3 | 3 | from pathlib import Path |
| 4 | +import json |
4 | 5 |
|
5 | 6 | import numpy as np |
6 | 7 | import nibabel as nb |
@@ -278,6 +279,46 @@ def test_DerivativesDataSink_build_path( |
278 | 279 | assert Path(out).relative_to(tmp_path) == Path(base) / exp |
279 | 280 |
|
280 | 281 |
|
| 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 | + |
281 | 322 | @pytest.mark.parametrize( |
282 | 323 | "space, size, units, xcodes, zipped, fixed, data_dtype", |
283 | 324 | [ |
|
0 commit comments