Skip to content

Commit 466cccf

Browse files
committed
add contrast outputs for EstimatedModel when factor_info used in Level1design
1 parent 75796d5 commit 466cccf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

nipype/interfaces/spm/model.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,34 @@ class EstimateModelOutputSpec(TraitedSpec):
250250
ImageFileSPM(exists=True),
251251
desc="Images of the standard deviation of parameter posteriors",
252252
)
253+
con_images = OutputMultiPath(
254+
File(exists=True),
255+
desc=(
256+
"contrast images from a t-contrast "
257+
"(created if factor_info used in Level1Design)"
258+
),
259+
)
260+
spmT_images = OutputMultiPath(
261+
File(exists=True),
262+
desc=(
263+
"stat images from a t-contrast"
264+
"(created if factor_info used in Level1Design)"
265+
),
266+
)
267+
ess_images = OutputMultiPath(
268+
File(exists=True),
269+
desc=(
270+
"contrast images from an F-contrast"
271+
"(created if factor_info used in Level1Design)"
272+
),
273+
)
274+
spmF_images = OutputMultiPath(
275+
File(exists=True),
276+
desc=(
277+
"stat images from an F-contrast"
278+
"(created if factor_info used in Level1Design)"
279+
),
280+
)
253281

254282

255283
class EstimateModel(SPMCommand):
@@ -319,6 +347,29 @@ def _list_outputs(self):
319347
outputs["residual_images"] = glob(os.path.join(pth, "Res_*"))
320348
if betas:
321349
outputs["beta_images"] = [os.path.join(pth, beta) for beta in betas]
350+
# When 'factor_info' is used in Level1Design
351+
# spm automatically creates contrast
352+
try:
353+
contrast = [c.Vcon[0][0].fname[0] for c in spm["SPM"][0, 0].xCon[0]]
354+
contrast_spm = [c.Vspm[0][0].fname[0] for c in spm["SPM"][0, 0].xCon[0]]
355+
except Exception:
356+
contrast = []
357+
contrast_spm = []
358+
359+
if contrast:
360+
outputs["con_images"] = [
361+
(os.path.join(pth, cont) for cont in contrast if 'con' in cont)
362+
]
363+
outputs["ess_images"] = [
364+
(os.path.join(pth, cont) for cont in contrast if 'ess' in cont)
365+
]
366+
if contrast_spm:
367+
outputs["spmT_images"] = [
368+
(os.path.join(pth, cont) for cont in contrast_spm if 'spmT' in cont)
369+
]
370+
outputs["spmF_images"] = [
371+
(os.path.join(pth, cont) for cont in contrast_spm if 'spmF' in cont)
372+
]
322373

323374
outputs["mask_image"] = os.path.join(pth, "mask.{}".format(outtype))
324375
outputs["spm_mat_file"] = os.path.join(pth, "SPM.mat")

nipype/interfaces/spm/tests/test_auto_EstimateModel.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def test_EstimateModel_outputs():
4646
SDbetas=dict(),
4747
SDerror=dict(),
4848
beta_images=dict(),
49+
con_images=dict(),
50+
ess_images=dict(),
4951
labels=dict(
5052
extensions=[".hdr", ".img", ".img.gz", ".nii"],
5153
),
@@ -56,6 +58,8 @@ def test_EstimateModel_outputs():
5658
extensions=[".hdr", ".img", ".img.gz", ".nii"],
5759
),
5860
residual_images=dict(),
61+
spmF_images=dict(),
62+
spmT_images=dict(),
5963
spm_mat_file=dict(
6064
extensions=None,
6165
),

0 commit comments

Comments
 (0)