Skip to content

Commit

Permalink
Fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Oct 23, 2024
1 parent 9c5fdd8 commit d7a59ee
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions min-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ scikit-image==0.18
scipy==1.8.1
templateflow
toml
warpkit==0.1.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ scikit-image>=0.18
scipy>=1.8.1
templateflow
toml
warpkit==0.1.1
38 changes: 28 additions & 10 deletions sdcflows/fieldmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,37 @@ def __attrs_post_init__(self):
raise TypeError(f"Incompatible suffixes found: <{','.join(fmap_types)}>.")

# Check for MEDIC
mag_bold, phase_bold, me_bold = 0, 0, 0
# They must have a bold suffix, multiple echoes, and both mag and phase data
echos = []
for f in self.sources:
if f.suffix == "bold" and ("part-mag" in f.path.name):
mag_bold += 1
echo = re.search(r"(?<=_echo-)\d+", f.path.name)
if echo:
echos.append(int(echo.group()))

echos = sorted(list(set(echos)))
if len(echos) > 1:
for echo in echos:
has_mag, has_phase = False, False
for f in self.sources:
if (
f.suffix == "bold"
and (f"echo-{echo}_" in f.path.name)
and ("part-mag" in f.path.name)
):
has_mag = True

if (
f.suffix == "bold"
and (f"echo-{echo}_" in f.path.name)
and ("part-phase" in f.path.name)
):
has_phase = True

if not (has_mag and has_phase):
break

Check warning on line 351 in sdcflows/fieldmaps.py

View check run for this annotation

Codecov / codecov/patch

sdcflows/fieldmaps.py#L351

Added line #L351 was not covered by tests

if f.suffix == "bold" and ("part-phase" in f.path.name):
phase_bold += 1

if f.suffix == "bold" and ("echo-" in f.path.name):
me_bold += 1

if (mag_bold > 1) and (phase_bold > 1) and (me_bold > 2) and (mag_bold == phase_bold):
self.method = EstimatorType.MEDIC
fmap_types = {}

if fmap_types:
sources = sorted(
Expand Down
37 changes: 23 additions & 14 deletions sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,22 +483,31 @@ def find_estimators(
str(item.path) for sublist in current_sources for item in sublist
]
if complex_imgs[0].path in current_sources:
print("Skipping fieldmap %s (already in use)" % complex_imgs[0].relpath)
logger.debug("Skipping fieldmap %s (already in use)", complex_imgs[0].relpath)
continue

if current_sources:
raise Exception(complex_imgs[0].path, current_sources)

e = fm.FieldmapEstimation(
[
fm.FieldmapFile(img.path, metadata=img.get_metadata())
for img in complex_imgs
]
)

_log_debug_estimation(logger, e, layout.root)
estimators.append(e)
continue
try:
e = fm.FieldmapEstimation(
[
fm.FieldmapFile(
img.path,
metadata=_filter_metadata(img.get_metadata(), subject),
)
for img in complex_imgs
]
)
except (ValueError, TypeError) as err:
_log_debug_estimator_fail(

Check warning on line 500 in sdcflows/utils/wrangler.py

View check run for this annotation

Codecov / codecov/patch

sdcflows/utils/wrangler.py#L499-L500

Added lines #L499 - L500 were not covered by tests
logger,
"unnamed MEDIC",
[],
layout.root,
str(err),
)
else:
_log_debug_estimation(logger, e, layout.root)
estimators.append(e)
continue

# At this point, only single-PE _epi files WITH ``IntendedFor`` can
# be automatically processed.
Expand Down

0 comments on commit d7a59ee

Please sign in to comment.