Data Requirements¶
This page describes the input data formats and requirements for csttool.
Supported Input Formats¶
csttool accepts diffusion MRI data in two formats:
| Format | Description |
|---|---|
| DICOM | Raw scanner output; automatically converted to NIfTI |
| NIfTI | Pre-converted .nii or .nii.gz with gradient files |
NIfTI Input¶
Required Files¶
For NIfTI input, you need three files with matching base names:
mdwi.nii.gz # 4D diffusion-weighted image
dwi.bval # b-values (one per volume)
dwi.bvec # b-vectors (3 × N matrix)
Gradient file extensions
csttool supports both singular (.bval, .bvec) and plural (.bvals, .bvecs) extensions. These are automatically detected.
File Specifications¶
| File | Format | Description |
|---|---|---|
.nii.gz |
4D NIfTI | Shape: (X, Y, Z, N) where N = number of volumes |
.bval |
Space-separated text | N b-values (e.g., 0 1000 1000 1000...) |
.bvec |
Space-separated text | 3 rows × N columns (gradient directions) |
Example b-value File¶
Example b-vector File¶
0.0 0.5774 -0.5774 0.5774 -0.5774 0.7071 -0.7071 0.0
0.0 0.5774 0.5774 -0.5774 0.5774 0.0 0.7071 0.7071
0.0 0.5774 0.5774 0.5774 -0.5774 0.7071 0.0 -0.7071
DICOM Input¶
For DICOM input, provide the path to the study directory:
study_folder/
├── series_001/ # T1-weighted (ignored)
├── series_002/ # DTI sequence (auto-selected)
│ ├── IM-0001.dcm
│ ├── IM-0002.dcm
│ └── ...
└── series_003/ # Another sequence
csttool will:
- Scan all series in the directory
- Analyze each for tractography suitability
- Auto-select the best diffusion series
- Convert to NIfTI with gradient files
Manual series selection
Use csttool import --series-index N to manually select a specific series.
Image Acquisition Requirements¶
Essential Requirements¶
| Parameter | Requirement | Rationale |
|---|---|---|
| Modality | Diffusion-weighted MRI | Required for tractography |
| b-values | At least one b=0 + one b>0 | Minimum for DTI fitting |
| Directions | ≥6 unique gradient directions | Tensor estimation |
Recommended Specifications¶
For reliable CST extraction:
| Parameter | Recommended | Notes |
|---|---|---|
| b-value | 1000–3000 s/mm² | Higher b improves angular resolution |
| Directions | ≥30 | Better fiber orientation estimation |
| Resolution | ≤2.5 mm isotropic | Finer detail in tract anatomy |
| FOV coverage | Full brain + brainstem | CST runs from cortex to brainstem |
Incomplete field of view
CST extraction will fail if the scan does not cover the motor cortex through the brainstem. Ensure full craniocaudal coverage.
Gradient-table validation (bvals/bvecs)¶
At load, csttool validates the gradient table and fails loudly — rather than silently producing a corrupt tensor fit — on:
- b-values that are non-finite or negative (unphysical);
- no b=0 volume at the configured b0 threshold (no reference signal → no tensor fit);
- DWI b-vectors that are not unit-norm (a sign of a truncated/miswritten
.bvecfile). b0 b-vectors may be zero.
The b0 threshold is the single default in csttool.defaults (50 s/mm²),
exposed via --b0-threshold on preprocess, track, and run. One execution
uses one threshold throughout: it builds the gradient table, and the resulting
gtab.b0s_mask is what brain masking and Patch2Self read, so no stage can
disagree about which volumes are b0.
DICOM b-vector reorientation
The dicom2nifti fallback converter reorients the image to a standard orientation but does not reorient the b-vectors, which would leave the gradients in the scanner's voxel space and the image in a different one — a silent gradient flip that corrupts the tensor fit. csttool converts in the native (scanner) voxel space and reorients both image and b-vectors to RAS+ together, matching the dcm2niix primary path. The primary dcm2niix path is unaffected. (AU21)
Coordinate Space Requirements¶
Critical: World Space (mm) Required¶
Tractogram streamlines must be in world coordinates (millimeters), not voxel indices. This is a common source of errors when using tractograms from external sources.
| Property | Correct (mm) | Incorrect (voxels) |
|---|---|---|
| Coordinate range | -100 to +100 | 0 to 256 |
| Typical values | -80.5, 45.2, 62.0 | 45, 120, 78 |
| Negative coordinates | Common (RAS space) | Rare or absent |
Automatic Validation¶
csttool automatically validates coordinate systems when running extraction. If your tractogram is in voxel space, you will see an error like:
Error: Coordinate validation failed. This can lead to incorrect results.
Errors: Coordinate space mismatch detected: values suggest voxel indices, not mm
The validator also asserts affine equality between the tractogram and the
FA map (translation ≤ 1.0 mm, rotation/scale ≤ 1e-3), not just bounding-box
overlap — a tractogram and FA map in mismatched coordinate spaces can have
overlapping world bounds and would otherwise pass, then yield
anatomically-plausible-but-wrong extraction. For .trk this is checked
explicitly; for headerless formats like .tck that carry no spatial header,
csttool warns that the affine could not be asserted (verify the tractogram is
in the same RASMM space as the FA map). (AU22)
Converting Voxel to World Coordinates¶
If your tractogram is in voxel space, convert it before using csttool:
import nibabel as nib
from dipy.io.streamline import load_tractogram, save_tractogram
from dipy.io.stateful_tractogram import Space
# Load with reference image
ref_img = nib.load("fa.nii.gz")
sft = load_tractogram("tractogram.trk", ref_img, to_space=Space.VOX)
# Convert to world coordinates
sft.to_rasmm()
# Save converted tractogram
save_tractogram(sft, "tractogram_rasmm.trk")
Skipping validation (not recommended)
You can bypass coordinate validation with --skip-coordinate-validation, but this is strongly discouraged as it can produce anatomically plausible but incorrect results.
Validating Your Data¶
Run csttool doctor to verify your environment, then:
# Check DICOM study
csttool import --dicom /path/to/study --out /path/to/output
# Check NIfTI files
csttool import --nifti /path/to/dwi.nii.gz --out /path/to/output
The import step will report:
- Number of volumes
- b-values present
- Number of gradient directions
- Any warnings about data quality
Recommended Datasets¶
For testing or learning, use these publicly available diffusion MRI datasets:
| Dataset | b-value | Directions | Access |
|---|---|---|---|
| HCP Young Adult | 1000/2000/3000 | 90×3 shells | Registration required |
| Brainlife Open Datasets | Various | Various | Free |
| OpenNeuro dMRI | Various | Various | Free |
Note that registration may be required.
Next Steps¶
- Quick Start — Run your first analysis
- Troubleshooting — Common data issues and fixes