@@ -45,9 +45,7 @@ def _type_setter(obj, attribute, value):
45
45
return value
46
46
47
47
if obj .method != EstimatorType .UNKNOWN and obj .method != value :
48
- raise TypeError (
49
- f"Cannot change determined method { obj .method } to { value } ."
50
- )
48
+ raise TypeError (f"Cannot change determined method { obj .method } to { value } ." )
51
49
52
50
if value not in (
53
51
EstimatorType .PEPOLAR ,
@@ -184,14 +182,12 @@ def __attrs_post_init__(self):
184
182
"""Validate metadata and additional checks."""
185
183
self .entities = parse_file_entities (str (self .path ))
186
184
self .suffix = self .entities .pop ("suffix" )
187
- extension = self .entities .pop (' extension' ).lstrip ('.' )
185
+ extension = self .entities .pop (" extension" ).lstrip ("." )
188
186
189
187
# Automatically fill metadata in when possible
190
188
# TODO: implement BIDS hierarchy of metadata
191
189
if self .find_meta :
192
- sidecar = Path (
193
- str (self .path ).replace (extension , "json" )
194
- )
190
+ sidecar = Path (str (self .path ).replace (extension , "json" ))
195
191
if sidecar .is_file ():
196
192
_meta = self .metadata or {}
197
193
self .metadata = loads (sidecar .read_text ())
@@ -200,26 +196,32 @@ def __attrs_post_init__(self):
200
196
# Attempt to infer a bids_root folder
201
197
relative_path = relative_to_root (self .path )
202
198
if str (relative_path ) != str (self .path ):
203
- self .bids_root = Path (str (self .path )[:- len (str (relative_path ))])
199
+ self .bids_root = Path (str (self .path )[: - len (str (relative_path ))])
204
200
205
201
# Check for REQUIRED metadata (depends on suffix.)
206
202
if self .suffix in ("bold" , "dwi" , "epi" , "sbref" ):
207
203
if "PhaseEncodingDirection" not in self .metadata :
208
- raise MetadataError (f"Missing 'PhaseEncodingDirection' for <{ self .path } >." )
204
+ raise MetadataError (
205
+ f"Missing 'PhaseEncodingDirection' for <{ self .path } >."
206
+ )
209
207
if not (
210
208
set (("TotalReadoutTime" , "EffectiveEchoSpacing" )).intersection (
211
- self .metadata .keys ())
209
+ self .metadata .keys ()
210
+ )
212
211
):
213
- raise MetadataError (f"Missing readout timing information for <{ self .path } >." )
212
+ raise MetadataError (
213
+ f"Missing readout timing information for <{ self .path } >."
214
+ )
214
215
215
216
if self .suffix == "fieldmap" and "Units" not in self .metadata :
216
217
raise MetadataError (f"Missing 'Units' for <{ self .path } >." )
217
218
218
- if (
219
- self .suffix == "phasediff"
220
- and ("EchoTime1" not in self .metadata or "EchoTime2" not in self .metadata )
219
+ if self .suffix == "phasediff" and (
220
+ "EchoTime1" not in self .metadata or "EchoTime2" not in self .metadata
221
221
):
222
- raise MetadataError (f"Missing 'EchoTime1' and/or 'EchoTime2' for <{ self .path } >." )
222
+ raise MetadataError (
223
+ f"Missing 'EchoTime1' and/or 'EchoTime2' for <{ self .path } >."
224
+ )
223
225
224
226
if self .suffix in ("phase1" , "phase2" ) and ("EchoTime" not in self .metadata ):
225
227
raise MetadataError (f"Missing 'EchoTime' for <{ self .path } >." )
@@ -256,13 +258,16 @@ def __attrs_post_init__(self):
256
258
suffix_set = set (suffix_list )
257
259
258
260
# Fieldmap option 1: actual field-mapping sequences
259
- fmap_types = suffix_set .intersection (("fieldmap" , "phasediff" , "phase1" , "phase2" ))
261
+ fmap_types = suffix_set .intersection (
262
+ ("fieldmap" , "phasediff" , "phase1" , "phase2" )
263
+ )
260
264
if len (fmap_types ) > 1 and fmap_types - set (("phase1" , "phase2" )):
261
265
raise TypeError (f"Incompatible suffices found: <{ ',' .join (fmap_types )} >." )
262
266
263
267
if fmap_types :
264
268
sources = sorted (
265
- str (f .path ) for f in self .sources
269
+ str (f .path )
270
+ for f in self .sources
266
271
if f .suffix in ("fieldmap" , "phasediff" , "phase1" , "phase2" )
267
272
)
268
273
@@ -282,22 +287,33 @@ def __attrs_post_init__(self):
282
287
magnitude = f"magnitude{ '' if self .method == EstimatorType .MAPPED else '1' } "
283
288
if magnitude not in suffix_set :
284
289
try :
285
- self .sources .append (FieldmapFile (
286
- sources [0 ].replace ("fieldmap" , "magnitude" ).replace (
287
- "diff" , "1" ).replace ("phase" , "magnitude" )
288
- ))
290
+ self .sources .append (
291
+ FieldmapFile (
292
+ sources [0 ]
293
+ .replace ("fieldmap" , "magnitude" )
294
+ .replace ("diff" , "1" )
295
+ .replace ("phase" , "magnitude" )
296
+ )
297
+ )
289
298
except Exception :
290
299
raise ValueError (
291
300
"A fieldmap or phase-difference estimation type was found, "
292
301
f"but an anatomical reference ({ magnitude } file) is missing."
293
302
)
294
303
295
304
# Check presence and try to find (if necessary) the second magnitude file
296
- if self .method == EstimatorType .PHASEDIFF and "magnitude2" not in suffix_set :
305
+ if (
306
+ self .method == EstimatorType .PHASEDIFF
307
+ and "magnitude2" not in suffix_set
308
+ ):
297
309
try :
298
- self .sources .append (FieldmapFile (
299
- sources [- 1 ].replace ("diff" , "2" ).replace ("phase" , "magnitude" )
300
- ))
310
+ self .sources .append (
311
+ FieldmapFile (
312
+ sources [- 1 ]
313
+ .replace ("diff" , "2" )
314
+ .replace ("phase" , "magnitude" )
315
+ )
316
+ )
301
317
except Exception :
302
318
if "phase2" in suffix_set :
303
319
raise ValueError (
@@ -308,9 +324,9 @@ def __attrs_post_init__(self):
308
324
# Fieldmap option 2: PEPOLAR (and fieldmap-less or ANAT)
309
325
# IMPORTANT NOTE: fieldmap-less approaches can be considered PEPOLAR with RO = 0.0s
310
326
pepolar_types = suffix_set .intersection (("bold" , "dwi" , "epi" , "sbref" ))
311
- _pepolar_estimation = len ([
312
- f for f in suffix_list if f in ("bold" , "dwi" , "epi" , "sbref" )
313
- ]) > 1
327
+ _pepolar_estimation = (
328
+ len ([ f for f in suffix_list if f in ("bold" , "dwi" , "epi" , "sbref" )]) > 1
329
+ )
314
330
315
331
if _pepolar_estimation :
316
332
self .method = MODALITIES [pepolar_types .pop ()]
0 commit comments