diff --git a/min-requirements.txt b/min-requirements.txt index c18a3e04ea..817a3b3ec4 100644 --- a/min-requirements.txt +++ b/min-requirements.txt @@ -12,3 +12,4 @@ scikit-image==0.18 scipy==1.8.1 templateflow toml +warpkit==0.1.1 diff --git a/requirements.txt b/requirements.txt index 898616b40d..da9e6638c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,3 +12,4 @@ scikit-image>=0.18 scipy>=1.8.1 templateflow toml +warpkit==0.1.1 diff --git a/sdcflows/fieldmaps.py b/sdcflows/fieldmaps.py index d1c9b26bf0..9ce0ea97ad 100644 --- a/sdcflows/fieldmaps.py +++ b/sdcflows/fieldmaps.py @@ -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 - 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( diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index 214d90ba82..e89996003e 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -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( + 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.