Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Find B0FieldIdentifiers when one image contributes to multiple #298

Merged
merged 11 commits into from
Dec 6, 2022
16 changes: 9 additions & 7 deletions sdcflows/fieldmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,15 @@ def __attrs_post_init__(self):
# Register this estimation method
if not self.bids_id:
# If not manually set, try to get it from BIDS metadata
bids_ids = set(
[
f.metadata.get("B0FieldIdentifier")
for f in self.sources
if f.metadata.get("B0FieldIdentifier")
]
)
bids_ids = [
set(listify(f.metadata.get("B0FieldIdentifier")))
for f in self.sources
if f.metadata.get("B0FieldIdentifier")
]

# intersection of B0FieldIdentifiers (in case of lists)
if len(bids_ids) > 1:
bids_ids = bids_ids[0].intersection(*bids_ids[1:])
if len(bids_ids) > 1:
raise ValueError(
f"Multiple ``B0FieldIdentifier`` set: <{', '.join(bids_ids)}>"
bpinsard marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 4 additions & 1 deletion sdcflows/utils/wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ def find_estimators(
b0_ids = tuple()
with suppress(BIDSEntityError):
b0_ids = layout.get_B0FieldIdentifiers(**base_entities)
# flatten lists from json (tupled in pybids for hashing), then unique
b0_ids = set(sum([(b0_id if isinstance(b0_id, tuple) else (b0_id,)) for b0_id in b0_ids ],()))

if b0_ids:
logger.debug(
Expand All @@ -296,7 +298,8 @@ def find_estimators(

e = fm.FieldmapEstimation([
fm.FieldmapFile(fmap.path, metadata=fmap.get_metadata())
for fmap in layout.get(**b0_entities)
for fmap in layout.get(**base_entities, B0FieldIdentifier=b0_id) +
layout.get(**base_entities, B0FieldIdentifier=f'"{b0_id}"', regex_search=True)
])
_log_debug_estimation(logger, e, layout.root)
estimators.append(e)
Expand Down