jesse-radiata commited on
Commit
3e3f6c5
·
verified ·
1 Parent(s): 4882dff

Add files using upload-large-folder tool

Browse files
Files changed (1) hide show
  1. brain-structure.py +12 -5
brain-structure.py CHANGED
@@ -117,17 +117,24 @@ class BrainStructure(datasets.GeneratorBasedBuilder):
117
  """
118
  id_ = 0
119
  data_path = Path(data_dir)
 
120
  for json_path in data_path.rglob("*_scandata.json"):
121
  with open(json_path, "r") as f:
122
  sidecar = json.load(f)
123
 
 
124
  if sidecar.get("split") == desired_split:
125
- # Build the matching NIfTI path
126
- possible_nii_name = json_path.name.replace("_scandata.json", "_T1w")
127
- # Look in the same folder for .nii.gz
128
- nii_path = json_path.parent / f"{possible_nii_name}.nii.gz"
 
 
 
 
 
129
 
130
- if not nii_path.is_file():
131
  logger.warning(f"No .nii.gz found for {json_path}")
132
  continue
133
 
 
117
  """
118
  id_ = 0
119
  data_path = Path(data_dir)
120
+
121
  for json_path in data_path.rglob("*_scandata.json"):
122
  with open(json_path, "r") as f:
123
  sidecar = json.load(f)
124
 
125
+ # Only yield if sidecar["split"] matches
126
  if sidecar.get("split") == desired_split:
127
+ # Build a base prefix from the JSON filename (minus "_scandata")
128
+ # e.g. "msub-OASIS20133_ses-03"
129
+ base_prefix = json_path.stem.replace("_scandata", "")
130
+
131
+ # Search for a NIfTI that starts with that prefix and includes '_T1w'
132
+ nii_path = None
133
+ for potential_nii in json_path.parent.glob(f"{base_prefix}*_T1w*.nii.gz"):
134
+ nii_path = potential_nii
135
+ break
136
 
137
+ if not nii_path or not nii_path.is_file():
138
  logger.warning(f"No .nii.gz found for {json_path}")
139
  continue
140