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

Pcolormesh update for interpolation with wrapped coordinates #1646

Merged
merged 4 commits into from
Sep 17, 2021

Conversation

greglucas
Copy link
Contributor

Fixes #1638

Rationale

The new shading keyword argument in MPL 3.3 causes an interpolation that creates new edges. With coordinates that could potentially be wrapped, as in map projections, this could cause new erroneous interpolation points to be inserted into the coordinates.

Implications

A big refactor of pcolormesh to avoid calling private MPL functions. We still have to use the private _coordinates Quadmesh attribute to get the coordinates, I couldn't find a way around that for now.

We also now calculate some edges in Cartopy, meaning more code to maintain.

args = (X, Y, args[2])
return args

def _wrap_quadmesh(self, collection, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks nice - is it clear that it covers changing the central longitude while preserving as much data as possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. central_longitude or any center point shouldn't come into play here. This "wrapping" function works on the transformed coordinates, identifying when those are large, so, just how wide the x_limits are to identify the masked areas.

For the other new function to do the edge interpolation:
We are identifying which direction the subtraction should be with the modulo arithmetic. i.e. is 1 -> 359 a difference of 358 or 2. Before it was 358 and a large jump, now we're saying it is 2. So again, no worries about central longitude. The central longitude is handled in the CRS/PROJ routines.

@greglucas
Copy link
Contributor Author

I think this is a pretty important PR to get in if anyone has the time for a review on it.

@mathause
Copy link
Contributor

This looks good and does solve my issue.

@greglucas greglucas force-pushed the pcolormesh_updates branch from 5d8644c to f70e61f Compare May 31, 2021 13:39
@greglucas
Copy link
Contributor Author

Yeah, I was hoping to get this in the last release :( The new shading will be the default in MPL 3.5, so it would be good to get a fix in for the next release. This needs a review from someone on @SciTools/cartopy-devs still.

@mathause
Copy link
Contributor

mathause commented Sep 8, 2021

Could you merge master/ rebase so I can test if #1845 would be solved by this?

@greglucas
Copy link
Contributor Author

@mathause, I just rebased this, but I think your issue was a separate bug!

lib/cartopy/mpl/geoaxes.py Outdated Show resolved Hide resolved
@greglucas
Copy link
Contributor Author

@QuLogic, I would also call this a critical update to get in before MPL 3.5. It removes the QuadMesh constructor calls, which were changed in 3.5 and throw a lot of warnings because of that. This defers all of that creation to MPL's pcolormesh instead.

@greglucas greglucas mentioned this pull request Sep 15, 2021
5 tasks
@greglucas greglucas requested a review from QuLogic September 16, 2021 19:08
lib/cartopy/mpl/geoaxes.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/geoaxes.py Outdated Show resolved Hide resolved
lib/cartopy/mpl/geoaxes.py Outdated Show resolved Hide resolved
This removes building the Quadmesh within Cartopy and pushes that up
to Matplotlib directly. It also adds the logic to wrap the Quadmesh
cells as a Cartopy specific private method that is called after
the Quadmesh is generated.
MPL 3.3 added a new interpolation routine to automatically create
edges for the grids when the input X/Y are the same shape as the
color data. This causes issues with map data due to the possiblity
of jumps in the coordinate arrays. This adds a modulo wrap to
the input arguments to do the interpolation in Cartopy before
sending the arguments on to Matplotlib.
Moves the list of wrappable projections up into the Projection classes
as a private attribute.
@greglucas greglucas force-pushed the pcolormesh_updates branch 2 times, most recently from cc0a3ef to 8d214a5 Compare September 17, 2021 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new shading default can mess up plots
4 participants