Skip to content

Commit

Permalink
add/fit-in suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bpinsard committed Aug 8, 2024
1 parent 7f82416 commit bd3efd8
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ def prep_conversion(
)


IMAGETYPE_TO_PARTS = {
"M": "mag",
"MAGNITUDE": "mag",
"P": "phase",
"PHASE": "phase",
"REAL": "real",
"IMAGINARY": "imag",
}


def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
"""
Insert `_part-<mag|phase|real|imag>` entity into filename if data are from a
Expand Down Expand Up @@ -330,18 +340,21 @@ def update_complex_name(metadata: dict[str, Any], filename: str) -> str:
if any(ut in filename for ut in unsupported_types):
return filename

# Check to see if it is magnitude or phase part:
img_type = cast(List[str], metadata.get("ImageType", []))
if "M" in img_type or "MAGNITUDE" in img_type:
part = "mag"
elif "P" in img_type or "PHASE" in img_type:
part = "phase"
elif "REAL" in img_type:
part = "real"
elif "IMAGINARY" in img_type:
part = "imag"

present_parts = set(
IMAGETYPE_TO_PARTS[type] for tp in img_type if tp in IMAGETYPE_TO_PARTS
)
if not present_parts:
raise RuntimeError(
f"Data type could not be inferred from the ImageType={img_type}. Known types are: {sorted(IMAGETYPE_TO_PARTS)}"
)
elif len(present_parts) == 1:
part = present_parts.pop()
else:
raise RuntimeError("Data type could not be inferred from the metadata.")
raise RuntimeError(
f"Data type could not be inferred from the ImageType={img_type}. Multiple BIDS parts matched: {present_parts}"
)

# Determine scan suffix
filetype = "_" + filename.split("_")[-1]
Expand Down Expand Up @@ -979,13 +992,12 @@ def save_converted_files(
is_uncombined = (
len(set(filter(bool, channel_names))) > 1
) # Check for uncombined data
CPLX_PARTS = ["MAGNITUDE", "PHASE", "IMAGINARY", "REAL"]
is_complex = len(
set(
[
part
for its in image_types
for part in CPLX_PARTS
for part in IMAGETYPE_TO_PARTS.keys()
if part in its or part[0] in its
]
)
Expand Down

0 comments on commit bd3efd8

Please sign in to comment.