-
Notifications
You must be signed in to change notification settings - Fork 370
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
Combine wrapped collection into GeoMesh data when get_array is called #1656
Conversation
When calling get_array with a QuadMesh object (from pcolormesh), the returned array only includes the unmasked data. This change fills in the masked data when present.
Looks like a good way to do it to me, @sdeastham! Can you add a test for this too? As simple as just putting Also, it looks like you've got one failing test currently. That is actually one that I just put in to make sure the cells were being wrapped properly. A good fix for that test would be to assert that the |
ping @sdeastham. I think all that is needed is updated tests here. |
@greglucas Got it. Sorry about the delay - I've never used pytest before and am having terrible trouble getting it to do anything except throw |
No worries at all. I think that error can be fixed by adding the pyargs argument to pytest: |
A new test has been added which verifies that the data returned by a pcolormesh get_array() command matches the data which was first given to the pcolormesh command, even if wrapping has occurred. One of the other tests (pcolormesh_diagonal_wrap) was also failing due to a faulty check, which has been removed.
@@ -321,6 +321,48 @@ def test_pcolormesh_global_with_wrap1(): | |||
ax.coastlines() | |||
ax.set_global() # make sure everything is visible | |||
|
|||
#@pytest.mark.natural_earth | |||
#@ImageTesting(['pcolormesh_global_wrap1'], tolerance=1.27) |
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.
E265 block comment should start with '# '
@@ -321,6 +321,48 @@ def test_pcolormesh_global_with_wrap1(): | |||
ax.coastlines() | |||
ax.set_global() # make sure everything is visible | |||
|
|||
#@pytest.mark.natural_earth | |||
#@ImageTesting(['pcolormesh_global_wrap1'], tolerance=1.27) | |||
def test_pcolormesh_get_array_with_mask(): |
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.
E302 expected 2 blank lines, found 1
assert c._wrapped_collection_fix is not None, \ | ||
'No pcolormesh wrapping was done when it should have been.' | ||
|
||
assert np.array_equal(data.ravel(),c.get_array()), \ |
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.
E231 missing whitespace after ','
ax.coastlines() | ||
ax.set_global() # make sure everything is visible | ||
|
||
assert getattr(c,"_wrapped_collection_fix",None) is None, \ |
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.
E231 missing whitespace after ','
assert getattr(c,"_wrapped_collection_fix",None) is None, \ | ||
'pcolormesh wrapping was done when it should not have been.' | ||
|
||
assert np.array_equal(data2.ravel(),c.get_array()), \ |
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.
E231 missing whitespace after ','
Stickler Bot identified six issues with the previous commit. Two were with commented-out code which was no longer necessary, one was because of a missing newline, and three were because of missing whitespace after commas. All have now been resolved.
@greglucas Thanks again for your patience! I've attempted to build some tests which test that |
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.
@sdeastham, glad you stuck with it and got all the tests working. This looks good to me! Thanks for contributing and hope to see you back again!
When calling get_array with a QuadMesh object (from pcolormesh), the returned array only included the unmasked data. This change fills in the masked data when present. This follows from the discussion in #1654.
Rationale
The
pcolormesh
set_array
method now correctly handles the wrapped, masked collections which can be generated when polygons cross the antimeridian. However, theget_array
method still only returns the data for the standard cells (those which did not cross the antimeridian). This caused unexpected behavior when running, for example:This would result in the same plot being shown, but now with the cells at 180E missing. This fix modifies the
get_array
call to compensate.Implications
Calling
get_array
now returns the complete array, with the masked elements filled in.