Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add contrast outputs for EstimatedModel #3577

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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