Skip to content

Commit

Permalink
handles real+imaginary data
Browse files Browse the repository at this point in the history
  • Loading branch information
bpinsard committed May 30, 2024
1 parent 73f157d commit 4304276
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ def prep_conversion(

def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
"""
Insert `_part-<mag|phase>` entity into filename if data are from a
sequence with magnitude/phase part.
Insert `_part-<mag|phase|real|imag>` entity into filename if data are from a
sequence with magnitude/phase/real/imaginary part.
Parameters
----------
Expand Down Expand Up @@ -329,17 +329,21 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
# Check to see if it is magnitude or phase part:
img_type = cast(List[str], metadata.get("ImageType", []))
if "M" in img_type:
mag_or_phase = "mag"
part = "mag"
elif "P" in img_type:
mag_or_phase = "phase"
part = "phase"
elif "REAL" in img_type:
part = "real"
elif "IMAGINARY" in img_type:
part = "imag"
else:
raise RuntimeError("Data type could not be inferred from the metadata.")

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

# Insert part label
if not ("_part-%s" % mag_or_phase) in filename:
if not ("_part-%s" % part) in filename:
# If "_part-" is specified, prepend the 'mag_or_phase' value.
if "_part-" in filename:
raise BIDSError(
Expand All @@ -364,7 +368,7 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
]
for label in entities_after_part:
if (label == filetype) or (label in filename):
filename = filename.replace(label, "_part-%s%s" % (mag_or_phase, label))
filename = filename.replace(label, "_part-%s%s" % (part, label))
break

return filename
Expand Down Expand Up @@ -971,8 +975,9 @@ def save_converted_files(
is_uncombined = (
len(set(filter(bool, channel_names))) > 1
) # Check for uncombined data
PARTS = ["M", "P", "IMAGINARY", "REAL"]
is_complex = (
"M" in image_types and "P" in image_types
len(set(filter(lambda x: [part in x for part in PARTS], image_types))) > 1
) # Determine if data are complex (magnitude + phase)
echo_times_lst = sorted(echo_times) # also converts to list
channel_names_lst = sorted(channel_names) # also converts to list
Expand Down

0 comments on commit 4304276

Please sign in to comment.