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

Copy input image header to the output by default #4397

Merged
merged 37 commits into from
Jun 4, 2024

Conversation

man-shu
Copy link
Contributor

@man-shu man-shu commented Apr 24, 2024

The following functions under nilearn.image have been updated to copy image header by default

Copy link
Contributor

👋 @man-shu 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.

Copy link

codecov bot commented Apr 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.99%. Comparing base (abb80ff) to head (9132c6e).
Report is 79 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4397      +/-   ##
==========================================
+ Coverage   91.85%   91.99%   +0.13%     
==========================================
  Files         144      145       +1     
  Lines       16419    16709     +290     
  Branches     3434     3551     +117     
==========================================
+ Hits        15082    15371     +289     
+ Misses        792      767      -25     
- Partials      545      571      +26     
Flag Coverage Δ
macos-latest_3.11_test_plotting 91.77% <100.00%> (-0.09%) ⬇️
ubuntu-latest_3.10_test_plotting ?
ubuntu-latest_3.8_test_min 68.75% <78.04%> (?)
ubuntu-latest_3.8_test_plot_min 91.44% <100.00%> (?)
ubuntu-latest_3.8_test_plotting 91.73% <100.00%> (?)
ubuntu-latest_3.9_test_plotting 91.74% <100.00%> (?)
windows-latest_3.10_test_plotting 91.76% <100.00%> (?)
windows-latest_3.11_test_plotting 91.76% <100.00%> (?)
windows-latest_3.8_test_plotting 91.72% <100.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@man-shu
Copy link
Contributor Author

man-shu commented Apr 24, 2024

The fix was indeed the one proposed in #4393.

So now the default behavior for all functions under nilearn.image module (except math_img) is to directly copy the input image's header info to the output image in whichever fields possible and update the rest, via new_img_like.

As for math_img, it was the most peculiar case and I think the choices made in #4337 should stay in place.

@man-shu man-shu marked this pull request as draft April 24, 2024 13:06
@man-shu man-shu marked this pull request as ready for review April 24, 2024 19:23
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.

The change LGTM but you must at least make it visible.
I'm wondering whether we should go through deprecation cycles...

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.

@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Apr 25, 2024

I'm wondering whether we should go through deprecation cycles...

yeah I am wondering about this as well, because some of this may induce behavior changes in the code.

unless we decide that the old behavior was a bug and that this is a bug fix

@emdupre
Copy link
Member

emdupre commented Apr 30, 2024

Personally I would be +1 deprecation cycles ! This is a noticeable enough change (and I don't know that the before was wrong ) that I think we should alert users.

@Remi-Gau
Copy link
Collaborator

Personally I would be +1 deprecation cycles ! This is a noticeable enough change (and I don't know that the previous before was wrong ) that I think we should alert users.

Good with me to err on the side of caution and let our users know.

@man-shu
Copy link
Contributor Author

man-shu commented May 2, 2024

Yes, I also agree with going through the deprecation cycles and letting people know.

But my feeling is that it should not affect existing internal nilearn routines because, as far as I know, we don't ever directly use the header information in any of the workflows. Some bids-dependent functionalities need TR info, but that is extracted from JSON sidecars.

However, some external software probably does use the headers.

nilearn/_utils/helpers.py Show resolved Hide resolved
nilearn/image/tests/conftest.py Show resolved Hide resolved
@man-shu man-shu requested a review from Remi-Gau May 31, 2024 12:35
@man-shu man-shu marked this pull request as ready for review May 31, 2024 12:38
nilearn/image/image.py Outdated Show resolved Hide resolved
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.

Can you add a test to make sure that the deprecation warning is thrown properly when users pass the value False?

@man-shu
Copy link
Contributor Author

man-shu commented May 31, 2024

Re: Setting copy_header=True to avoid warnings in tests and examples:

There are quite a few tests that throw this warning:
Screenshot 2024-05-31 at 5 26 30 PM
Potentially, several examples, too.

Will update those now.

@man-shu man-shu marked this pull request as draft May 31, 2024 16:24
assert result.header["cal_max"] == 1


@pytest.mark.parametrize(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Remi-Gau, here I test the warning being thrown for copy_header=False (for all image.py functions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just so you dont have to review everything again

)


@pytest.mark.parametrize(
Copy link
Contributor Author

@man-shu man-shu Jun 3, 2024

Choose a reason for hiding this comment

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

and here, the test for warning for resampling.py functions

@man-shu man-shu marked this pull request as ready for review June 3, 2024 13:33
@man-shu man-shu requested a review from Remi-Gau June 3, 2024 13:33
@man-shu man-shu linked an issue Jun 3, 2024 that may be closed by this pull request
@man-shu
Copy link
Contributor Author

man-shu commented Jun 4, 2024

Now we are ready for final reviews @Remi-Gau and @bthirion

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.

Let's see what CI says but it looks good to me.

@Remi-Gau
Copy link
Collaborator

Remi-Gau commented Jun 4, 2024

Everything looks green. You can merge at will @man-shu

@man-shu man-shu merged commit 1d0cab6 into nilearn:main Jun 4, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants