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
Conversation
👋 @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.
For new features:
For bug fixes:
We will review it as quick as possible, feel free to ping us with questions if needed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -102,6 +102,7 @@ | |||
threshold=2, | |||
symmetric_cbar=False, | |||
cmap="viridis", | |||
title="only plot positive values", |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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 ?
Strange because the codecov patch check says that every is fine. |
Yes, as usually, there are wrong messages when reading through the code... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx.
Changes proposed in this pull request: