jesse-radiata commited on
Commit
3b76088
·
verified ·
1 Parent(s): ef674c5

Add files using upload-large-folder tool

Browse files
.DS_Store ADDED
Binary file (12.3 kB). View file
 
OASIS-1/.DS_Store CHANGED
Binary files a/OASIS-1/.DS_Store and b/OASIS-1/.DS_Store differ
 
OASIS-1/sub-OASIS10253/.DS_Store ADDED
Binary file (6.15 kB). View file
 
OASIS-1/sub-OASIS10253/ses-M000/.DS_Store ADDED
Binary file (6.15 kB). View file
 
OASIS-1/sub-OASIS10280/.DS_Store ADDED
Binary file (6.15 kB). View file
 
OASIS-1/sub-OASIS10280/ses-M000/.DS_Store ADDED
Binary file (6.15 kB). View file
 
brain-structure.py CHANGED
@@ -133,47 +133,50 @@ class BrainStructure(datasets.GeneratorBasedBuilder):
133
  id_ = 0
134
  for root, dirs, files in os.walk(data_dir):
135
  for fname in files:
136
- if fname.endswith("_scandata.json"):
137
- sidecar_path = os.path.join(root, fname)
138
- with open(sidecar_path, "r") as f:
139
- sidecar = json.load(f)
140
-
141
- # Only yield if 'split' matches the requested split
142
- if sidecar.get("split") == desired_split:
143
- # Locate corresponding NIfTI .nii.gz
144
- nii_prefix = fname.replace("_scandata.json", "_T1w")
145
- nii_filepath = None
146
- for potential_file in files:
147
- if (potential_file.startswith(nii_prefix)
148
- and potential_file.endswith(".nii.gz")):
149
- nii_filepath = os.path.join(root, potential_file)
150
- break
151
-
152
- if not nii_filepath:
153
- logger.warning(f"No .nii.gz found for {sidecar_path}")
154
- continue
155
-
156
- yield id_, {
157
- "id": str(id_),
158
- "nii_filepath": nii_filepath,
159
- "metadata": {
160
- "split": sidecar.get("split", ""),
161
- "participant_id": sidecar.get("participant_id", ""),
162
- "session_id": sidecar.get("session_id", ""),
163
- "study": sidecar.get("study", ""),
164
- "age": sidecar.get("age", 0),
165
- "sex": sidecar.get("sex", ""),
166
- "clinical_diagnosis": sidecar.get("clinical_diagnosis", ""),
167
- "scanner_manufacturer": sidecar.get("scanner_manufacturer", ""),
168
- "scanner_model": sidecar.get("scanner_model", ""),
169
- "field_strength": sidecar.get("field_strength", ""),
170
- "image_quality_rating": float(sidecar.get("image_quality_rating", 0.0)),
171
- "total_intracranial_volume": float(sidecar.get("total_intracranial_volume", 0.0)),
172
- "license": sidecar.get("license", ""),
173
- "website": sidecar.get("website", ""),
174
- "citation": sidecar.get("citation", ""),
175
- "t1_file_name": sidecar.get("t1_file_name", ""),
176
- "radiata_id": sidecar.get("radiata_id", 0),
177
- },
178
- }
179
- id_ += 1
 
 
 
 
133
  id_ = 0
134
  for root, dirs, files in os.walk(data_dir):
135
  for fname in files:
136
+ # Only consider sidecar files that start with "msub" and end with "_scandata.json"
137
+ if not (fname.startswith("msub") and fname.endswith("_scandata.json")):
138
+ continue
139
+
140
+ sidecar_path = os.path.join(root, fname)
141
+ with open(sidecar_path, "r") as f:
142
+ sidecar = json.load(f)
143
+
144
+ # if sidecar's "split" matches the desired_split...
145
+ if sidecar.get("split") == desired_split:
146
+ # attempt to find the .nii.gz with the same "msub" prefix
147
+ possible_nii_prefix = fname.replace("_scandata.json", "_T1w")
148
+ nii_filepath = None
149
+ for potential_file in files:
150
+ if (potential_file.startswith(possible_nii_prefix)
151
+ and potential_file.endswith(".nii.gz")):
152
+ nii_filepath = os.path.join(root, potential_file)
153
+ break
154
+
155
+ if not nii_filepath:
156
+ logger.warning(f"No corresponding .nii.gz file found for {sidecar_path}")
157
+ continue
158
+
159
+ yield id_, {
160
+ "id": str(id_),
161
+ "nii_filepath": nii_filepath,
162
+ "metadata": {
163
+ "split": sidecar.get("split", ""),
164
+ "participant_id": sidecar.get("participant_id", ""),
165
+ "session_id": sidecar.get("session_id", ""),
166
+ "study": sidecar.get("study", ""),
167
+ "age": sidecar.get("age", 0),
168
+ "sex": sidecar.get("sex", ""),
169
+ "clinical_diagnosis": sidecar.get("clinical_diagnosis", ""),
170
+ "scanner_manufacturer": sidecar.get("scanner_manufacturer", ""),
171
+ "scanner_model": sidecar.get("scanner_model", ""),
172
+ "field_strength": sidecar.get("field_strength", ""),
173
+ "image_quality_rating": float(sidecar.get("image_quality_rating", 0.0)),
174
+ "total_intracranial_volume": float(sidecar.get("total_intracranial_volume", 0.0)),
175
+ "license": sidecar.get("license", ""),
176
+ "website": sidecar.get("website", ""),
177
+ "citation": sidecar.get("citation", ""),
178
+ "t1_file_name": sidecar.get("t1_file_name", ""),
179
+ "radiata_id": sidecar.get("radiata_id", 0),
180
+ },
181
+ }
182
+ id_ += 1