Repository: bids-standard/pybids

Issue:
get_fieldmaps not compatible with multiple 'intendedfor'
currently `if path.endswith(metadata["IntendedFor"]):` assumes string, but current specs allow list as well

get_fieldmaps not compatible with multiple 'intendedfor'
currently `if path.endswith(metadata["IntendedFor"]):` assumes string, but current specs allow list as well



Discussion:

Resolving patch:
diff --git a/bids/grabbids/bids_layout.py b/bids/grabbids/bids_layout.py
--- a/bids/grabbids/bids_layout.py
+++ b/bids/grabbids/bids_layout.py
@@ -67,7 +67,11 @@ def get_fieldmap(self, path):
                              extensions=['nii.gz', 'nii']):
             metadata = self.get_metadata(file.filename)
             if metadata and "IntendedFor" in metadata.keys():
-                if path.endswith(metadata["IntendedFor"]):
+                if isinstance(metadata["IntendedFor"], list):
+                    intended_for = metadata["IntendedFor"]
+                else:
+                    intended_for = [metadata["IntendedFor"]]
+                if any([path.endswith(suffix) for suffix in intended_for]):
                     if file.type == "phasediff":
                         fieldmap_set = {"phasediff": file.filename,
                                         "magnitude1": file.filename.replace(


Test patch:
diff --git a/bids/grabbids/tests/data/7t_trt/sub-03/ses-2/fmap/sub-03_ses-2_run-2_phasediff.json b/bids/grabbids/tests/data/7t_trt/sub-03/ses-2/fmap/sub-03_ses-2_run-2_phasediff.json
--- a/bids/grabbids/tests/data/7t_trt/sub-03/ses-2/fmap/sub-03_ses-2_run-2_phasediff.json
+++ b/bids/grabbids/tests/data/7t_trt/sub-03/ses-2/fmap/sub-03_ses-2_run-2_phasediff.json
@@ -1 +1 @@
-{"EchoTime2": 0.00702, "EchoTime1": 0.006, "IntendedFor": "ses-2/func/sub-03_ses-2_task-rest_acq-fullbrain_run-2_bold.nii.gz"}
\ No newline at end of file
+{"EchoTime2": 0.00702, "EchoTime1": 0.006, "IntendedFor": ["ses-2/func/sub-03_ses-2_task-rest_acq-fullbrain_run-2_bold.nii.gz", "ses-2/func/sub-03_ses-2_task-rest_acq-fullbrain_run-1_bold.nii.gz"]}
\ No newline at end of file
diff --git a/bids/grabbids/tests/test_grabbids.py b/bids/grabbids/tests/test_grabbids.py
--- a/bids/grabbids/tests/test_grabbids.py
+++ b/bids/grabbids/tests/test_grabbids.py
@@ -39,8 +39,18 @@ def test_get_subjects():
 def test_get_fieldmap():
     data_dir = join(dirname(__file__), 'data', '7t_trt')
     layout = BIDSLayout(data_dir)
-    target = 'sub-03/ses-2/func/sub-03_ses-2_task-' \
+    target = 'sub-03/ses-1/func/sub-03_ses-1_task-' \
              'rest_acq-fullbrain_run-1_bold.nii.gz'
     result = layout.get_fieldmap(join(data_dir, target))
     assert result["type"] == "phasediff"
-    assert result["phasediff"].endswith('sub-03_ses-2_run-1_phasediff.nii.gz')
+    assert result["phasediff"].endswith('sub-03_ses-1_run-1_phasediff.nii.gz')
+
+
+def test_get_fieldmap2():
+    data_dir = join(dirname(__file__), 'data', '7t_trt')
+    layout = BIDSLayout(data_dir)
+    target = 'sub-03/ses-2/func/sub-03_ses-2_task-' \
+             'rest_acq-fullbrain_run-2_bold.nii.gz'
+    result = layout.get_fieldmap(join(data_dir, target))
+    assert result["type"] == "phasediff"
+    assert result["phasediff"].endswith('sub-03_ses-2_run-2_phasediff.nii.gz')