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] Fix color bar handling with color map with only 1 level #4256

Merged
merged 8 commits into from Feb 27, 2024

Conversation

Remi-Gau
Copy link
Collaborator

@Remi-Gau Remi-Gau commented Feb 2, 2024

Changes proposed in this pull request:

  • add regression test
  • add code to fix

Copy link
Contributor

github-actions bot commented Feb 2, 2024

👋 @Remi-Gau 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 Feb 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.08%. Comparing base (abb80ff) to head (0ad60c7).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4256      +/-   ##
==========================================
+ Coverage   91.85%   92.08%   +0.22%     
==========================================
  Files         144      144              
  Lines       16419    16428       +9     
  Branches     3434     3438       +4     
==========================================
+ Hits        15082    15127      +45     
+ Misses        792      760      -32     
+ Partials      545      541       -4     
Flag Coverage Δ
macos-latest_3.10_test_plotting 91.87% <100.00%> (?)
macos-latest_3.11_test_plotting ?
macos-latest_3.12_test_plotting 91.87% <100.00%> (?)
macos-latest_3.8_test_plotting 91.83% <100.00%> (?)
macos-latest_3.9_test_plotting 91.84% <100.00%> (?)
ubuntu-latest_3.10_test_plotting 91.87% <100.00%> (+0.01%) ⬆️
ubuntu-latest_3.11_test_plotting 91.87% <100.00%> (?)
ubuntu-latest_3.12_test_plotting 91.87% <100.00%> (?)
ubuntu-latest_3.12_test_pre 91.87% <100.00%> (?)
ubuntu-latest_3.8_test_min 68.90% <0.00%> (?)
ubuntu-latest_3.8_test_plot_min 91.58% <100.00%> (?)
ubuntu-latest_3.8_test_plotting 91.83% <100.00%> (?)
ubuntu-latest_3.9_test_plotting 91.84% <100.00%> (?)
windows-latest_3.10_test_plotting 91.84% <100.00%> (?)
windows-latest_3.11_test_plotting 91.84% <100.00%> (?)
windows-latest_3.12_test_plotting 91.84% <100.00%> (?)
windows-latest_3.8_test_plotting 91.81% <100.00%> (?)
windows-latest_3.9_test_plotting 91.81% <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.

@@ -102,6 +102,7 @@
threshold=2,
symmetric_cbar=False,
cmap="viridis",
title="only plot positive values",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

those plots were added in the #3993
just adding some title so the figures are easier to identify when running the example dumps > 20 figures on you

Comment on lines 398 to 406
if threshold is not None:
data = safe_get_data(img, ensure_finite=True)
if threshold == 0:
data = np.ma.masked_equal(data, 0, copy=False)
else:
data = np.ma.masked_inside(
data, -threshold, threshold, copy=False
)
img = new_img_like(img, data, img.affine)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@michellewang do you remember why this got removed in #3993 ?

I can see you refactored part of it into a new method used later in the code but I cannot quite see if readding this code now will interfere with something.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Remi-Gau I tried plotting some things and I don't see anything obviously wrong. Since the lines you added back only address the threshold part of the masking (not the vmin/vmax parts of the _threshold function I added), I don't think it would break anything. However, it might be confusing/not optimal to have 2 places in a function where thresholding/masking is done? I checked and the reason why I moved the thresholding further down in that function is because, for glass brain plotting with custom vmin, the thresholding needed to be done after we take the absolute value of the data if plot_abs is True (otherwise we incorrectly lose whatever is lower than vmin), but for some reason the absolute value is only taken in GlassBrainAxes.transform_to_2d, which gives the 2D views to be plotted in each panel. It doesn't look like there is currently an easy way to take the absolute value of the whole 3D data (possibly because plot_abs is only for glass brain plots?), but maybe we can add a plot_abs parameter to the slicer objects and do the absolute value handling inside _map_show?

Anyway if this needs to be fixed as soon as possible I think your fix should be fine, but in the future we might want to consider not having the double thresholding/masking part.

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right. Passing the argument below sounds like the best fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd say that we merge this as is and do the refactoring suggested by @michellewang in another PR to keep things easier to review

@Remi-Gau Remi-Gau marked this pull request as ready for review February 2, 2024 13:27
@Remi-Gau Remi-Gau changed the title [WIP][FIX] Fix color bar handling with color map with only 1 level [FIX] Fix color bar handling with color map with only 1 level Feb 2, 2024
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.

some lines are not covered by tests ?

@Remi-Gau
Copy link
Collaborator Author

Remi-Gau commented Feb 2, 2024

some lines are not covered by tests ?

Strange because the codecov patch check says that every is fine.

@Remi-Gau
Copy link
Collaborator Author

Remi-Gau commented Feb 2, 2024

@bthirion
Copy link
Member

bthirion commented Feb 2, 2024

some lines are not covered by tests ?

Strange because the codecov patch check says that every is fine.

Yes, as usually, there are wrong messages when reading through the code...

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.

@Remi-Gau Remi-Gau merged commit 35a4d8f into nilearn:main Feb 27, 2024
33 checks passed
@Remi-Gau Remi-Gau deleted the 4255 branch February 27, 2024 10:17
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.

[BUG] plot_roi cannot handle cmap with only 1 level
3 participants