|
1 | 1 | ''' Testing module for fmriprep.workflows.bold.util '''
|
2 | 2 | import pytest
|
3 | 3 | import os
|
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import numpy as np
|
6 | 7 | from nipype.pipeline import engine as pe
|
7 |
| -from nipype.utils.filemanip import fname_presuffix |
| 8 | +from nipype.utils.filemanip import fname_presuffix, copyfile |
8 | 9 | from nilearn.image import load_img
|
9 | 10 |
|
10 | 11 | from niworkflows.interfaces.masks import ROIsPlot
|
@@ -46,33 +47,49 @@ def symmetric_overlap(img1, img2):
|
46 | 47 | 'ds000216/sub-03_task-rest_echo-4_bold.nii.gz',
|
47 | 48 | 'ds000237/sub-03_task-MemorySpan_acq-multiband_run-01_bold.nii.gz',
|
48 | 49 | '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 | +]) |
51 | 60 | def test_masking(input_fname, expected_fname):
|
52 | 61 | bold_reference_wf = init_bold_reference_wf(omp_nthreads=1, enhance_t2=True)
|
53 | 62 | bold_reference_wf.inputs.inputnode.bold_file = input_fname
|
54 | 63 |
|
55 | 64 | # Reconstruct base_fname from above
|
56 | 65 | 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 |
59 | 69 | 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) |
62 | 72 |
|
63 | 73 | mask_diff_plot = pe.Node(ROIsPlot(), name='mask_diff_plot')
|
64 | 74 | mask_diff_plot.inputs.in_mask = expected_fname
|
65 | 75 | mask_diff_plot.inputs.out_report = out_fname
|
66 | 76 |
|
| 77 | + outputnode = bold_reference_wf.get_node('outputnode') |
67 | 78 | 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 | + ]) |
72 | 82 | res = bold_reference_wf.run(plugin='MultiProc')
|
73 | 83 |
|
74 | 84 | combine_masks = [node for node in res.nodes if node.name.endswith('combine_masks')][0]
|
75 | 85 | overlap = symmetric_overlap(expected_fname,
|
76 | 86 | combine_masks.result.outputs.out_file)
|
77 | 87 |
|
| 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 | + |
78 | 95 | assert overlap > 0.95, input_fname
|
0 commit comments