Repository: nipreps/niworkflows (language: python)

Issue:
``DerivativesDataSink`` drops ``fmapid`` entity when storing fieldmap reportlets
DerivativesDataSink produces ``derivatives/dmriprep/sub-36/figures/sub-36_desc-pepolar_fieldmap.svg`` instead of ``derivatives/dmriprep/sub-36/figures/sub-36_fmapid-auto0000_desc-pepolar_fieldmap.svg``

```
        DerivativesDataSink(
            base_directory=str(output_dir),
            datatype="figures",
            suffix="fieldmap",
            desc=fmap_type,
            dismiss_entities=("fmap",),
            allowed_entities=("fmapid",),
            source_file=["sub-36/fmap/sub-36_dir-1_run-1_epi.nii.gz", "sub-36/fmap/sub-36_dir-1_run-2_epi.nii.gz", "sub-36/fmap/sub-36_dir-2_run-1_epi.nii.gz", "sub-36/fmap/sub-36_dir-2_run-2_epi.nii.gz"],
            fmapid="auto0000"
        )
```

It seems that ``allowed_entities`` is not respected in this case.


Discussion / hints:

Fix patch:
diff --git a/niworkflows/data/nipreps.json b/niworkflows/data/nipreps.json
index 7addae8c63f..03c8f9b4c4d 100644
--- a/niworkflows/data/nipreps.json
+++ b/niworkflows/data/nipreps.json
@@ -153,7 +153,7 @@
     "sub-{subject}[/ses-{session}]/{datatype<dwi>|dwi}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_dir-{direction}][_rec-{reconstruction}][_run-{run}][_space-{space}][_cohort-{cohort}][_res-{resolution}]_desc-{desc}_{suffix<mask>}{extension<.json|.nii.gz|.nii>|.nii.gz}",
     "sub-{subject}[/ses-{session}]/{datatype<dwi>|dwi}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_dir-{direction}][_rec-{reconstruction}][_run-{run}][_space-{space}][_cohort-{cohort}][_res-{resolution}][_desc-{desc}]_{suffix<dwi>}{extension<.tsv|.bval|.bvec>|.tsv}",
     "sub-{subject}[/ses-{session}]/{datatype<fmap>|fmap}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_dir-{direction}][_run-{run}][_space-{space}][_cohort-{cohort}][_res-{resolution}][_fmapid-{fmapid}][_desc-{desc}]_{suffix<fieldmap>}{extension<.nii|.nii.gz|.json>|.nii.gz}",
-    "sub-{subject}/{datatype<figures>}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_space-{space}][_cohort-{cohort}][_desc-{desc}]_{suffix<T1w|T2w|T1rho|T1map|T2map|T2star|FLAIR|FLASH|PDmap|PD|PDT2|inplaneT[12]|angio|dseg|mask|dwi|epiref|fieldmap|T2starw|MTw|TSE>}{extension<.html|.svg>|.svg}",
+    "sub-{subject}/{datatype<figures>}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_space-{space}][_cohort-{cohort}][_desc-{desc}]_{suffix<T1w|T2w|T1rho|T1map|T2map|T2star|FLAIR|FLASH|PDmap|PD|PDT2|inplaneT[12]|angio|dseg|mask|dwi|epiref|T2starw|MTw|TSE>}{extension<.html|.svg>|.svg}",
     "sub-{subject}/{datatype<figures>}/sub-{subject}[_ses-{session}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_space-{space}][_cohort-{cohort}][_fmapid-{fmapid}][_desc-{desc}]_{suffix<fieldmap>}{extension<.html|.svg>|.svg}",
     "sub-{subject}/{datatype<figures>}/sub-{subject}[_ses-{session}]_task-{task}[_acq-{acquisition}][_ce-{ceagent}][_dir-{direction}][_rec-{reconstruction}][_run-{run}][_echo-{echo}][_space-{space}][_cohort-{cohort}][_desc-{desc}]_{suffix<bold>}{extension<.html|.svg>|.svg}"
   ]


Test patch:
diff --git a/niworkflows/interfaces/tests/test_bids.py b/niworkflows/interfaces/tests/test_bids.py
index 9cbeb32ffd5..0a87752427c 100644
--- a/niworkflows/interfaces/tests/test_bids.py
+++ b/niworkflows/interfaces/tests/test_bids.py
@@ -490,6 +490,38 @@ def make_empty_nii_with_dtype(fname, dtype):
     assert nii.get_data_dtype() == np.dtype(source_dtype)
 
 
+def test_DerivativesDataSink_fmapid(tmp_path):
+    """Ascertain #637 is not regressing."""
+    source_file = [
+        (tmp_path / s)
+        for s in [
+            "sub-36/fmap/sub-36_dir-1_run-1_epi.nii.gz",
+            "sub-36/fmap/sub-36_dir-1_run-2_epi.nii.gz",
+            "sub-36/fmap/sub-36_dir-2_run-1_epi.nii.gz",
+            "sub-36/fmap/sub-36_dir-2_run-2_epi.nii.gz",
+        ]
+    ]
+    for fname in source_file:
+        fname.parent.mkdir(exist_ok=True, parents=True)
+        fname.write_text("")
+
+    in_file = tmp_path / "report.svg"
+    in_file.write_text("")
+
+    dds = bintfs.DerivativesDataSink(
+        base_directory=str(tmp_path),
+        datatype="figures",
+        suffix="fieldmap",
+        desc="pepolar",
+        dismiss_entities=("fmap",),
+        allowed_entities=("fmapid",),
+        fmapid="auto00000",
+        source_file=[str(s.absolute()) for s in source_file],
+        in_file=str(in_file),
+    ).run()
+    assert dds.outputs.out_file.endswith("sub-36_fmapid-auto00000_desc-pepolar_fieldmap.svg")
+
+
 @pytest.mark.parametrize("field", ["RepetitionTime", "UndefinedField"])
 def test_ReadSidecarJSON_connection(testdata_dir, field):
     """