Skip to content

Commit 2b2e400

Browse files
committed
Add informative ValueError for sparse fMRI acquisitions missing TR
1 parent 0de4346 commit 2b2e400

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

pipeline/nifti_loader.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,30 @@ def __init__(self, file_path, dataset_name):
1414
super().__init__(file_path, dataset_name)
1515
self.tr_time = None # Repetition Time (fMRI's version of sampling rate)
1616

17-
# COMPOSITION: Plug in the filter engine we built earlier!
1817
self.filter_engine = StringFilterEngine()
1918

2019
def _parse_bids_metadata(self):
2120
"""
2221
Automatically extracts RepetitionTime (TR) from the BIDS sidecar JSON.
23-
This proves domain expertise in the Brain Imaging Data Structure (BIDS) standard.
22+
Includes safety checks for sparse acquisition paradigms where TR is undefined.
2423
"""
25-
# A valid BIDS NIfTI (sub-01_task-rest_bold.nii.gz) always has a matching JSON
2624
base_name = self.file_path.replace(".nii.gz", "").replace(".nii", "")
2725
json_path = f"{base_name}.json"
2826

2927
if os.path.exists(json_path):
3028
with open(json_path, "r") as f:
3129
metadata = json.load(f)
32-
# Safely extract the TR time
3330
self.tr_time = metadata.get("RepetitionTime", None)
31+
32+
# edge case for sparse acquisition
33+
if self.tr_time is None:
34+
raise ValueError(
35+
f"\n[{self.dataset_name}] BIDS ERROR: 'RepetitionTime' is missing in the JSON sidecar.\n"
36+
f"NeuroAlign currently requires a defined TR for continuous temporal alignment.\n"
37+
f"Sparse acquisition paradigms (where TR is undefined) are not yet supported. "
38+
f"See BIDS MRI Spec 1.11.1 for details."
39+
)
40+
3441
print(
3542
f"[{self.dataset_name}] BIDS Metadata automatically parsed. TR = {self.tr_time}s"
3643
)

0 commit comments

Comments
 (0)