From c58fa622e917bc12303ffdf22b244374db43dcee Mon Sep 17 00:00:00 2001 From: bpinsard Date: Mon, 7 Oct 2024 22:17:12 -0400 Subject: [PATCH 1/5] add test for force_fmapless on top of self-correcting pepolar bold --- sdcflows/utils/tests/test_wrangler.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sdcflows/utils/tests/test_wrangler.py b/sdcflows/utils/tests/test_wrangler.py index f5e7c6cdd5..470fb17734 100644 --- a/sdcflows/utils/tests/test_wrangler.py +++ b/sdcflows/utils/tests/test_wrangler.py @@ -472,3 +472,24 @@ def test_fieldmapless(tmp_path): assert len(est[0].sources) == 2 clear_registry() rmtree(bids_dir) + + # force fmapless on top of self-pepolar + self_pepolar_metadata = { + **bold["metadata"], + "B0FieldIdentifier": "pepolar_fmap", + "B0FieldSource": "pepolar_fmap" + } + + spec = { + "01": { + "anat": [T1w], + "func": [{"run": i, **bold, "metadata": {**self_pepolar_metadata, "PhaseEncodingDirection": pedir}, } for i, pedir in zip(range(1, 3), ["j", "j-"])], + }, + } + generate_bids_skeleton(bids_dir, spec) + layout = gen_layout(bids_dir) + est = find_estimators(layout=layout, subject="01", fmapless=True, force_fmapless=True) + assert len(est) == 2 + assert len(est[0].sources) == 2 + clear_registry() + rmtree(bids_dir) From 84553d98521112a7cb37084b5c8a0cf9e1d50475 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 8 Oct 2024 21:49:33 -0400 Subject: [PATCH 2/5] simple fix: generate bids_id for fmapless --- sdcflows/utils/tests/test_wrangler.py | 33 ++++++++++++++++++--------- sdcflows/utils/wrangler.py | 4 ++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/sdcflows/utils/tests/test_wrangler.py b/sdcflows/utils/tests/test_wrangler.py index 470fb17734..65c0f86ff9 100644 --- a/sdcflows/utils/tests/test_wrangler.py +++ b/sdcflows/utils/tests/test_wrangler.py @@ -326,12 +326,15 @@ def test_wrangler_filter(tmpdir, name, skeleton, estimations): ('phasediff', phasediff, 3), ], ) -@pytest.mark.parametrize("session, estimations", [ - ("01", 1), - ("02", 1), - ("03", 1), - (None, None), -]) +@pytest.mark.parametrize( + "session, estimations", + [ + ("01", 1), + ("02", 1), + ("03", 1), + (None, None), + ], +) def test_wrangler_URIs(tmpdir, name, skeleton, session, estimations, total_estimations): bids_dir = str(tmpdir / name) generate_bids_skeleton(bids_dir, skeleton) @@ -477,19 +480,27 @@ def test_fieldmapless(tmp_path): self_pepolar_metadata = { **bold["metadata"], "B0FieldIdentifier": "pepolar_fmap", - "B0FieldSource": "pepolar_fmap" + "B0FieldSource": "pepolar_fmap", } spec = { "01": { "anat": [T1w], - "func": [{"run": i, **bold, "metadata": {**self_pepolar_metadata, "PhaseEncodingDirection": pedir}, } for i, pedir in zip(range(1, 3), ["j", "j-"])], + "func": [ + { + "run": i, + **bold, + "metadata": {**self_pepolar_metadata, "PhaseEncodingDirection": pedir}, + } + for i, pedir in zip(range(1, 3), ["j", "j-"]) + ], }, } generate_bids_skeleton(bids_dir, spec) layout = gen_layout(bids_dir) - est = find_estimators(layout=layout, subject="01", fmapless=True, force_fmapless=True) - assert len(est) == 2 - assert len(est[0].sources) == 2 + ests = find_estimators(layout=layout, subject="01", fmapless=True, force_fmapless=True) + assert len(ests) == 3 + for est in ests: + assert len(est.sources) == 2 clear_registry() rmtree(bids_dir) diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index 67743b496d..2aad097fe7 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -550,9 +550,9 @@ def find_estimators( base_entities=base_entities, suffixes=fmapless, ) - for spec in estimator_specs: + for si, spec in enumerate(estimator_specs): try: - estimator = fm.FieldmapEstimation(spec) + estimator = fm.FieldmapEstimation(spec, bids_id=f"fmapless{si}") except (ValueError, TypeError) as err: _log_debug_estimator_fail(logger, "ANAT", spec, layout.root, str(err)) else: From dc6d2f7a2f375090f63d1da7a785365fcd9c9fe2 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Tue, 8 Oct 2024 22:12:43 -0400 Subject: [PATCH 3/5] fix base name for existing tests --- sdcflows/utils/wrangler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index 2aad097fe7..c46629bcf8 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -552,7 +552,7 @@ def find_estimators( ) for si, spec in enumerate(estimator_specs): try: - estimator = fm.FieldmapEstimation(spec, bids_id=f"fmapless{si}") + estimator = fm.FieldmapEstimation(spec, bids_id=f"auto_fmapless_{si}") except (ValueError, TypeError) as err: _log_debug_estimator_fail(logger, "ANAT", spec, layout.root, str(err)) else: From 503c7458f68b86e58b5985a4c8bfcad839f34535 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Thu, 10 Oct 2024 14:27:20 -0400 Subject: [PATCH 4/5] fix pre-commit errors --- .git_archival.txt | 2 +- docs/examples.rst | 2 +- docs/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.git_archival.txt b/.git_archival.txt index b1a286bbb6..8fb235d704 100644 --- a/.git_archival.txt +++ b/.git_archival.txt @@ -1,4 +1,4 @@ node: $Format:%H$ node-date: $Format:%cI$ describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ -ref-names: $Format:%D$ \ No newline at end of file +ref-names: $Format:%D$ diff --git a/docs/examples.rst b/docs/examples.rst index 4efb78ab02..af6f58b215 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -5,4 +5,4 @@ Examples :maxdepth: 2 :caption: Contents: - notebooks/SDC - Theory and physics \ No newline at end of file + notebooks/SDC - Theory and physics diff --git a/docs/requirements.txt b/docs/requirements.txt index bb636713a2..dad96f7142 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -18,4 +18,4 @@ sphinx >= 7.2.2 sphinx-argparse sphinxcontrib-apidoc templateflow -traits < 6.4 \ No newline at end of file +traits < 6.4 From a2a68771e111f9366d580260944750078c4138ad Mon Sep 17 00:00:00 2001 From: bpinsard Date: Fri, 11 Oct 2024 10:59:02 -0400 Subject: [PATCH 5/5] autonaming of fmapless require tests to flush the fmap registry --- sdcflows/utils/wrangler.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sdcflows/utils/wrangler.py b/sdcflows/utils/wrangler.py index c46629bcf8..c0b7d28d9e 100644 --- a/sdcflows/utils/wrangler.py +++ b/sdcflows/utils/wrangler.py @@ -231,6 +231,7 @@ def find_estimators( Likewise in a more comprehensive dataset: + >>> fm.clear_registry() >>> find_estimators( ... layout=layouts['ds001771'], ... subject="36", @@ -259,6 +260,7 @@ def find_estimators( heuristics come back empty (BOLD and DWI files are missing the mandatory ``PhaseEncodingDirection``, in this case): + >>> fm.clear_registry() >>> find_estimators( ... layout=layouts['dsA'], ... subject="01", @@ -277,6 +279,7 @@ def find_estimators( This function should also correctly investigate multi-session datasets: + >>> fm.clear_registry() >>> find_estimators( ... layout=layouts['ds000206'], ... subject="05", @@ -309,6 +312,7 @@ def find_estimators( The only exception to the priority of ``B0FieldIdentifier`` is when fieldmaps are searched with the ``force_fmapless`` argument on: + >>> fm.clear_registry() >>> fm.clear_registry() # Necessary as `pepolar4pe` is not changing. >>> find_estimators( ... layout=layouts['dsC'],