You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The only change I make is adding precision_weighted=True. I would expect fixed_fx_contrast to be a 3D image, but it is a 4D image where the 4th dimension = # of contrasts
I'm fairly certain the error is occurring here, where the contrast images are read in. For these data,
contrasts = np.array(
[masker.transform(contrast_img) for contrast_img in contrast_imgs]
)
yields a numpy array with size (2, 1, 28008) and that second dimension of 1 is an issue. Then problems compound here
since contrasts * weights will be (2, 2, 28008) and so the sum won't work as expected.
Hope that helps!
Jeanette
Current behavior & error messages
There are no errors, but the output data dimension is not correct. Code is provided that shows this.
Steps and code to reproduce bug
frompathlibimportPathimportnumpyasnpimportpandasaspdfromnilearn.datasetsimportfuncfromnilearn.glm.first_levelimportFirstLevelModelfromnilearn.glm.contrastsimportcompute_fixed_effectsoutput_dir=Path.cwd() /"results"/"plot_two_runs_model"output_dir.mkdir(exist_ok=True, parents=True)
print(f"Output will be saved to: {output_dir}")
data=func.fetch_fiac_first_level()
fmri_imgs= [data["func1"], data["func2"]]
fromnilearn.imageimportmean_imgmean_img_=mean_img(fmri_imgs[0])
design_files= [data["design_matrix1"], data["design_matrix2"]]
design_matrices= [pd.DataFrame(np.load(df)["X"]) fordfindesign_files]
fmri_glm=FirstLevelModel(
mask_img=data["mask"],
smoothing_fwhm=5,
minimize_memory=True,
)
contrast_val= [[-1, -1, 1, 1]]
fmri_glm_run_1=fmri_glm.fit(fmri_imgs[0], design_matrices=design_matrices[0])
summary_statistics_run_1=fmri_glm_run_1.compute_contrast(
contrast_val,
output_type="all",
)
fmri_glm_run_2=fmri_glm.fit(fmri_imgs[1], design_matrices=design_matrices[1])
contrast_val=np.array([[-1, -1, 1, 1]])
summary_statistics_run_2=fmri_glm_run_2.compute_contrast(
contrast_val,
output_type="all",
)
# Run fixed effects analysiscontrast_imgs= [
summary_statistics_run_1["effect_size"],
summary_statistics_run_2["effect_size"],
]
variance_imgs= [
summary_statistics_run_1["effect_variance"],
summary_statistics_run_2["effect_variance"],
]
fixed_fx_contrast, fixed_fx_variance, fixed_fx_stat=compute_fixed_effects(
contrast_imgs,
variance_imgs,
data["mask"],
precision_weighted=True
)
print('This should be a 3D image and it is not')
print(fixed_fx_contrast.shape)
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Operating system
Operating system version
Mac 14.4.1 (23E224)
Python version
nilearn version
0.10.3
tested using code directly from github as well.
Expected behavior
I'm working off of the sample analysis here.
The only change I make is adding precision_weighted=True. I would expect fixed_fx_contrast to be a 3D image, but it is a 4D image where the 4th dimension = # of contrasts
I'm fairly certain the error is occurring here, where the contrast images are read in. For these data,
yields a numpy array with size (2, 1, 28008) and that second dimension of 1 is an issue. Then problems compound here
since
contrasts * weights
will be (2, 2, 28008) and so the sum won't work as expected.Hope that helps!
Jeanette
Current behavior & error messages
There are no errors, but the output data dimension is not correct. Code is provided that shows this.
Steps and code to reproduce bug
The text was updated successfully, but these errors were encountered: