-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
CenteredNorm changes #24132
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
Merged
Merged
CenteredNorm changes #24132
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
``CenteredNorm`` halfrange is not modified when vcenter changes | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Previously, the **halfrange** would expand in proportion to the | ||
amount that **vcenter** was moved away from either **vmin** or **vmax**. | ||
Now, the halfrange remains fixed when vcenter is changed, and **vmin** and | ||
**vmax** are updated based on the **vcenter** and **halfrange** values. | ||
|
||
For example, this is what the values were when changing vcenter previously. | ||
|
||
.. code-block:: | ||
|
||
norm = CenteredNorm(vcenter=0, halfrange=1) | ||
# Move vcenter up by one | ||
norm.vcenter = 1 | ||
# updates halfrange and vmax (vmin stays the same) | ||
# norm.halfrange == 2, vmin == -1, vmax == 3 | ||
|
||
and now, with that same example | ||
|
||
.. code-block:: | ||
|
||
norm = CenteredNorm(vcenter=0, halfrange=1) | ||
norm.vcenter = 1 | ||
# updates vmin and vmax (halfrange stays the same) | ||
# norm.halfrange == 1, vmin == 0, vmax == 2 | ||
|
||
The **halfrange** can be set manually or ``norm.autoscale()`` | ||
can be used to automatically set the limits after setting **vcenter**. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -485,11 +485,25 @@ def test_CenteredNorm(): | |
norm(np.linspace(-1.0, 0.0, 10)) | ||
assert norm.vmax == 1.0 | ||
assert norm.halfrange == 1.0 | ||
# set vcenter to 1, which should double halfrange | ||
# set vcenter to 1, which should move the center but leave the | ||
# halfrange unchanged | ||
Comment on lines
-488
to
+489
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I found odd. Updating vcenter should double the halfrange? Those seem like the two fixed quantities to me and one shouldn't update the other. I think this would better be handled by doing an autoscale after setting vcenter if you want this functionality. |
||
norm.vcenter = 1 | ||
assert norm.vmin == -1.0 | ||
assert norm.vmax == 3.0 | ||
assert norm.halfrange == 2.0 | ||
assert norm.vmin == 0 | ||
assert norm.vmax == 2 | ||
assert norm.halfrange == 1 | ||
|
||
# Check setting vmin directly updates the halfrange and vmax, but | ||
# leaves vcenter alone | ||
norm.vmin = -1 | ||
assert norm.halfrange == 2 | ||
assert norm.vmax == 3 | ||
assert norm.vcenter == 1 | ||
|
||
# also check vmax updates | ||
norm.vmax = 2 | ||
assert norm.halfrange == 1 | ||
assert norm.vmin == 0 | ||
assert norm.vcenter == 1 | ||
|
||
|
||
@pytest.mark.parametrize("vmin,vmax", [[-1, 2], [3, 1]]) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 have a slight confusion - what happens to half range when these are changed?
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.
halfrange is an
@property
which is dynamically computed from vmin/vmax and is not held in memory directly (and inversely sets vmin/vmax in the@halfrange.setter
)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.
halfrange is defined by vmin/vmax now, so the halfrange is shrunk/expanded accordingly. I added a couple of tests at the end to demonstrate what the expected behavior of this is. (vcenter constant, halfrange changed)
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.
thanks I missed that part of 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.
ok, so just to confirm, basically calling self.halfrange(val) updates the min and max, so that then
self.halfrange = self.halfrange()
which is why there's noself._halfrange
- sorry I'm tiredThere 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.
yes
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.
thanks!
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.
(though caveat that it is a property, so the syntax is
self.halfrange = self.halfrange
(which looks odd, but that is why there is a comment) andself.halfrange = val
rather than the parentheses version)