Skip to content

Commit

Permalink
ENH: Improve logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Sep 27, 2022
1 parent 90b4c45 commit 67cab9e
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,17 @@ def find_estimators(*,
b0_entities = base_entities.copy()
b0_entities["B0FieldIdentifier"] = b0_id

_e = fm.FieldmapEstimation([
e = fm.FieldmapEstimation([
fm.FieldmapFile(fmap.path, metadata=fmap.get_metadata())
for fmap in layout.get(**b0_entities)
])
logger.debug("Found PEPOLAR estimation %s from sources %s", _e, [x.path for x in _e.sources])
estimators.append(_e)
logger.debug(
"Found %s estimation from %d sources:\n- %s",
e.method.name,
len(e.sources),
"\n- ".join([str(x.path.relative_to(layout.root)) for x in e.sources]),
)
estimators.append(e)

# Step 2. If no B0FieldIdentifiers were found, try several heuristics
if not estimators:
Expand All @@ -304,7 +309,12 @@ def find_estimators(*,
e = fm.FieldmapEstimation(
fm.FieldmapFile(fmap.path, metadata=fmap.get_metadata())
)
logger.debug("Found estimation %s from fmap %s", e, fmap.path)
logger.debug(
"Found %s estimation from %d sources:\n- %s",
e.method.name,
len(e.sources),
"\n- ".join([str(x.path.relative_to(layout.root)) for x in e.sources]),
)
estimators.append(e)

# A bunch of heuristics to select EPI fieldmaps
Expand All @@ -324,7 +334,12 @@ def find_estimators(*,
for fmap in layout.get(direction=dirs, **entities)
]
)
logger.debug("Found PEPOLAR estimation %s from sources %s", e, [x.path for x in e.sources])
logger.debug(
"Found %s estimation from %d sources:\n- %s",
e.method.name,
len(e.sources),
"\n- ".join([str(x.path.relative_to(layout.root)) for x in e.sources]),
)
estimators.append(e)

# At this point, only single-PE _epi files WITH ``IntendedFor`` can
Expand All @@ -335,10 +350,10 @@ def find_estimators(*,

for epi_fmap in has_intended:
if epi_fmap.path in fm._estimators.sources:
logger.debug("Single PE fieldmap %s already in use", epi_fmap.path)
logger.debug("Skipping fieldmap %s (already in use)", epi_fmap.relpath)
continue # skip EPI images already considered above

logger.debug("Found single PE fieldmap %s", epi_fmap.path)
logger.debug("Found single PE fieldmap %s", epi_fmap.relpath)
epi_base_md = epi_fmap.get_metadata()

# There are two possible interpretations of an IntendedFor list:
Expand All @@ -353,7 +368,7 @@ def find_estimators(*,
logger.debug("Single PE target %s not found", target)
continue

logger.debug("Found single PE target %s", target.path)
logger.debug("Found single PE target %s", target.relpath)
# The new estimator is IntendedFor the individual targets,
# even if the EPI file is IntendedFor multiple
estimator_md = epi_base_md.copy()
Expand All @@ -365,7 +380,12 @@ def find_estimators(*,
fm.FieldmapFile(target.path, metadata=target.get_metadata())
]
)
logger.debug("Found estimation %s from fmap %s", e, epi_fmap.path)
logger.debug(
"Found %s estimation from %d sources:\n- %s",
e.method.name,
len(e.sources),
"\n- ".join([str(x.path.relative_to(layout.root)) for x in e.sources]),
)
estimators.append(e)

if estimators and not force_fmapless:
Expand All @@ -378,6 +398,7 @@ def find_estimators(*,
logger.debug("Skipping fmap-less estimation")
return estimators

logger.debug("Attempting fmap-less estimation")
from .epimanip import get_trt

for ses, suffix in sorted(product(sessions or (None,), fmapless)):
Expand Down Expand Up @@ -423,7 +444,12 @@ def find_estimators(*,
*fmfiles,
]
)
logger.debug("Fieldmap-less estimation %s with sources %s", e, [x.path for x in e.sources])
logger.debug(
"Found %s estimation from %d sources:\n- %s",
e.method.name,
len(e.sources),
"\n- ".join([str(x.path.relative_to(layout.root)) for x in e.sources]),
)
estimators.append(e)

return estimators

0 comments on commit 67cab9e

Please sign in to comment.