Skip to content

Commit

Permalink
Merge pull request #3577 from manuegrx/bugfix_spm_model
Browse files Browse the repository at this point in the history
add contrast outputs for EstimatedModel
  • Loading branch information
effigies authored Jul 5, 2023
2 parents b4cc4db + 1467f1c commit 40199f1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
51 changes: 51 additions & 0 deletions nipype/interfaces/spm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,34 @@ class EstimateModelOutputSpec(TraitedSpec):
ImageFileSPM(exists=True),
desc="Images of the standard deviation of parameter posteriors",
)
con_images = OutputMultiPath(
File(exists=True),
desc=(
"contrast images from a t-contrast "
"(created if factor_info used in Level1Design)"
),
)
spmT_images = OutputMultiPath(
File(exists=True),
desc=(
"stat images from a t-contrast"
"(created if factor_info used in Level1Design)"
),
)
ess_images = OutputMultiPath(
File(exists=True),
desc=(
"contrast images from an F-contrast"
"(created if factor_info used in Level1Design)"
),
)
spmF_images = OutputMultiPath(
File(exists=True),
desc=(
"stat images from an F-contrast"
"(created if factor_info used in Level1Design)"
),
)


class EstimateModel(SPMCommand):
Expand Down Expand Up @@ -310,6 +338,29 @@ def _list_outputs(self):
outputs["residual_images"] = glob(os.path.join(pth, "Res_*"))
if betas:
outputs["beta_images"] = [os.path.join(pth, beta) for beta in betas]
# When 'factor_info' is used in Level1Design
# spm automatically creates contrast
try:
contrast = [c.Vcon[0][0].fname[0] for c in spm["SPM"][0, 0].xCon[0]]
contrast_spm = [c.Vspm[0][0].fname[0] for c in spm["SPM"][0, 0].xCon[0]]
except Exception:
contrast = []
contrast_spm = []

if contrast:
outputs["con_images"] = [
os.path.join(pth, cont) for cont in contrast if 'con' in cont
]
outputs["ess_images"] = [
os.path.join(pth, cont) for cont in contrast if 'ess' in cont
]
if contrast_spm:
outputs["spmT_images"] = [
os.path.join(pth, cont) for cont in contrast_spm if 'spmT' in cont
]
outputs["spmF_images"] = [
os.path.join(pth, cont) for cont in contrast_spm if 'spmF' in cont
]

outputs["mask_image"] = os.path.join(pth, f"mask.{outtype}")
outputs["spm_mat_file"] = os.path.join(pth, "SPM.mat")
Expand Down
4 changes: 4 additions & 0 deletions nipype/interfaces/spm/tests/test_auto_EstimateModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def test_EstimateModel_outputs():
SDbetas=dict(),
SDerror=dict(),
beta_images=dict(),
con_images=dict(),
ess_images=dict(),
labels=dict(
extensions=[".hdr", ".img", ".img.gz", ".nii"],
),
Expand All @@ -56,6 +58,8 @@ def test_EstimateModel_outputs():
extensions=[".hdr", ".img", ".img.gz", ".nii"],
),
residual_images=dict(),
spmF_images=dict(),
spmT_images=dict(),
spm_mat_file=dict(
extensions=None,
),
Expand Down

0 comments on commit 40199f1

Please sign in to comment.