-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Added FuncNorm and PiecewiseNorm classes in colors #7294
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
Changes from 1 commit
2d90c5a
57aad3d
f818aff
ffe1b9d
1d22b90
b5801ea
e93d82d
3749b0a
de62491
d148756
5373a98
13edeab
21d5cd0
d359a4e
4622829
30ff404
df835cb
dfaa0f8
a386395
b9dafb0
d10be73
c85a14c
7597ddd
7fce503
bcd7dd0
a71e1e9
33f57d1
9687173
46395aa
63dab61
8abf2c2
b4ecdb2
42007ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,24 @@ def test_LogNorm(): | |
ln = mcolors.LogNorm(clip=True, vmax=5) | ||
assert_array_equal(ln([1, 6]), [0, 1.0]) | ||
|
||
def test_FuncNorm(): | ||
# Testing limits using a string | ||
norm = mcolors.FuncNorm(f='log', vmin=0.01, vmax=2) | ||
assert_array_equal(norm([0.01, 2]), [0, 1.0]) | ||
|
||
# Testing limits using a string | ||
norm = mcolors.FuncNorm(f=lambda x: np.log10(x), | ||
finv=lambda x: 10.**(x), vmin=0.01, vmax=2) | ||
assert_array_equal(norm([0.01, 2]), [0, 1.0]) | ||
|
||
# Testing limits without vmin, vmax | ||
norm = mcolors.FuncNorm(f='log') | ||
assert_array_equal(norm([0.01, 2]), [0, 1.0]) | ||
|
||
# Testing intermediate values | ||
norm = mcolors.FuncNorm(f='log') | ||
assert_array_almost_equal(norm([0.01, 0.5, 2]), [0, 0.73835195870437, 1.0]) | ||
|
||
|
||
def test_PowerNorm(): | ||
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. :) that you broke up the above tests, wanna see these tests broken up too. 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. What do you mean by "these"? I guess for now I would only like to change the tests related to the new functionality. Maybe we can have a separate PR later for refactoring all tests test_colors.py. 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. Oh, sorry, didn't realize PowerNorm wasn't one of yours. 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. Haha, I do not blame you, it could perfectly be. In fact I have been tempted to re-implement it inheriting from PiecewiseNorm (It would not inherit from FuncNorm due to a difference in the normalization policy that @anntzer mentioned. (FuncNorm does the "LogNorm" way, because it is a rawer function, and PiecewiseNorm does it the "PowerNorm" way, because it really wants to ensure that the normalization function for each interval is bounded). Again, my view on this would be to first merge the new classes, and give it a round of tests, and then maybe consider re-implementing other classes to make them inherit from these. 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. That's fine by me. |
||
a = np.array([0, 0.5, 1, 1.5], dtype=float) | ||
|
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.
These should probably either be broken into separate tests or parameterized cause if one of the tests fails, it would likely require going back to the source to figure which subcategories failed.
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 guess the line of the assert is always shown, but in any case, could you show me an example of parameterized, please?
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.
But assert doesn't spit error messages, so you're kind of left guessing what specific thing that assert was trying to test.
http://doc.pytest.org/en/latest/parametrize.html and test_category.py has lots of mpl examples.
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 now included a test class for each of the implemented classes, and each assert in a separate name method. It also includes a parametric test to replace the loop I had before.
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.
However, the parametric test is not working, for some reason. Do you know, if apart from using the decorator, I have to do anything else? All other tests in the file are single method very basic tests (which is why I did it like that originally)
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 @QuLogic, it should build now!