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

[ENH] Adapt FirstLevelModel to work with surface data objects from new API #4126

Merged
merged 46 commits into from
Jun 4, 2024
Merged
Changes from 3 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1b785fa
Add masker structure
Nov 30, 2023
5459d6b
Define surfaceimage
Nov 30, 2023
006e258
Update
Nov 30, 2023
c4ddf21
Update docstring
Dec 6, 2023
0da09ae
Skip niimg checks if surface
Dec 6, 2023
b5a4de7
Fix code breaking tests
Dec 7, 2023
5a82233
Merge branch 'main' into flm_surfaceimage
Dec 7, 2023
4a1c25a
Add some tests
Dec 7, 2023
415fa4f
Add more tests
Dec 7, 2023
3928ece
Refactor tests
Dec 7, 2023
a51abfc
Replace parameters for fitted surface masker
Dec 8, 2023
66def1e
Add test
Dec 8, 2023
93230df
Remove breakpoint
Dec 8, 2023
8dbdd1d
Adapt compute contrast
Dec 8, 2023
7b5b130
Handle one hemisphere
Dec 11, 2023
429442d
Merge branch 'main' into flm_surfaceimage
Jan 8, 2024
99bf608
Refactor
Jan 8, 2024
50f780b
Resolve surface case for default mask
Jan 8, 2024
3028d55
Fix doctsring
Jan 8, 2024
a1f2112
Added GLM example
bthirion Jan 5, 2024
1698323
Remove default arg
Jan 9, 2024
f01b667
Fix conflict
Jan 9, 2024
8167603
Merge branch 'main' into flm_surfaceimage
ymzayek Jan 9, 2024
bdf2f23
Formatting
Jan 9, 2024
5f80c63
Working report with no plots
Jan 9, 2024
ddc8ef1
Allow black on example
Jan 10, 2024
7d65d14
Revert "Working report with no plots"
Jan 11, 2024
4d2e782
NotImplementedError for reports
Jan 11, 2024
5c6f759
Move test
Jan 11, 2024
bcac629
Add test
Jan 12, 2024
3c7ae7f
Clarify doctsring
Jan 16, 2024
04a14cc
Refactor mask application
Jan 16, 2024
e08831d
Method name and docstring
Jan 16, 2024
6126ed8
Merge branch 'main' into flm_surfaceimage
Remi-Gau Jan 17, 2024
9f4d8d0
extract example as experimental
Remi-Gau Jan 26, 2024
6ba25f8
move example
Remi-Gau Jan 26, 2024
455887c
update bids example
Remi-Gau Jan 26, 2024
85d6e8a
clean up
Remi-Gau Jan 26, 2024
a5de9b3
Merge remote-tracking branch 'upstream/main' into pr/ymzayek/4126
Remi-Gau Jan 26, 2024
661843e
adapt fetcher
Remi-Gau Jan 26, 2024
a0138f0
use confounds
Remi-Gau Jan 26, 2024
f203e2c
Merge branch 'main' into flm_surfaceimage
Remi-Gau May 31, 2024
e259384
Merge branch 'main' into flm_surfaceimage
Remi-Gau Jun 3, 2024
a99bf90
fix test
Remi-Gau Jun 3, 2024
079bb38
fix examples
Remi-Gau Jun 3, 2024
2c0c193
refactor
Remi-Gau Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 42 additions & 5 deletions nilearn/glm/first_level/first_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from nilearn._utils import fill_doc, stringify_path
from nilearn._utils.niimg_conversions import check_niimg
from nilearn._utils.param_validation import check_run_sample_masks
from nilearn.experimental.surface import SurfaceImage, SurfaceMasker
from nilearn.glm._base import BaseGLM
from nilearn.glm._utils import (
_check_events_file_uses_tab_separators,
Expand Down Expand Up @@ -576,11 +577,27 @@
# Learn the mask
if self.mask_img is False:
# We create a dummy mask to preserve functionality of api
ref_img = check_niimg(run_imgs[0])
self.mask_img = Nifti1Image(
np.ones(ref_img.shape[:3]), ref_img.affine
)
if not isinstance(self.mask_img, NiftiMasker):
if isinstance(run_imgs[0], SurfaceImage):
left, right = run_imgs[0].mesh.keys()
ymzayek marked this conversation as resolved.
Show resolved Hide resolved
self.mask_img = SurfaceImage(

Check warning on line 582 in nilearn/glm/first_level/first_level.py

View check run for this annotation

Codecov / codecov/patch

nilearn/glm/first_level/first_level.py#L581-L582

Added lines #L581 - L582 were not covered by tests
mesh=run_imgs[0].mesh,
data={
"left_hemisphere": np.ones(
run_imgs[0].data[left].shape
ymzayek marked this conversation as resolved.
Show resolved Hide resolved
),
"right_hemisphere": np.ones(
run_imgs[0].data[right].shape
ymzayek marked this conversation as resolved.
Show resolved Hide resolved
),
},
)
else:
ref_img = check_niimg(run_imgs[0])
self.mask_img = Nifti1Image(
np.ones(ref_img.shape[:3]), ref_img.affine
)
if not isinstance(
self.mask_img, (NiftiMasker, SurfaceMasker, SurfaceImage)
):
self.masker_ = NiftiMasker(
mask_img=self.mask_img,
smoothing_fwhm=self.smoothing_fwhm,
Expand All @@ -594,6 +611,25 @@
memory_level=self.memory_level,
)
self.masker_.fit(run_imgs[0])
elif isinstance(self.mask_img, (SurfaceMasker, SurfaceImage)):
if isinstance(self.mask_img, SurfaceImage):
self.masker_ = SurfaceMasker(

Check warning on line 616 in nilearn/glm/first_level/first_level.py

View check run for this annotation

Codecov / codecov/patch

nilearn/glm/first_level/first_level.py#L616

Added line #L616 was not covered by tests
mask_img=self.mask_img,
smoothing_fwhm=self.smoothing_fwhm,
target_affine=self.target_affine,
standardize=self.standardize,
t_r=self.t_r,
memory=self.memory,
memory_level=self.memory_level,
)
self.masker_.fit(run_imgs[0])

Check warning on line 625 in nilearn/glm/first_level/first_level.py

View check run for this annotation

Codecov / codecov/patch

nilearn/glm/first_level/first_level.py#L625

Added line #L625 was not covered by tests
else:
self.mask_img._check_fitted()

Check warning on line 627 in nilearn/glm/first_level/first_level.py

View check run for this annotation

Codecov / codecov/patch

nilearn/glm/first_level/first_level.py#L627

Added line #L627 was not covered by tests
if self.mask_img.mask_img_ is None and self.masker_ is None:
# TODO check parameters and override with flm params
self.masker_.fit(run_imgs[0])

Check warning on line 630 in nilearn/glm/first_level/first_level.py

View check run for this annotation

Codecov / codecov/patch

nilearn/glm/first_level/first_level.py#L630

Added line #L630 was not covered by tests
else:
self.masker_ = self.mask_img

Check warning on line 632 in nilearn/glm/first_level/first_level.py

View check run for this annotation

Codecov / codecov/patch

nilearn/glm/first_level/first_level.py#L632

Added line #L632 was not covered by tests
else:
# Make sure masker has been fitted otherwise no attribute mask_img_
self.mask_img._check_fitted()
Expand Down Expand Up @@ -642,6 +678,7 @@
)

# Build the experimental design for the glm
# TODO: adapt check and get_data
run_img = check_niimg(run_img, ensure_ndim=4)
if design_matrices is None:
n_scans = get_data(run_img).shape[3]
Expand Down