Skip to content

Commit

Permalink
Merge pull request #1329 from poldracklab/tests/add-more-masks
Browse files Browse the repository at this point in the history
[TST] Add heavily-nonuniform boldrefs for regression tests
  • Loading branch information
oesteban committed Oct 18, 2018
2 parents 3c6303d + 36b369e commit 53a96a8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 24 deletions.
40 changes: 27 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ jobs:
steps:
- restore_cache:
keys:
- regression-v0-{{ epoch }}
- regression-v0-
- regression-v2-{{ epoch }}
- regression-v2-
- run:
name: Get truncated BOLD series
command: |
Expand All @@ -193,7 +193,7 @@ jobs:
paths:
- data
- save_cache:
key: regression-v0-{{ epoch }}
key: regression-v2-{{ epoch }}
paths:
- /tmp/data

Expand Down Expand Up @@ -227,10 +227,6 @@ jobs:
fi
- attach_workspace:
at: /tmp
- restore_cache:
keys:
- regression-v0-{{ epoch }}
- regression-v0-
- run:
name: Check PyPi preconditions
command: |
Expand Down Expand Up @@ -260,7 +256,13 @@ jobs:
-e FMRIPREP_REGRESSION_REPORTS=/tmp/data/reports \
--entrypoint="py.test" poldracklab/fmriprep:latest \
/root/src/fmriprep/ \
--doctest-modules --ignore=/root/src/fmriprep/docs --ignore=setup.py
-svx --doctest-modules --ignore=/root/src/fmriprep/docs --ignore=setup.py
- run:
name: Package new masks
no_output_timeout: 10m
working_directory: /tmp/data/reports
command: |
tar cfz fmriprep_bold_mask.tar.gz fmriprep_bold_mask/*/*.nii.gz
- run:
name: Test fmriprep-wrapper (Python 2)
command: |
Expand Down Expand Up @@ -719,7 +721,9 @@ workflows:
- get_data:
filters:
branches:
ignore: /docs?\/.*/
ignore:
- /docs?\/.*/
- /tests?\/.*/
tags:
only: /.*/

Expand All @@ -732,6 +736,8 @@ workflows:
requires:
- build
filters:
branches:
ignore: /tests?\/.*/
tags:
only: /.*/

Expand All @@ -740,7 +746,9 @@ workflows:
- build
filters:
branches:
ignore: /docs?\/.*/
ignore:
- /docs?\/.*/
- /tests?\/.*/
tags:
only: /.*/

Expand All @@ -760,7 +768,9 @@ workflows:
- build
filters:
branches:
ignore: /docs?\/.*/
ignore:
- /docs?\/.*/
- /tests?\/.*/
tags:
only: /.*/

Expand All @@ -770,7 +780,9 @@ workflows:
- build
filters:
branches:
ignore: /docs?\/.*/
ignore:
- /docs?\/.*/
- /tests?\/.*/
tags:
only: /.*/

Expand All @@ -781,7 +793,9 @@ workflows:
filters:
branches:
# only: /meepi.*/
ignore: /docs?\/.*/
ignore:
- /docs?\/.*/
- /tests?\/.*/
tags:
only: /.*/

Expand Down
39 changes: 28 additions & 11 deletions fmriprep/workflows/bold/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
''' Testing module for fmriprep.workflows.bold.util '''
import pytest
import os
from pathlib import Path

import numpy as np
from nipype.pipeline import engine as pe
from nipype.utils.filemanip import fname_presuffix
from nipype.utils.filemanip import fname_presuffix, copyfile
from nilearn.image import load_img

from niworkflows.interfaces.masks import ROIsPlot
Expand Down Expand Up @@ -46,33 +47,49 @@ def symmetric_overlap(img1, img2):
'ds000216/sub-03_task-rest_echo-4_bold.nii.gz',
'ds000237/sub-03_task-MemorySpan_acq-multiband_run-01_bold.nii.gz',
'ds000237/sub-06_task-MemorySpan_acq-multiband_run-01_bold.nii.gz',
)
])
'ds001240/sub-26_task-localizerimagination_bold.nii.gz',
'ds001240/sub-26_task-localizerviewing_bold.nii.gz',
'ds001240/sub-26_task-molencoding_run-01_bold.nii.gz',
'ds001240/sub-26_task-molencoding_run-02_bold.nii.gz',
'ds001240/sub-26_task-molretrieval_run-01_bold.nii.gz',
'ds001240/sub-26_task-molretrieval_run-02_bold.nii.gz',
'ds001240/sub-26_task-rest_bold.nii.gz',
'ds001362/sub-01_task-taskname_run-01_bold.nii.gz',
)
])
def test_masking(input_fname, expected_fname):
bold_reference_wf = init_bold_reference_wf(omp_nthreads=1, enhance_t2=True)
bold_reference_wf.inputs.inputnode.bold_file = input_fname

# Reconstruct base_fname from above
dirname, basename = os.path.split(input_fname)
newpath = os.path.join(os.getenv('FMRIPREP_REGRESSION_REPORTS', '.'),
os.path.basename(dirname))
dsname = os.path.basename(dirname)
reports_dir = Path(os.getenv('FMRIPREP_REGRESSION_REPORTS', ''))
newpath = reports_dir / dsname
out_fname = fname_presuffix(basename, suffix='_masks.svg', use_ext=False,
newpath=newpath)
os.makedirs(newpath, exist_ok=True)
newpath=str(newpath))
newpath.mkdir(parents=True, exist_ok=True)

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

outputnode = bold_reference_wf.get_node('outputnode')
bold_reference_wf.connect([
(bold_reference_wf.get_node('outputnode'), mask_diff_plot, [
('ref_image', 'in_file'),
('bold_mask', 'in_rois'),
])])
(outputnode, mask_diff_plot, [('ref_image', 'in_file'),
('bold_mask', 'in_rois')])
])
res = bold_reference_wf.run(plugin='MultiProc')

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

mask_dir = reports_dir / 'fmriprep_bold_mask' / dsname
mask_dir.mkdir(parents=True, exist_ok=True)
copyfile(combine_masks.result.outputs.out_file,
fname_presuffix(basename, suffix='_mask',
use_ext=True, newpath=str(mask_dir)),
copy=True)

assert overlap > 0.95, input_fname

0 comments on commit 53a96a8

Please sign in to comment.