@@ -295,8 +295,8 @@ def prep_conversion(
295
295
296
296
def update_complex_name (metadata : dict [str , Any ], filename : str ) -> str :
297
297
"""
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.
300
300
301
301
Parameters
302
302
----------
@@ -329,17 +329,21 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
329
329
# Check to see if it is magnitude or phase part:
330
330
img_type = cast (List [str ], metadata .get ("ImageType" , []))
331
331
if "M" in img_type :
332
- mag_or_phase = "mag"
332
+ part = "mag"
333
333
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"
335
339
else :
336
340
raise RuntimeError ("Data type could not be inferred from the metadata." )
337
341
338
342
# Determine scan suffix
339
343
filetype = "_" + filename .split ("_" )[- 1 ]
340
344
341
345
# Insert part label
342
- if not ("_part-%s" % mag_or_phase ) in filename :
346
+ if not ("_part-%s" % part ) in filename :
343
347
# If "_part-" is specified, prepend the 'mag_or_phase' value.
344
348
if "_part-" in filename :
345
349
raise BIDSError (
@@ -364,7 +368,7 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
364
368
]
365
369
for label in entities_after_part :
366
370
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 ))
368
372
break
369
373
370
374
return filename
@@ -971,8 +975,9 @@ def save_converted_files(
971
975
is_uncombined = (
972
976
len (set (filter (bool , channel_names ))) > 1
973
977
) # Check for uncombined data
978
+ PARTS = ["M" , "P" , "IMAGINARY" , "REAL" ]
974
979
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
976
981
) # Determine if data are complex (magnitude + phase)
977
982
echo_times_lst = sorted (echo_times ) # also converts to list
978
983
channel_names_lst = sorted (channel_names ) # also converts to list
0 commit comments