Skip to content

Commit ba524c1

Browse files
committed
handles real+imaginary data
1 parent 68231ef commit ba524c1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

heudiconv/convert.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ def prep_conversion(
299299

300300
def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
301301
"""
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.
304304
305305
Parameters
306306
----------
@@ -333,17 +333,21 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
333333
# Check to see if it is magnitude or phase part:
334334
img_type = cast(List[str], metadata.get("ImageType", []))
335335
if "M" in img_type:
336-
mag_or_phase = "mag"
336+
part = "mag"
337337
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"
339343
else:
340344
raise RuntimeError("Data type could not be inferred from the metadata.")
341345

342346
# Determine scan suffix
343347
filetype = "_" + filename.split("_")[-1]
344348

345349
# Insert part label
346-
if not ("_part-%s" % mag_or_phase) in filename:
350+
if not ("_part-%s" % part) in filename:
347351
# If "_part-" is specified, prepend the 'mag_or_phase' value.
348352
if "_part-" in filename:
349353
raise BIDSError(
@@ -368,7 +372,7 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
368372
]
369373
for label in entities_after_part:
370374
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))
372376
break
373377

374378
return filename
@@ -975,8 +979,9 @@ def save_converted_files(
975979
is_uncombined = (
976980
len(set(filter(bool, channel_names))) > 1
977981
) # Check for uncombined data
982+
PARTS = ["M", "P", "IMAGINARY", "REAL"]
978983
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
980985
) # Determine if data are complex (magnitude + phase)
981986
echo_times_lst = sorted(echo_times) # also converts to list
982987
channel_names_lst = sorted(channel_names) # also converts to list

0 commit comments

Comments
 (0)