Open htonchia opened 4 years ago
Hi there,
Is there a workaround for this as yet? I'm trying to plot contours on top of a `pcolormesh' instance with cartopy but I consistently get the wrapping issue. The ocean field I am trying to plot is regional, not global if that makes any difference?
Thanks!
Description
Curvilinear grids are grids indexed by two dummy variables X and Y that are not defined in projection coordinates. The coordinates of the vertices can be given in latitudes longitudes but are not rectilinear in any projection. In some case, rectilinear data in a projection for which the parameters are missing and for which the vertices coordinates are known only in longitudes and latitudes can be handled as curvilinear grids. Currently Matplotlib and cartopy don't really handle the wrapping, or crossing of the projection boundary. There is (or will) be an exception. pcolormesh has a patch which (when updated #1418 and #1420) manages the overlapping cells produced by a wrapping grid.
The next figure shows a curvilinear dataset plotted with Matplolib. The first scatter plot shows the data and a third of the vertices. The second scatter plot shows the same data and vertices on a radial plot. The Atlantic Ocean is in the lower half center, with Groenland above, Europe on the right and North America on the right.
The contour, contourf, pcolor and pcolormesh plots are traversed by overlapping cells and contours.
When we plot the same data with cartopy in PlateCarree and Stereographic projections, we discover that the pcolormesh plots are fine while the pcolor, contour and contourf are traversed by overlapping data. The fine pcolormesh plots are due to the patch managing the overlapping data.
PLEASE NOTE, that this has been plotted with a geoaxes.py updated with #1418 and #1420 PRs. Without this update, the pcolormesh plots may not be so fine.
SUGGESTION I suggest to create a Geodetic_curvilinear CRS to handle those data. I suggest to create a function to handle overlaps in data in that Geodetic_curvilinear CRS, the same way it is handled in pcolormesh. When we get that Geodetic_curvilinear CRS in pcolor, contour or contourf, instead of rejecting it as it is not a projection, we would project the data in the axe.projection and handle the overlaps by masking the corresponding data vertices before sending the projected coordinates and the masked data to the Matplotib pcolor, contour or contourf function.
This should also fix issues #1400 #1151 (contourf case) #1225 #1076 and #522. SOLUTION BY PREPROCESSING THE DATA The overlaps cells can be masked before plotting the data with cartopy with pcolor, contour or contourf (even pcolormesh).
The result with the dataset above is the following:
The results with two of the datasets from issue #522 are:
Code to reproduce
CODE WITH THE PREPROCESSING FIX FUNCTION z_masked_overlap
Traceback
Full environment definition
### Operating system ### Cartopy version ### conda list ``` ``` ### pip list ``` ```