@@ -45,9 +45,7 @@ def _type_setter(obj, attribute, value):
4545 return value
4646
4747 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 } ." )
5149
5250 if value not in (
5351 EstimatorType .PEPOLAR ,
@@ -184,14 +182,12 @@ def __attrs_post_init__(self):
184182 """Validate metadata and additional checks."""
185183 self .entities = parse_file_entities (str (self .path ))
186184 self .suffix = self .entities .pop ("suffix" )
187- extension = self .entities .pop (' extension' ).lstrip ('.' )
185+ extension = self .entities .pop (" extension" ).lstrip ("." )
188186
189187 # Automatically fill metadata in when possible
190188 # TODO: implement BIDS hierarchy of metadata
191189 if self .find_meta :
192- sidecar = Path (
193- str (self .path ).replace (extension , "json" )
194- )
190+ sidecar = Path (str (self .path ).replace (extension , "json" ))
195191 if sidecar .is_file ():
196192 _meta = self .metadata or {}
197193 self .metadata = loads (sidecar .read_text ())
@@ -200,26 +196,32 @@ def __attrs_post_init__(self):
200196 # Attempt to infer a bids_root folder
201197 relative_path = relative_to_root (self .path )
202198 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 ))])
204200
205201 # Check for REQUIRED metadata (depends on suffix.)
206202 if self .suffix in ("bold" , "dwi" , "epi" , "sbref" ):
207203 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+ )
209207 if not (
210208 set (("TotalReadoutTime" , "EffectiveEchoSpacing" )).intersection (
211- self .metadata .keys ())
209+ self .metadata .keys ()
210+ )
212211 ):
213- raise MetadataError (f"Missing readout timing information for <{ self .path } >." )
212+ raise MetadataError (
213+ f"Missing readout timing information for <{ self .path } >."
214+ )
214215
215216 if self .suffix == "fieldmap" and "Units" not in self .metadata :
216217 raise MetadataError (f"Missing 'Units' for <{ self .path } >." )
217218
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
221221 ):
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+ )
223225
224226 if self .suffix in ("phase1" , "phase2" ) and ("EchoTime" not in self .metadata ):
225227 raise MetadataError (f"Missing 'EchoTime' for <{ self .path } >." )
@@ -256,13 +258,16 @@ def __attrs_post_init__(self):
256258 suffix_set = set (suffix_list )
257259
258260 # 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+ )
260264 if len (fmap_types ) > 1 and fmap_types - set (("phase1" , "phase2" )):
261265 raise TypeError (f"Incompatible suffices found: <{ ',' .join (fmap_types )} >." )
262266
263267 if fmap_types :
264268 sources = sorted (
265- str (f .path ) for f in self .sources
269+ str (f .path )
270+ for f in self .sources
266271 if f .suffix in ("fieldmap" , "phasediff" , "phase1" , "phase2" )
267272 )
268273
@@ -282,22 +287,33 @@ def __attrs_post_init__(self):
282287 magnitude = f"magnitude{ '' if self .method == EstimatorType .MAPPED else '1' } "
283288 if magnitude not in suffix_set :
284289 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+ )
289298 except Exception :
290299 raise ValueError (
291300 "A fieldmap or phase-difference estimation type was found, "
292301 f"but an anatomical reference ({ magnitude } file) is missing."
293302 )
294303
295304 # 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+ ):
297309 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+ )
301317 except Exception :
302318 if "phase2" in suffix_set :
303319 raise ValueError (
@@ -308,9 +324,9 @@ def __attrs_post_init__(self):
308324 # Fieldmap option 2: PEPOLAR (and fieldmap-less or ANAT)
309325 # IMPORTANT NOTE: fieldmap-less approaches can be considered PEPOLAR with RO = 0.0s
310326 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+ )
314330
315331 if _pepolar_estimation :
316332 self .method = MODALITIES [pepolar_types .pop ()]
0 commit comments