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 Sep 24, 2024
1 parent 8a5d27c commit 44544e4
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[tp] 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(

Check warning on line 355 in heudiconv/convert.py

View check run for this annotation

Codecov / codecov/patch

heudiconv/convert.py#L355

Added line #L355 was not covered by tests
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 44544e4

Please sign in to comment.