@@ -295,8 +295,8 @@ def prep_conversion(
295295
296296def update_complex_name (metadata : dict [str , Any ], filename : str ) -> str :
297297 """
298- Insert `_part-<mag|phase>` entity into filename if data are from a
299- sequence with magnitude/phase part.
298+ Insert `_part-<mag|phase|real|imag >` entity into filename if data are from a
299+ sequence with magnitude/phase/real/imaginary part.
300300
301301 Parameters
302302 ----------
@@ -329,17 +329,21 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
329329 # Check to see if it is magnitude or phase part:
330330 img_type = cast (List [str ], metadata .get ("ImageType" , []))
331331 if "M" in img_type :
332- mag_or_phase = "mag"
332+ part = "mag"
333333 elif "P" in img_type :
334- mag_or_phase = "phase"
334+ part = "phase"
335+ elif "REAL" in img_type :
336+ part = "real"
337+ elif "IMAGINARY" in img_type :
338+ part = "imag"
335339 else :
336340 raise RuntimeError ("Data type could not be inferred from the metadata." )
337341
338342 # Determine scan suffix
339343 filetype = "_" + filename .split ("_" )[- 1 ]
340344
341345 # Insert part label
342- if not ("_part-%s" % mag_or_phase ) in filename :
346+ if not ("_part-%s" % part ) in filename :
343347 # If "_part-" is specified, prepend the 'mag_or_phase' value.
344348 if "_part-" in filename :
345349 raise BIDSError (
@@ -364,7 +368,7 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
364368 ]
365369 for label in entities_after_part :
366370 if (label == filetype ) or (label in filename ):
367- filename = filename .replace (label , "_part-%s%s" % (mag_or_phase , label ))
371+ filename = filename .replace (label , "_part-%s%s" % (part , label ))
368372 break
369373
370374 return filename
@@ -971,8 +975,9 @@ def save_converted_files(
971975 is_uncombined = (
972976 len (set (filter (bool , channel_names ))) > 1
973977 ) # Check for uncombined data
978+ PARTS = ["M" , "P" , "IMAGINARY" , "REAL" ]
974979 is_complex = (
975- "M" in image_types and "P" in image_types
980+ len ( set ( filter ( lambda x : [ part in x for part in PARTS ], image_types ))) > 1
976981 ) # Determine if data are complex (magnitude + phase)
977982 echo_times_lst = sorted (echo_times ) # also converts to list
978983 channel_names_lst = sorted (channel_names ) # also converts to list
0 commit comments