Skip to content

Commit 7ab44c8

Browse files
authored
Merge pull request #491 from mgxd/enh/cifti-carpet
ENH: CIFTI carpetplot
2 parents 49343a0 + 03e8b78 commit 7ab44c8

File tree

4 files changed

+192
-91
lines changed

4 files changed

+192
-91
lines changed

niworkflows/interfaces/plotting.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from nipype.utils.filemanip import fname_presuffix
88
from nipype.interfaces.base import (
9-
File, BaseInterfaceInputSpec, TraitedSpec, SimpleInterface, traits
9+
File, BaseInterfaceInputSpec, TraitedSpec, SimpleInterface, traits, isdefined
1010
)
1111
from ..viz.plots import (
1212
fMRIPlot, compcor_variance_plot, confounds_correlation_plot
@@ -15,8 +15,8 @@
1515

1616
class _FMRISummaryInputSpec(BaseInterfaceInputSpec):
1717
in_func = File(exists=True, mandatory=True, desc='')
18-
in_mask = File(exists=True, mandatory=True, desc='')
19-
in_segm = File(exists=True, mandatory=True, desc='')
18+
in_mask = File(exists=True, desc='')
19+
in_segm = File(exists=True, desc='')
2020
in_spikes_bg = File(exists=True, mandatory=True, desc='')
2121
fd = File(exists=True, mandatory=True, desc='')
2222
fd_thres = traits.Float(0.2, usedefault=True, desc='')
@@ -56,8 +56,8 @@ def _run_interface(self, runtime):
5656

5757
fig = fMRIPlot(
5858
self.inputs.in_func,
59-
mask_file=self.inputs.in_mask,
60-
seg_file=self.inputs.in_segm,
59+
mask_file=self.inputs.in_mask if isdefined(self.inputs.in_mask) else None,
60+
seg_file=self.inputs.in_segm if isdefined(self.inputs.seg_file) else None,
6161
spikes_files=[self.inputs.in_spikes_bg],
6262
tr=self.inputs.tr,
6363
data=dataframe[['outliers', 'DVARS', 'FD']],

niworkflows/tests/test_viz.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,32 @@
1010

1111
def test_carpetplot():
1212
"""Write a carpetplot"""
13-
out_file = None
13+
out_file_nifti = None
14+
out_file_cifti = None
1415
save_artifacts = os.getenv('SAVE_CIRCLE_ARTIFACTS', False)
1516
if save_artifacts:
16-
out_file = os.path.join(save_artifacts, 'carpetplot.svg')
17+
out_file_nifti = os.path.join(save_artifacts, 'carpetplot_nifti.svg')
18+
out_file_cifti = os.path.join(save_artifacts, 'carpetplot_cifti.svg')
19+
20+
# volumetric NIfTI
1721
viz.plot_carpet(
1822
os.path.join(datadir, 'sub-ds205s03_task-functionallocalizer_run-01_bold_volreg.nii.gz'),
19-
np.asanyarray(nb.load(os.path.join(
23+
atlaslabels=np.asanyarray(nb.load(os.path.join(
2024
datadir,
2125
'sub-ds205s03_task-functionallocalizer_run-01_bold_parc.nii.gz')).dataobj),
22-
output_file=out_file,
26+
output_file=out_file_nifti,
2327
legend=True
2428
)
2529

30+
# CIFTI
31+
viz.plot_carpet(
32+
os.path.join(
33+
datadir,
34+
'sub-01_task-mixedgamblestask_run-02_space-fsLR_den-91k_bold.dtseries.nii'
35+
),
36+
output_file=out_file_cifti,
37+
)
38+
2639

2740
def test_plot_melodic_components(tmp_path):
2841
"""Test plotting melodic components"""

0 commit comments

Comments
 (0)