Note
This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.
brainprep.utils.sidecar_from_file¶
- brainprep.utils.sidecar_from_file(image_file)[source]¶
Infers the corresponding JSON sidecar file for a given NIfTI image file.
This function checks that the input file has a
.nii.gzextension and attempts to locate a sidecar.jsonfile with the same base name. If either condition fails, it raises a ValueError.- Parameters:
- image_fileFile
The NIfTI image file for which to infer the JSON sidecar.
- Returns:
- sidecar_fileFile
Path to the inferred JSON sidecar file.
- Raises:
- ValueError
If the input file does not have a .nii.gz extension or if the corresponding JSON sidecar file does not exist.
Examples
>>> from pathlib import Path >>> from brainprep.utils import sidecar_from_file >>> >>> image_file = Path("/tmp/sub-01_T1w.nii.gz") >>> sidecar_file = Path("/tmp/sub-01_T1w.json") >>> sidecar_file.touch() >>> >>> sidecar_from_file(image_file) PosixPath('/tmp/sub-01_T1w.json')