@@ -299,8 +299,8 @@ def prep_conversion(
299
299
300
300
def update_complex_name (metadata : dict [str , Any ], filename : str ) -> str :
301
301
"""
302
- Insert `_part-<mag|phase>` entity into filename if data are from a
303
- sequence with magnitude/phase part.
302
+ Insert `_part-<mag|phase|real|imag >` entity into filename if data are from a
303
+ sequence with magnitude/phase/real/imaginary part.
304
304
305
305
Parameters
306
306
----------
@@ -333,17 +333,21 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
333
333
# Check to see if it is magnitude or phase part:
334
334
img_type = cast (List [str ], metadata .get ("ImageType" , []))
335
335
if "M" in img_type :
336
- mag_or_phase = "mag"
336
+ part = "mag"
337
337
elif "P" in img_type :
338
- mag_or_phase = "phase"
338
+ part = "phase"
339
+ elif "REAL" in img_type :
340
+ part = "real"
341
+ elif "IMAGINARY" in img_type :
342
+ part = "imag"
339
343
else :
340
344
raise RuntimeError ("Data type could not be inferred from the metadata." )
341
345
342
346
# Determine scan suffix
343
347
filetype = "_" + filename .split ("_" )[- 1 ]
344
348
345
349
# Insert part label
346
- if not ("_part-%s" % mag_or_phase ) in filename :
350
+ if not ("_part-%s" % part ) in filename :
347
351
# If "_part-" is specified, prepend the 'mag_or_phase' value.
348
352
if "_part-" in filename :
349
353
raise BIDSError (
@@ -368,7 +372,7 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
368
372
]
369
373
for label in entities_after_part :
370
374
if (label == filetype ) or (label in filename ):
371
- filename = filename .replace (label , "_part-%s%s" % (mag_or_phase , label ))
375
+ filename = filename .replace (label , "_part-%s%s" % (part , label ))
372
376
break
373
377
374
378
return filename
@@ -975,8 +979,9 @@ def save_converted_files(
975
979
is_uncombined = (
976
980
len (set (filter (bool , channel_names ))) > 1
977
981
) # Check for uncombined data
982
+ PARTS = ["M" , "P" , "IMAGINARY" , "REAL" ]
978
983
is_complex = (
979
- "M" in image_types and "P" in image_types
984
+ len ( set ( filter ( lambda x : [ part in x for part in PARTS ], image_types ))) > 1
980
985
) # Determine if data are complex (magnitude + phase)
981
986
echo_times_lst = sorted (echo_times ) # also converts to list
982
987
channel_names_lst = sorted (channel_names ) # also converts to list
0 commit comments