From 8100cc05a4aa3502065d34aff5780498907d0f94 Mon Sep 17 00:00:00 2001 From: Basile Date: Fri, 2 Dec 2022 20:20:21 -0500 Subject: [PATCH] Update sdcflows/fieldmaps.py Co-authored-by: Chris Markiewicz --- sdcflows/fieldmaps.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sdcflows/fieldmaps.py b/sdcflows/fieldmaps.py index cf6bb8a406..a620e9abf2 100644 --- a/sdcflows/fieldmaps.py +++ b/sdcflows/fieldmaps.py @@ -404,18 +404,20 @@ 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(listify(f.metadata.get("B0FieldIdentifier"))) + b0_ids = [ + 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: + bids_ids = b0_ids[0].intersection(*b0_ids[1:]) + + if not bids_ids: + raise ValueError( + f"No common ``B0FieldIdentifier`` found: <{', '.join(b0_ids)}>" + ) + elif len(bids_ids) > 1: raise ValueError( - f"Multiple ``B0FieldIdentifier`` set: <{', '.join(bids_ids)}>" + f"Multiple common ``B0FieldIdentifier``s found: <{', '.join(bids_ids)}>" ) elif bids_ids: object.__setattr__(self, "bids_id", bids_ids.pop())