Skip to content

Commit 53a96a8

Browse files
authored
Merge pull request #1329 from poldracklab/tests/add-more-masks
[TST] Add heavily-nonuniform boldrefs for regression tests
2 parents 3c6303d + 36b369e commit 53a96a8

File tree

2 files changed

+55
-24
lines changed

2 files changed

+55
-24
lines changed

.circleci/config.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ jobs:
165165
steps:
166166
- restore_cache:
167167
keys:
168-
- regression-v0-{{ epoch }}
169-
- regression-v0-
168+
- regression-v2-{{ epoch }}
169+
- regression-v2-
170170
- run:
171171
name: Get truncated BOLD series
172172
command: |
@@ -193,7 +193,7 @@ jobs:
193193
paths:
194194
- data
195195
- save_cache:
196-
key: regression-v0-{{ epoch }}
196+
key: regression-v2-{{ epoch }}
197197
paths:
198198
- /tmp/data
199199

@@ -227,10 +227,6 @@ jobs:
227227
fi
228228
- attach_workspace:
229229
at: /tmp
230-
- restore_cache:
231-
keys:
232-
- regression-v0-{{ epoch }}
233-
- regression-v0-
234230
- run:
235231
name: Check PyPi preconditions
236232
command: |
@@ -260,7 +256,13 @@ jobs:
260256
-e FMRIPREP_REGRESSION_REPORTS=/tmp/data/reports \
261257
--entrypoint="py.test" poldracklab/fmriprep:latest \
262258
/root/src/fmriprep/ \
263-
--doctest-modules --ignore=/root/src/fmriprep/docs --ignore=setup.py
259+
-svx --doctest-modules --ignore=/root/src/fmriprep/docs --ignore=setup.py
260+
- run:
261+
name: Package new masks
262+
no_output_timeout: 10m
263+
working_directory: /tmp/data/reports
264+
command: |
265+
tar cfz fmriprep_bold_mask.tar.gz fmriprep_bold_mask/*/*.nii.gz
264266
- run:
265267
name: Test fmriprep-wrapper (Python 2)
266268
command: |
@@ -719,7 +721,9 @@ workflows:
719721
- get_data:
720722
filters:
721723
branches:
722-
ignore: /docs?\/.*/
724+
ignore:
725+
- /docs?\/.*/
726+
- /tests?\/.*/
723727
tags:
724728
only: /.*/
725729

@@ -732,6 +736,8 @@ workflows:
732736
requires:
733737
- build
734738
filters:
739+
branches:
740+
ignore: /tests?\/.*/
735741
tags:
736742
only: /.*/
737743

@@ -740,7 +746,9 @@ workflows:
740746
- build
741747
filters:
742748
branches:
743-
ignore: /docs?\/.*/
749+
ignore:
750+
- /docs?\/.*/
751+
- /tests?\/.*/
744752
tags:
745753
only: /.*/
746754

@@ -760,7 +768,9 @@ workflows:
760768
- build
761769
filters:
762770
branches:
763-
ignore: /docs?\/.*/
771+
ignore:
772+
- /docs?\/.*/
773+
- /tests?\/.*/
764774
tags:
765775
only: /.*/
766776

@@ -770,7 +780,9 @@ workflows:
770780
- build
771781
filters:
772782
branches:
773-
ignore: /docs?\/.*/
783+
ignore:
784+
- /docs?\/.*/
785+
- /tests?\/.*/
774786
tags:
775787
only: /.*/
776788

@@ -781,7 +793,9 @@ workflows:
781793
filters:
782794
branches:
783795
# only: /meepi.*/
784-
ignore: /docs?\/.*/
796+
ignore:
797+
- /docs?\/.*/
798+
- /tests?\/.*/
785799
tags:
786800
only: /.*/
787801

fmriprep/workflows/bold/tests/test_util.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
''' Testing module for fmriprep.workflows.bold.util '''
22
import pytest
33
import os
4+
from pathlib import Path
45

56
import numpy as np
67
from nipype.pipeline import engine as pe
7-
from nipype.utils.filemanip import fname_presuffix
8+
from nipype.utils.filemanip import fname_presuffix, copyfile
89
from nilearn.image import load_img
910

1011
from niworkflows.interfaces.masks import ROIsPlot
@@ -46,33 +47,49 @@ def symmetric_overlap(img1, img2):
4647
'ds000216/sub-03_task-rest_echo-4_bold.nii.gz',
4748
'ds000237/sub-03_task-MemorySpan_acq-multiband_run-01_bold.nii.gz',
4849
'ds000237/sub-06_task-MemorySpan_acq-multiband_run-01_bold.nii.gz',
49-
)
50-
])
50+
'ds001240/sub-26_task-localizerimagination_bold.nii.gz',
51+
'ds001240/sub-26_task-localizerviewing_bold.nii.gz',
52+
'ds001240/sub-26_task-molencoding_run-01_bold.nii.gz',
53+
'ds001240/sub-26_task-molencoding_run-02_bold.nii.gz',
54+
'ds001240/sub-26_task-molretrieval_run-01_bold.nii.gz',
55+
'ds001240/sub-26_task-molretrieval_run-02_bold.nii.gz',
56+
'ds001240/sub-26_task-rest_bold.nii.gz',
57+
'ds001362/sub-01_task-taskname_run-01_bold.nii.gz',
58+
)
59+
])
5160
def test_masking(input_fname, expected_fname):
5261
bold_reference_wf = init_bold_reference_wf(omp_nthreads=1, enhance_t2=True)
5362
bold_reference_wf.inputs.inputnode.bold_file = input_fname
5463

5564
# Reconstruct base_fname from above
5665
dirname, basename = os.path.split(input_fname)
57-
newpath = os.path.join(os.getenv('FMRIPREP_REGRESSION_REPORTS', '.'),
58-
os.path.basename(dirname))
66+
dsname = os.path.basename(dirname)
67+
reports_dir = Path(os.getenv('FMRIPREP_REGRESSION_REPORTS', ''))
68+
newpath = reports_dir / dsname
5969
out_fname = fname_presuffix(basename, suffix='_masks.svg', use_ext=False,
60-
newpath=newpath)
61-
os.makedirs(newpath, exist_ok=True)
70+
newpath=str(newpath))
71+
newpath.mkdir(parents=True, exist_ok=True)
6272

6373
mask_diff_plot = pe.Node(ROIsPlot(), name='mask_diff_plot')
6474
mask_diff_plot.inputs.in_mask = expected_fname
6575
mask_diff_plot.inputs.out_report = out_fname
6676

77+
outputnode = bold_reference_wf.get_node('outputnode')
6778
bold_reference_wf.connect([
68-
(bold_reference_wf.get_node('outputnode'), mask_diff_plot, [
69-
('ref_image', 'in_file'),
70-
('bold_mask', 'in_rois'),
71-
])])
79+
(outputnode, mask_diff_plot, [('ref_image', 'in_file'),
80+
('bold_mask', 'in_rois')])
81+
])
7282
res = bold_reference_wf.run(plugin='MultiProc')
7383

7484
combine_masks = [node for node in res.nodes if node.name.endswith('combine_masks')][0]
7585
overlap = symmetric_overlap(expected_fname,
7686
combine_masks.result.outputs.out_file)
7787

88+
mask_dir = reports_dir / 'fmriprep_bold_mask' / dsname
89+
mask_dir.mkdir(parents=True, exist_ok=True)
90+
copyfile(combine_masks.result.outputs.out_file,
91+
fname_presuffix(basename, suffix='_mask',
92+
use_ext=True, newpath=str(mask_dir)),
93+
copy=True)
94+
7895
assert overlap > 0.95, input_fname

0 commit comments

Comments
 (0)