inspect_file¶
Point it at any supported file and you get back a dictionary with the structural facts about that file — shape, dtype, headers — without loading the actual voxel/pixel data into memory. Think of it as a fast "what is this thing?" tool.
Signature¶
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
file_path |
str or Path |
required | Path to a .nii, .nii.gz, .h5, .hdf5, .npy, .npz, .tif, .tiff, or .dcm file. Can also be a directory containing DICOM slices. |
include_phi |
bool |
False |
DICOM only. When True, patient identifiers are included in the result. No effect on any other format. |
Return value¶
The shape of the returned dictionary depends on the file format.
{
"filename": "scan.dcm",
"format": "dicom",
"source": "file",
"shape": [512, 512],
"ndim": 2,
"dtype": "uint16",
"slice_count": 1,
"modality": "CT",
"voxel_size": [0.7, 0.7, 1.0]
}
For a series directory the source field is "series" and shape becomes three-dimensional:
{
"filename": "series",
"format": "dicom",
"source": "series",
"shape": [128, 512, 512],
"ndim": 3,
"slice_count": 128,
"modality": "MR",
"voxel_size": [1.0, 1.0, 1.2]
}
See inspect_dicom for full DICOM details including PHI fields.
Errors¶
| Exception | When it's raised |
|---|---|
ValueError |
The file extension is not supported |
FileNotFoundError |
The file path doesn't exist |
Example¶
from voxelkit import inspect_file
result = inspect_file("subject01_bold.nii.gz")
print(result["shape"]) # [64, 64, 30, 200]
print(result["data_dtype"]) # "float32"
print(result["voxel_sizes"]) # [3.0, 3.0, 4.0]
For HDF5 files, you get a list of all datasets inside: