Skip to content

Commit

Permalink
Get normalization figure working.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 2, 2024
1 parent cffd29c commit 138a918
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/fmripost_aroma/data/io_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
},
"anat_dseg": {
"datatype": "anat",
"task": null,
"run": null,
"space": null,
"res": null,
"den": null,
Expand Down
16 changes: 7 additions & 9 deletions src/fmripost_aroma/data/reports-spec-func.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ sections:
reportlets:
- bids: {datatype: figures, desc: summary, suffix: bold}
- bids: {datatype: figures, desc: validation, suffix: bold}
- bids: {datatype: figures, desc: aroma, suffix: bold}
- bids: {datatype: figures, desc: metrics, suffix: bold}
- bids: {datatype: figures, desc: coreg, suffix: bold}
- bids: {datatype: figures, desc: normalization, suffix: bold}
caption: This panel shows the alignment of the reference EPI (BOLD) image to the
anatomical (T1-weighted) image.
The reference EPI has been contrast enhanced and susceptibility-distortion
corrected (if applicable) for improved anatomical fidelity.
The anatomical image has been resampled into EPI space, as well as the
anatomical white matter mask, which appears as a red contour.
MNI152NLin6Asym template.
The anatomical white matter mask has been warped to MNI152NLin6Asym space
and appears as a red contour.
static: false
subtitle: Alignment of functional and anatomical MRI data (coregistration)
subtitle: Alignment of functional and template MRI data (normalization)
- bids: {datatype: figures, desc: aroma, suffix: bold}
- bids: {datatype: figures, desc: metrics, suffix: bold}
- bids: {datatype: figures, desc: preprocCarpetplot, suffix: bold}
title: Preprocessed BOLD
- bids: {datatype: figures, desc: nonaggrCarpetplot, suffix: bold}
Expand Down
16 changes: 7 additions & 9 deletions src/fmripost_aroma/data/reports-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ sections:
reportlets:
- bids: {datatype: figures, desc: summary, suffix: bold}
- bids: {datatype: figures, desc: validation, suffix: bold}
- bids: {datatype: figures, desc: aroma, suffix: bold}
- bids: {datatype: figures, desc: metrics, suffix: bold}
- bids: {datatype: figures, desc: coreg, suffix: bold}
- bids: {datatype: figures, desc: normalization, suffix: bold}
caption: This panel shows the alignment of the reference EPI (BOLD) image to the
anatomical (T1-weighted) image.
The reference EPI has been contrast enhanced and susceptibility-distortion
corrected (if applicable) for improved anatomical fidelity.
The anatomical image has been resampled into EPI space, as well as the
anatomical white matter mask, which appears as a red contour.
MNI152NLin6Asym template.
The anatomical white matter mask has been warped to MNI152NLin6Asym space
and appears as a red contour.
static: false
subtitle: Alignment of functional and anatomical MRI data (coregistration)
subtitle: Alignment of functional and template MRI data (normalization)
- bids: {datatype: figures, desc: aroma, suffix: bold}
- bids: {datatype: figures, desc: metrics, suffix: bold}
- bids: {datatype: figures, desc: preprocCarpetplot, suffix: bold}
title: Preprocessed BOLD
- bids: {datatype: figures, desc: nonaggrCarpetplot, suffix: bold}
Expand Down
16 changes: 12 additions & 4 deletions src/fmripost_aroma/interfaces/nilearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _MeanImageInputSpec(BaseInterfaceInputSpec):
)
mask_file = File(
exists=True,
mandatory=True,
mandatory=False,
desc='A binary brain mask.',
)
out_file = File(
Expand All @@ -46,11 +46,19 @@ class MeanImage(NilearnBaseInterface, SimpleInterface):
output_spec = _MeanImageOutputSpec

def _run_interface(self, runtime):
import nibabel as nb

Check warning on line 49 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L49

Added line #L49 was not covered by tests
from nilearn.masking import apply_mask, unmask
from nipype.interfaces.base import isdefined

Check warning on line 51 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L51

Added line #L51 was not covered by tests

if isdefined(self.inputs.mask_file):
data = apply_mask(self.inputs.bold_file, self.inputs.mask_file)
mean_data = data.mean(axis=0)
mean_img = unmask(mean_data, self.inputs.mask_file)

Check warning on line 56 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L54-L56

Added lines #L54 - L56 were not covered by tests
else:
in_img = nb.load(self.inputs.bold_file)
mean_data = in_img.get_fdata().mean(axis=3)
mean_img = nb.Nifti1Image(mean_data, in_img.affine, in_img.header)

Check warning on line 60 in src/fmripost_aroma/interfaces/nilearn.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/interfaces/nilearn.py#L58-L60

Added lines #L58 - L60 were not covered by tests

data = apply_mask(self.inputs.bold_file, self.inputs.mask_file)
mean_data = data.mean(axis=0)
mean_img = unmask(mean_data, self.inputs.mask_file)
self._results['out_file'] = os.path.join(runtime.cwd, self.inputs.out_file)
mean_img.to_filename(self._results['out_file'])

Expand Down
21 changes: 15 additions & 6 deletions src/fmripost_aroma/workflows/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def init_func_fit_reports_wf(
from nireports.interfaces.reporting.base import (

Check warning on line 58 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L58

Added line #L58 was not covered by tests
SimpleBeforeAfterRPT as SimpleBeforeAfter,
)
from templateflow.api import get as get_template

Check warning on line 61 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L61

Added line #L61 was not covered by tests

from fmripost_aroma.interfaces.nilearn import MeanImage

Check warning on line 63 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L63

Added line #L63 was not covered by tests

Expand Down Expand Up @@ -99,28 +100,36 @@ def init_func_fit_reports_wf(
mem_gb=DEFAULT_MEMORY_MIN_GB,
)
mni6_wm.inputs.label = 2 # BIDS default is WM=2
workflow.connect([(dseg_to_mni6, mni6_wm, [('output_image', 'in_file')])])
workflow.connect([(dseg_to_mni6, mni6_wm, [('output_image', 'in_seg')])])

Check warning on line 103 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L102-L103

Added lines #L102 - L103 were not covered by tests

# EPI-MNI registration
epi_mni_report = pe.Node(

Check warning on line 106 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L106

Added line #L106 was not covered by tests
SimpleBeforeAfter(
before_label='T1w',
after_label='EPI',
after=str(
get_template(
'MNI152NLin6Asym',
resolution=2,
desc='brain',
suffix='T1w',
extension=['.nii', '.nii.gz'],
)
),
before_label='EPI',
after_label='MNI152NLin6Asym',
dismiss_affine=True,
),
name='epi_mni_report',
mem_gb=0.1,
)
workflow.connect([

Check warning on line 124 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L124

Added line #L124 was not covered by tests
(inputnode, epi_mni_report, [('coreg_boldref', 'after')]),
(calculate_mean_bold, epi_mni_report, [('out_file', 'before')]),
(mni6_wm, epi_mni_report, [('output_image', 'wm_seg')]),
(mni6_wm, epi_mni_report, [('out', 'wm_seg')]),
]) # fmt:skip

ds_epi_mni_report = pe.Node(

Check warning on line 129 in src/fmripost_aroma/workflows/outputs.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/outputs.py#L129

Added line #L129 was not covered by tests
DerivativesDataSink(
base_directory=output_dir,
desc='coreg',
desc='normalization',
suffix='bold',
datatype='figures',
dismiss_entities=dismiss_echo(),
Expand Down

0 comments on commit 138a918

Please sign in to comment.