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

[FIX/ENH] Improve generate_report method to work with fit_transform for the maskers #3897

Merged
merged 8 commits into from Aug 28, 2023

Conversation

ymzayek
Copy link
Member

@ymzayek ymzayek commented Aug 7, 2023

Changes proposed in this pull request:

  • Pass image data to fit() in fit_transform()
  • Use better colormap or instead allow users to pass colormap
  • Improve docstrings to explain image data being passed to reporter
  • Store 1 time point for reporting using 4D images (will handle in a separate PR)

@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2023

👋 @ymzayek Thanks for creating a PR!

Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft.

Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.

  • PR has an interpretable title.
  • PR links to Github issue with mention Closes #XXXX (see our documentation on PR structure)
  • Code is PEP8-compliant (see our documentation on coding style)
  • Changelog or what's new entry in doc/changes/latest.rst (see our documentation on PR structure)

For new features:

  • There is at least one unit test per new function / class (see our documentation on testing)
  • The new feature is demoed in at least one relevant example.

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

We will review it as quick as possible, feel free to ping us with questions if needed.

@ymzayek
Copy link
Member Author

ymzayek commented Aug 7, 2023

Now

data = masker.fit_transform(img)
report = masker.generate_report()

works the same as:

masker.fit(img)
report = masker.generate_report()

to generate:
Screenshot from 2023-08-18 11-56-13

I changed the colormap but maybe there are suggestions for something better??

To fully reproduce:
from nilearn.maskers import NiftiLabelsMasker
from nilearn import datasets

atlas = datasets.fetch_atlas_harvard_oxford("cort-maxprob-thr25-2mm")
atlas_filename, labels = atlas.maps, atlas.labels

dataset = datasets.fetch_development_fmri(n_subjects=1)
fmri_filename = dataset.func[0]
#%%
masker = NiftiLabelsMasker(labels_img=atlas_filename, standardize=True)
masker.fit(fmri_filename)

#%%
masker = NiftiLabelsMasker(labels_img=atlas_filename, standardize=True)
masker.fit_transform(fmri_filename)

@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Merging #3897 (7f6e11c) into main (457c79e) will increase coverage by 0.00%.
Report is 1 commits behind head on main.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #3897   +/-   ##
=======================================
  Coverage   91.76%   91.77%           
=======================================
  Files         134      134           
  Lines       15747    15750    +3     
  Branches     3283     3283           
=======================================
+ Hits        14451    14454    +3     
  Misses        752      752           
  Partials      544      544           
Flag Coverage Δ
macos-latest_3.10 91.68% <100.00%> (?)
macos-latest_3.11 91.68% <100.00%> (?)
macos-latest_3.8 91.64% <100.00%> (?)
macos-latest_3.9 91.64% <100.00%> (?)
ubuntu-latest_3.10 91.68% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.11 91.68% <100.00%> (+<0.01%) ⬆️
ubuntu-latest_3.8 91.64% <100.00%> (?)
ubuntu-latest_3.9 91.64% <100.00%> (+<0.01%) ⬆️
windows-latest_3.10 91.62% <100.00%> (?)
windows-latest_3.11 91.62% <100.00%> (+<0.01%) ⬆️
windows-latest_3.8 91.59% <100.00%> (+<0.01%) ⬆️
windows-latest_3.9 91.59% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
nilearn/maskers/nifti_labels_masker.py 90.00% <100.00%> (+0.05%) ⬆️
nilearn/maskers/nifti_maps_masker.py 93.92% <100.00%> (+0.03%) ⬆️
nilearn/maskers/nifti_masker.py 86.89% <100.00%> (+0.09%) ⬆️
nilearn/maskers/nifti_spheres_masker.py 93.15% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ymzayek
Copy link
Member Author

ymzayek commented Aug 9, 2023

Storing one time point for the report seems a bit more involved than I thought given the failures here: https://github.com/nilearn/nilearn/actions/runs/5787425257 so I will handle it in a separate follow-up PR

@ymzayek ymzayek added this to the release 0.10.2 milestone Aug 21, 2023
@bthirion
Copy link
Member

The red background is not great for the atlas display. I'll try to get a neutral one.

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

@ymzayek
Copy link
Member Author

ymzayek commented Aug 24, 2023

I changed it back to the default colormap but now allowing the user to pass a custom colormap as a **kwarg that is passed to plot_img.

For reference, the default colormap looks like this in my example (same as in the example gallery)
image

But I guess it is suboptimal for the example shown in the issue #3709

Copy link
Member

@bthirion bthirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx.

@ymzayek ymzayek requested a review from Remi-Gau August 25, 2023 07:58
Copy link
Collaborator

@Remi-Gau Remi-Gau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good with me!

@Remi-Gau Remi-Gau merged commit 3297258 into nilearn:main Aug 28, 2023
29 checks passed
@ymzayek ymzayek deleted the generate_report_behavior branch August 29, 2023 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants